blob: af6b5d5ff4d8b61037da08eff75f247d20c2ca83 [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
chen xuc93cc282018-11-04 17:17:00 -08002134 public int getSubscriptionPreciseCarrierId(int subId) {
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final Phone phone = getPhone(subId);
2138 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2139 : phone.getPreciseCarrierId();
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
2142 }
2143 }
2144
2145 @Override
2146 public String getSubscriptionPreciseCarrierName(int subId) {
2147 final long identity = Binder.clearCallingIdentity();
2148 try {
2149 final Phone phone = getPhone(subId);
2150 return phone == null ? null : phone.getPreciseCarrierName();
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
2153 }
2154 }
2155
chen xu02581692018-11-11 19:03:44 -08002156 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002157 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2158 if (!isSubscriptionMccMnc) {
2159 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2160 }
chen xu02581692018-11-11 19:03:44 -08002161 final Phone phone = PhoneFactory.getPhone(slotIndex);
2162 if (phone == null) {
2163 return TelephonyManager.UNKNOWN_CARRIER_ID;
2164 }
2165 final long identity = Binder.clearCallingIdentity();
2166 try {
2167 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2168 } finally {
2169 Binder.restoreCallingIdentity(identity);
2170 }
2171 }
2172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 //
2174 // Internal helper methods.
2175 //
2176
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002177 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2179 *
2180 * @throws SecurityException if the caller does not have the required permission
2181 */
2182 private void enforceModifyPermission() {
2183 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2184 }
2185
2186 /**
2187 * Make sure the caller has the CALL_PHONE permission.
2188 *
2189 * @throws SecurityException if the caller does not have the required permission
2190 */
2191 private void enforceCallPermission() {
2192 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2193 }
2194
Stuart Scott8eef64f2015-04-08 15:13:54 -07002195 private void enforceConnectivityInternalPermission() {
2196 mApp.enforceCallingOrSelfPermission(
2197 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2198 "ConnectivityService");
2199 }
2200
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 private String createTelUrl(String number) {
2202 if (TextUtils.isEmpty(number)) {
2203 return null;
2204 }
2205
Jake Hambye994d462014-02-03 13:10:13 -08002206 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 }
2208
Ihab Awadf9e92732013-12-05 18:02:52 -08002209 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2211 }
2212
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002213 private static void logv(String msg) {
2214 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2215 }
2216
Ihab Awadf9e92732013-12-05 18:02:52 -08002217 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2219 }
2220
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002221 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002223 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002224 }
2225
Sanket Padawe356d7632015-06-22 14:03:32 -07002226 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002227 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 final Phone phone = PhoneFactory.getPhone(slotIndex);
2231 if (phone == null) {
2232 return PhoneConstants.PHONE_TYPE_NONE;
2233 } else {
2234 return phone.getPhoneType();
2235 }
2236 } finally {
2237 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
2241 /**
2242 * Returns the CDMA ERI icon index to display
2243 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002244 @Override
2245 public int getCdmaEriIconIndex(String callingPackage) {
2246 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002247 }
2248
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002250 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002252 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002253 return -1;
2254 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002255
2256 final long identity = Binder.clearCallingIdentity();
2257 try {
2258 final Phone phone = getPhone(subId);
2259 if (phone != null) {
2260 return phone.getCdmaEriIconIndex();
2261 } else {
2262 return -1;
2263 }
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
2269 /**
2270 * Returns the CDMA ERI icon mode,
2271 * 0 - ON
2272 * 1 - FLASHING
2273 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002274 @Override
2275 public int getCdmaEriIconMode(String callingPackage) {
2276 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002277 }
2278
Sanket Padawe356d7632015-06-22 14:03:32 -07002279 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002280 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002282 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002283 return -1;
2284 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002285
2286 final long identity = Binder.clearCallingIdentity();
2287 try {
2288 final Phone phone = getPhone(subId);
2289 if (phone != null) {
2290 return phone.getCdmaEriIconMode();
2291 } else {
2292 return -1;
2293 }
2294 } finally {
2295 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
2299 /**
2300 * Returns the CDMA ERI text,
2301 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002302 @Override
2303 public String getCdmaEriText(String callingPackage) {
2304 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002305 }
2306
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002308 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002310 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002311 return null;
2312 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002313
2314 final long identity = Binder.clearCallingIdentity();
2315 try {
2316 final Phone phone = getPhone(subId);
2317 if (phone != null) {
2318 return phone.getCdmaEriText();
2319 } else {
2320 return null;
2321 }
2322 } finally {
2323 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002324 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 }
2326
2327 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002328 * Returns the CDMA MDN.
2329 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002330 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002331 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2333 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002334
2335 final long identity = Binder.clearCallingIdentity();
2336 try {
2337 final Phone phone = getPhone(subId);
2338 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2339 return phone.getLine1Number();
2340 } else {
2341 return null;
2342 }
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002345 }
2346 }
2347
2348 /**
2349 * Returns the CDMA MIN.
2350 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002351 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002352 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2354 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002355
2356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 final Phone phone = getPhone(subId);
2359 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2360 return phone.getCdmaMin();
2361 } else {
2362 return null;
2363 }
2364 } finally {
2365 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002366 }
2367 }
2368
2369 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 * Returns true if CDMA provisioning needs to run.
2371 */
2372 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002373 final long identity = Binder.clearCallingIdentity();
2374 try {
2375 return mPhone.needsOtaServiceProvisioning();
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
2378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 }
2380
2381 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002382 * Sets the voice mail number of a given subId.
2383 */
2384 @Override
2385 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002386 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2391 new Pair<String, String>(alphaTag, number), new Integer(subId));
2392 return success;
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
2395 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002396 }
2397
Ta-wei Yen87c49842016-05-13 21:19:52 -07002398 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002399 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2400 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2401 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2402 if (!TextUtils.equals(callingPackage, systemDialer)) {
2403 throw new SecurityException("caller must be system dialer");
2404 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002405
2406 final long identity = Binder.clearCallingIdentity();
2407 try {
2408 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2409 if (phoneAccountHandle == null) {
2410 return null;
2411 }
2412 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002415 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002416 }
2417
2418 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002419 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002420 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002422 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002423 return null;
2424 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002425
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 return RemoteVvmTaskManager
2429 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2430 } finally {
2431 Binder.restoreCallingIdentity(identity);
2432 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002433 }
2434
2435 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002436 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2437 VisualVoicemailSmsFilterSettings settings) {
2438 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002439
2440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2443 mPhone.getContext(), callingPackage, subId, settings);
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
2446 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002447 }
2448
2449 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002450 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2456 mPhone.getContext(), callingPackage, subId);
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
2459 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002460 }
2461
2462 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002463 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2464 String callingPackage, int subId) {
2465 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002466
2467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2470 mPhone.getContext(), callingPackage, subId);
2471 } finally {
2472 Binder.restoreCallingIdentity(identity);
2473 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002474 }
2475
2476 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002477 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002478 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002479
2480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2483 mPhone.getContext(), subId);
2484 } finally {
2485 Binder.restoreCallingIdentity(identity);
2486 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002487 }
2488
2489 @Override
2490 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2491 String number, int port, String text, PendingIntent sentIntent) {
2492 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002493 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002494 enforceSendSmsPermission();
2495 // Make the calls as the phone process.
2496 final long identity = Binder.clearCallingIdentity();
2497 try {
2498 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2499 if (port == 0) {
2500 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2501 sentIntent, null, false);
2502 } else {
2503 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2504 smsManager.sendDataMessageWithSelfPermissions(number, null,
2505 (short) port, data, sentIntent, null);
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
2509 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002510 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002511 /**
fionaxu0152e512016-11-14 13:36:14 -08002512 * Sets the voice activation state of a given subId.
2513 */
2514 @Override
2515 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2517 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002518
2519 final long identity = Binder.clearCallingIdentity();
2520 try {
2521 final Phone phone = getPhone(subId);
2522 if (phone != null) {
2523 phone.setVoiceActivationState(activationState);
2524 } else {
2525 loge("setVoiceActivationState fails with invalid subId: " + subId);
2526 }
2527 } finally {
2528 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002529 }
2530 }
2531
2532 /**
2533 * Sets the data activation state of a given subId.
2534 */
2535 @Override
2536 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2538 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002539
2540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 final Phone phone = getPhone(subId);
2543 if (phone != null) {
2544 phone.setDataActivationState(activationState);
2545 } else {
2546 loge("setVoiceActivationState fails with invalid subId: " + subId);
2547 }
2548 } finally {
2549 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002550 }
2551 }
2552
2553 /**
2554 * Returns the voice activation state of a given subId.
2555 */
2556 @Override
2557 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002558 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002559
fionaxu0152e512016-11-14 13:36:14 -08002560 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002561 final long identity = Binder.clearCallingIdentity();
2562 try {
2563 if (phone != null) {
2564 return phone.getVoiceActivationState();
2565 } else {
2566 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2567 }
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002570 }
2571 }
2572
2573 /**
2574 * Returns the data activation state of a given subId.
2575 */
2576 @Override
2577 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002578 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002579
fionaxu0152e512016-11-14 13:36:14 -08002580 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002581 final long identity = Binder.clearCallingIdentity();
2582 try {
2583 if (phone != null) {
2584 return phone.getDataActivationState();
2585 } else {
2586 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2587 }
2588 } finally {
2589 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002590 }
2591 }
2592
2593 /**
Wink Saville36469e72014-06-11 15:17:00 -07002594 * Returns the unread count of voicemails for a subId
2595 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002596 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002597 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2599 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2600 return 0;
2601 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 final Phone phone = getPhone(subId);
2605 if (phone != null) {
2606 return phone.getVoiceMessageCount();
2607 } else {
2608 return 0;
2609 }
2610 } finally {
2611 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 }
2614
2615 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002616 * returns true, if the device is in a state where both voice and data
2617 * are supported simultaneously. This can change based on location or network condition.
2618 */
2619 @Override
2620 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 final Phone phone = getPhone(subId);
2624 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002628 }
2629
2630 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002631 * Send the dialer code if called from the current default dialer or the caller has
2632 * carrier privilege.
2633 * @param inputCode The dialer code to send
2634 */
2635 @Override
2636 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2637 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2638 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2639 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002640 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2641 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002642 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002643
2644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 mPhone.sendDialerSpecialCode(inputCode);
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
2649 }
fionaxu235cc5e2017-03-06 22:25:57 -08002650 }
2651
2652 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002653 * Returns the data network type.
2654 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 *
2656 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2657 */
2658 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002659 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 final Phone phone = getPhone(getDefaultSubscription());
2663 if (phone != null) {
2664 return phone.getServiceState().getDataNetworkType();
2665 } else {
2666 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2667 }
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002670 }
Wink Saville36469e72014-06-11 15:17:00 -07002671 }
2672
Pengquan Meng0c05b502018-09-06 09:59:22 -07002673 @Override
2674 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002675 if (!isActiveSubscription(subId)) {
2676 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2677 }
2678
Pengquan Meng0c05b502018-09-06 09:59:22 -07002679 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2680 }
2681
Brad Ebinger4c460712018-10-01 10:40:55 -07002682 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002683 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2684 throws RemoteException {
2685 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2687 final long token = Binder.clearCallingIdentity();
2688 try {
2689 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2690 .addRegistrationCallbackForSubscription(c, subId);
2691 } finally {
2692 Binder.restoreCallingIdentity(token);
2693 }
2694 }
2695
2696 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002697 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2698 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2700 Binder.withCleanCallingIdentity(() ->
2701 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2702 .removeRegistrationCallbackForSubscription(c, subId));
2703 }
2704
2705 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002706 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2707 throws RemoteException {
2708 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002709 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2710 final long token = Binder.clearCallingIdentity();
2711 try {
2712 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2713 .addCapabilitiesCallbackForSubscription(c, subId);
2714 } finally {
2715 Binder.restoreCallingIdentity(token);
2716 }
2717 }
2718
2719 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002720 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2721 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2723 Binder.withCleanCallingIdentity(() ->
2724 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2725 .removeCapabilitiesCallbackForSubscription(c, subId));
2726 }
2727
2728 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002729 public boolean isCapable(int subId, int capability, int regTech) {
2730 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002731 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2732 final long token = Binder.clearCallingIdentity();
2733 try {
2734 return ImsManager.getInstance(mPhone.getContext(),
2735 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2736 } catch (ImsException e) {
2737 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2738 return false;
2739 } finally {
2740 Binder.restoreCallingIdentity(token);
2741 }
2742 }
2743
2744 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002745 public boolean isAvailable(int subId, int capability, int regTech) {
2746 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002747 final long token = Binder.clearCallingIdentity();
2748 try {
2749 Phone phone = getPhone(subId);
2750 if (phone == null) return false;
2751 return phone.isImsCapabilityAvailable(capability, regTech);
2752 } finally {
2753 Binder.restoreCallingIdentity(token);
2754 }
2755 }
2756
2757 @Override
2758 public boolean isAdvancedCallingSettingEnabled(int subId) {
2759 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2760 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2761 final long token = Binder.clearCallingIdentity();
2762 try {
2763 return ImsManager.getInstance(mPhone.getContext(),
2764 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2765 } finally {
2766 Binder.restoreCallingIdentity(token);
2767 }
2768 }
2769
2770 @Override
2771 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2773 "setAdvancedCallingSetting");
2774 final long identity = Binder.clearCallingIdentity();
2775 try {
2776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2777 ImsManager.getInstance(mPhone.getContext(),
2778 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
2781 }
2782 }
2783
2784 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002785 public boolean isVtSettingEnabled(int subId) {
2786 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2790 return ImsManager.getInstance(mPhone.getContext(),
2791 getSlotIndexOrException(subId)).isVtEnabledByUser();
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
2794 }
2795 }
2796
2797 @Override
2798 public void setVtSetting(int subId, boolean isEnabled) {
2799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2800 "setVtSetting");
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2804 ImsManager.getInstance(mPhone.getContext(),
2805 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2806 } finally {
2807 Binder.restoreCallingIdentity(identity);
2808 }
2809 }
2810
2811 @Override
2812 public boolean isVoWiFiSettingEnabled(int subId) {
2813 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2814 final long identity = Binder.clearCallingIdentity();
2815 try {
2816 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2817 return ImsManager.getInstance(mPhone.getContext(),
2818 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
2821 }
2822 }
2823
2824 @Override
2825 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2827 "setVoWiFiSetting");
2828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2831 ImsManager.getInstance(mPhone.getContext(),
2832 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
2835 }
2836 }
2837
2838 @Override
2839 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2840 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2844 return ImsManager.getInstance(mPhone.getContext(),
2845 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
2848 }
2849 }
2850
2851 @Override
2852 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2854 "setVoWiFiRoamingSetting");
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2858 ImsManager.getInstance(mPhone.getContext(),
2859 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
2862 }
2863 }
2864
2865 @Override
2866 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2868 "setVoWiFiNonPersistent");
2869 final long identity = Binder.clearCallingIdentity();
2870 try {
2871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2872 ImsManager.getInstance(mPhone.getContext(),
2873 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2874 } finally {
2875 Binder.restoreCallingIdentity(identity);
2876 }
2877 }
2878
2879 @Override
2880 public int getVoWiFiModeSetting(int subId) {
2881 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2885 return ImsManager.getInstance(mPhone.getContext(),
2886 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
2889 }
2890 }
2891
2892 @Override
2893 public void setVoWiFiModeSetting(int subId, int mode) {
2894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2895 "setVoWiFiModeSetting");
2896 final long identity = Binder.clearCallingIdentity();
2897 try {
2898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2899 ImsManager.getInstance(mPhone.getContext(),
2900 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2901 } finally {
2902 Binder.restoreCallingIdentity(identity);
2903 }
2904 }
2905
2906 @Override
2907 public int getVoWiFiRoamingModeSetting(int subId) {
2908 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2912 return ImsManager.getInstance(mPhone.getContext(),
2913 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
2917 }
2918
2919 @Override
2920 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2922 "setVoWiFiRoamingModeSetting");
2923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2926 ImsManager.getInstance(mPhone.getContext(),
2927 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
2931 }
2932
2933 @Override
2934 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2936 "setRttCapabilityEnabled");
2937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2940 ImsManager.getInstance(mPhone.getContext(),
2941 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
2945 }
2946
2947 @Override
2948 public boolean isTtyOverVolteEnabled(int subId) {
2949 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2950 final long identity = Binder.clearCallingIdentity();
2951 try {
2952 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2953 return ImsManager.getInstance(mPhone.getContext(),
2954 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
2958 }
2959
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002960 @Override
2961 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2962 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2963 final long identity = Binder.clearCallingIdentity();
2964 try {
2965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2966 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2967 .getConfigInterface().addConfigCallback(callback);
2968 } catch (ImsException e) {
2969 throw new IllegalArgumentException(e.getMessage());
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
2972 }
2973 }
2974
2975 @Override
2976 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2977 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2981 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2982 .getConfigInterface().removeConfigCallback(callback);
2983 } catch (ImsException e) {
2984 throw new IllegalArgumentException(e.getMessage());
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
2988 }
2989
2990 @Override
2991 public int getImsProvisioningInt(int subId, int key) {
2992 enforceReadPrivilegedPermission("getImsProvisioningInt");
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2996 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2997 .getConfigInterface().getConfigInt(key);
2998 } catch (ImsException e) {
2999 throw new IllegalArgumentException(e.getMessage());
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
3003 }
3004
3005 @Override
3006 public String getImsProvisioningString(int subId, int key) {
3007 enforceReadPrivilegedPermission("getImsProvisioningString");
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3011 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3012 .getConfigInterface().getConfigString(key);
3013 } catch (ImsException e) {
3014 throw new IllegalArgumentException(e.getMessage());
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
3018 }
3019
3020 @Override
3021 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3023 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3027 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3028 .getConfigInterface().setConfig(key, value);
3029 } catch (ImsException e) {
3030 throw new IllegalArgumentException(e.getMessage());
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
3034 }
3035
3036 @Override
3037 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3039 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3043 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3044 .getConfigInterface().setConfig(key, value);
3045 } catch (ImsException e) {
3046 throw new IllegalArgumentException(e.getMessage());
3047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
3050 }
3051
Brad Ebinger4c460712018-10-01 10:40:55 -07003052 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3053 int slotId = SubscriptionManager.getSlotIndex(subId);
3054 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3055 throw new IllegalArgumentException("Invalid Subscription Id.");
3056 }
3057 return slotId;
3058 }
3059
Wink Saville36469e72014-06-11 15:17:00 -07003060 /**
3061 * Returns the network type for a subId
3062 */
3063 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003064 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003066 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003067 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3068 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003069
Malcolm Chend965c8b2018-02-28 15:00:40 -08003070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 final Phone phone = getPhone(subId);
3073 if (phone != null) {
3074 return phone.getServiceState().getDataNetworkType();
3075 } else {
3076 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3077 }
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 }
3082
3083 /**
3084 * Returns the data network type
3085 */
3086 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003087 public int getDataNetworkType(String callingPackage) {
3088 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003089 }
3090
3091 /**
3092 * Returns the data network type for a subId
3093 */
3094 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003095 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003097 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003098 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3099 }
3100
Malcolm Chend965c8b2018-02-28 15:00:40 -08003101 final long identity = Binder.clearCallingIdentity();
3102 try {
3103 final Phone phone = getPhone(subId);
3104 if (phone != null) {
3105 return phone.getServiceState().getDataNetworkType();
3106 } else {
3107 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3108 }
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003112 }
3113
3114 /**
Wink Saville36469e72014-06-11 15:17:00 -07003115 * Returns the Voice network type for a subId
3116 */
3117 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003118 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003120 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003121 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3122 }
3123
Malcolm Chend965c8b2018-02-28 15:00:40 -08003124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 final Phone phone = getPhone(subId);
3127 if (phone != null) {
3128 return phone.getServiceState().getVoiceNetworkType();
3129 } else {
3130 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3131 }
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003135 }
3136
3137 /**
3138 * @return true if a ICC card is present
3139 */
3140 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003141 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003142 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3143 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003144 }
3145
3146 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003147 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003148 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003149 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003150 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 final Phone phone = PhoneFactory.getPhone(slotIndex);
3154 if (phone != null) {
3155 return phone.getIccCard().hasIccCard();
3156 } else {
3157 return false;
3158 }
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162 }
3163
3164 /**
3165 * Return if the current radio is LTE on CDMA. This
3166 * is a tri-state return value as for a period of time
3167 * the mode may be unknown.
3168 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003169 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003171 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003173 @Override
3174 public int getLteOnCdmaMode(String callingPackage) {
3175 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003176 }
3177
Sanket Padawe356d7632015-06-22 14:03:32 -07003178 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003179 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003181 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003182 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3183 }
3184
Malcolm Chend965c8b2018-02-28 15:00:40 -08003185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = getPhone(subId);
3188 if (phone == null) {
3189 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3190 } else {
3191 return phone.getLteOnCdmaMode();
3192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003195 }
Wink Saville36469e72014-06-11 15:17:00 -07003196 }
3197
3198 public void setPhone(Phone phone) {
3199 mPhone = phone;
3200 }
3201
3202 /**
3203 * {@hide}
3204 * Returns Default subId, 0 in the case of single standby.
3205 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003206 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003207 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003208 }
3209
Shishir Agrawala9f32182016-04-12 12:00:16 -07003210 private int getSlotForDefaultSubscription() {
3211 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3212 }
3213
Wink Savilleb564aae2014-10-23 10:18:09 -07003214 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003215 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003217
Pengquan Meng466e2482018-09-21 15:54:48 -07003218 private boolean isActiveSubscription(int subId) {
3219 return mSubscriptionController.isActiveSubId(subId);
3220 }
3221
Ihab Awadf2177b72013-11-25 13:33:23 -08003222 /**
3223 * @see android.telephony.TelephonyManager.WifiCallingChoices
3224 */
3225 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3229 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3230 getWhenToMakeWifiCallsDefaultPreference());
3231 } finally {
3232 Binder.restoreCallingIdentity(identity);
3233 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003234 }
3235
3236 /**
3237 * @see android.telephony.TelephonyManager.WifiCallingChoices
3238 */
3239 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3243 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3244 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003248 }
3249
Sailesh Nepald1e68152013-12-12 19:08:02 -08003250 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003251 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003252 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003253 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003254
Shishir Agrawal566b7612013-10-28 14:41:00 -07003255 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003256 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3257 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3259 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003261
Malcolm Chend965c8b2018-02-28 15:00:40 -08003262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 if (TextUtils.equals(ISDR_AID, aid)) {
3265 // Only allows LPA to open logical channel to ISD-R.
3266 ComponentInfo bestComponent =
3267 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3268 if (bestComponent == null
3269 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3270 loge("The calling package is not allowed to access ISD-R.");
3271 throw new SecurityException(
3272 "The calling package is not allowed to access ISD-R.");
3273 }
Derek Tan740e1672017-06-27 14:56:27 -07003274 }
Derek Tan740e1672017-06-27 14:56:27 -07003275
Malcolm Chend965c8b2018-02-28 15:00:40 -08003276 if (DBG) {
3277 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3278 }
3279 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3280 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3281 if (DBG) log("iccOpenLogicalChannel: " + response);
3282 return response;
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003286 }
3287
3288 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003289 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003292
Malcolm Chend965c8b2018-02-28 15:00:40 -08003293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3296 if (channel < 0) {
3297 return false;
3298 }
3299 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3300 if (DBG) log("iccCloseLogicalChannel: " + success);
3301 return success;
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003304 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003305 }
3306
3307 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003308 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003309 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3311 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003312
Malcolm Chend965c8b2018-02-28 15:00:40 -08003313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 if (DBG) {
3316 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3317 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3318 + p3 + " data=" + data);
3319 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003320
Malcolm Chend965c8b2018-02-28 15:00:40 -08003321 if (channel < 0) {
3322 return "";
3323 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003324
Malcolm Chend965c8b2018-02-28 15:00:40 -08003325 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3326 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3327 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003328
Malcolm Chend965c8b2018-02-28 15:00:40 -08003329 // Append the returned status code to the end of the response payload.
3330 String s = Integer.toHexString(
3331 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3332 if (response.payload != null) {
3333 s = IccUtils.bytesToHexString(response.payload) + s;
3334 }
3335 return s;
3336 } finally {
3337 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003338 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003339 }
Jake Hambye994d462014-02-03 13:10:13 -08003340
Evan Charltonc66da362014-05-16 14:06:40 -07003341 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003342 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3343 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3345 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003346 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003347
Malcolm Chend965c8b2018-02-28 15:00:40 -08003348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3351 && TextUtils.equals(ISDR_AID, data)) {
3352 // Only allows LPA to select ISD-R.
3353 ComponentInfo bestComponent =
3354 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3355 if (bestComponent == null
3356 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3357 loge("The calling package is not allowed to select ISD-R.");
3358 throw new SecurityException(
3359 "The calling package is not allowed to select ISD-R.");
3360 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003361 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003362
Malcolm Chend965c8b2018-02-28 15:00:40 -08003363 if (DBG) {
3364 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3365 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3366 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003367
Malcolm Chend965c8b2018-02-28 15:00:40 -08003368 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3369 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3370 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003371
Malcolm Chend965c8b2018-02-28 15:00:40 -08003372 // Append the returned status code to the end of the response payload.
3373 String s = Integer.toHexString(
3374 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3375 if (response.payload != null) {
3376 s = IccUtils.bytesToHexString(response.payload) + s;
3377 }
3378 return s;
3379 } finally {
3380 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003381 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003382 }
3383
3384 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003385 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003386 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3388 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003389
Malcolm Chend965c8b2018-02-28 15:00:40 -08003390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 if (DBG) {
3393 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3394 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3395 }
3396
3397 IccIoResult response =
3398 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3399 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3400 subId);
3401
3402 if (DBG) {
3403 log("Exchange SIM_IO [R]" + response);
3404 }
3405
3406 byte[] result = null;
3407 int length = 2;
3408 if (response.payload != null) {
3409 length = 2 + response.payload.length;
3410 result = new byte[length];
3411 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3412 } else {
3413 result = new byte[length];
3414 }
3415
3416 result[length - 1] = (byte) response.sw2;
3417 result[length - 2] = (byte) response.sw1;
3418 return result;
3419 } finally {
3420 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003421 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003422 }
3423
Nathan Haroldb3014052017-01-25 15:57:32 -08003424 /**
3425 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3426 * on a particular subscription
3427 */
sqianb6e41952018-03-12 14:54:01 -07003428 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3430 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3431 return null;
3432 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003433
3434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 if (appType != TelephonyManager.APPTYPE_USIM
3437 && appType != TelephonyManager.APPTYPE_SIM) {
3438 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3439 return null;
3440 }
3441 Object response = sendRequest(
3442 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3443 if (response instanceof String[]) {
3444 return (String[]) response;
3445 }
3446 // Response is an Exception of some kind,
3447 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003448 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003449 } finally {
3450 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003451 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003452 }
3453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003454 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003455 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3457 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003458
Malcolm Chend965c8b2018-02-28 15:00:40 -08003459 final long identity = Binder.clearCallingIdentity();
3460 try {
3461 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3462 if (response.payload == null) {
3463 return "";
3464 }
Evan Charltonc66da362014-05-16 14:06:40 -07003465
Malcolm Chend965c8b2018-02-28 15:00:40 -08003466 // Append the returned status code to the end of the response payload.
3467 String s = Integer.toHexString(
3468 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3469 s = IccUtils.bytesToHexString(response.payload) + s;
3470 return s;
3471 } finally {
3472 Binder.restoreCallingIdentity(identity);
3473 }
Evan Charltonc66da362014-05-16 14:06:40 -07003474 }
3475
Jake Hambye994d462014-02-03 13:10:13 -08003476 /**
3477 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3478 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3479 *
3480 * @param itemID the ID of the item to read
3481 * @return the NV item as a String, or null on error.
3482 */
3483 @Override
3484 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3487 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003492 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003493 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3494 return value;
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
Jake Hambye994d462014-02-03 13:10:13 -08003498 }
3499
3500 /**
3501 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3502 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3503 *
3504 * @param itemID the ID of the item to read
3505 * @param itemValue the value to write, as a String
3506 * @return true on success; false on any failure
3507 */
3508 @Override
3509 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3512 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003513
3514 final long identity = Binder.clearCallingIdentity();
3515 try {
3516 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3517 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003518 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003519 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3520 return success;
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
Jake Hambye994d462014-02-03 13:10:13 -08003524 }
3525
3526 /**
3527 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3528 * Used for device configuration by some CDMA operators.
3529 *
3530 * @param preferredRoamingList byte array containing the new PRL
3531 * @return true on success; false on any failure
3532 */
3533 @Override
3534 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3536 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003537
3538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3541 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3542 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3543 return success;
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
Jake Hambye994d462014-02-03 13:10:13 -08003547 }
3548
3549 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003550 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003551 * Used for device configuration by some CDMA operators.
3552 *
chen xu1cc0abe2018-10-26 17:39:23 -07003553 * @param slotIndex - device slot.
3554 *
Jake Hambye994d462014-02-03 13:10:13 -08003555 * @return true on success; false on any failure
3556 */
3557 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003558 public boolean resetModemConfig(int slotIndex) {
3559 Phone phone = PhoneFactory.getPhone(slotIndex);
3560 if (phone != null) {
3561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3562 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003563
chen xu1cc0abe2018-10-26 17:39:23 -07003564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3567 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3568 return success;
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
3571 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003572 }
chen xu1cc0abe2018-10-26 17:39:23 -07003573 return false;
3574 }
3575
3576 /**
3577 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3578 *
3579 * @param slotIndex - device slot.
3580 *
3581 * @return true on success; false on any failure
3582 */
3583 @Override
3584 public boolean rebootModem(int slotIndex) {
3585 Phone phone = PhoneFactory.getPhone(slotIndex);
3586 if (phone != null) {
3587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3588 mApp, phone.getSubId(), "rebootModem");
3589
3590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3593 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3594 return success;
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
3598 }
3599 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003600 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003601
Svet Ganovb320e182015-04-16 12:30:10 -07003602 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003604 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003605 return new String[0];
3606 }
3607
Malcolm Chend965c8b2018-02-28 15:00:40 -08003608 final long identity = Binder.clearCallingIdentity();
3609 try {
3610 return mPhone.getPcscfAddress(apnType);
3611 } finally {
3612 Binder.restoreCallingIdentity(identity);
3613 }
Wink Saville36469e72014-06-11 15:17:00 -07003614 }
3615
Brad Ebinger51f743a2017-01-23 13:50:20 -08003616 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003617 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3618 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003619 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003620 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003621 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003622
3623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 PhoneFactory.getImsResolver().enableIms(slotId);
3626 } finally {
3627 Binder.restoreCallingIdentity(identity);
3628 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003629 }
3630
3631 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003632 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3633 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003634 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003635 public void disableIms(int slotId) {
3636 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003637
3638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 PhoneFactory.getImsResolver().disableIms(slotId);
3641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003644 }
3645
3646 /**
3647 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3648 * feature or {@link null} if the service is not available. If the feature is available, the
3649 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3650 */
3651 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003652 IImsServiceFeatureCallback callback) {
3653 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003654
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003661 }
3662
3663 /**
3664 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3665 * feature during emergency calling or {@link null} if the service is not available. If the
3666 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3667 * listener for feature updates.
3668 */
3669 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3670 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003671
3672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003678 }
3679
Brad Ebinger5f64b052017-12-14 14:26:15 -08003680 /**
3681 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3682 * specified.
3683 */
3684 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3685 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003693 }
3694
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003695 /**
3696 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3697 * specified.
3698 */
3699 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3700 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003701
3702 final long identity = Binder.clearCallingIdentity();
3703 try {
3704 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003708 }
3709
Brad Ebinger884c07b2018-02-15 16:17:40 -08003710 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003711 * Sets the ImsService Package Name that Telephony will bind to.
3712 *
3713 * @param slotId the slot ID that the ImsService should bind for.
3714 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3715 * ImsService is the device default ImsService.
3716 * @param packageName The package name of the application that contains the ImsService to bind
3717 * to.
3718 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3719 * @hide
3720 */
3721 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003722 int[] subIds = SubscriptionManager.getSubId(slotId);
3723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3724 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3725 "setImsService");
3726
Malcolm Chend965c8b2018-02-28 15:00:40 -08003727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3730 isCarrierImsService, packageName);
3731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003734 }
3735
3736 /**
3737 * Return the ImsService configuration.
3738 *
3739 * @param slotId The slot that the ImsService is associated with.
3740 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3741 * the device default.
3742 * @return the package name of the ImsService configuration.
3743 */
3744 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003745 int[] subIds = SubscriptionManager.getSubId(slotId);
3746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3747 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3748 "getImsService");
3749
Malcolm Chend965c8b2018-02-28 15:00:40 -08003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3753 isCarrierImsService);
3754 } finally {
3755 Binder.restoreCallingIdentity(identity);
3756 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003757 }
3758
Wink Saville36469e72014-06-11 15:17:00 -07003759 public void setImsRegistrationState(boolean registered) {
3760 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 mPhone.setImsRegistrationState(registered);
3765 } finally {
3766 Binder.restoreCallingIdentity(identity);
3767 }
Wink Saville36469e72014-06-11 15:17:00 -07003768 }
3769
3770 /**
Stuart Scott54788802015-03-30 13:18:01 -07003771 * Set the network selection mode to automatic.
3772 *
3773 */
3774 @Override
3775 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3777 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003778
Pengquan Meng466e2482018-09-21 15:54:48 -07003779 if (!isActiveSubscription(subId)) {
3780 return;
3781 }
3782
Malcolm Chend965c8b2018-02-28 15:00:40 -08003783 final long identity = Binder.clearCallingIdentity();
3784 try {
3785 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3786 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
Stuart Scott54788802015-03-30 13:18:01 -07003790 }
3791
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003792 /**
3793 * Ask the radio to connect to the input network and change selection mode to manual.
3794 *
3795 * @param subId the id of the subscription.
3796 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3797 * the operator to attach to.
3798 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3799 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3800 * normal network selection next time.
3801 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003802 */
3803 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003804 public boolean setNetworkSelectionModeManual(
3805 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3807 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003808
3809 if (!isActiveSubscription(subId)) {
3810 return false;
3811 }
3812
Malcolm Chend965c8b2018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003815 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003816 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003817 if (DBG) {
3818 log("setNetworkSelectionModeManual: subId: " + subId
3819 + " operator: " + operatorInfo);
3820 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003821 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
3824 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003825 }
3826
3827 /**
3828 * Scans for available networks.
3829 */
3830 @Override
3831 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3833 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003834
Pengquan Meng0c05b502018-09-06 09:59:22 -07003835 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003836 try {
3837 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003838 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003839 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003843 }
3844
3845 /**
yinxub1bed742017-04-17 11:45:04 -07003846 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003847 *
yinxub1bed742017-04-17 11:45:04 -07003848 * @param subId id of the subscription
3849 * @param request contains the radio access networks with bands/channels to scan
3850 * @param messenger callback messenger for scan results or errors
3851 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003852 * @return the id of the requested scan which can be used to stop the scan.
3853 */
3854 @Override
3855 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3856 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3858 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003859
3860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 return mNetworkScanRequestTracker.startNetworkScan(
3863 request, messenger, binder, getPhone(subId));
3864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
yinxu504e1392017-04-12 16:03:22 -07003867 }
3868
3869 /**
3870 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003871 *
3872 * @param subId id of the subscription
3873 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003874 */
3875 @Override
3876 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3878 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003879
3880 final long identity = Binder.clearCallingIdentity();
3881 try {
3882 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3883 } finally {
3884 Binder.restoreCallingIdentity(identity);
3885 }
yinxu504e1392017-04-12 16:03:22 -07003886 }
3887
3888 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003889 * Get the calculated preferred network type.
3890 * Used for debugging incorrect network type.
3891 *
3892 * @return the preferred network type, defined in RILConstants.java.
3893 */
3894 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003895 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003897 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003898 return RILConstants.PREFERRED_NETWORK_MODE;
3899 }
3900
Malcolm Chend965c8b2018-02-28 15:00:40 -08003901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 // FIXME: need to get SubId from somewhere.
3904 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3905 } finally {
3906 Binder.restoreCallingIdentity(identity);
3907 }
Junda Liu84d15a22014-07-02 11:21:04 -07003908 }
3909
3910 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003911 * Get the preferred network type.
3912 * Used for device configuration by some CDMA operators.
3913 *
3914 * @return the preferred network type, defined in RILConstants.java.
3915 */
3916 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003917 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3919 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003920
3921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 if (DBG) log("getPreferredNetworkType");
3924 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3925 int networkType = (result != null ? result[0] : -1);
3926 if (DBG) log("getPreferredNetworkType: " + networkType);
3927 return networkType;
3928 } finally {
3929 Binder.restoreCallingIdentity(identity);
3930 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003931 }
3932
3933 /**
3934 * Set the preferred network type.
3935 * Used for device configuration by some CDMA operators.
3936 *
3937 * @param networkType the preferred network type, defined in RILConstants.java.
3938 * @return true on success; false on any failure.
3939 */
3940 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003941 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3943 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003944
3945 final long identity = Binder.clearCallingIdentity();
3946 try {
3947 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3948 Boolean success = (Boolean) sendRequest(
3949 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3950 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3951 if (success) {
3952 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3953 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3954 }
3955 return success;
3956 } finally {
3957 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003958 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003959 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003960
3961 /**
Junda Liu475951f2014-11-07 16:45:03 -08003962 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003963 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003964 * tethering.
3965 *
3966 * @return 0: Not required. 1: required. 2: Not set.
3967 * @hide
3968 */
3969 @Override
3970 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003971 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003972
3973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3976 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07003977 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08003978 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3979 dunRequired = 1;
3980 }
3981 return dunRequired;
3982 } finally {
3983 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003984 }
Junda Liu475951f2014-11-07 16:45:03 -08003985 }
3986
3987 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003988 * Set mobile data enabled
3989 * Used by the user through settings etc to turn on/off mobile data
3990 *
3991 * @param enable {@code true} turn turn data on, else {@code false}
3992 */
3993 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003994 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3996 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003997
3998 final long identity = Binder.clearCallingIdentity();
3999 try {
4000 int phoneId = mSubscriptionController.getPhoneId(subId);
4001 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4002 Phone phone = PhoneFactory.getPhone(phoneId);
4003 if (phone != null) {
4004 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4005 phone.setUserDataEnabled(enable);
4006 } else {
4007 loge("setUserDataEnabled: no phone for subId=" + subId);
4008 }
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004011 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004012 }
4013
4014 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004015 * Get the user enabled state of Mobile Data.
4016 *
4017 * TODO: remove and use isUserDataEnabled.
4018 * This can't be removed now because some vendor codes
4019 * calls through ITelephony directly while they should
4020 * use TelephonyManager.
4021 *
4022 * @return true on enabled
4023 */
4024 @Override
4025 public boolean getDataEnabled(int subId) {
4026 return isUserDataEnabled(subId);
4027 }
4028
4029 /**
4030 * Get whether mobile data is enabled per user setting.
4031 *
4032 * There are other factors deciding whether mobile data is actually enabled, but they are
4033 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004034 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004035 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004036 *
4037 * @return {@code true} if data is enabled else {@code false}
4038 */
4039 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004040 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004041 try {
4042 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4043 null);
4044 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4046 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004047 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004048
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 int phoneId = mSubscriptionController.getPhoneId(subId);
4052 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4053 Phone phone = PhoneFactory.getPhone(phoneId);
4054 if (phone != null) {
4055 boolean retVal = phone.isUserDataEnabled();
4056 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4057 return retVal;
4058 } else {
4059 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4060 return false;
4061 }
4062 } finally {
4063 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004064 }
4065 }
4066
4067 /**
4068 * Get whether mobile data is enabled.
4069 *
4070 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4071 * whether mobile data is actually enabled.
4072 *
4073 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4074 *
4075 * @return {@code true} if data is enabled else {@code false}
4076 */
4077 @Override
4078 public boolean isDataEnabled(int subId) {
4079 try {
4080 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4081 null);
4082 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4084 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004085 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004086
4087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 int phoneId = mSubscriptionController.getPhoneId(subId);
4090 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4091 Phone phone = PhoneFactory.getPhone(phoneId);
4092 if (phone != null) {
4093 boolean retVal = phone.isDataEnabled();
4094 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4095 return retVal;
4096 } else {
4097 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4098 return false;
4099 }
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004102 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004103 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004104
4105 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004106 public int getCarrierPrivilegeStatus(int subId) {
4107 final Phone phone = getPhone(subId);
4108 if (phone == null) {
4109 loge("getCarrierPrivilegeStatus: Invalid subId");
4110 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4111 }
4112 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004113 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004114 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004115 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4116 }
4117 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004118 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004119 }
Junda Liu29340342014-07-10 15:23:27 -07004120
4121 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004122 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4123 final Phone phone = getPhone(subId);
4124 if (phone == null) {
4125 loge("getCarrierPrivilegeStatus: Invalid subId");
4126 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4127 }
4128 UiccProfile profile =
4129 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4130 if (profile == null) {
4131 loge("getCarrierPrivilegeStatus: No UICC");
4132 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4133 }
4134 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4135 }
4136
4137 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004138 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004139 if (TextUtils.isEmpty(pkgName))
4140 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004141 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004142 if (card == null) {
4143 loge("checkCarrierPrivilegesForPackage: No UICC");
4144 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4145 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004146 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4147 }
4148
4149 @Override
4150 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004151 if (TextUtils.isEmpty(pkgName))
4152 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004153 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4154 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4155 UiccCard card = UiccController.getInstance().getUiccCard(i);
4156 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004157 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004158 continue;
4159 }
4160
4161 result = card.getCarrierPrivilegeStatus(
4162 mPhone.getContext().getPackageManager(), pkgName);
4163 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4164 break;
4165 }
4166 }
4167
4168 return result;
Junda Liu29340342014-07-10 15:23:27 -07004169 }
Derek Tan89e89d42014-07-08 17:00:10 -07004170
4171 @Override
Junda Liue64de782015-04-16 17:19:16 -07004172 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4173 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4174 loge("phoneId " + phoneId + " is not valid.");
4175 return null;
4176 }
4177 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004178 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004179 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004180 return null ;
4181 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004182 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004183 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004184 }
4185
Amith Yamasani6e118872016-02-19 12:53:51 -08004186 @Override
4187 public List<String> getPackagesWithCarrierPrivileges() {
4188 PackageManager pm = mPhone.getContext().getPackageManager();
4189 List<String> privilegedPackages = new ArrayList<>();
4190 List<PackageInfo> packages = null;
4191 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4192 UiccCard card = UiccController.getInstance().getUiccCard(i);
4193 if (card == null) {
4194 // No UICC in that slot.
4195 continue;
4196 }
4197 if (card.hasCarrierPrivilegeRules()) {
4198 if (packages == null) {
4199 // Only check packages in user 0 for now
4200 packages = pm.getInstalledPackagesAsUser(
4201 PackageManager.MATCH_DISABLED_COMPONENTS
4202 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4203 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4204 }
4205 for (int p = packages.size() - 1; p >= 0; p--) {
4206 PackageInfo pkgInfo = packages.get(p);
4207 if (pkgInfo != null && pkgInfo.packageName != null
4208 && card.getCarrierPrivilegeStatus(pkgInfo)
4209 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4210 privilegedPackages.add(pkgInfo.packageName);
4211 }
4212 }
4213 }
4214 }
4215 return privilegedPackages;
4216 }
4217
Wink Savilleb564aae2014-10-23 10:18:09 -07004218 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004219 final Phone phone = getPhone(subId);
4220 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004221 if (card == null) {
4222 loge("getIccId: No UICC");
4223 return null;
4224 }
4225 String iccId = card.getIccId();
4226 if (TextUtils.isEmpty(iccId)) {
4227 loge("getIccId: ICC ID is null or empty.");
4228 return null;
4229 }
4230 return iccId;
4231 }
4232
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004233 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004234 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4235 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004236 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4237 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004238
Malcolm Chend965c8b2018-02-28 15:00:40 -08004239 final long identity = Binder.clearCallingIdentity();
4240 try {
4241 final String iccId = getIccId(subId);
4242 final Phone phone = getPhone(subId);
4243 if (phone == null) {
4244 return false;
4245 }
4246 final String subscriberId = phone.getSubscriberId();
4247
4248 if (DBG_MERGE) {
4249 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4250 + subscriberId + " to " + number);
4251 }
4252
4253 if (TextUtils.isEmpty(iccId)) {
4254 return false;
4255 }
4256
4257 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4258
4259 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4260 if (alphaTag == null) {
4261 editor.remove(alphaTagPrefKey);
4262 } else {
4263 editor.putString(alphaTagPrefKey, alphaTag);
4264 }
4265
4266 // Record both the line number and IMSI for this ICCID, since we need to
4267 // track all merged IMSIs based on line number
4268 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4269 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4270 if (number == null) {
4271 editor.remove(numberPrefKey);
4272 editor.remove(subscriberPrefKey);
4273 } else {
4274 editor.putString(numberPrefKey, number);
4275 editor.putString(subscriberPrefKey, subscriberId);
4276 }
4277
4278 editor.commit();
4279 return true;
4280 } finally {
4281 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004282 }
Derek Tan7226c842014-07-02 17:42:23 -07004283 }
4284
4285 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004286 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004287 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004289 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004290 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004291 return null;
4292 }
Derek Tan97ebb422014-09-05 16:55:38 -07004293
Malcolm Chend965c8b2018-02-28 15:00:40 -08004294 final long identity = Binder.clearCallingIdentity();
4295 try {
4296 String iccId = getIccId(subId);
4297 if (iccId != null) {
4298 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4299 if (DBG_MERGE) {
4300 log("getLine1NumberForDisplay returning "
4301 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4302 }
4303 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004304 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004305 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4306 return null;
4307 } finally {
4308 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004309 }
Derek Tan7226c842014-07-02 17:42:23 -07004310 }
4311
4312 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004313 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004315 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004316 return null;
4317 }
Derek Tan97ebb422014-09-05 16:55:38 -07004318
Malcolm Chend965c8b2018-02-28 15:00:40 -08004319 final long identity = Binder.clearCallingIdentity();
4320 try {
4321 String iccId = getIccId(subId);
4322 if (iccId != null) {
4323 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4324 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4325 }
4326 return null;
4327 } finally {
4328 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004329 }
Derek Tan7226c842014-07-02 17:42:23 -07004330 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004331
4332 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004333 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004334 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4335 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004337 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4338 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004339 return null;
4340 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004341
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004342 final long identity = Binder.clearCallingIdentity();
4343 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004344 final Context context = mPhone.getContext();
4345 final TelephonyManager tele = TelephonyManager.from(context);
4346 final SubscriptionManager sub = SubscriptionManager.from(context);
4347
4348 // Figure out what subscribers are currently active
4349 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4350 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4351 // the process, where TelephonyManager was instantiated.
4352 // Otherwise AppOps check will fail.
4353
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004354 final int[] subIds = sub.getActiveSubscriptionIdList();
4355 for (int subId : subIds) {
4356 activeSubscriberIds.add(tele.getSubscriberId(subId));
4357 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004358
4359 // First pass, find a number override for an active subscriber
4360 String mergeNumber = null;
4361 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4362 for (String key : prefs.keySet()) {
4363 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4364 final String subscriberId = (String) prefs.get(key);
4365 if (activeSubscriberIds.contains(subscriberId)) {
4366 final String iccId = key.substring(
4367 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4368 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4369 mergeNumber = (String) prefs.get(numberKey);
4370 if (DBG_MERGE) {
4371 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4372 + " for active subscriber " + subscriberId);
4373 }
4374 if (!TextUtils.isEmpty(mergeNumber)) {
4375 break;
4376 }
4377 }
4378 }
4379 }
4380
4381 // Shortcut when no active merged subscribers
4382 if (TextUtils.isEmpty(mergeNumber)) {
4383 return null;
4384 }
4385
4386 // Second pass, find all subscribers under that line override
4387 final ArraySet<String> result = new ArraySet<>();
4388 for (String key : prefs.keySet()) {
4389 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4390 final String number = (String) prefs.get(key);
4391 if (mergeNumber.equals(number)) {
4392 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4393 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4394 final String subscriberId = (String) prefs.get(subscriberKey);
4395 if (!TextUtils.isEmpty(subscriberId)) {
4396 result.add(subscriberId);
4397 }
4398 }
4399 }
4400 }
4401
4402 final String[] resultArray = result.toArray(new String[result.size()]);
4403 Arrays.sort(resultArray);
4404 if (DBG_MERGE) {
4405 Slog.d(LOG_TAG,
4406 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4407 }
4408 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004409 } finally {
4410 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004411 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004412 }
4413
4414 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004415 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004416 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4417 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004418
4419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 final Phone phone = getPhone(subId);
4422 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004426 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004427
4428 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004429 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004430 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4431 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004432 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004433
4434 final long identity = Binder.clearCallingIdentity();
4435 try {
4436 final Phone phone = getPhone(subId);
4437 if (phone == null) {
4438 return false;
4439 }
4440 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4441 cdmaNonRoamingList);
4442 } finally {
4443 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004444 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004445 }
4446
4447 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004448 @Deprecated
4449 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4450 enforceModifyPermission();
4451
4452 int returnValue = 0;
4453 try {
vagdevie435a3e2018-08-15 16:01:53 -07004454 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004455 if(result.exception == null) {
4456 if (result.result != null) {
4457 byte[] responseData = (byte[])(result.result);
4458 if(responseData.length > oemResp.length) {
4459 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4460 responseData.length + "bytes. Buffer Size is " +
4461 oemResp.length + "bytes.");
4462 }
4463 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4464 returnValue = responseData.length;
4465 }
4466 } else {
4467 CommandException ex = (CommandException) result.exception;
4468 returnValue = ex.getCommandError().ordinal();
4469 if(returnValue > 0) returnValue *= -1;
4470 }
4471 } catch (RuntimeException e) {
4472 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4473 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4474 if(returnValue > 0) returnValue *= -1;
4475 }
4476
4477 return returnValue;
4478 }
4479
4480 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004481 public void setRadioCapability(RadioAccessFamily[] rafs) {
4482 try {
4483 ProxyController.getInstance().setRadioCapability(rafs);
4484 } catch (RuntimeException e) {
4485 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4486 }
4487 }
4488
4489 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004490 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004491 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004492 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004493 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004494 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004495 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
chen xufeeed752018-10-26 14:17:57 -07004498 TelephonyPermissions
4499 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4500 mApp, phone.getSubId(), "getRadioAccessFamily");
4501 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004502 } finally {
4503 Binder.restoreCallingIdentity(identity);
4504 }
chen xufeeed752018-10-26 14:17:57 -07004505 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004506 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004507
4508 @Override
4509 public void enableVideoCalling(boolean enable) {
4510 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004511
4512 final long identity = Binder.clearCallingIdentity();
4513 try {
4514 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4515 } finally {
4516 Binder.restoreCallingIdentity(identity);
4517 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004518 }
4519
4520 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004521 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4523 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4524 return false;
4525 }
Svet Ganovb320e182015-04-16 12:30:10 -07004526
Malcolm Chend965c8b2018-02-28 15:00:40 -08004527 final long identity = Binder.clearCallingIdentity();
4528 try {
4529 // Check the user preference and the system-level IMS setting. Even if the user has
4530 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4531 // In the long run, we may instead need to check if there exists a connection service
4532 // which can support video calling.
4533 ImsManager imsManager =
4534 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4535 return imsManager.isVtEnabledByPlatform()
4536 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4537 && imsManager.isVtEnabledByUser();
4538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004541 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004542
Andrew Leea1239f22015-03-02 17:44:07 -08004543 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004544 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4546 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4547 return false;
4548 }
4549
4550 final long identity = Binder.clearCallingIdentity();
4551 try {
4552 CarrierConfigManager configManager =
4553 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4554 return configManager.getConfigForSubId(mPhone.getSubId())
4555 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4556 } finally {
4557 Binder.restoreCallingIdentity(identity);
4558 }
Andrew Leea1239f22015-03-02 17:44:07 -08004559 }
4560
4561 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004562 public boolean isWorldPhone(int subId, String callingPackage) {
4563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4564 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4565 return false;
4566 }
4567
4568 final long identity = Binder.clearCallingIdentity();
4569 try {
4570 CarrierConfigManager configManager =
4571 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4572 return configManager.getConfigForSubId(mPhone.getSubId())
4573 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4574 } finally {
4575 Binder.restoreCallingIdentity(identity);
4576 }
Andrew Leea1239f22015-03-02 17:44:07 -08004577 }
4578
Andrew Lee9431b832015-03-09 18:46:45 -07004579 @Override
4580 public boolean isTtyModeSupported() {
4581 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004582 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004583 }
4584
4585 @Override
4586 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004587 final long identity = Binder.clearCallingIdentity();
4588 try {
4589 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
Andrew Lee9431b832015-03-09 18:46:45 -07004593 }
4594
Hall Liuf6668912018-10-31 17:05:23 -07004595 /**
4596 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4597 * support for the feature and device firmware support.
4598 *
4599 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4600 */
4601 @Override
4602 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004603 final long identity = Binder.clearCallingIdentity();
4604 try {
4605 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4606 mPhone.getSubId()).getBoolean(
4607 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4608 boolean isDeviceSupported =
4609 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4610 return isCarrierSupported && isDeviceSupported;
4611 } finally {
4612 Binder.restoreCallingIdentity(identity);
4613 }
Hall Liu98187582018-01-22 19:15:32 -08004614 }
4615
Hall Liuf6668912018-10-31 17:05:23 -07004616 /**
4617 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4618 * both also support RTT.
4619 */
4620 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004621 final long identity = Binder.clearCallingIdentity();
4622 try {
Hall Liuf6668912018-10-31 17:05:23 -07004623 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004624 mPhone.getContext().getContentResolver(),
4625 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4626 } finally {
4627 Binder.restoreCallingIdentity(identity);
4628 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004629 }
4630
Sanket Padawe7310cc72015-01-14 09:53:20 -08004631 /**
4632 * Returns the unique device ID of phone, for example, the IMEI for
4633 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4634 *
4635 * <p>Requires Permission:
4636 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4637 */
4638 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004639 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004640 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004641 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004642 return null;
4643 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004644 int subId = phone.getSubId();
4645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4646 mApp, subId, callingPackage, "getDeviceId")) {
4647 return null;
4648 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004649
4650 final long identity = Binder.clearCallingIdentity();
4651 try {
4652 return phone.getDeviceId();
4653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004656 }
4657
Ping Sunc67b7c22016-03-02 19:16:45 +08004658 /**
4659 * {@hide}
4660 * Returns the IMS Registration Status on a particular subid
4661 *
4662 * @param subId
4663 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004664 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004665 Phone phone = getPhone(subId);
4666 if (phone != null) {
4667 return phone.isImsRegistered();
4668 } else {
4669 return false;
4670 }
4671 }
4672
Santos Cordon7a1885b2015-02-03 11:15:19 -08004673 @Override
4674 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004675 final long identity = Binder.clearCallingIdentity();
4676 try {
4677 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4678 } finally {
4679 Binder.restoreCallingIdentity(identity);
4680 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004681 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004682
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004683 /**
4684 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004685 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004686 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004687 final long identity = Binder.clearCallingIdentity();
4688 try {
4689 Phone phone = getPhone(subId);
4690 if (phone != null) {
4691 return phone.isWifiCallingEnabled();
4692 } else {
4693 return false;
4694 }
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004697 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004698 }
4699
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004700 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004701 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004702 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004703 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004704 final long identity = Binder.clearCallingIdentity();
4705 try {
4706 Phone phone = getPhone(subId);
4707 if (phone != null) {
4708 return phone.isVideoEnabled();
4709 } else {
4710 return false;
4711 }
4712 } finally {
4713 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004714 }
4715 }
4716
4717 /**
4718 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4719 * defined in {@link ImsRegistrationImplBase}.
4720 */
4721 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004722 final long identity = Binder.clearCallingIdentity();
4723 try {
4724 Phone phone = getPhone(subId);
4725 if (phone != null) {
4726 return phone.getImsRegistrationTech();
4727 } else {
4728 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4729 }
4730 } finally {
4731 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004732 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004733 }
4734
Stuart Scott8eef64f2015-04-08 15:13:54 -07004735 @Override
4736 public void factoryReset(int subId) {
4737 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004738 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4739 return;
4740 }
4741
Svet Ganovcc087f82015-05-12 20:35:54 -07004742 final long identity = Binder.clearCallingIdentity();
4743 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004744 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4745 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004746 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004747 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004748 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4749 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004750 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004751 }
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004754 }
4755 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004756
4757 @Override
4758 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 // We query all subscriptions instead of just the active ones, because
4762 // this might be called early on in the provisioning flow when the
4763 // subscriptions potentially aren't active yet.
4764 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4765 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004766 return null;
4767 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004768
Malcolm Chend965c8b2018-02-28 15:00:40 -08004769 // This function may be called very early, say, from the setup wizard, at
4770 // which point we won't have a default subscription set. If that's the case
4771 // we just choose the first, which will be valid in "most cases".
4772 final int defaultSubId = getDefaultSubscription();
4773 SubscriptionInfo info = null;
4774 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4775 info = slist.get(0);
4776 } else {
4777 for (SubscriptionInfo item : slist) {
4778 if (item.getSubscriptionId() == defaultSubId) {
4779 info = item;
4780 break;
4781 }
4782 }
4783
4784 if (info == null) {
4785 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004786 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004787 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004788
Malcolm Chend965c8b2018-02-28 15:00:40 -08004789 // Try and fetch the locale from the carrier properties or from the SIM language
4790 // preferences (EF-PL and EF-LI)...
4791 final int mcc = info.getMcc();
4792 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4793 String simLanguage = null;
4794 if (defaultPhone != null) {
4795 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4796 if (localeFromDefaultSim != null) {
4797 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4798 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4799 return localeFromDefaultSim.toLanguageTag();
4800 } else {
4801 simLanguage = localeFromDefaultSim.getLanguage();
4802 }
4803 }
4804 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004805
Malcolm Chend965c8b2018-02-28 15:00:40 -08004806 // The SIM language preferences only store a language (e.g. fr = French), not an
4807 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4808 // the SIM and carrier preferences does not include a country we add the country
4809 // determined from the SIM MCC to provide an exact locale.
4810 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4811 simLanguage);
4812 if (mccLocale != null) {
4813 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4814 return mccLocale.toLanguageTag();
4815 }
4816
4817 if (DBG) log("No locale found - returning null");
4818 return null;
4819 } finally {
4820 Binder.restoreCallingIdentity(identity);
4821 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004822 }
4823
4824 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004825 return mSubscriptionController.getAllSubInfoList(
4826 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004827 }
4828
Malcolm Chend965c8b2018-02-28 15:00:40 -08004829 /**
4830 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4831 */
4832 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4833 return mSubscriptionController.getActiveSubscriptionInfoList(
4834 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004835 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004836
Chenjie Yu1ba97252018-01-11 18:16:20 -08004837 private final ModemActivityInfo mLastModemActivityInfo =
4838 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4839
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004840 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004841 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4842 * representing the state of the modem.
4843 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004844 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4845 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004846 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004847 */
4848 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004849 public void requestModemActivityInfo(ResultReceiver result) {
4850 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004851 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004852
4853 final long identity = Binder.clearCallingIdentity();
4854 try {
4855 ModemActivityInfo ret = null;
4856 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004857 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4858 CMD_GET_MODEM_ACTIVITY_INFO,
4859 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004860 if (isModemActivityInfoValid(info)) {
4861 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4862 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4863 mergedTxTimeMs[i] =
4864 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4865 }
4866 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4867 mLastModemActivityInfo.setSleepTimeMillis(
4868 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4869 mLastModemActivityInfo.setIdleTimeMillis(
4870 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4871 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4872 mLastModemActivityInfo.setRxTimeMillis(
4873 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4874 mLastModemActivityInfo.setEnergyUsed(
4875 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004876 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004877 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4878 mLastModemActivityInfo.getSleepTimeMillis(),
4879 mLastModemActivityInfo.getIdleTimeMillis(),
4880 mLastModemActivityInfo.getTxTimeMillis(),
4881 mLastModemActivityInfo.getRxTimeMillis(),
4882 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004883 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004884 Bundle bundle = new Bundle();
4885 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4886 result.send(0, bundle);
4887 } finally {
4888 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004889 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004890 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004891
Siddharth Rayf5d29552018-06-17 15:02:38 -07004892 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4893 // less than total activity duration.
4894 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4895 if (info == null) {
4896 return false;
4897 }
4898 int activityDurationMs =
4899 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4900 int totalTxTimeMs = 0;
4901 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4902 totalTxTimeMs += info.getTxTimeMillis()[i];
4903 }
4904 return (info.isValid()
4905 && (info.getSleepTimeMillis() <= activityDurationMs)
4906 && (info.getIdleTimeMillis() <= activityDurationMs)
4907 && (info.getRxTimeMillis() <= activityDurationMs)
4908 && (totalTxTimeMs <= activityDurationMs));
4909 }
4910
Jack Yu85bd38a2015-11-09 11:34:32 -08004911 /**
4912 * {@hide}
4913 * Returns the service state information on specified subscription.
4914 */
4915 @Override
4916 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004918 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004919 return null;
4920 }
4921
Malcolm Chend965c8b2018-02-28 15:00:40 -08004922 final long identity = Binder.clearCallingIdentity();
4923 try {
4924 final Phone phone = getPhone(subId);
4925 if (phone == null) {
4926 return null;
4927 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004928
Malcolm Chend965c8b2018-02-28 15:00:40 -08004929 return phone.getServiceState();
4930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004933 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004934
4935 /**
4936 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4937 *
4938 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4939 * voicemail ringtone.
4940 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4941 * PhoneAccount.
4942 */
4943 @Override
4944 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4948 if (phone == null) {
4949 phone = mPhone;
4950 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004951
Malcolm Chend965c8b2018-02-28 15:00:40 -08004952 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004956 }
4957
4958 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004959 * Sets the per-account voicemail ringtone.
4960 *
4961 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4962 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4963 *
4964 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4965 * voicemail ringtone.
4966 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4967 * PhoneAccount.
4968 */
4969 @Override
4970 public void setVoicemailRingtoneUri(String callingPackage,
4971 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4972 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4973 if (!TextUtils.equals(callingPackage,
4974 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4976 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4977 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004978 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004979
4980 final long identity = Binder.clearCallingIdentity();
4981 try {
4982 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4983 if (phone == null) {
4984 phone = mPhone;
4985 }
4986 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4987 } finally {
4988 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004989 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004990 }
4991
4992 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004993 * Returns whether vibration is set for voicemail notification in Phone settings.
4994 *
4995 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4996 * voicemail vibration setting.
4997 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4998 */
4999 @Override
5000 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005001 final long identity = Binder.clearCallingIdentity();
5002 try {
5003 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5004 if (phone == null) {
5005 phone = mPhone;
5006 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005007
Malcolm Chend965c8b2018-02-28 15:00:40 -08005008 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005012 }
5013
Youhan Wange64578a2016-05-02 15:32:42 -07005014 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005015 * Sets the per-account voicemail vibration.
5016 *
5017 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5018 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5019 *
5020 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5021 * voicemail vibration setting.
5022 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5023 * specific PhoneAccount.
5024 */
5025 @Override
5026 public void setVoicemailVibrationEnabled(String callingPackage,
5027 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5028 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5029 if (!TextUtils.equals(callingPackage,
5030 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5032 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5033 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005034 }
5035
Malcolm Chend965c8b2018-02-28 15:00:40 -08005036 final long identity = Binder.clearCallingIdentity();
5037 try {
5038 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5039 if (phone == null) {
5040 phone = mPhone;
5041 }
5042 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005045 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005046 }
5047
5048 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005049 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5050 *
5051 * @throws SecurityException if the caller does not have the required permission
5052 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005053 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005054 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005055 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005056 }
5057
5058 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005059 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5060 * permission.
5061 *
5062 * @throws SecurityException if the caller does not have the required permission
5063 */
5064 private void enforceSendSmsPermission() {
5065 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5066 }
5067
5068 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005069 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005070 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005071 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005072 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005073 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 ComponentName componentName =
5077 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5078 if (componentName == null) {
5079 throw new SecurityException(
5080 "Caller not current active visual voicemail package[null]");
5081 }
5082 String vvmPackage = componentName.getPackageName();
5083 if (!callingPackage.equals(vvmPackage)) {
5084 throw new SecurityException("Caller not current active visual voicemail package["
5085 + vvmPackage + "]");
5086 }
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005089 }
5090 }
5091
5092 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005093 * Return the application ID for the app type.
5094 *
5095 * @param subId the subscription ID that this request applies to.
5096 * @param appType the uicc app type.
5097 * @return Application ID for specificied app type, or null if no uicc.
5098 */
5099 @Override
5100 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005101 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005102 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005103
5104 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005105 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005106 if (phone == null) {
5107 return null;
5108 }
5109 String aid = null;
5110 try {
5111 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5112 .getApplicationByType(appType).getAid();
5113 } catch (Exception e) {
5114 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5115 }
5116 return aid;
5117 } finally {
5118 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005119 }
Youhan Wange64578a2016-05-02 15:32:42 -07005120 }
5121
Youhan Wang4001d252016-05-11 10:29:41 -07005122 /**
5123 * Return the Electronic Serial Number.
5124 *
5125 * @param subId the subscription ID that this request applies to.
5126 * @return ESN or null if error.
5127 */
5128 @Override
5129 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005130 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005131 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005132
5133 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005134 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005135 if (phone == null) {
5136 return null;
5137 }
5138 String esn = null;
5139 try {
5140 esn = phone.getEsn();
5141 } catch (Exception e) {
5142 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5143 }
5144 return esn;
5145 } finally {
5146 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005147 }
Youhan Wang4001d252016-05-11 10:29:41 -07005148 }
5149
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005150 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005151 * Return the Preferred Roaming List Version.
5152 *
5153 * @param subId the subscription ID that this request applies to.
5154 * @return PRLVersion or null if error.
5155 */
5156 @Override
5157 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005158 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005159 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005160
5161 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005162 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005163 if (phone == null) {
5164 return null;
5165 }
5166 String cdmaPrlVersion = null;
5167 try {
5168 cdmaPrlVersion = phone.getCdmaPrlVersion();
5169 } catch (Exception e) {
5170 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5171 }
5172 return cdmaPrlVersion;
5173 } finally {
5174 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005175 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005176 }
5177
5178 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005179 * Get snapshot of Telephony histograms
5180 * @return List of Telephony histograms
5181 * @hide
5182 */
5183 @Override
5184 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5186 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005187
5188 final long identity = Binder.clearCallingIdentity();
5189 try {
5190 return RIL.getTelephonyRILTimingHistograms();
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005194 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005195
5196 /**
5197 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005198 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005199 * Require system privileges. In the future we may add this to carrier APIs.
5200 *
5201 * @return The number of carriers set successfully, should match length of carriers
5202 */
5203 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005204 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005205 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005206 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005207
Meng Wang9b7c4e92017-02-17 11:41:27 -08005208 if (carriers == null) {
5209 throw new NullPointerException("carriers cannot be null");
5210 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005211
Malcolm Chend965c8b2018-02-28 15:00:40 -08005212 final long identity = Binder.clearCallingIdentity();
5213 try {
5214 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005215 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5216 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005217 return retVal[0];
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005221 }
5222
5223 /**
5224 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005225 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005226 * Require system privileges. In the future we may add this to carrier APIs.
5227 *
5228 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5229 * means all carriers are allowed.
5230 */
5231 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005232 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005233 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005234 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005235
5236 final long identity = Binder.clearCallingIdentity();
5237 try {
5238 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005239 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5240 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005241 } finally {
5242 Binder.restoreCallingIdentity(identity);
5243 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005244 }
5245
fionaxu59545b42016-05-25 15:53:37 -07005246 /**
5247 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5248 * @param subId the subscription ID that this action applies to.
5249 * @param enabled control enable or disable metered apns.
5250 * {@hide}
5251 */
5252 @Override
5253 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5254 enforceModifyPermission();
5255 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005256
5257 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005258 if (phone == null) {
5259 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5260 return;
5261 }
5262 try {
5263 phone.carrierActionSetMeteredApnsEnabled(enabled);
5264 } catch (Exception e) {
5265 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005266 } finally {
5267 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005268 }
5269 }
5270
5271 /**
5272 * Action set from carrier signalling broadcast receivers to enable/disable radio
5273 * @param subId the subscription ID that this action applies to.
5274 * @param enabled control enable or disable radio.
5275 * {@hide}
5276 */
5277 @Override
5278 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5279 enforceModifyPermission();
5280 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005281
5282 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005283 if (phone == null) {
5284 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5285 return;
5286 }
5287 try {
5288 phone.carrierActionSetRadioEnabled(enabled);
5289 } catch (Exception e) {
5290 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005291 } finally {
5292 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005293 }
5294 }
5295
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005296 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005297 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5298 * network status based on which carrier apps could apply actions accordingly,
5299 * enable/disable default url handler for example.
5300 *
5301 * @param subId the subscription ID that this action applies to.
5302 * @param report control start/stop reporting the default network status.
5303 * {@hide}
5304 */
5305 @Override
5306 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5307 enforceModifyPermission();
5308 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005309
5310 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005311 if (phone == null) {
5312 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5313 return;
5314 }
5315 try {
5316 phone.carrierActionReportDefaultNetworkStatus(report);
5317 } catch (Exception e) {
5318 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005319 } finally {
5320 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005321 }
5322 }
5323
5324 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005325 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5326 * bug report is being generated.
5327 */
5328 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005329 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005330 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5331 != PackageManager.PERMISSION_GRANTED) {
5332 writer.println("Permission Denial: can't dump Phone from pid="
5333 + Binder.getCallingPid()
5334 + ", uid=" + Binder.getCallingUid()
5335 + "without permission "
5336 + android.Manifest.permission.DUMP);
5337 return;
5338 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005339 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005340 }
Jack Yueb89b242016-06-22 13:27:47 -07005341
Brad Ebingerdac2f002018-04-03 15:17:52 -07005342 @Override
5343 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5344 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5345 throws RemoteException {
5346 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5347 }
5348
Jack Yueb89b242016-06-22 13:27:47 -07005349 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005350 * Get aggregated video call data usage since boot.
5351 *
5352 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5353 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005354 * {@hide}
5355 */
5356 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005357 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005358 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5359 null);
5360
Malcolm Chend965c8b2018-02-28 15:00:40 -08005361 final long identity = Binder.clearCallingIdentity();
5362 try {
5363 // NetworkStatsService keeps tracking the active network interface and identity. It
5364 // records the delta with the corresponding network identity.
5365 // We just return the total video call data usage snapshot since boot.
5366 Phone phone = getPhone(subId);
5367 if (phone != null) {
5368 return phone.getVtDataUsage(perUidStats);
5369 }
5370 return null;
5371 } finally {
5372 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005373 }
Jack Yueb89b242016-06-22 13:27:47 -07005374 }
Jack Yu75ab2952016-07-08 14:29:33 -07005375
5376 /**
5377 * Policy control of data connection. Usually used when data limit is passed.
5378 * @param enabled True if enabling the data, otherwise disabling.
5379 * @param subId Subscription index
5380 * {@hide}
5381 */
5382 @Override
5383 public void setPolicyDataEnabled(boolean enabled, int subId) {
5384 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005385
5386 final long identity = Binder.clearCallingIdentity();
5387 try {
5388 Phone phone = getPhone(subId);
5389 if (phone != null) {
5390 phone.setPolicyDataEnabled(enabled);
5391 }
5392 } finally {
5393 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005394 }
5395 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005396
5397 /**
5398 * Get Client request stats
5399 * @return List of Client Request Stats
5400 * @hide
5401 */
5402 @Override
5403 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005405 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005406 return null;
5407 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005408 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005409
Malcolm Chend965c8b2018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 if (phone != null) {
5413 return phone.getClientRequestStats();
5414 }
5415
5416 return null;
5417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005420 }
5421
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005422 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005423 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005424 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005425 }
Jack Yueb4124c2017-02-16 15:32:43 -08005426
5427 /**
Grace Chen70990072017-03-24 17:21:30 -07005428 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005429 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005430 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005431 * @param state State of SIM (power down, power up, pass through)
5432 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5433 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5434 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005435 *
5436 **/
5437 @Override
Grace Chen70990072017-03-24 17:21:30 -07005438 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005439 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005440 Phone phone = PhoneFactory.getPhone(slotIndex);
5441
vagdevie435a3e2018-08-15 16:01:53 -07005442 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5443
Malcolm Chend965c8b2018-02-28 15:00:40 -08005444 final long identity = Binder.clearCallingIdentity();
5445 try {
5446 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005447 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005448 }
5449 } finally {
5450 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005451 }
5452 }
Shuo Qiandd210312017-04-12 22:11:33 +00005453
Tyler Gunn65d45c22017-06-05 11:22:26 -07005454 private boolean isUssdApiAllowed(int subId) {
5455 CarrierConfigManager configManager =
5456 (CarrierConfigManager) mPhone.getContext().getSystemService(
5457 Context.CARRIER_CONFIG_SERVICE);
5458 if (configManager == null) {
5459 return false;
5460 }
5461 PersistableBundle pb = configManager.getConfigForSubId(subId);
5462 if (pb == null) {
5463 return false;
5464 }
5465 return pb.getBoolean(
5466 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5467 }
5468
Shuo Qiandd210312017-04-12 22:11:33 +00005469 /**
5470 * Check if phone is in emergency callback mode
5471 * @return true if phone is in emergency callback mode
5472 * @param subId sub id
5473 */
goneil9c5f4872017-12-05 14:07:56 -08005474 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005475 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005476 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005477 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005478
5479 final long identity = Binder.clearCallingIdentity();
5480 try {
5481 if (phone != null) {
5482 return phone.isInEcm();
5483 } else {
5484 return false;
5485 }
5486 } finally {
5487 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005488 }
5489 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005490
5491 /**
5492 * Get the current signal strength information for the given subscription.
5493 * Because this information is not updated when the device is in a low power state
5494 * it should not be relied-upon to be current.
5495 * @param subId Subscription index
5496 * @return the most recent cached signal strength info from the modem
5497 */
5498 @Override
5499 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005500 final long identity = Binder.clearCallingIdentity();
5501 try {
5502 Phone p = getPhone(subId);
5503 if (p == null) {
5504 return null;
5505 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005506
Malcolm Chend965c8b2018-02-28 15:00:40 -08005507 return p.getSignalStrength();
5508 } finally {
5509 Binder.restoreCallingIdentity(identity);
5510 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005511 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005512
Pengquan Meng9140aec2018-08-22 14:49:57 -07005513 /**
chen xu907e5a22018-10-11 13:21:04 -07005514 * Get the current modem radio state for the given slot.
5515 * @param slotIndex slot index.
5516 * @param callingPackage the name of the package making the call.
5517 * @return the current radio power state from the modem
5518 */
5519 @Override
5520 public int getRadioPowerState(int slotIndex, String callingPackage) {
5521 Phone phone = PhoneFactory.getPhone(slotIndex);
5522 if (phone != null) {
5523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5524 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5525 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5526 }
5527
5528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 return phone.getRadioPowerState();
5531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
5534 }
5535 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5536 }
5537
5538 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005539 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5540 *
5541 * <p>Requires one of the following permissions:
5542 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5543 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5544 * privileges.
5545 *
5546 * @param subId subscription id
5547 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5548 * {@code false}.
5549 */
5550 @Override
5551 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005552 boolean isEnabled = false;
5553 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005554 try {
5555 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005556 null /* message */);
5557 Phone phone = getPhone(subId);
5558 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005559 } catch (Exception e) {
5560 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5561 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005562 } finally {
5563 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005564 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005565 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005566 }
5567
5568
5569 /**
5570 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5571 *
5572 * <p> Requires permission:
5573 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5574 * privileges.
5575 *
5576 * @param subId subscription id
5577 * @param isEnabled {@code true} means enable, {@code false} means disable.
5578 */
5579 @Override
5580 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5584 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005585
Pengquan Meng0c05b502018-09-06 09:59:22 -07005586 Phone phone = getPhone(subId);
5587 if (phone != null) {
5588 phone.setDataRoamingEnabled(isEnabled);
5589 }
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005592 }
5593 }
5594
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005595 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005596 public boolean isManualNetworkSelectionAllowed(int subId) {
5597 boolean isAllowed = true;
5598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5601 mApp, subId, "isManualNetworkSelectionAllowed");
5602 Phone phone = getPhone(subId);
5603 if (phone != null) {
5604 isAllowed = phone.isCspPlmnEnabled();
5605 }
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
5609 return isAllowed;
5610 }
5611
5612 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005613 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005614 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005615
Malcolm Chend965c8b2018-02-28 15:00:40 -08005616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5619 if (slots == null) {
5620 Rlog.i(LOG_TAG, "slots is null.");
5621 return null;
5622 }
5623
5624 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5625 for (int i = 0; i < slots.length; i++) {
5626 UiccSlot slot = slots[i];
5627 if (slot == null) {
5628 continue;
5629 }
5630
5631 String cardId;
5632 UiccCard card = slot.getUiccCard();
5633 if (card != null) {
5634 cardId = card.getCardId();
5635 } else {
5636 cardId = slot.getIccId();
5637 }
5638
5639 int cardState = 0;
5640 switch (slot.getCardState()) {
5641 case CARDSTATE_ABSENT:
5642 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5643 break;
5644 case CARDSTATE_PRESENT:
5645 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5646 break;
5647 case CARDSTATE_ERROR:
5648 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5649 break;
5650 case CARDSTATE_RESTRICTED:
5651 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5652 break;
5653 default:
5654 break;
5655
5656 }
5657
5658 infos[i] = new UiccSlotInfo(
5659 slot.isActive(),
5660 slot.isEuicc(),
5661 cardId,
5662 cardState,
5663 slot.getPhoneId(),
5664 slot.isExtendedApduSupported());
5665 }
5666 return infos;
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005669 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005670 }
5671
5672 @Override
5673 public boolean switchSlots(int[] physicalSlots) {
5674 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5679 } finally {
5680 Binder.restoreCallingIdentity(identity);
5681 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005682 }
Jack Yu4c988042018-02-27 15:30:01 -08005683
5684 @Override
5685 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5686 enforceModifyPermission();
5687 final Phone phone = getPhone(subId);
5688 if (phone == null) {
5689 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5690 return;
5691 }
5692
Malcolm Chend965c8b2018-02-28 15:00:40 -08005693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 phone.setRadioIndicationUpdateMode(filters, mode);
5696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
Jack Yu4c988042018-02-27 15:30:01 -08005699 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005700
5701 /**
goneil47ffb6e2018-04-06 15:40:58 -07005702 * A test API to reload the UICC profile.
5703 *
5704 * <p>Requires that the calling app has permission
5705 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5706 * @hide
5707 */
5708 @Override
5709 public void refreshUiccProfile(int subId) {
5710 enforceModifyPermission();
5711
5712 final long identity = Binder.clearCallingIdentity();
5713 try {
5714 Phone phone = getPhone(subId);
5715 if (phone == null) {
5716 return;
5717 }
5718 UiccCard uiccCard = phone.getUiccCard();
5719 if (uiccCard == null) {
5720 return;
5721 }
5722 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5723 if (uiccProfile == null) {
5724 return;
5725 }
5726 uiccProfile.refresh();
5727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
5730 }
5731
5732 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005733 * Returns false if the mobile data is disabled by default, otherwise return true.
5734 */
5735 private boolean getDefaultDataEnabled() {
5736 return "true".equalsIgnoreCase(
5737 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5738 }
5739
5740 /**
5741 * Returns true if the data roaming is enabled by default, i.e the system property
5742 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5743 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5744 */
5745 private boolean getDefaultDataRoamingEnabled(int subId) {
5746 final CarrierConfigManager configMgr = (CarrierConfigManager)
5747 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5748 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5749 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5750 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5751 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5752 return isDataRoamingEnabled;
5753 }
5754
5755 /**
5756 * Returns the default network type for the given {@code subId}, if the default network type is
5757 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5758 */
5759 private int getDefaultNetworkType(int subId) {
5760 return Integer.parseInt(
5761 TelephonyManager.getTelephonyProperty(
5762 mSubscriptionController.getPhoneId(subId),
5763 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5764 String.valueOf(Phone.PREFERRED_NT_MODE)));
5765 }
fionaxua13278b2018-03-21 00:08:13 -07005766
5767 @Override
5768 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5769 gid1, String gid2, String plmn, String spn) {
5770 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005771
5772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 final Phone phone = getPhone(subId);
5775 if (phone == null) {
5776 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5777 return;
5778 }
5779 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5780 } finally {
5781 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005782 }
fionaxua13278b2018-03-21 00:08:13 -07005783 }
5784
5785 @Override
5786 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005787 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005788
5789 final long identity = Binder.clearCallingIdentity();
5790 try {
5791 final Phone phone = getPhone(subId);
5792 if (phone == null) {
5793 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5794 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5795 }
5796 return phone.getCarrierIdListVersion();
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005799 }
fionaxua13278b2018-03-21 00:08:13 -07005800 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005801
5802 @Override
5803 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5804 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5805 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5806 return -1;
5807 }
5808
5809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
5814 }
5815 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005816
5817 @Override
5818 public int getCdmaRoamingMode(int subId) {
5819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5820 mApp, subId, "getCdmaRoamingMode");
5821
5822 final long identity = Binder.clearCallingIdentity();
5823 try {
5824 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5825 } finally {
5826 Binder.restoreCallingIdentity(identity);
5827 }
5828 }
5829
5830 @Override
5831 public boolean setCdmaRoamingMode(int subId, int mode) {
5832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5833 mApp, subId, "setCdmaRoamingMode");
5834
5835 final long identity = Binder.clearCallingIdentity();
5836 try {
5837 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5838 } finally {
5839 Binder.restoreCallingIdentity(identity);
5840 }
5841 }
5842
5843 @Override
5844 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5846 mApp, subId, "setCdmaSubscriptionMode");
5847
5848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5851 } finally {
5852 Binder.restoreCallingIdentity(identity);
5853 }
5854 }
chen xu7ee67862018-10-30 22:27:10 -07005855
sqian2fff4a32018-11-05 14:18:37 -08005856 private void ensureUserRunning(int userId) {
5857 if (!mUserManager.isUserRunning(userId)) {
5858 throw new IllegalStateException("User " + userId + " does not exist or not running");
5859 }
5860 }
5861
5862 /**
5863 * Returns a list of SMS apps on a given user.
5864 *
5865 * Only the shell user (UID 2000 or 0) can call it.
5866 * Target user must be running.
5867 */
5868 @Override
5869 public String[] getSmsApps(int userId) {
5870 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5871 ensureUserRunning(userId);
5872
5873 final Collection<SmsApplicationData> apps =
5874 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5875
5876 String[] ret = new String[apps.size()];
5877 int i = 0;
5878 for (SmsApplicationData app : apps) {
5879 ret[i++] = app.mPackageName;
5880 }
5881 return ret;
5882 }
5883
5884 /**
5885 * Returns the default SMS app package name on a given user.
5886 *
5887 * Only the shell user (UID 2000 or 0) can call it.
5888 * Target user must be running.
5889 */
5890 @Override
5891 public String getDefaultSmsApp(int userId) {
5892 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5893 ensureUserRunning(userId);
5894
5895 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5896 /* updateIfNeeded= */ true, userId);
5897 return cn == null ? null : cn.getPackageName();
5898 }
5899
5900 /**
5901 * Set a package as the default SMS app on a given user.
5902 *
5903 * Only the shell user (UID 2000 or 0) can call it.
5904 * Target user must be running.
5905 */
5906 @Override
5907 public void setDefaultSmsApp(int userId, String packageName) {
5908 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5909 ensureUserRunning(userId);
5910
5911 boolean found = false;
5912 for (String pkg : getSmsApps(userId)) {
5913 if (TextUtils.equals(packageName, pkg)) {
5914 found = true;
5915 break;
5916 }
5917 }
5918 if (!found) {
5919 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5920 }
5921
5922 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5923 }
5924
chen xu7ee67862018-10-30 22:27:10 -07005925 @Override
sqian04b86072018-11-07 14:02:21 -08005926 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5927 String callingPackage) {
5928 // TODO connect with internal content
5929 return null;
5930 }
5931
5932 @Override
5933 public boolean isCurrentEmergencyNumber(String number) {
5934 // TODO connect with internal content
5935 return false;
5936 }
5937
5938 @Override
chen xu7ee67862018-10-30 22:27:10 -07005939 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5940 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5941 Phone phone = getPhone(subId);
5942 if (phone == null) {
5943 return null;
5944 }
5945 final long identity = Binder.clearCallingIdentity();
5946 try {
5947 UiccProfile profile = UiccController.getInstance()
5948 .getUiccProfileForPhone(phone.getPhoneId());
5949 if (profile != null) {
5950 return profile.getCertsFromCarrierPrivilegeAccessRules();
5951 }
5952 } finally {
5953 Binder.restoreCallingIdentity(identity);
5954 }
5955 return null;
5956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005957}