blob: dfea90c11847335f9ab438a4b6c69a1b7245fead [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070028import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080043import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070046import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070047import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070049import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070050import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080052import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070053import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080054import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080055import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070056import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070057import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070059import android.telephony.CellInfoGsm;
60import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070061import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070063import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070064import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080065import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070066import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080067import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070068import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070069import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080072import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070073import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080074import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070076import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000078import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070081import android.telephony.cdma.CdmaCellLocation;
calvinpaneed9ae82018-11-01 19:43:06 +080082import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070083import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070084import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080085import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070086import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080087import android.telephony.ims.aidl.IImsMmTelFeature;
88import android.telephony.ims.aidl.IImsRcsFeature;
89import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070090import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080091import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080093import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080095import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080097
Brad Ebinger4c460712018-10-01 10:40:55 -070098import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070099import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800100import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700101import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700102import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700103import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800104import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700105import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800109import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700110import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100111import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700112import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700113import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700115import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800116import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700117import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700118import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700119import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700120import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700121import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700122import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800123import com.android.internal.telephony.SmsApplication;
124import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800125import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800126import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700127import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.uicc.IccIoResult;
129import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800130import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700131import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800132import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700133import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800134import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000135import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700136import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800137import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700138import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800139import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700140import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700141import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700143import java.io.FileDescriptor;
144import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800145import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800147import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800148import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800149import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100150import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800151import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152
153/**
154 * Implementation of the ITelephony interface.
155 */
Santos Cordon117fee72014-05-16 17:56:12 -0700156public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157 private static final String LOG_TAG = "PhoneInterfaceManager";
158 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
159 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800160 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161
162 // Message codes used with mMainThreadHandler
163 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700164 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
165 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166 private static final int CMD_OPEN_CHANNEL = 9;
167 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
168 private static final int CMD_CLOSE_CHANNEL = 11;
169 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800170 private static final int CMD_NV_READ_ITEM = 13;
171 private static final int EVENT_NV_READ_ITEM_DONE = 14;
172 private static final int CMD_NV_WRITE_ITEM = 15;
173 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
174 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
175 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700176 private static final int CMD_RESET_MODEM_CONFIG = 19;
177 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800178 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
179 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
180 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
181 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800182 private static final int CMD_SEND_ENVELOPE = 25;
183 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000184 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
185 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700186 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
187 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
188 private static final int CMD_EXCHANGE_SIM_IO = 31;
189 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800190 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
191 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700192 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
193 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700194 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
195 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700196 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
197 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
198 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
199 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700200 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
201 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
202 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
203 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700204 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800205 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
206 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000207 private static final int CMD_SWITCH_SLOTS = 50;
208 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700209 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
210 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
211 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
212 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
213 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
214 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
215 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
216 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700217 private static final int CMD_GET_ALL_CELL_INFO = 60;
218 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
219 private static final int CMD_GET_CELL_LOCATION = 62;
220 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700221 private static final int CMD_MODEM_REBOOT = 64;
222 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700223 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
224 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800226 // Parameters of select command.
227 private static final int SELECT_COMMAND = 0xA4;
228 private static final int SELECT_P1 = 0x04;
229 private static final int SELECT_P2 = 0;
230 private static final int SELECT_P3 = 0x10;
231
Pengquan Meng85728fb2018-03-12 16:31:21 -0700232 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
233 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
234 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
235
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236 /** The singleton instance. */
237 private static PhoneInterfaceManager sInstance;
238
Wink Saville3ab207e2014-11-20 13:07:20 -0800239 private PhoneGlobals mApp;
240 private Phone mPhone;
241 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700242 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800243 private AppOpsManager mAppOps;
244 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800245 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800246 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700247 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
Derek Tan97ebb422014-09-05 16:55:38 -0700249 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
250 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800251 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700252
Derek Tan740e1672017-06-27 14:56:27 -0700253 // The AID of ISD-R.
254 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
255
yinxub1bed742017-04-17 11:45:04 -0700256 private NetworkScanRequestTracker mNetworkScanRequestTracker;
257
David Kelly5e06a7f2018-03-12 14:10:59 +0000258 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
259 private static final int MANUFACTURER_CODE_LENGTH = 8;
260
Derek Tan89e89d42014-07-08 17:00:10 -0700261 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700262 * A request object to use for transmitting data to an ICC.
263 */
264 private static final class IccAPDUArgument {
265 public int channel, cla, command, p1, p2, p3;
266 public String data;
267
268 public IccAPDUArgument(int channel, int cla, int command,
269 int p1, int p2, int p3, String data) {
270 this.channel = channel;
271 this.cla = cla;
272 this.command = command;
273 this.p1 = p1;
274 this.p2 = p2;
275 this.p3 = p3;
276 this.data = data;
277 }
278 }
279
280 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700281 * A request object to use for transmitting data to an ICC.
282 */
283 private static final class ManualNetworkSelectionArgument {
284 public OperatorInfo operatorInfo;
285 public boolean persistSelection;
286
287 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
288 this.operatorInfo = operatorInfo;
289 this.persistSelection = persistSelection;
290 }
291 }
292
293 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
295 * request after sending. The main thread will notify the request when it is complete.
296 */
297 private static final class MainThreadRequest {
298 /** The argument to use for the request */
299 public Object argument;
300 /** The result of the request that is run on the main thread */
301 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800302 // The subscriber id that this request applies to. Defaults to
303 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
304 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305
Nathan Harold92bed182018-10-12 18:16:49 -0700306 // In cases where subId is unavailable, the caller needs to specify the phone.
307 public Phone phone;
308
vagdevie435a3e2018-08-15 16:01:53 -0700309 public WorkSource workSource;
310
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311 public MainThreadRequest(Object argument) {
312 this.argument = argument;
313 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800314
Nathan Harold92bed182018-10-12 18:16:49 -0700315 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
316 this.argument = argument;
317 if (phone != null) {
318 this.phone = phone;
319 }
320 this.workSource = workSource;
321 }
322
vagdevie435a3e2018-08-15 16:01:53 -0700323 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800325 if (subId != null) {
326 this.subId = subId;
327 }
vagdevie435a3e2018-08-15 16:01:53 -0700328 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 }
331
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800332 private static final class IncomingThirdPartyCallArgs {
333 public final ComponentName component;
334 public final String callId;
335 public final String callerDisplayName;
336
337 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
338 String callerDisplayName) {
339 this.component = component;
340 this.callId = callId;
341 this.callerDisplayName = callerDisplayName;
342 }
343 }
344
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 /**
346 * A handler that processes messages on the main thread in the phone process. Since many
347 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
348 * inbound binder threads to the main thread in the phone process. The Binder thread
349 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
350 * on, which will be notified when the operation completes and will contain the result of the
351 * request.
352 *
353 * <p>If a MainThreadRequest object is provided in the msg.obj field,
354 * note that request.result must be set to something non-null for the calling thread to
355 * unblock.
356 */
357 private final class MainThreadHandler extends Handler {
358 @Override
359 public void handleMessage(Message msg) {
360 MainThreadRequest request;
361 Message onCompleted;
362 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800363 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700364 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
366 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700367 case CMD_HANDLE_USSD_REQUEST: {
368 request = (MainThreadRequest) msg.obj;
369 final Phone phone = getPhoneFromRequest(request);
370 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
371 String ussdRequest = ussdObject.first;
372 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700373
Pengquan Meng0c05b502018-09-06 09:59:22 -0700374 if (!isUssdApiAllowed(request.subId)) {
375 // Carrier does not support use of this API, return failure.
376 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
377 UssdResponse response = new UssdResponse(ussdRequest, null);
378 Bundle returnData = new Bundle();
379 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
380 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700381
Pengquan Meng0c05b502018-09-06 09:59:22 -0700382 request.result = true;
383 notifyRequester(request);
384 return;
385 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700386
Pengquan Meng0c05b502018-09-06 09:59:22 -0700387 try {
388 request.result = phone != null
389 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
390 } catch (CallStateException cse) {
391 request.result = false;
392 }
393 // Wake up the requesting thread
394 notifyRequester(request);
395 break;
pkanwar32d516d2016-10-14 19:37:38 -0700396 }
397
Yorke Lee716f67e2015-06-17 15:39:16 -0700398 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700400 final Phone phone = getPhoneFromRequest(request);
401 request.result = phone != null ?
402 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
403 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700405 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700409 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700410 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800412 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700413 if (uiccCard == null) {
414 loge("iccTransmitApduLogicalChannel: No UICC");
415 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700416 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
419 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700420 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 iccArgument.channel, iccArgument.cla, iccArgument.command,
422 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700424 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 break;
426
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 ar = (AsyncResult) msg.obj;
429 request = (MainThreadRequest) ar.userObj;
430 if (ar.exception == null && ar.result != null) {
431 request.result = ar.result;
432 } else {
433 request.result = new IccIoResult(0x6F, 0, (byte[])null);
434 if (ar.result == null) {
435 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800436 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800438 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 } else {
440 loge("iccTransmitApduLogicalChannel: Unknown exception");
441 }
442 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700443 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 break;
445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
447 request = (MainThreadRequest) msg.obj;
448 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 if (uiccCard == null) {
451 loge("iccTransmitApduBasicChannel: No UICC");
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 } else {
455 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
456 request);
457 uiccCard.iccTransmitApduBasicChannel(
458 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
459 iccArgument.p3, iccArgument.data, onCompleted);
460 }
461 break;
462
463 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
464 ar = (AsyncResult) msg.obj;
465 request = (MainThreadRequest) ar.userObj;
466 if (ar.exception == null && ar.result != null) {
467 request.result = ar.result;
468 } else {
469 request.result = new IccIoResult(0x6F, 0, (byte[])null);
470 if (ar.result == null) {
471 loge("iccTransmitApduBasicChannel: Empty response");
472 } else if (ar.exception instanceof CommandException) {
473 loge("iccTransmitApduBasicChannel: CommandException: " +
474 ar.exception);
475 } else {
476 loge("iccTransmitApduBasicChannel: Unknown exception");
477 }
478 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700479 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 break;
481
482 case CMD_EXCHANGE_SIM_IO:
483 request = (MainThreadRequest) msg.obj;
484 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800485 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 if (uiccCard == null) {
487 loge("iccExchangeSimIO: No UICC");
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700489 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 } else {
491 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
492 request);
493 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
494 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
495 iccArgument.data, onCompleted);
496 }
497 break;
498
499 case EVENT_EXCHANGE_SIM_IO_DONE:
500 ar = (AsyncResult) msg.obj;
501 request = (MainThreadRequest) ar.userObj;
502 if (ar.exception == null && ar.result != null) {
503 request.result = ar.result;
504 } else {
505 request.result = new IccIoResult(0x6f, 0, (byte[])null);
506 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700507 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 break;
509
Derek Tan4d5e5c12014-02-04 11:54:58 -0800510 case CMD_SEND_ENVELOPE:
511 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800512 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700513 if (uiccCard == null) {
514 loge("sendEnvelopeWithStatus: No UICC");
515 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700517 } else {
518 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
519 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
520 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800521 break;
522
523 case EVENT_SEND_ENVELOPE_DONE:
524 ar = (AsyncResult) msg.obj;
525 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700526 if (ar.exception == null && ar.result != null) {
527 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800528 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
530 if (ar.result == null) {
531 loge("sendEnvelopeWithStatus: Empty response");
532 } else if (ar.exception instanceof CommandException) {
533 loge("sendEnvelopeWithStatus: CommandException: " +
534 ar.exception);
535 } else {
536 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
537 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700539 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 break;
541
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 case CMD_OPEN_CHANNEL:
543 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800544 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800545 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 if (uiccCard == null) {
547 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800548 request.result = new IccOpenLogicalChannelResponse(-1,
549 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700550 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 } else {
552 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800553 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
554 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 break;
557
558 case EVENT_OPEN_CHANNEL_DONE:
559 ar = (AsyncResult) msg.obj;
560 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 int[] result = (int[]) ar.result;
564 int channelId = result[0];
565 byte[] selectResponse = null;
566 if (result.length > 1) {
567 selectResponse = new byte[result.length - 1];
568 for (int i = 1; i < result.length; ++i) {
569 selectResponse[i - 1] = (byte) result[i];
570 }
571 }
572 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700573 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 if (ar.result == null) {
576 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700578 if (ar.exception != null) {
579 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
580 }
581
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700583 if (ar.exception instanceof CommandException) {
584 CommandException.Error error =
585 ((CommandException) (ar.exception)).getCommandError();
586 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700587 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700588 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700589 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 }
591 }
592 openChannelResp = new IccOpenLogicalChannelResponse(
593 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700595 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 break;
598
599 case CMD_CLOSE_CHANNEL:
600 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800601 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 if (uiccCard == null) {
603 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900604 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700606 } else {
607 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
608 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
609 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 break;
611
612 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800613 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
614 break;
615
616 case CMD_NV_READ_ITEM:
617 request = (MainThreadRequest) msg.obj;
618 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700619 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800620 break;
621
622 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 ar = (AsyncResult) msg.obj;
624 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800625 if (ar.exception == null && ar.result != null) {
626 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800628 request.result = "";
629 if (ar.result == null) {
630 loge("nvReadItem: Empty response");
631 } else if (ar.exception instanceof CommandException) {
632 loge("nvReadItem: CommandException: " +
633 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800635 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 }
637 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 break;
640
Jake Hambye994d462014-02-03 13:10:13 -0800641 case CMD_NV_WRITE_ITEM:
642 request = (MainThreadRequest) msg.obj;
643 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
644 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700645 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
646 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800647 break;
648
649 case EVENT_NV_WRITE_ITEM_DONE:
650 handleNullReturnEvent(msg, "nvWriteItem");
651 break;
652
653 case CMD_NV_WRITE_CDMA_PRL:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
656 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
657 break;
658
659 case EVENT_NV_WRITE_CDMA_PRL_DONE:
660 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
661 break;
662
chen xu1cc0abe2018-10-26 17:39:23 -0700663 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800664 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700665 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
666 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800667 break;
668
chen xu1cc0abe2018-10-26 17:39:23 -0700669 case EVENT_RESET_MODEM_CONFIG_DONE:
670 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
Jake Hamby7c27be32014-03-03 13:25:59 -0800673 case CMD_GET_PREFERRED_NETWORK_TYPE:
674 request = (MainThreadRequest) msg.obj;
675 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700676 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800677 break;
678
679 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
682 if (ar.exception == null && ar.result != null) {
683 request.result = ar.result; // Integer
684 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800685 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800686 if (ar.result == null) {
687 loge("getPreferredNetworkType: Empty response");
688 } else if (ar.exception instanceof CommandException) {
689 loge("getPreferredNetworkType: CommandException: " +
690 ar.exception);
691 } else {
692 loge("getPreferredNetworkType: Unknown exception");
693 }
694 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700695 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800696 break;
697
698 case CMD_SET_PREFERRED_NETWORK_TYPE:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
701 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700702 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800703 break;
704
705 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
706 handleNullReturnEvent(msg, "setPreferredNetworkType");
707 break;
708
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000709 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
710 request = (MainThreadRequest)msg.obj;
711 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700712 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000713 break;
714
715 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
716 ar = (AsyncResult)msg.obj;
717 request = (MainThreadRequest)ar.userObj;
718 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700719 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000720 break;
721
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800722 case CMD_SET_VOICEMAIL_NUMBER:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
725 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800726 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
727 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800728 break;
729
730 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
731 handleNullReturnEvent(msg, "setVoicemailNumber");
732 break;
733
Stuart Scott54788802015-03-30 13:18:01 -0700734 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
737 request);
738 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
739 break;
740
741 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
742 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
743 break;
744
Shishir Agrawal302c8692015-06-19 13:49:39 -0700745 case CMD_PERFORM_NETWORK_SCAN:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
748 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
749 break;
750
751 case EVENT_PERFORM_NETWORK_SCAN_DONE:
752 ar = (AsyncResult) msg.obj;
753 request = (MainThreadRequest) ar.userObj;
754 CellNetworkScanResult cellScanResult;
755 if (ar.exception == null && ar.result != null) {
756 cellScanResult = new CellNetworkScanResult(
757 CellNetworkScanResult.STATUS_SUCCESS,
758 (List<OperatorInfo>) ar.result);
759 } else {
760 if (ar.result == null) {
761 loge("getCellNetworkScanResults: Empty response");
762 }
763 if (ar.exception != null) {
764 loge("getCellNetworkScanResults: Exception: " + ar.exception);
765 }
766 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
767 if (ar.exception instanceof CommandException) {
768 CommandException.Error error =
769 ((CommandException) (ar.exception)).getCommandError();
770 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
771 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
772 } else if (error == CommandException.Error.GENERIC_FAILURE) {
773 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
774 }
775 }
776 cellScanResult = new CellNetworkScanResult(errorCode, null);
777 }
778 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700779 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700780 break;
781
782 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
783 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700784 ManualNetworkSelectionArgument selArg =
785 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700786 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
787 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700788 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
789 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 break;
791
792 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700793 ar = (AsyncResult) msg.obj;
794 request = (MainThreadRequest) ar.userObj;
795 if (ar.exception == null) {
796 request.result = true;
797 } else {
798 request.result = false;
799 loge("setNetworkSelectionModeManual " + ar.exception);
800 }
801 notifyRequester(request);
802 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700803 break;
804
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700805 case CMD_GET_MODEM_ACTIVITY_INFO:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700808 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700809 break;
810
811 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
812 ar = (AsyncResult) msg.obj;
813 request = (MainThreadRequest) ar.userObj;
814 if (ar.exception == null && ar.result != null) {
815 request.result = ar.result;
816 } else {
817 if (ar.result == null) {
818 loge("queryModemActivityInfo: Empty response");
819 } else if (ar.exception instanceof CommandException) {
820 loge("queryModemActivityInfo: CommandException: " +
821 ar.exception);
822 } else {
823 loge("queryModemActivityInfo: Unknown exception");
824 }
825 }
Amit Mahajand4766222016-01-28 15:28:28 -0800826 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
827 if (request.result == null) {
828 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
829 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700830 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700831 break;
832
Meng Wang1a7c35a2016-05-05 20:56:15 -0700833 case CMD_SET_ALLOWED_CARRIERS:
834 request = (MainThreadRequest) msg.obj;
835 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
836 mPhone.setAllowedCarriers(
837 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700838 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700839 break;
840
841 case EVENT_SET_ALLOWED_CARRIERS_DONE:
842 ar = (AsyncResult) msg.obj;
843 request = (MainThreadRequest) ar.userObj;
844 if (ar.exception == null && ar.result != null) {
845 request.result = ar.result;
846 } else {
847 if (ar.result == null) {
848 loge("setAllowedCarriers: Empty response");
849 } else if (ar.exception instanceof CommandException) {
850 loge("setAllowedCarriers: CommandException: " +
851 ar.exception);
852 } else {
853 loge("setAllowedCarriers: Unknown exception");
854 }
855 }
856 // Result cannot be null. Return -1 on error.
857 if (request.result == null) {
858 request.result = new int[]{-1};
859 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700860 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700861 break;
862
863 case CMD_GET_ALLOWED_CARRIERS:
864 request = (MainThreadRequest) msg.obj;
865 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700866 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700867 break;
868
869 case EVENT_GET_ALLOWED_CARRIERS_DONE:
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null && ar.result != null) {
873 request.result = ar.result;
874 } else {
875 if (ar.result == null) {
876 loge("getAllowedCarriers: Empty response");
877 } else if (ar.exception instanceof CommandException) {
878 loge("getAllowedCarriers: CommandException: " +
879 ar.exception);
880 } else {
881 loge("getAllowedCarriers: Unknown exception");
882 }
883 }
884 // Result cannot be null. Return empty list of CarrierIdentifier.
885 if (request.result == null) {
886 request.result = new ArrayList<CarrierIdentifier>(0);
887 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700888 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 break;
890
Nathan Haroldb3014052017-01-25 15:57:32 -0800891 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result;
896 } else {
897 request.result = new IllegalArgumentException(
898 "Failed to retrieve Forbidden Plmns");
899 if (ar.result == null) {
900 loge("getForbiddenPlmns: Empty response");
901 } else {
902 loge("getForbiddenPlmns: Unknown exception");
903 }
904 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700905 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800906 break;
907
908 case CMD_GET_FORBIDDEN_PLMNS:
909 request = (MainThreadRequest) msg.obj;
910 uiccCard = getUiccCardFromRequest(request);
911 if (uiccCard == null) {
912 loge("getForbiddenPlmns() UiccCard is null");
913 request.result = new IllegalArgumentException(
914 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700915 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800916 break;
917 }
918 Integer appType = (Integer) request.argument;
919 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
920 if (uiccApp == null) {
921 loge("getForbiddenPlmns() no app with specified type -- "
922 + appType);
923 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700924 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800925 break;
926 } else {
927 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
928 + " specified type -- " + appType);
929 }
930 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
931 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
932 onCompleted);
933 break;
934
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000935 case CMD_SWITCH_SLOTS:
936 request = (MainThreadRequest) msg.obj;
937 int[] physicalSlots = (int[]) request.argument;
938 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
939 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
940 break;
941
942 case EVENT_SWITCH_SLOTS_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700946 notifyRequester(request);
947 break;
948 case CMD_GET_NETWORK_SELECTION_MODE:
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
951 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
952 break;
953
954 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
955 ar = (AsyncResult) msg.obj;
956 request = (MainThreadRequest) ar.userObj;
957 if (ar.exception != null) {
958 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
959 } else {
960 int mode = ((int[]) ar.result)[0];
961 if (mode == 0) {
962 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
963 } else {
964 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
965 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000966 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700967 notifyRequester(request);
968 break;
969 case CMD_GET_CDMA_ROAMING_MODE:
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
972 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
973 break;
974 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
975 ar = (AsyncResult) msg.obj;
976 request = (MainThreadRequest) ar.userObj;
977 if (ar.exception != null) {
978 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
979 } else {
980 request.result = ((int[]) ar.result)[0];
981 }
982 notifyRequester(request);
983 break;
984 case CMD_SET_CDMA_ROAMING_MODE:
985 request = (MainThreadRequest) msg.obj;
986 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
987 int mode = (int) request.argument;
988 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
989 break;
990 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
993 request.result = ar.exception == null;
994 notifyRequester(request);
995 break;
996 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
997 request = (MainThreadRequest) msg.obj;
998 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
999 int subscriptionMode = (int) request.argument;
1000 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1001 break;
1002 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
1005 request.result = ar.exception == null;
1006 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001007 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001008 case CMD_GET_ALL_CELL_INFO:
1009 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001010 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001011 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001012 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001013 case EVENT_GET_ALL_CELL_INFO_DONE:
1014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001016 // If a timeout occurs, the response will be null
1017 request.result = (ar.exception == null && ar.result != null)
1018 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001019 synchronized (request) {
1020 request.notifyAll();
1021 }
1022 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001023 case CMD_REQUEST_CELL_INFO_UPDATE:
1024 request = (MainThreadRequest) msg.obj;
1025 request.phone.requestCellInfoUpdate(request.workSource,
1026 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1027 break;
1028 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1032 try {
1033 if (ar.exception != null) {
1034 // something went wrong... the response is null
1035 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1036 cb.onCellInfo(null);
1037 } else if (ar.result == null) {
1038 // timeout occurred, so force the result to non-null "empty"
1039 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1040 cb.onCellInfo(new ArrayList<CellInfo>());
1041 } else {
1042 // use the result as returned
1043 cb.onCellInfo((List<CellInfo>) ar.result);
1044 }
1045 } catch (RemoteException re) {
1046 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1047 }
1048 break;
1049 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 request = (MainThreadRequest) msg.obj;
1051 WorkSource ws = (WorkSource) request.argument;
1052 Phone phone = getPhoneFromRequest(request);
1053 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1054 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001055 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 if (ar.exception == null) {
1059 request.result = ar.result;
1060 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1063 ? new CdmaCellLocation() : new GsmCellLocation();
1064 }
1065
1066 synchronized (request) {
1067 request.notifyAll();
1068 }
1069 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001070 case CMD_MODEM_REBOOT:
1071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1073 mPhone.rebootModem(onCompleted);
1074 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001075 case EVENT_CMD_MODEM_REBOOT_DONE:
1076 handleNullReturnEvent(msg, "rebootModem");
1077 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 default:
1079 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1080 break;
1081 }
1082 }
Jake Hambye994d462014-02-03 13:10:13 -08001083
Pengquan Meng0c05b502018-09-06 09:59:22 -07001084 private void notifyRequester(MainThreadRequest request) {
1085 synchronized (request) {
1086 request.notifyAll();
1087 }
1088 }
1089
Jake Hambye994d462014-02-03 13:10:13 -08001090 private void handleNullReturnEvent(Message msg, String command) {
1091 AsyncResult ar = (AsyncResult) msg.obj;
1092 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1093 if (ar.exception == null) {
1094 request.result = true;
1095 } else {
1096 request.result = false;
1097 if (ar.exception instanceof CommandException) {
1098 loge(command + ": CommandException: " + ar.exception);
1099 } else {
1100 loge(command + ": Unknown exception");
1101 }
1102 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001103 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001105 }
1106
1107 /**
1108 * Posts the specified command to be executed on the main thread,
1109 * waits for the request to complete, and returns the result.
1110 * @see #sendRequestAsync
1111 */
1112 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001113 return sendRequest(
1114 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001115 }
1116
1117 /**
1118 * Posts the specified command to be executed on the main thread,
1119 * waits for the request to complete, and returns the result.
1120 * @see #sendRequestAsync
1121 */
1122 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1123 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001124 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001125 }
1126
1127 /**
1128 * Posts the specified command to be executed on the main thread,
1129 * waits for the request to complete, and returns the result.
1130 * @see #sendRequestAsync
1131 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001132 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001133 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001134 }
1135
1136 /**
1137 * Posts the specified command to be executed on the main thread,
1138 * waits for the request to complete, and returns the result.
1139 * @see #sendRequestAsync
1140 */
Nathan Harold92bed182018-10-12 18:16:49 -07001141 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1142 return sendRequest(command, argument, subId, null, workSource);
1143 }
1144
1145 /**
1146 * Posts the specified command to be executed on the main thread,
1147 * waits for the request to complete, and returns the result.
1148 * @see #sendRequestAsync
1149 */
1150 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1151 return sendRequest(
1152 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1153 }
1154
1155 /**
1156 * Posts the specified command to be executed on the main thread,
1157 * waits for the request to complete, and returns the result.
1158 * @see #sendRequestAsync
1159 */
1160 private Object sendRequest(
1161 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1163 throw new RuntimeException("This method will deadlock if called from the main thread.");
1164 }
1165
Nathan Harold92bed182018-10-12 18:16:49 -07001166 MainThreadRequest request = null;
1167 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1168 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1169 } else if (phone != null) {
1170 request = new MainThreadRequest(argument, phone, workSource);
1171 } else {
1172 request = new MainThreadRequest(argument, subId, workSource);
1173 }
1174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 Message msg = mMainThreadHandler.obtainMessage(command, request);
1176 msg.sendToTarget();
1177
1178 // Wait for the request to complete
1179 synchronized (request) {
1180 while (request.result == null) {
1181 try {
1182 request.wait();
1183 } catch (InterruptedException e) {
1184 // Do nothing, go back and wait until the request is complete
1185 }
1186 }
1187 }
1188 return request.result;
1189 }
1190
1191 /**
1192 * Asynchronous ("fire and forget") version of sendRequest():
1193 * Posts the specified command to be executed on the main thread, and
1194 * returns immediately.
1195 * @see #sendRequest
1196 */
1197 private void sendRequestAsync(int command) {
1198 mMainThreadHandler.sendEmptyMessage(command);
1199 }
1200
1201 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001202 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001203 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001204 */
1205 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001206 sendRequestAsync(command, argument, null, null);
1207 }
1208
1209 /**
1210 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1211 * @see {@link #sendRequest(int,Object)}
1212 */
1213 private void sendRequestAsync(
1214 int command, Object argument, Phone phone, WorkSource workSource) {
1215 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001216 Message msg = mMainThreadHandler.obtainMessage(command, request);
1217 msg.sendToTarget();
1218 }
1219
1220 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 * Initialize the singleton PhoneInterfaceManager instance.
1222 * This is only done once, at startup, from PhoneApp.onCreate().
1223 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001224 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225 synchronized (PhoneInterfaceManager.class) {
1226 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001227 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 } else {
1229 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1230 }
1231 return sInstance;
1232 }
1233 }
1234
1235 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001236 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237 mApp = app;
1238 mPhone = phone;
1239 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001240 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1242 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001243 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001244 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001245 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001246 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001247 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001248
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 publish();
1250 }
1251
1252 private void publish() {
1253 if (DBG) log("publish: " + this);
1254
1255 ServiceManager.addService("phone", this);
1256 }
1257
Stuart Scott584921c2015-01-15 17:10:34 -08001258 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001259 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1260 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001261 }
1262
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001263 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1264 Phone phone = getPhoneFromRequest(request);
1265 return phone == null ? null :
1266 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1267 }
1268
Wink Saville36469e72014-06-11 15:17:00 -07001269 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001270 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001271 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273
1274 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001275 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001276 }
1277
Wink Savilleb564aae2014-10-23 10:18:09 -07001278 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 if (DBG) log("dial: " + number);
1280 // No permission check needed here: This is just a wrapper around the
1281 // ACTION_DIAL intent, which is available to any app since it puts up
1282 // the UI before it does anything.
1283
Malcolm Chend965c8b2018-02-28 15:00:40 -08001284 final long identity = Binder.clearCallingIdentity();
1285 try {
1286 String url = createTelUrl(number);
1287 if (url == null) {
1288 return;
1289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290
Malcolm Chend965c8b2018-02-28 15:00:40 -08001291 // PENDING: should we just silently fail if phone is offhook or ringing?
1292 PhoneConstants.State state = mCM.getState(subId);
1293 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1294 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1295 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1296 mApp.startActivity(intent);
1297 }
1298 } finally {
1299 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 }
1301 }
1302
1303 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001304 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001305 }
1306
Wink Savilleb564aae2014-10-23 10:18:09 -07001307 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 if (DBG) log("call: " + number);
1309
1310 // This is just a wrapper around the ACTION_CALL intent, but we still
1311 // need to do a permission check since we're calling startActivity()
1312 // from the context of the phone app.
1313 enforceCallPermission();
1314
1315 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1316 != AppOpsManager.MODE_ALLOWED) {
1317 return;
1318 }
1319
Malcolm Chend965c8b2018-02-28 15:00:40 -08001320 final long identity = Binder.clearCallingIdentity();
1321 try {
1322 String url = createTelUrl(number);
1323 if (url == null) {
1324 return;
1325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326
Malcolm Chend965c8b2018-02-28 15:00:40 -08001327 boolean isValid = false;
1328 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1329 if (slist != null) {
1330 for (SubscriptionInfo subInfoRecord : slist) {
1331 if (subInfoRecord.getSubscriptionId() == subId) {
1332 isValid = true;
1333 break;
1334 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001335 }
Wink Saville08874612014-08-31 19:19:58 -07001336 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001337 if (!isValid) {
1338 return;
1339 }
Wink Saville08874612014-08-31 19:19:58 -07001340
Malcolm Chend965c8b2018-02-28 15:00:40 -08001341 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1342 intent.putExtra(SUBSCRIPTION_KEY, subId);
1343 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1344 mApp.startActivity(intent);
1345 } finally {
1346 Binder.restoreCallingIdentity(identity);
1347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 }
1349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001351 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001352 }
1353
Wink Savilleb564aae2014-10-23 10:18:09 -07001354 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001355 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001356 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1357 }
1358
1359 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001360 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001361 }
1362
Wink Savilleb564aae2014-10-23 10:18:09 -07001363 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001364 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001365 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1366 }
1367
1368 /** {@hide} */
1369 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001370 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
1372
Wink Savilleb564aae2014-10-23 10:18:09 -07001373 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001375
1376 final long identity = Binder.clearCallingIdentity();
1377 try {
1378 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1379 checkSimPin.start();
1380 return checkSimPin.unlockSim(null, pin);
1381 } finally {
1382 Binder.restoreCallingIdentity(identity);
1383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 }
1385
Wink Saville9de0f752013-10-22 19:04:03 -07001386 /** {@hide} */
1387 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001388 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001389 }
1390
Wink Savilleb564aae2014-10-23 10:18:09 -07001391 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001393
1394 final long identity = Binder.clearCallingIdentity();
1395 try {
1396 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1397 checkSimPuk.start();
1398 return checkSimPuk.unlockSim(puk, pin);
1399 } finally {
1400 Binder.restoreCallingIdentity(identity);
1401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 }
1403
1404 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001405 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 * a synchronous one.
1407 */
1408 private static class UnlockSim extends Thread {
1409
1410 private final IccCard mSimCard;
1411
1412 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001413 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1414 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415
1416 // For replies from SimCard interface
1417 private Handler mHandler;
1418
1419 // For async handler to identify request type
1420 private static final int SUPPLY_PIN_COMPLETE = 100;
1421
1422 public UnlockSim(IccCard simCard) {
1423 mSimCard = simCard;
1424 }
1425
1426 @Override
1427 public void run() {
1428 Looper.prepare();
1429 synchronized (UnlockSim.this) {
1430 mHandler = new Handler() {
1431 @Override
1432 public void handleMessage(Message msg) {
1433 AsyncResult ar = (AsyncResult) msg.obj;
1434 switch (msg.what) {
1435 case SUPPLY_PIN_COMPLETE:
1436 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1437 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001438 mRetryCount = msg.arg1;
1439 if (ar.exception != null) {
1440 if (ar.exception instanceof CommandException &&
1441 ((CommandException)(ar.exception)).getCommandError()
1442 == CommandException.Error.PASSWORD_INCORRECT) {
1443 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1444 } else {
1445 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1446 }
1447 } else {
1448 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 mDone = true;
1451 UnlockSim.this.notifyAll();
1452 }
1453 break;
1454 }
1455 }
1456 };
1457 UnlockSim.this.notifyAll();
1458 }
1459 Looper.loop();
1460 }
1461
1462 /*
1463 * Use PIN or PUK to unlock SIM card
1464 *
1465 * If PUK is null, unlock SIM card with PIN
1466 *
1467 * If PUK is not null, unlock SIM card with PUK and set PIN code
1468 */
Wink Saville9de0f752013-10-22 19:04:03 -07001469 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470
1471 while (mHandler == null) {
1472 try {
1473 wait();
1474 } catch (InterruptedException e) {
1475 Thread.currentThread().interrupt();
1476 }
1477 }
1478 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1479
1480 if (puk == null) {
1481 mSimCard.supplyPin(pin, callback);
1482 } else {
1483 mSimCard.supplyPuk(puk, pin, callback);
1484 }
1485
1486 while (!mDone) {
1487 try {
1488 Log.d(LOG_TAG, "wait for done");
1489 wait();
1490 } catch (InterruptedException e) {
1491 // Restore the interrupted status
1492 Thread.currentThread().interrupt();
1493 }
1494 }
1495 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001496 int[] resultArray = new int[2];
1497 resultArray[0] = mResult;
1498 resultArray[1] = mRetryCount;
1499 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 }
1501 }
1502
1503 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001504 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001505
1506 }
1507
Wink Savilleb564aae2014-10-23 10:18:09 -07001508 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 // No permission check needed here: this call is harmless, and it's
1510 // needed for the ServiceState.requestStateUpdate() call (which is
1511 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001512 final long identity = Binder.clearCallingIdentity();
1513 try {
1514 final Phone phone = getPhone(subId);
1515 if (phone != null) {
1516 phone.updateServiceLocation();
1517 }
1518 } finally {
1519 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001521 }
1522
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001523 @Override
1524 public boolean isRadioOn(String callingPackage) {
1525 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001526 }
1527
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001528 @Override
1529 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001531 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001532 return false;
1533 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001534
1535 final long identity = Binder.clearCallingIdentity();
1536 try {
1537 return isRadioOnForSubscriber(subId);
1538 } finally {
1539 Binder.restoreCallingIdentity(identity);
1540 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001541 }
1542
1543 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001544 final long identity = Binder.clearCallingIdentity();
1545 try {
1546 final Phone phone = getPhone(subId);
1547 if (phone != null) {
1548 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1549 } else {
1550 return false;
1551 }
1552 } finally {
1553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 }
1556
1557 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001558 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 }
Wink Saville36469e72014-06-11 15:17:00 -07001560
Wink Savilleb564aae2014-10-23 10:18:09 -07001561 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001563
1564 final long identity = Binder.clearCallingIdentity();
1565 try {
1566 final Phone phone = getPhone(subId);
1567 if (phone != null) {
1568 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1569 }
1570 } finally {
1571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001572 }
Wink Saville36469e72014-06-11 15:17:00 -07001573 }
1574
1575 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001576 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001577 }
1578
Wink Savilleb564aae2014-10-23 10:18:09 -07001579 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001580 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001581
1582 final long identity = Binder.clearCallingIdentity();
1583 try {
1584 final Phone phone = getPhone(subId);
1585 if (phone == null) {
1586 return false;
1587 }
1588 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1589 toggleRadioOnOffForSubscriber(subId);
1590 }
1591 return true;
1592 } finally {
1593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 }
Wink Saville36469e72014-06-11 15:17:00 -07001596
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001597 public boolean needMobileRadioShutdown() {
1598 /*
1599 * If any of the Radios are available, it will need to be
1600 * shutdown. So return true if any Radio is available.
1601 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001602 final long identity = Binder.clearCallingIdentity();
1603 try {
1604 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1605 Phone phone = PhoneFactory.getPhone(i);
1606 if (phone != null && phone.isRadioAvailable()) return true;
1607 }
1608 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1609 return false;
1610 } finally {
1611 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001612 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001613 }
1614
Malcolm Chend965c8b2018-02-28 15:00:40 -08001615 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001616 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001617 enforceModifyPermission();
1618
1619 final long identity = Binder.clearCallingIdentity();
1620 try {
1621 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1622 logv("Shutting down Phone " + i);
1623 shutdownRadioUsingPhoneId(i);
1624 }
1625 } finally {
1626 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001627 }
1628 }
1629
1630 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 Phone phone = PhoneFactory.getPhone(phoneId);
1632 if (phone != null && phone.isRadioAvailable()) {
1633 phone.shutdownRadio();
1634 }
1635 }
1636
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001638 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001639
1640 final long identity = Binder.clearCallingIdentity();
1641 try {
1642 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1643 if (defaultPhone != null) {
1644 defaultPhone.setRadioPower(turnOn);
1645 return true;
1646 } else {
1647 loge("There's no default phone.");
1648 return false;
1649 }
1650 } finally {
1651 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001652 }
Wink Saville36469e72014-06-11 15:17:00 -07001653 }
1654
Wink Savilleb564aae2014-10-23 10:18:09 -07001655 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001657
1658 final long identity = Binder.clearCallingIdentity();
1659 try {
1660 final Phone phone = getPhone(subId);
1661 if (phone != null) {
1662 phone.setRadioPower(turnOn);
1663 return true;
1664 } else {
1665 return false;
1666 }
1667 } finally {
1668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 }
1671
Wink Saville36469e72014-06-11 15:17:00 -07001672 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001673 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 public boolean enableDataConnectivity() {
1675 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001676
1677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 int subId = mSubscriptionController.getDefaultDataSubId();
1680 final Phone phone = getPhone(subId);
1681 if (phone != null) {
1682 phone.setUserDataEnabled(true);
1683 return true;
1684 } else {
1685 return false;
1686 }
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
1691
Wink Saville36469e72014-06-11 15:17:00 -07001692 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 public boolean disableDataConnectivity() {
1695 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001696
1697 final long identity = Binder.clearCallingIdentity();
1698 try {
1699 int subId = mSubscriptionController.getDefaultDataSubId();
1700 final Phone phone = getPhone(subId);
1701 if (phone != null) {
1702 phone.setUserDataEnabled(false);
1703 return true;
1704 } else {
1705 return false;
1706 }
1707 } finally {
1708 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 }
1711
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001713 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 return phone.isDataAllowed();
1719 } else {
1720 return false;
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
1727 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001728 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001729 }
1730
pkanwarae03a6b2016-11-06 20:37:09 -08001731 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001732 enforceCallPermission();
1733
1734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1737 return;
1738 }
1739 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1740 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
1743 }
pkanwar32d516d2016-10-14 19:37:38 -07001744 };
1745
Wink Savilleb564aae2014-10-23 10:18:09 -07001746 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001748
1749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1752 return false;
1753 }
1754 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001761 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001762 }
1763
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001764 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001765 final long identity = Binder.clearCallingIdentity();
1766 try {
1767 Phone phone = PhoneFactory.getPhone(slotIndex);
1768 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1769 PhoneConstantConversions.convertCallState(phone.getState());
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
1772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Sanket Padawe356d7632015-06-22 14:03:32 -07001775 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1780 if (phone != null) {
1781 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1782 } else {
1783 return PhoneConstantConversions.convertDataState(
1784 PhoneConstants.DataState.DISCONNECTED);
1785 }
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001793 final long identity = Binder.clearCallingIdentity();
1794 try {
1795 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1796 if (phone != null) {
1797 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1798 } else {
1799 return TelephonyManager.DATA_ACTIVITY_NONE;
1800 }
1801 } finally {
1802 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 }
1805
1806 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001807 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001808 mPhone.getContext().getSystemService(AppOpsManager.class)
1809 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001810 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001811 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001812 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001815 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001816 final long identity = Binder.clearCallingIdentity();
1817 try {
1818 if (DBG_LOC) log("getCellLocation: is active user");
1819 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001820 int subId = mSubscriptionController.getDefaultDataSubId();
1821 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1822 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001823 return data;
1824 } finally {
1825 Binder.restoreCallingIdentity(identity);
1826 }
Svetoslav64fad262015-04-14 14:35:21 -07001827 }
1828
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001830 public String getNetworkCountryIsoForPhone(int phoneId) {
1831 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1832 // registered cell info, so return a NULL country instead.
1833 final long identity = Binder.clearCallingIdentity();
1834 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001835 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1836 // Get default phone in this case.
1837 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1838 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001839 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001840 // Todo: fix this when we can get the actual cellular network info when the device
1841 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001842 if (TelephonyManager.NETWORK_TYPE_IWLAN
1843 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1844 return "";
1845 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001846 Phone phone = PhoneFactory.getPhone(phoneId);
1847 if (phone != null) {
1848 ServiceStateTracker sst = phone.getServiceStateTracker();
1849 if (sst != null) {
1850 LocaleTracker lt = sst.getLocaleTracker();
1851 if (lt != null) {
1852 return lt.getCurrentCountry();
1853 }
1854 }
1855 }
1856 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001857 } finally {
1858 Binder.restoreCallingIdentity(identity);
1859 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001860 }
1861
1862 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001864 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001865 }
1866
Sanket Padawe356d7632015-06-22 14:03:32 -07001867 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001868 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 mApp.enforceCallingOrSelfPermission(
1870 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001871
1872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 final Phone phone = getPhone(subId);
1875 if (phone != null) {
1876 phone.enableLocationUpdates();
1877 }
1878 } finally {
1879 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 }
1882
1883 @Override
1884 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001885 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001886 }
1887
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001889 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 mApp.enforceCallingOrSelfPermission(
1891 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001892
1893 final long identity = Binder.clearCallingIdentity();
1894 try {
1895 final Phone phone = getPhone(subId);
1896 if (phone != null) {
1897 phone.disableLocationUpdates();
1898 }
1899 } finally {
1900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
Nathan Harold31d7ff32018-10-15 20:20:30 -07001904 /**
1905 * Returns the target SDK version number for a given package name.
1906 *
1907 * @return target SDK if the package is found or INT_MAX.
1908 */
1909 private int getTargetSdk(String packageName) {
1910 try {
1911 final ApplicationInfo ai =
1912 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1913 if (ai != null) return ai.targetSdkVersion;
1914 } catch (PackageManager.NameNotFoundException unexpected) {
1915 }
1916 return Integer.MAX_VALUE;
1917 }
1918
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 @Override
1920 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001921 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1922 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001923 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1924 throw new SecurityException(
1925 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1926 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001927
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1929 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1930 return null;
1931 }
Svetoslav64fad262015-04-14 14:35:21 -07001932
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001933 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934
Nathan Haroldf180aac2018-06-01 18:43:55 -07001935 List<CellInfo> info = getAllCellInfo(callingPackage);
1936 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937
Nathan Haroldf180aac2018-06-01 18:43:55 -07001938 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1939 for (CellInfo ci : info) {
1940 if (ci instanceof CellInfoGsm) {
1941 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1942 } else if (ci instanceof CellInfoWcdma) {
1943 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001946 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001949 private List<CellInfo> getCachedCellInfo() {
1950 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1951 for (Phone phone : PhoneFactory.getPhones()) {
1952 List<CellInfo> info = phone.getAllCellInfo();
1953 if (info != null) cellInfos.addAll(info);
1954 }
1955 return cellInfos;
1956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957
1958 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001959 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001960 mPhone.getContext().getSystemService(AppOpsManager.class)
1961 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001962 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001963 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001964 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965 }
1966
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001967 final int targetSdk = getTargetSdk(callingPackage);
1968 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1969 return getCachedCellInfo();
1970 }
1971
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001972 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001974 final long identity = Binder.clearCallingIdentity();
1975 try {
1976 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1977 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001978 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001979 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001980 if (info != null) cellInfos.addAll(info);
1981 }
1982 return cellInfos;
1983 } finally {
1984 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 }
1986 }
1987
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001988 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001989 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
1990 requestCellInfoUpdateInternal(
1991 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
1992 }
1993
1994 @Override
1995 public void requestCellInfoUpdateWithWorkSource(
1996 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
1997 enforceModifyPermission();
1998 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
1999 }
2000
2001 private void requestCellInfoUpdateInternal(
2002 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2003 mPhone.getContext().getSystemService(AppOpsManager.class)
2004 .checkPackage(Binder.getCallingUid(), callingPackage);
2005 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
2006 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
2007 return;
2008 }
2009
2010 final Phone phone = getPhone(subId);
2011 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2012
2013 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2014 }
2015
2016 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002018 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002020
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 mPhone.setCellInfoListRate(rateInMillis, workSource);
2024 } finally {
2025 Binder.restoreCallingIdentity(identity);
2026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 }
2028
Shishir Agrawala9f32182016-04-12 12:00:16 -07002029 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002030 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002031 Phone phone = PhoneFactory.getPhone(slotIndex);
2032 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002033 return null;
2034 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002035 int subId = phone.getSubId();
2036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2037 mApp, subId, callingPackage, "getImeiForSlot")) {
2038 return null;
2039 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002040
2041 final long identity = Binder.clearCallingIdentity();
2042 try {
2043 return phone.getImei();
2044 } finally {
2045 Binder.restoreCallingIdentity(identity);
2046 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002047 }
2048
2049 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002050 public String getTypeAllocationCodeForSlot(int slotIndex) {
2051 Phone phone = PhoneFactory.getPhone(slotIndex);
2052 String tac = null;
2053 if (phone != null) {
2054 String imei = phone.getImei();
2055 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2056 }
2057 return tac;
2058 }
2059
2060 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002061 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002062 Phone phone = PhoneFactory.getPhone(slotIndex);
2063 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002064 return null;
2065 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002066 int subId = phone.getSubId();
2067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2068 mApp, subId, callingPackage, "getMeidForSlot")) {
2069 return null;
2070 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002071
2072 final long identity = Binder.clearCallingIdentity();
2073 try {
2074 return phone.getMeid();
2075 } finally {
2076 Binder.restoreCallingIdentity(identity);
2077 }
Jack Yu2af8d712017-03-15 17:14:14 -07002078 }
2079
2080 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002081 public String getManufacturerCodeForSlot(int slotIndex) {
2082 Phone phone = PhoneFactory.getPhone(slotIndex);
2083 String manufacturerCode = null;
2084 if (phone != null) {
2085 String meid = phone.getMeid();
2086 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2087 }
2088 return manufacturerCode;
2089 }
2090
2091 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002092 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002093 Phone phone = PhoneFactory.getPhone(slotIndex);
2094 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002095 return null;
2096 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002097 int subId = phone.getSubId();
2098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2099 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2100 return null;
2101 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002102
2103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 return phone.getDeviceSvn();
2106 } finally {
2107 Binder.restoreCallingIdentity(identity);
2108 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002109 }
2110
fionaxu43304da2017-11-27 22:51:16 -08002111 @Override
2112 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 final Phone phone = getPhone(subId);
2116 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
fionaxu43304da2017-11-27 22:51:16 -08002120 }
2121
2122 @Override
2123 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002124 final long identity = Binder.clearCallingIdentity();
2125 try {
2126 final Phone phone = getPhone(subId);
2127 return phone == null ? null : phone.getCarrierName();
2128 } finally {
2129 Binder.restoreCallingIdentity(identity);
2130 }
fionaxu43304da2017-11-27 22:51:16 -08002131 }
2132
calvinpaneed9ae82018-11-01 19:43:06 +08002133 @Override
2134 public int getSubscriptionMNOCarrierId(int subId) {
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final Phone phone = getPhone(subId);
2138 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2139 } finally {
2140 Binder.restoreCallingIdentity(identity);
2141 }
2142 }
2143
chen xuc93cc282018-11-04 17:17:00 -08002144 @Override
2145 public int getSubscriptionPreciseCarrierId(int subId) {
2146 final long identity = Binder.clearCallingIdentity();
2147 try {
2148 final Phone phone = getPhone(subId);
2149 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2150 : phone.getPreciseCarrierId();
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
2153 }
2154 }
2155
2156 @Override
2157 public String getSubscriptionPreciseCarrierName(int subId) {
2158 final long identity = Binder.clearCallingIdentity();
2159 try {
2160 final Phone phone = getPhone(subId);
2161 return phone == null ? null : phone.getPreciseCarrierName();
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
2164 }
2165 }
2166
chen xu02581692018-11-11 19:03:44 -08002167 @Override
2168 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc) {
2169 final Phone phone = PhoneFactory.getPhone(slotIndex);
2170 if (phone == null) {
2171 return TelephonyManager.UNKNOWN_CARRIER_ID;
2172 }
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2176 } finally {
2177 Binder.restoreCallingIdentity(identity);
2178 }
2179 }
2180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 //
2182 // Internal helper methods.
2183 //
2184
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002185 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2187 *
2188 * @throws SecurityException if the caller does not have the required permission
2189 */
2190 private void enforceModifyPermission() {
2191 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2192 }
2193
2194 /**
2195 * Make sure the caller has the CALL_PHONE permission.
2196 *
2197 * @throws SecurityException if the caller does not have the required permission
2198 */
2199 private void enforceCallPermission() {
2200 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2201 }
2202
Stuart Scott8eef64f2015-04-08 15:13:54 -07002203 private void enforceConnectivityInternalPermission() {
2204 mApp.enforceCallingOrSelfPermission(
2205 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2206 "ConnectivityService");
2207 }
2208
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 private String createTelUrl(String number) {
2210 if (TextUtils.isEmpty(number)) {
2211 return null;
2212 }
2213
Jake Hambye994d462014-02-03 13:10:13 -08002214 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Ihab Awadf9e92732013-12-05 18:02:52 -08002217 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2219 }
2220
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002221 private static void logv(String msg) {
2222 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2223 }
2224
Ihab Awadf9e92732013-12-05 18:02:52 -08002225 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002226 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2227 }
2228
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002229 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002231 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002232 }
2233
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002235 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 final Phone phone = PhoneFactory.getPhone(slotIndex);
2239 if (phone == null) {
2240 return PhoneConstants.PHONE_TYPE_NONE;
2241 } else {
2242 return phone.getPhoneType();
2243 }
2244 } finally {
2245 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 }
2248
2249 /**
2250 * Returns the CDMA ERI icon index to display
2251 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002252 @Override
2253 public int getCdmaEriIconIndex(String callingPackage) {
2254 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002255 }
2256
Sanket Padawe356d7632015-06-22 14:03:32 -07002257 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002258 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002260 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002261 return -1;
2262 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002263
2264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 final Phone phone = getPhone(subId);
2267 if (phone != null) {
2268 return phone.getCdmaEriIconIndex();
2269 } else {
2270 return -1;
2271 }
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
2276
2277 /**
2278 * Returns the CDMA ERI icon mode,
2279 * 0 - ON
2280 * 1 - FLASHING
2281 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002282 @Override
2283 public int getCdmaEriIconMode(String callingPackage) {
2284 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002285 }
2286
Sanket Padawe356d7632015-06-22 14:03:32 -07002287 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002288 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002291 return -1;
2292 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002293
2294 final long identity = Binder.clearCallingIdentity();
2295 try {
2296 final Phone phone = getPhone(subId);
2297 if (phone != null) {
2298 return phone.getCdmaEriIconMode();
2299 } else {
2300 return -1;
2301 }
2302 } finally {
2303 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 }
2306
2307 /**
2308 * Returns the CDMA ERI text,
2309 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002310 @Override
2311 public String getCdmaEriText(String callingPackage) {
2312 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002313 }
2314
Sanket Padawe356d7632015-06-22 14:03:32 -07002315 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002316 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002318 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002319 return null;
2320 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002321
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 final Phone phone = getPhone(subId);
2325 if (phone != null) {
2326 return phone.getCdmaEriText();
2327 } else {
2328 return null;
2329 }
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334
2335 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002336 * Returns the CDMA MDN.
2337 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002339 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2341 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 final Phone phone = getPhone(subId);
2346 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2347 return phone.getLine1Number();
2348 } else {
2349 return null;
2350 }
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002353 }
2354 }
2355
2356 /**
2357 * Returns the CDMA MIN.
2358 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002360 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2362 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002363
2364 final long identity = Binder.clearCallingIdentity();
2365 try {
2366 final Phone phone = getPhone(subId);
2367 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2368 return phone.getCdmaMin();
2369 } else {
2370 return null;
2371 }
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002374 }
2375 }
2376
2377 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 * Returns true if CDMA provisioning needs to run.
2379 */
2380 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 return mPhone.needsOtaServiceProvisioning();
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
2386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
2388
2389 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002390 * Sets the voice mail number of a given subId.
2391 */
2392 @Override
2393 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002394 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002395
2396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2399 new Pair<String, String>(alphaTag, number), new Integer(subId));
2400 return success;
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002404 }
2405
Ta-wei Yen87c49842016-05-13 21:19:52 -07002406 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002407 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2408 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2409 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2410 if (!TextUtils.equals(callingPackage, systemDialer)) {
2411 throw new SecurityException("caller must be system dialer");
2412 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002413
2414 final long identity = Binder.clearCallingIdentity();
2415 try {
2416 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2417 if (phoneAccountHandle == null) {
2418 return null;
2419 }
2420 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002423 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002424 }
2425
2426 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002427 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002428 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002430 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002431 return null;
2432 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002433
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002434 final long identity = Binder.clearCallingIdentity();
2435 try {
2436 return RemoteVvmTaskManager
2437 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
2440 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002441 }
2442
2443 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002444 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2445 VisualVoicemailSmsFilterSettings settings) {
2446 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002447
2448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2451 mPhone.getContext(), callingPackage, subId, settings);
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
2454 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002455 }
2456
2457 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002458 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002460
2461 final long identity = Binder.clearCallingIdentity();
2462 try {
2463 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2464 mPhone.getContext(), callingPackage, subId);
2465 } finally {
2466 Binder.restoreCallingIdentity(identity);
2467 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002468 }
2469
2470 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002471 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2472 String callingPackage, int subId) {
2473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002474
2475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2478 mPhone.getContext(), callingPackage, subId);
2479 } finally {
2480 Binder.restoreCallingIdentity(identity);
2481 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002482 }
2483
2484 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002485 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002486 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2491 mPhone.getContext(), subId);
2492 } finally {
2493 Binder.restoreCallingIdentity(identity);
2494 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002495 }
2496
2497 @Override
2498 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2499 String number, int port, String text, PendingIntent sentIntent) {
2500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002501 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002502 enforceSendSmsPermission();
2503 // Make the calls as the phone process.
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2507 if (port == 0) {
2508 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2509 sentIntent, null, false);
2510 } else {
2511 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2512 smsManager.sendDataMessageWithSelfPermissions(number, null,
2513 (short) port, data, sentIntent, null);
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002518 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002519 /**
fionaxu0152e512016-11-14 13:36:14 -08002520 * Sets the voice activation state of a given subId.
2521 */
2522 @Override
2523 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2525 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002526
2527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 final Phone phone = getPhone(subId);
2530 if (phone != null) {
2531 phone.setVoiceActivationState(activationState);
2532 } else {
2533 loge("setVoiceActivationState fails with invalid subId: " + subId);
2534 }
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002537 }
2538 }
2539
2540 /**
2541 * Sets the data activation state of a given subId.
2542 */
2543 @Override
2544 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2546 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002547
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 final Phone phone = getPhone(subId);
2551 if (phone != null) {
2552 phone.setDataActivationState(activationState);
2553 } else {
2554 loge("setVoiceActivationState fails with invalid subId: " + subId);
2555 }
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002558 }
2559 }
2560
2561 /**
2562 * Returns the voice activation state of a given subId.
2563 */
2564 @Override
2565 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002566 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002567
fionaxu0152e512016-11-14 13:36:14 -08002568 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 if (phone != null) {
2572 return phone.getVoiceActivationState();
2573 } else {
2574 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2575 }
2576 } finally {
2577 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002578 }
2579 }
2580
2581 /**
2582 * Returns the data activation state of a given subId.
2583 */
2584 @Override
2585 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002586 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002587
fionaxu0152e512016-11-14 13:36:14 -08002588 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 if (phone != null) {
2592 return phone.getDataActivationState();
2593 } else {
2594 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2595 }
2596 } finally {
2597 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002598 }
2599 }
2600
2601 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 * Returns the unread count of voicemails
2603 */
2604 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002605 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002606 }
2607
2608 /**
2609 * Returns the unread count of voicemails for a subId
2610 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002612 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 final Phone phone = getPhone(subId);
2616 if (phone != null) {
2617 return phone.getVoiceMessageCount();
2618 } else {
2619 return 0;
2620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 }
2625
2626 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002627 * returns true, if the device is in a state where both voice and data
2628 * are supported simultaneously. This can change based on location or network condition.
2629 */
2630 @Override
2631 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 final Phone phone = getPhone(subId);
2635 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
2638 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002639 }
2640
2641 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002642 * Send the dialer code if called from the current default dialer or the caller has
2643 * carrier privilege.
2644 * @param inputCode The dialer code to send
2645 */
2646 @Override
2647 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2648 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2649 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2650 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002651 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2652 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002653 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002654
2655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 mPhone.sendDialerSpecialCode(inputCode);
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
fionaxu235cc5e2017-03-06 22:25:57 -08002661 }
2662
2663 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002664 * Returns the data network type.
2665 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 *
2667 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2668 */
2669 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002670 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002671 final long identity = Binder.clearCallingIdentity();
2672 try {
2673 final Phone phone = getPhone(getDefaultSubscription());
2674 if (phone != null) {
2675 return phone.getServiceState().getDataNetworkType();
2676 } else {
2677 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2678 }
2679 } finally {
2680 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002681 }
Wink Saville36469e72014-06-11 15:17:00 -07002682 }
2683
Pengquan Meng0c05b502018-09-06 09:59:22 -07002684 @Override
2685 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002686 if (!isActiveSubscription(subId)) {
2687 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2688 }
2689
Pengquan Meng0c05b502018-09-06 09:59:22 -07002690 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2691 }
2692
Brad Ebinger4c460712018-10-01 10:40:55 -07002693 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002694 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2695 throws RemoteException {
2696 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002697 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2698 final long token = Binder.clearCallingIdentity();
2699 try {
2700 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2701 .addRegistrationCallbackForSubscription(c, subId);
2702 } finally {
2703 Binder.restoreCallingIdentity(token);
2704 }
2705 }
2706
2707 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002708 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2709 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002710 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2711 Binder.withCleanCallingIdentity(() ->
2712 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2713 .removeRegistrationCallbackForSubscription(c, subId));
2714 }
2715
2716 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002717 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2718 throws RemoteException {
2719 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2721 final long token = Binder.clearCallingIdentity();
2722 try {
2723 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2724 .addCapabilitiesCallbackForSubscription(c, subId);
2725 } finally {
2726 Binder.restoreCallingIdentity(token);
2727 }
2728 }
2729
2730 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002731 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2732 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002733 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2734 Binder.withCleanCallingIdentity(() ->
2735 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2736 .removeCapabilitiesCallbackForSubscription(c, subId));
2737 }
2738
2739 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002740 public boolean isCapable(int subId, int capability, int regTech) {
2741 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2743 final long token = Binder.clearCallingIdentity();
2744 try {
2745 return ImsManager.getInstance(mPhone.getContext(),
2746 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2747 } catch (ImsException e) {
2748 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2749 return false;
2750 } finally {
2751 Binder.restoreCallingIdentity(token);
2752 }
2753 }
2754
2755 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002756 public boolean isAvailable(int subId, int capability, int regTech) {
2757 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002758 final long token = Binder.clearCallingIdentity();
2759 try {
2760 Phone phone = getPhone(subId);
2761 if (phone == null) return false;
2762 return phone.isImsCapabilityAvailable(capability, regTech);
2763 } finally {
2764 Binder.restoreCallingIdentity(token);
2765 }
2766 }
2767
2768 @Override
2769 public boolean isAdvancedCallingSettingEnabled(int subId) {
2770 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2771 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2772 final long token = Binder.clearCallingIdentity();
2773 try {
2774 return ImsManager.getInstance(mPhone.getContext(),
2775 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2776 } finally {
2777 Binder.restoreCallingIdentity(token);
2778 }
2779 }
2780
2781 @Override
2782 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2784 "setAdvancedCallingSetting");
2785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2788 ImsManager.getInstance(mPhone.getContext(),
2789 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
2792 }
2793 }
2794
2795 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002796 public boolean isVtSettingEnabled(int subId) {
2797 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2801 return ImsManager.getInstance(mPhone.getContext(),
2802 getSlotIndexOrException(subId)).isVtEnabledByUser();
2803 } finally {
2804 Binder.restoreCallingIdentity(identity);
2805 }
2806 }
2807
2808 @Override
2809 public void setVtSetting(int subId, boolean isEnabled) {
2810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2811 "setVtSetting");
2812 final long identity = Binder.clearCallingIdentity();
2813 try {
2814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2815 ImsManager.getInstance(mPhone.getContext(),
2816 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2817 } finally {
2818 Binder.restoreCallingIdentity(identity);
2819 }
2820 }
2821
2822 @Override
2823 public boolean isVoWiFiSettingEnabled(int subId) {
2824 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2828 return ImsManager.getInstance(mPhone.getContext(),
2829 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
2832 }
2833 }
2834
2835 @Override
2836 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2838 "setVoWiFiSetting");
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2842 ImsManager.getInstance(mPhone.getContext(),
2843 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
2846 }
2847 }
2848
2849 @Override
2850 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2851 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2855 return ImsManager.getInstance(mPhone.getContext(),
2856 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
2859 }
2860 }
2861
2862 @Override
2863 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2865 "setVoWiFiRoamingSetting");
2866 final long identity = Binder.clearCallingIdentity();
2867 try {
2868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2869 ImsManager.getInstance(mPhone.getContext(),
2870 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
2873 }
2874 }
2875
2876 @Override
2877 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2879 "setVoWiFiNonPersistent");
2880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2883 ImsManager.getInstance(mPhone.getContext(),
2884 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
2888 }
2889
2890 @Override
2891 public int getVoWiFiModeSetting(int subId) {
2892 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2896 return ImsManager.getInstance(mPhone.getContext(),
2897 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
2900 }
2901 }
2902
2903 @Override
2904 public void setVoWiFiModeSetting(int subId, int mode) {
2905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2906 "setVoWiFiModeSetting");
2907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2910 ImsManager.getInstance(mPhone.getContext(),
2911 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
2914 }
2915 }
2916
2917 @Override
2918 public int getVoWiFiRoamingModeSetting(int subId) {
2919 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2923 return ImsManager.getInstance(mPhone.getContext(),
2924 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
2927 }
2928 }
2929
2930 @Override
2931 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2933 "setVoWiFiRoamingModeSetting");
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2937 ImsManager.getInstance(mPhone.getContext(),
2938 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
2941 }
2942 }
2943
2944 @Override
2945 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2947 "setRttCapabilityEnabled");
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2951 ImsManager.getInstance(mPhone.getContext(),
2952 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
2955 }
2956 }
2957
2958 @Override
2959 public boolean isTtyOverVolteEnabled(int subId) {
2960 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2964 return ImsManager.getInstance(mPhone.getContext(),
2965 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002971 @Override
2972 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2973 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2977 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2978 .getConfigInterface().addConfigCallback(callback);
2979 } catch (ImsException e) {
2980 throw new IllegalArgumentException(e.getMessage());
2981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
2984 }
2985
2986 @Override
2987 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2988 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
2991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2992 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2993 .getConfigInterface().removeConfigCallback(callback);
2994 } catch (ImsException e) {
2995 throw new IllegalArgumentException(e.getMessage());
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
2999 }
3000
3001 @Override
3002 public int getImsProvisioningInt(int subId, int key) {
3003 enforceReadPrivilegedPermission("getImsProvisioningInt");
3004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3007 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3008 .getConfigInterface().getConfigInt(key);
3009 } catch (ImsException e) {
3010 throw new IllegalArgumentException(e.getMessage());
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
3014 }
3015
3016 @Override
3017 public String getImsProvisioningString(int subId, int key) {
3018 enforceReadPrivilegedPermission("getImsProvisioningString");
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3022 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3023 .getConfigInterface().getConfigString(key);
3024 } catch (ImsException e) {
3025 throw new IllegalArgumentException(e.getMessage());
3026 } finally {
3027 Binder.restoreCallingIdentity(identity);
3028 }
3029 }
3030
3031 @Override
3032 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3034 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3038 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3039 .getConfigInterface().setConfig(key, value);
3040 } catch (ImsException e) {
3041 throw new IllegalArgumentException(e.getMessage());
3042 } finally {
3043 Binder.restoreCallingIdentity(identity);
3044 }
3045 }
3046
3047 @Override
3048 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3050 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3054 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3055 .getConfigInterface().setConfig(key, value);
3056 } catch (ImsException e) {
3057 throw new IllegalArgumentException(e.getMessage());
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
3060 }
3061 }
3062
Brad Ebinger4c460712018-10-01 10:40:55 -07003063 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3064 int slotId = SubscriptionManager.getSlotIndex(subId);
3065 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3066 throw new IllegalArgumentException("Invalid Subscription Id.");
3067 }
3068 return slotId;
3069 }
3070
Wink Saville36469e72014-06-11 15:17:00 -07003071 /**
3072 * Returns the network type for a subId
3073 */
3074 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003075 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003077 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003078 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3079 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003080
Malcolm Chend965c8b2018-02-28 15:00:40 -08003081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 final Phone phone = getPhone(subId);
3084 if (phone != null) {
3085 return phone.getServiceState().getDataNetworkType();
3086 } else {
3087 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3088 }
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003092 }
3093
3094 /**
3095 * Returns the data network type
3096 */
3097 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003098 public int getDataNetworkType(String callingPackage) {
3099 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003100 }
3101
3102 /**
3103 * Returns the data network type for a subId
3104 */
3105 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003106 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003108 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003109 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3110 }
3111
Malcolm Chend965c8b2018-02-28 15:00:40 -08003112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 final Phone phone = getPhone(subId);
3115 if (phone != null) {
3116 return phone.getServiceState().getDataNetworkType();
3117 } else {
3118 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3119 }
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 }
3124
3125 /**
Wink Saville36469e72014-06-11 15:17:00 -07003126 * Returns the Voice network type for a subId
3127 */
3128 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003129 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003131 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003132 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3133 }
3134
Malcolm Chend965c8b2018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 final Phone phone = getPhone(subId);
3138 if (phone != null) {
3139 return phone.getServiceState().getVoiceNetworkType();
3140 } else {
3141 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3142 }
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146 }
3147
3148 /**
3149 * @return true if a ICC card is present
3150 */
3151 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003152 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003153 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3154 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003155 }
3156
3157 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003158 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003159 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003160 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003161 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 final Phone phone = PhoneFactory.getPhone(slotIndex);
3165 if (phone != null) {
3166 return phone.getIccCard().hasIccCard();
3167 } else {
3168 return false;
3169 }
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 }
3174
3175 /**
3176 * Return if the current radio is LTE on CDMA. This
3177 * is a tri-state return value as for a period of time
3178 * the mode may be unknown.
3179 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003180 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003182 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003183 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003184 @Override
3185 public int getLteOnCdmaMode(String callingPackage) {
3186 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003187 }
3188
Sanket Padawe356d7632015-06-22 14:03:32 -07003189 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003190 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003192 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003193 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3194 }
3195
Malcolm Chend965c8b2018-02-28 15:00:40 -08003196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 final Phone phone = getPhone(subId);
3199 if (phone == null) {
3200 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3201 } else {
3202 return phone.getLteOnCdmaMode();
3203 }
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003206 }
Wink Saville36469e72014-06-11 15:17:00 -07003207 }
3208
3209 public void setPhone(Phone phone) {
3210 mPhone = phone;
3211 }
3212
3213 /**
3214 * {@hide}
3215 * Returns Default subId, 0 in the case of single standby.
3216 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003217 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003218 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003219 }
3220
Shishir Agrawala9f32182016-04-12 12:00:16 -07003221 private int getSlotForDefaultSubscription() {
3222 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3223 }
3224
Wink Savilleb564aae2014-10-23 10:18:09 -07003225 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003226 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003227 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003228
Pengquan Meng466e2482018-09-21 15:54:48 -07003229 private boolean isActiveSubscription(int subId) {
3230 return mSubscriptionController.isActiveSubId(subId);
3231 }
3232
Ihab Awadf2177b72013-11-25 13:33:23 -08003233 /**
3234 * @see android.telephony.TelephonyManager.WifiCallingChoices
3235 */
3236 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3240 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3241 getWhenToMakeWifiCallsDefaultPreference());
3242 } finally {
3243 Binder.restoreCallingIdentity(identity);
3244 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003245 }
3246
3247 /**
3248 * @see android.telephony.TelephonyManager.WifiCallingChoices
3249 */
3250 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003251 final long identity = Binder.clearCallingIdentity();
3252 try {
3253 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3254 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3255 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003259 }
3260
Sailesh Nepald1e68152013-12-12 19:08:02 -08003261 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003262 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003263 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003264 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003265
Shishir Agrawal566b7612013-10-28 14:41:00 -07003266 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003267 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3268 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3270 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003271 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003272
Malcolm Chend965c8b2018-02-28 15:00:40 -08003273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 if (TextUtils.equals(ISDR_AID, aid)) {
3276 // Only allows LPA to open logical channel to ISD-R.
3277 ComponentInfo bestComponent =
3278 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3279 if (bestComponent == null
3280 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3281 loge("The calling package is not allowed to access ISD-R.");
3282 throw new SecurityException(
3283 "The calling package is not allowed to access ISD-R.");
3284 }
Derek Tan740e1672017-06-27 14:56:27 -07003285 }
Derek Tan740e1672017-06-27 14:56:27 -07003286
Malcolm Chend965c8b2018-02-28 15:00:40 -08003287 if (DBG) {
3288 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3289 }
3290 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3291 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3292 if (DBG) log("iccOpenLogicalChannel: " + response);
3293 return response;
3294 } finally {
3295 Binder.restoreCallingIdentity(identity);
3296 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003297 }
3298
3299 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003300 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3302 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003303
Malcolm Chend965c8b2018-02-28 15:00:40 -08003304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3307 if (channel < 0) {
3308 return false;
3309 }
3310 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3311 if (DBG) log("iccCloseLogicalChannel: " + success);
3312 return success;
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003315 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003316 }
3317
3318 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003319 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003320 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3322 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003323
Malcolm Chend965c8b2018-02-28 15:00:40 -08003324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 if (DBG) {
3327 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3328 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3329 + p3 + " data=" + data);
3330 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003331
Malcolm Chend965c8b2018-02-28 15:00:40 -08003332 if (channel < 0) {
3333 return "";
3334 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003335
Malcolm Chend965c8b2018-02-28 15:00:40 -08003336 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3337 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3338 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003339
Malcolm Chend965c8b2018-02-28 15:00:40 -08003340 // Append the returned status code to the end of the response payload.
3341 String s = Integer.toHexString(
3342 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3343 if (response.payload != null) {
3344 s = IccUtils.bytesToHexString(response.payload) + s;
3345 }
3346 return s;
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003349 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003350 }
Jake Hambye994d462014-02-03 13:10:13 -08003351
Evan Charltonc66da362014-05-16 14:06:40 -07003352 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003353 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3354 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3356 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003358
Malcolm Chend965c8b2018-02-28 15:00:40 -08003359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3362 && TextUtils.equals(ISDR_AID, data)) {
3363 // Only allows LPA to select ISD-R.
3364 ComponentInfo bestComponent =
3365 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3366 if (bestComponent == null
3367 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3368 loge("The calling package is not allowed to select ISD-R.");
3369 throw new SecurityException(
3370 "The calling package is not allowed to select ISD-R.");
3371 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003372 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003373
Malcolm Chend965c8b2018-02-28 15:00:40 -08003374 if (DBG) {
3375 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3376 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3377 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003378
Malcolm Chend965c8b2018-02-28 15:00:40 -08003379 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3380 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3381 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003382
Malcolm Chend965c8b2018-02-28 15:00:40 -08003383 // Append the returned status code to the end of the response payload.
3384 String s = Integer.toHexString(
3385 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3386 if (response.payload != null) {
3387 s = IccUtils.bytesToHexString(response.payload) + s;
3388 }
3389 return s;
3390 } finally {
3391 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003392 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003393 }
3394
3395 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003396 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003397 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3399 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003400
Malcolm Chend965c8b2018-02-28 15:00:40 -08003401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 if (DBG) {
3404 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3405 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3406 }
3407
3408 IccIoResult response =
3409 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3410 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3411 subId);
3412
3413 if (DBG) {
3414 log("Exchange SIM_IO [R]" + response);
3415 }
3416
3417 byte[] result = null;
3418 int length = 2;
3419 if (response.payload != null) {
3420 length = 2 + response.payload.length;
3421 result = new byte[length];
3422 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3423 } else {
3424 result = new byte[length];
3425 }
3426
3427 result[length - 1] = (byte) response.sw2;
3428 result[length - 2] = (byte) response.sw1;
3429 return result;
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003432 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003433 }
3434
Nathan Haroldb3014052017-01-25 15:57:32 -08003435 /**
3436 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3437 * on a particular subscription
3438 */
sqianb6e41952018-03-12 14:54:01 -07003439 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3441 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3442 return null;
3443 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003444
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 if (appType != TelephonyManager.APPTYPE_USIM
3448 && appType != TelephonyManager.APPTYPE_SIM) {
3449 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3450 return null;
3451 }
3452 Object response = sendRequest(
3453 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3454 if (response instanceof String[]) {
3455 return (String[]) response;
3456 }
3457 // Response is an Exception of some kind,
3458 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003459 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003460 } finally {
3461 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003462 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003463 }
3464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003465 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003466 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3468 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003469
Malcolm Chend965c8b2018-02-28 15:00:40 -08003470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3473 if (response.payload == null) {
3474 return "";
3475 }
Evan Charltonc66da362014-05-16 14:06:40 -07003476
Malcolm Chend965c8b2018-02-28 15:00:40 -08003477 // Append the returned status code to the end of the response payload.
3478 String s = Integer.toHexString(
3479 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3480 s = IccUtils.bytesToHexString(response.payload) + s;
3481 return s;
3482 } finally {
3483 Binder.restoreCallingIdentity(identity);
3484 }
Evan Charltonc66da362014-05-16 14:06:40 -07003485 }
3486
Jake Hambye994d462014-02-03 13:10:13 -08003487 /**
3488 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3489 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3490 *
3491 * @param itemID the ID of the item to read
3492 * @return the NV item as a String, or null on error.
3493 */
3494 @Override
3495 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003496 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3498 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003499
3500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003503 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003504 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3505 return value;
3506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
Jake Hambye994d462014-02-03 13:10:13 -08003509 }
3510
3511 /**
3512 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3513 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3514 *
3515 * @param itemID the ID of the item to read
3516 * @param itemValue the value to write, as a String
3517 * @return true on success; false on any failure
3518 */
3519 @Override
3520 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003521 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3523 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003524
3525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3528 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003529 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003530 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3531 return success;
3532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
Jake Hambye994d462014-02-03 13:10:13 -08003535 }
3536
3537 /**
3538 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3539 * Used for device configuration by some CDMA operators.
3540 *
3541 * @param preferredRoamingList byte array containing the new PRL
3542 * @return true on success; false on any failure
3543 */
3544 @Override
3545 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3547 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003548
3549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3552 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3553 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3554 return success;
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
Jake Hambye994d462014-02-03 13:10:13 -08003558 }
3559
3560 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003561 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003562 * Used for device configuration by some CDMA operators.
3563 *
chen xu1cc0abe2018-10-26 17:39:23 -07003564 * @param slotIndex - device slot.
3565 *
Jake Hambye994d462014-02-03 13:10:13 -08003566 * @return true on success; false on any failure
3567 */
3568 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003569 public boolean resetModemConfig(int slotIndex) {
3570 Phone phone = PhoneFactory.getPhone(slotIndex);
3571 if (phone != null) {
3572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3573 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003574
chen xu1cc0abe2018-10-26 17:39:23 -07003575 final long identity = Binder.clearCallingIdentity();
3576 try {
3577 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3578 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3579 return success;
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
3582 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003583 }
chen xu1cc0abe2018-10-26 17:39:23 -07003584 return false;
3585 }
3586
3587 /**
3588 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3589 *
3590 * @param slotIndex - device slot.
3591 *
3592 * @return true on success; false on any failure
3593 */
3594 @Override
3595 public boolean rebootModem(int slotIndex) {
3596 Phone phone = PhoneFactory.getPhone(slotIndex);
3597 if (phone != null) {
3598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3599 mApp, phone.getSubId(), "rebootModem");
3600
3601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3604 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3605 return success;
3606 } finally {
3607 Binder.restoreCallingIdentity(identity);
3608 }
3609 }
3610 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003611 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003612
Svet Ganovb320e182015-04-16 12:30:10 -07003613 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003615 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003616 return new String[0];
3617 }
3618
Malcolm Chend965c8b2018-02-28 15:00:40 -08003619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 return mPhone.getPcscfAddress(apnType);
3622 } finally {
3623 Binder.restoreCallingIdentity(identity);
3624 }
Wink Saville36469e72014-06-11 15:17:00 -07003625 }
3626
Brad Ebinger51f743a2017-01-23 13:50:20 -08003627 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003628 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3629 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003630 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003631 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003632 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003633
3634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 PhoneFactory.getImsResolver().enableIms(slotId);
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003640 }
3641
3642 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003643 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3644 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003645 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003646 public void disableIms(int slotId) {
3647 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 PhoneFactory.getImsResolver().disableIms(slotId);
3652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003655 }
3656
3657 /**
3658 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3659 * feature or {@link null} if the service is not available. If the feature is available, the
3660 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3661 */
3662 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003663 IImsServiceFeatureCallback callback) {
3664 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003665
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003672 }
3673
3674 /**
3675 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3676 * feature during emergency calling or {@link null} if the service is not available. If the
3677 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3678 * listener for feature updates.
3679 */
3680 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3681 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003682
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003689 }
3690
Brad Ebinger5f64b052017-12-14 14:26:15 -08003691 /**
3692 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3693 * specified.
3694 */
3695 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3696 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003697
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003704 }
3705
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003706 /**
3707 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3708 * specified.
3709 */
3710 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3711 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003712
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003719 }
3720
Brad Ebinger884c07b2018-02-15 16:17:40 -08003721 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003722 * Sets the ImsService Package Name that Telephony will bind to.
3723 *
3724 * @param slotId the slot ID that the ImsService should bind for.
3725 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3726 * ImsService is the device default ImsService.
3727 * @param packageName The package name of the application that contains the ImsService to bind
3728 * to.
3729 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3730 * @hide
3731 */
3732 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003733 int[] subIds = SubscriptionManager.getSubId(slotId);
3734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3735 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3736 "setImsService");
3737
Malcolm Chend965c8b2018-02-28 15:00:40 -08003738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3741 isCarrierImsService, packageName);
3742 } finally {
3743 Binder.restoreCallingIdentity(identity);
3744 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003745 }
3746
3747 /**
3748 * Return the ImsService configuration.
3749 *
3750 * @param slotId The slot that the ImsService is associated with.
3751 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3752 * the device default.
3753 * @return the package name of the ImsService configuration.
3754 */
3755 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003756 int[] subIds = SubscriptionManager.getSubId(slotId);
3757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3758 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3759 "getImsService");
3760
Malcolm Chend965c8b2018-02-28 15:00:40 -08003761 final long identity = Binder.clearCallingIdentity();
3762 try {
3763 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3764 isCarrierImsService);
3765 } finally {
3766 Binder.restoreCallingIdentity(identity);
3767 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003768 }
3769
Wink Saville36469e72014-06-11 15:17:00 -07003770 public void setImsRegistrationState(boolean registered) {
3771 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003772
3773 final long identity = Binder.clearCallingIdentity();
3774 try {
3775 mPhone.setImsRegistrationState(registered);
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
Wink Saville36469e72014-06-11 15:17:00 -07003779 }
3780
3781 /**
Stuart Scott54788802015-03-30 13:18:01 -07003782 * Set the network selection mode to automatic.
3783 *
3784 */
3785 @Override
3786 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3788 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003789
Pengquan Meng466e2482018-09-21 15:54:48 -07003790 if (!isActiveSubscription(subId)) {
3791 return;
3792 }
3793
Malcolm Chend965c8b2018-02-28 15:00:40 -08003794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3797 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3798 } finally {
3799 Binder.restoreCallingIdentity(identity);
3800 }
Stuart Scott54788802015-03-30 13:18:01 -07003801 }
3802
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003803 /**
3804 * Ask the radio to connect to the input network and change selection mode to manual.
3805 *
3806 * @param subId the id of the subscription.
3807 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3808 * the operator to attach to.
3809 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3810 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3811 * normal network selection next time.
3812 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003813 */
3814 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003815 public boolean setNetworkSelectionModeManual(
3816 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3818 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003819
3820 if (!isActiveSubscription(subId)) {
3821 return false;
3822 }
3823
Malcolm Chend965c8b2018-02-28 15:00:40 -08003824 final long identity = Binder.clearCallingIdentity();
3825 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003826 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003827 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003828 if (DBG) {
3829 log("setNetworkSelectionModeManual: subId: " + subId
3830 + " operator: " + operatorInfo);
3831 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003832 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3833 } finally {
3834 Binder.restoreCallingIdentity(identity);
3835 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003836 }
3837
3838 /**
3839 * Scans for available networks.
3840 */
3841 @Override
3842 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3844 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003845
Pengquan Meng0c05b502018-09-06 09:59:22 -07003846 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003847 try {
3848 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003849 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003850 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003851 } finally {
3852 Binder.restoreCallingIdentity(identity);
3853 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003854 }
3855
3856 /**
yinxub1bed742017-04-17 11:45:04 -07003857 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003858 *
yinxub1bed742017-04-17 11:45:04 -07003859 * @param subId id of the subscription
3860 * @param request contains the radio access networks with bands/channels to scan
3861 * @param messenger callback messenger for scan results or errors
3862 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003863 * @return the id of the requested scan which can be used to stop the scan.
3864 */
3865 @Override
3866 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3867 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3869 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003870
3871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 return mNetworkScanRequestTracker.startNetworkScan(
3874 request, messenger, binder, getPhone(subId));
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
yinxu504e1392017-04-12 16:03:22 -07003878 }
3879
3880 /**
3881 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003882 *
3883 * @param subId id of the subscription
3884 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003885 */
3886 @Override
3887 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3889 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003890
3891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
3896 }
yinxu504e1392017-04-12 16:03:22 -07003897 }
3898
3899 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003900 * Get the calculated preferred network type.
3901 * Used for debugging incorrect network type.
3902 *
3903 * @return the preferred network type, defined in RILConstants.java.
3904 */
3905 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003906 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003908 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003909 return RILConstants.PREFERRED_NETWORK_MODE;
3910 }
3911
Malcolm Chend965c8b2018-02-28 15:00:40 -08003912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 // FIXME: need to get SubId from somewhere.
3915 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
3918 }
Junda Liu84d15a22014-07-02 11:21:04 -07003919 }
3920
3921 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003922 * Get the preferred network type.
3923 * Used for device configuration by some CDMA operators.
3924 *
3925 * @return the preferred network type, defined in RILConstants.java.
3926 */
3927 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003928 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3930 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003931
3932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 if (DBG) log("getPreferredNetworkType");
3935 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3936 int networkType = (result != null ? result[0] : -1);
3937 if (DBG) log("getPreferredNetworkType: " + networkType);
3938 return networkType;
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003942 }
3943
3944 /**
3945 * Set the preferred network type.
3946 * Used for device configuration by some CDMA operators.
3947 *
3948 * @param networkType the preferred network type, defined in RILConstants.java.
3949 * @return true on success; false on any failure.
3950 */
3951 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003952 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3954 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003955
3956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3959 Boolean success = (Boolean) sendRequest(
3960 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3961 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3962 if (success) {
3963 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3964 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3965 }
3966 return success;
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003969 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003970 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003971
3972 /**
Junda Liu475951f2014-11-07 16:45:03 -08003973 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003974 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003975 * tethering.
3976 *
3977 * @return 0: Not required. 1: required. 2: Not set.
3978 * @hide
3979 */
3980 @Override
3981 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003982 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003983
3984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3987 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07003988 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08003989 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3990 dunRequired = 1;
3991 }
3992 return dunRequired;
3993 } finally {
3994 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003995 }
Junda Liu475951f2014-11-07 16:45:03 -08003996 }
3997
3998 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003999 * Set mobile data enabled
4000 * Used by the user through settings etc to turn on/off mobile data
4001 *
4002 * @param enable {@code true} turn turn data on, else {@code false}
4003 */
4004 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004005 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4007 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004008
4009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 int phoneId = mSubscriptionController.getPhoneId(subId);
4012 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4013 Phone phone = PhoneFactory.getPhone(phoneId);
4014 if (phone != null) {
4015 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4016 phone.setUserDataEnabled(enable);
4017 } else {
4018 loge("setUserDataEnabled: no phone for subId=" + subId);
4019 }
4020 } finally {
4021 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004022 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004023 }
4024
4025 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004026 * Get the user enabled state of Mobile Data.
4027 *
4028 * TODO: remove and use isUserDataEnabled.
4029 * This can't be removed now because some vendor codes
4030 * calls through ITelephony directly while they should
4031 * use TelephonyManager.
4032 *
4033 * @return true on enabled
4034 */
4035 @Override
4036 public boolean getDataEnabled(int subId) {
4037 return isUserDataEnabled(subId);
4038 }
4039
4040 /**
4041 * Get whether mobile data is enabled per user setting.
4042 *
4043 * There are other factors deciding whether mobile data is actually enabled, but they are
4044 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004045 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004046 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004047 *
4048 * @return {@code true} if data is enabled else {@code false}
4049 */
4050 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004051 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004052 try {
4053 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4054 null);
4055 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4057 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004058 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004059
4060 final long identity = Binder.clearCallingIdentity();
4061 try {
4062 int phoneId = mSubscriptionController.getPhoneId(subId);
4063 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4064 Phone phone = PhoneFactory.getPhone(phoneId);
4065 if (phone != null) {
4066 boolean retVal = phone.isUserDataEnabled();
4067 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4068 return retVal;
4069 } else {
4070 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4071 return false;
4072 }
4073 } finally {
4074 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004075 }
4076 }
4077
4078 /**
4079 * Get whether mobile data is enabled.
4080 *
4081 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4082 * whether mobile data is actually enabled.
4083 *
4084 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4085 *
4086 * @return {@code true} if data is enabled else {@code false}
4087 */
4088 @Override
4089 public boolean isDataEnabled(int subId) {
4090 try {
4091 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4092 null);
4093 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4095 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004096 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004097
4098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 int phoneId = mSubscriptionController.getPhoneId(subId);
4101 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4102 Phone phone = PhoneFactory.getPhone(phoneId);
4103 if (phone != null) {
4104 boolean retVal = phone.isDataEnabled();
4105 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4106 return retVal;
4107 } else {
4108 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4109 return false;
4110 }
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004113 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004114 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004115
4116 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004117 public int getCarrierPrivilegeStatus(int subId) {
4118 final Phone phone = getPhone(subId);
4119 if (phone == null) {
4120 loge("getCarrierPrivilegeStatus: Invalid subId");
4121 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4122 }
4123 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004124 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004125 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004126 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4127 }
4128 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004129 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004130 }
Junda Liu29340342014-07-10 15:23:27 -07004131
4132 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004133 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4134 final Phone phone = getPhone(subId);
4135 if (phone == null) {
4136 loge("getCarrierPrivilegeStatus: Invalid subId");
4137 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4138 }
4139 UiccProfile profile =
4140 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4141 if (profile == null) {
4142 loge("getCarrierPrivilegeStatus: No UICC");
4143 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4144 }
4145 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4146 }
4147
4148 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004149 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004150 if (TextUtils.isEmpty(pkgName))
4151 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004152 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004153 if (card == null) {
4154 loge("checkCarrierPrivilegesForPackage: No UICC");
4155 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4156 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004157 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4158 }
4159
4160 @Override
4161 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004162 if (TextUtils.isEmpty(pkgName))
4163 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004164 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4165 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4166 UiccCard card = UiccController.getInstance().getUiccCard(i);
4167 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004168 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004169 continue;
4170 }
4171
4172 result = card.getCarrierPrivilegeStatus(
4173 mPhone.getContext().getPackageManager(), pkgName);
4174 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4175 break;
4176 }
4177 }
4178
4179 return result;
Junda Liu29340342014-07-10 15:23:27 -07004180 }
Derek Tan89e89d42014-07-08 17:00:10 -07004181
4182 @Override
Junda Liue64de782015-04-16 17:19:16 -07004183 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4184 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4185 loge("phoneId " + phoneId + " is not valid.");
4186 return null;
4187 }
4188 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004189 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004190 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004191 return null ;
4192 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004193 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004194 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004195 }
4196
Amith Yamasani6e118872016-02-19 12:53:51 -08004197 @Override
4198 public List<String> getPackagesWithCarrierPrivileges() {
4199 PackageManager pm = mPhone.getContext().getPackageManager();
4200 List<String> privilegedPackages = new ArrayList<>();
4201 List<PackageInfo> packages = null;
4202 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4203 UiccCard card = UiccController.getInstance().getUiccCard(i);
4204 if (card == null) {
4205 // No UICC in that slot.
4206 continue;
4207 }
4208 if (card.hasCarrierPrivilegeRules()) {
4209 if (packages == null) {
4210 // Only check packages in user 0 for now
4211 packages = pm.getInstalledPackagesAsUser(
4212 PackageManager.MATCH_DISABLED_COMPONENTS
4213 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4214 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4215 }
4216 for (int p = packages.size() - 1; p >= 0; p--) {
4217 PackageInfo pkgInfo = packages.get(p);
4218 if (pkgInfo != null && pkgInfo.packageName != null
4219 && card.getCarrierPrivilegeStatus(pkgInfo)
4220 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4221 privilegedPackages.add(pkgInfo.packageName);
4222 }
4223 }
4224 }
4225 }
4226 return privilegedPackages;
4227 }
4228
Wink Savilleb564aae2014-10-23 10:18:09 -07004229 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004230 final Phone phone = getPhone(subId);
4231 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004232 if (card == null) {
4233 loge("getIccId: No UICC");
4234 return null;
4235 }
4236 String iccId = card.getIccId();
4237 if (TextUtils.isEmpty(iccId)) {
4238 loge("getIccId: ICC ID is null or empty.");
4239 return null;
4240 }
4241 return iccId;
4242 }
4243
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004244 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004245 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4246 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004247 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4248 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004249
Malcolm Chend965c8b2018-02-28 15:00:40 -08004250 final long identity = Binder.clearCallingIdentity();
4251 try {
4252 final String iccId = getIccId(subId);
4253 final Phone phone = getPhone(subId);
4254 if (phone == null) {
4255 return false;
4256 }
4257 final String subscriberId = phone.getSubscriberId();
4258
4259 if (DBG_MERGE) {
4260 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4261 + subscriberId + " to " + number);
4262 }
4263
4264 if (TextUtils.isEmpty(iccId)) {
4265 return false;
4266 }
4267
4268 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4269
4270 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4271 if (alphaTag == null) {
4272 editor.remove(alphaTagPrefKey);
4273 } else {
4274 editor.putString(alphaTagPrefKey, alphaTag);
4275 }
4276
4277 // Record both the line number and IMSI for this ICCID, since we need to
4278 // track all merged IMSIs based on line number
4279 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4280 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4281 if (number == null) {
4282 editor.remove(numberPrefKey);
4283 editor.remove(subscriberPrefKey);
4284 } else {
4285 editor.putString(numberPrefKey, number);
4286 editor.putString(subscriberPrefKey, subscriberId);
4287 }
4288
4289 editor.commit();
4290 return true;
4291 } finally {
4292 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004293 }
Derek Tan7226c842014-07-02 17:42:23 -07004294 }
4295
4296 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004297 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004298 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004300 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004301 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004302 return null;
4303 }
Derek Tan97ebb422014-09-05 16:55:38 -07004304
Malcolm Chend965c8b2018-02-28 15:00:40 -08004305 final long identity = Binder.clearCallingIdentity();
4306 try {
4307 String iccId = getIccId(subId);
4308 if (iccId != null) {
4309 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4310 if (DBG_MERGE) {
4311 log("getLine1NumberForDisplay returning "
4312 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4313 }
4314 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004315 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004316 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4317 return null;
4318 } finally {
4319 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004320 }
Derek Tan7226c842014-07-02 17:42:23 -07004321 }
4322
4323 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004324 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004326 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004327 return null;
4328 }
Derek Tan97ebb422014-09-05 16:55:38 -07004329
Malcolm Chend965c8b2018-02-28 15:00:40 -08004330 final long identity = Binder.clearCallingIdentity();
4331 try {
4332 String iccId = getIccId(subId);
4333 if (iccId != null) {
4334 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4335 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4336 }
4337 return null;
4338 } finally {
4339 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004340 }
Derek Tan7226c842014-07-02 17:42:23 -07004341 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004342
4343 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004344 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004345 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4346 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004348 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4349 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004350 return null;
4351 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004352
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004353 final long identity = Binder.clearCallingIdentity();
4354 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004355 final Context context = mPhone.getContext();
4356 final TelephonyManager tele = TelephonyManager.from(context);
4357 final SubscriptionManager sub = SubscriptionManager.from(context);
4358
4359 // Figure out what subscribers are currently active
4360 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4361 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4362 // the process, where TelephonyManager was instantiated.
4363 // Otherwise AppOps check will fail.
4364
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004365 final int[] subIds = sub.getActiveSubscriptionIdList();
4366 for (int subId : subIds) {
4367 activeSubscriberIds.add(tele.getSubscriberId(subId));
4368 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004369
4370 // First pass, find a number override for an active subscriber
4371 String mergeNumber = null;
4372 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4373 for (String key : prefs.keySet()) {
4374 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4375 final String subscriberId = (String) prefs.get(key);
4376 if (activeSubscriberIds.contains(subscriberId)) {
4377 final String iccId = key.substring(
4378 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4379 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4380 mergeNumber = (String) prefs.get(numberKey);
4381 if (DBG_MERGE) {
4382 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4383 + " for active subscriber " + subscriberId);
4384 }
4385 if (!TextUtils.isEmpty(mergeNumber)) {
4386 break;
4387 }
4388 }
4389 }
4390 }
4391
4392 // Shortcut when no active merged subscribers
4393 if (TextUtils.isEmpty(mergeNumber)) {
4394 return null;
4395 }
4396
4397 // Second pass, find all subscribers under that line override
4398 final ArraySet<String> result = new ArraySet<>();
4399 for (String key : prefs.keySet()) {
4400 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4401 final String number = (String) prefs.get(key);
4402 if (mergeNumber.equals(number)) {
4403 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4404 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4405 final String subscriberId = (String) prefs.get(subscriberKey);
4406 if (!TextUtils.isEmpty(subscriberId)) {
4407 result.add(subscriberId);
4408 }
4409 }
4410 }
4411 }
4412
4413 final String[] resultArray = result.toArray(new String[result.size()]);
4414 Arrays.sort(resultArray);
4415 if (DBG_MERGE) {
4416 Slog.d(LOG_TAG,
4417 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4418 }
4419 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004420 } finally {
4421 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004422 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004423 }
4424
4425 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004426 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004427 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4428 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004429
4430 final long identity = Binder.clearCallingIdentity();
4431 try {
4432 final Phone phone = getPhone(subId);
4433 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004437 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004438
4439 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004440 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004441 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4442 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004443 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004444
4445 final long identity = Binder.clearCallingIdentity();
4446 try {
4447 final Phone phone = getPhone(subId);
4448 if (phone == null) {
4449 return false;
4450 }
4451 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4452 cdmaNonRoamingList);
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004455 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004456 }
4457
4458 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004459 @Deprecated
4460 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4461 enforceModifyPermission();
4462
4463 int returnValue = 0;
4464 try {
vagdevie435a3e2018-08-15 16:01:53 -07004465 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004466 if(result.exception == null) {
4467 if (result.result != null) {
4468 byte[] responseData = (byte[])(result.result);
4469 if(responseData.length > oemResp.length) {
4470 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4471 responseData.length + "bytes. Buffer Size is " +
4472 oemResp.length + "bytes.");
4473 }
4474 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4475 returnValue = responseData.length;
4476 }
4477 } else {
4478 CommandException ex = (CommandException) result.exception;
4479 returnValue = ex.getCommandError().ordinal();
4480 if(returnValue > 0) returnValue *= -1;
4481 }
4482 } catch (RuntimeException e) {
4483 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4484 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4485 if(returnValue > 0) returnValue *= -1;
4486 }
4487
4488 return returnValue;
4489 }
4490
4491 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004492 public void setRadioCapability(RadioAccessFamily[] rafs) {
4493 try {
4494 ProxyController.getInstance().setRadioCapability(rafs);
4495 } catch (RuntimeException e) {
4496 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4497 }
4498 }
4499
4500 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004501 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004502 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004503 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004504 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004505 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004506 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004507 final long identity = Binder.clearCallingIdentity();
4508 try {
chen xufeeed752018-10-26 14:17:57 -07004509 TelephonyPermissions
4510 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4511 mApp, phone.getSubId(), "getRadioAccessFamily");
4512 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
chen xufeeed752018-10-26 14:17:57 -07004516 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004517 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004518
4519 @Override
4520 public void enableVideoCalling(boolean enable) {
4521 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004522
4523 final long identity = Binder.clearCallingIdentity();
4524 try {
4525 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004529 }
4530
4531 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004532 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004533 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4534 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4535 return false;
4536 }
Svet Ganovb320e182015-04-16 12:30:10 -07004537
Malcolm Chend965c8b2018-02-28 15:00:40 -08004538 final long identity = Binder.clearCallingIdentity();
4539 try {
4540 // Check the user preference and the system-level IMS setting. Even if the user has
4541 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4542 // In the long run, we may instead need to check if there exists a connection service
4543 // which can support video calling.
4544 ImsManager imsManager =
4545 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4546 return imsManager.isVtEnabledByPlatform()
4547 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4548 && imsManager.isVtEnabledByUser();
4549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004552 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004553
Andrew Leea1239f22015-03-02 17:44:07 -08004554 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004555 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4557 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4558 return false;
4559 }
4560
4561 final long identity = Binder.clearCallingIdentity();
4562 try {
4563 CarrierConfigManager configManager =
4564 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4565 return configManager.getConfigForSubId(mPhone.getSubId())
4566 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4567 } finally {
4568 Binder.restoreCallingIdentity(identity);
4569 }
Andrew Leea1239f22015-03-02 17:44:07 -08004570 }
4571
4572 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004573 public boolean isWorldPhone(int subId, String callingPackage) {
4574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4575 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4576 return false;
4577 }
4578
4579 final long identity = Binder.clearCallingIdentity();
4580 try {
4581 CarrierConfigManager configManager =
4582 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4583 return configManager.getConfigForSubId(mPhone.getSubId())
4584 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
4587 }
Andrew Leea1239f22015-03-02 17:44:07 -08004588 }
4589
Andrew Lee9431b832015-03-09 18:46:45 -07004590 @Override
4591 public boolean isTtyModeSupported() {
4592 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004593 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004594 }
4595
4596 @Override
4597 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004598 final long identity = Binder.clearCallingIdentity();
4599 try {
4600 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4601 } finally {
4602 Binder.restoreCallingIdentity(identity);
4603 }
Andrew Lee9431b832015-03-09 18:46:45 -07004604 }
4605
Hall Liuf6668912018-10-31 17:05:23 -07004606 /**
4607 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4608 * support for the feature and device firmware support.
4609 *
4610 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4611 */
4612 @Override
4613 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004614 final long identity = Binder.clearCallingIdentity();
4615 try {
4616 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4617 mPhone.getSubId()).getBoolean(
4618 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4619 boolean isDeviceSupported =
4620 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4621 return isCarrierSupported && isDeviceSupported;
4622 } finally {
4623 Binder.restoreCallingIdentity(identity);
4624 }
Hall Liu98187582018-01-22 19:15:32 -08004625 }
4626
Hall Liuf6668912018-10-31 17:05:23 -07004627 /**
4628 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4629 * both also support RTT.
4630 */
4631 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004632 final long identity = Binder.clearCallingIdentity();
4633 try {
Hall Liuf6668912018-10-31 17:05:23 -07004634 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004635 mPhone.getContext().getContentResolver(),
4636 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4637 } finally {
4638 Binder.restoreCallingIdentity(identity);
4639 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004640 }
4641
Sanket Padawe7310cc72015-01-14 09:53:20 -08004642 /**
4643 * Returns the unique device ID of phone, for example, the IMEI for
4644 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4645 *
4646 * <p>Requires Permission:
4647 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4648 */
4649 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004650 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004651 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004652 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004653 return null;
4654 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004655 int subId = phone.getSubId();
4656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4657 mApp, subId, callingPackage, "getDeviceId")) {
4658 return null;
4659 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004660
4661 final long identity = Binder.clearCallingIdentity();
4662 try {
4663 return phone.getDeviceId();
4664 } finally {
4665 Binder.restoreCallingIdentity(identity);
4666 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004667 }
4668
Ping Sunc67b7c22016-03-02 19:16:45 +08004669 /**
4670 * {@hide}
4671 * Returns the IMS Registration Status on a particular subid
4672 *
4673 * @param subId
4674 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004675 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004676 Phone phone = getPhone(subId);
4677 if (phone != null) {
4678 return phone.isImsRegistered();
4679 } else {
4680 return false;
4681 }
4682 }
4683
Santos Cordon7a1885b2015-02-03 11:15:19 -08004684 @Override
4685 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004686 final long identity = Binder.clearCallingIdentity();
4687 try {
4688 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4689 } finally {
4690 Binder.restoreCallingIdentity(identity);
4691 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004692 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004693
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004694 /**
4695 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004696 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004697 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004698 final long identity = Binder.clearCallingIdentity();
4699 try {
4700 Phone phone = getPhone(subId);
4701 if (phone != null) {
4702 return phone.isWifiCallingEnabled();
4703 } else {
4704 return false;
4705 }
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004708 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004709 }
4710
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004711 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004712 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004713 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004714 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004715 final long identity = Binder.clearCallingIdentity();
4716 try {
4717 Phone phone = getPhone(subId);
4718 if (phone != null) {
4719 return phone.isVideoEnabled();
4720 } else {
4721 return false;
4722 }
4723 } finally {
4724 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004725 }
4726 }
4727
4728 /**
4729 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4730 * defined in {@link ImsRegistrationImplBase}.
4731 */
4732 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004733 final long identity = Binder.clearCallingIdentity();
4734 try {
4735 Phone phone = getPhone(subId);
4736 if (phone != null) {
4737 return phone.getImsRegistrationTech();
4738 } else {
4739 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4740 }
4741 } finally {
4742 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004743 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004744 }
4745
Stuart Scott8eef64f2015-04-08 15:13:54 -07004746 @Override
4747 public void factoryReset(int subId) {
4748 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004749 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4750 return;
4751 }
4752
Svet Ganovcc087f82015-05-12 20:35:54 -07004753 final long identity = Binder.clearCallingIdentity();
4754 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004755 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4756 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004757 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004758 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004759 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4760 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004761 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004762 }
4763 } finally {
4764 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004765 }
4766 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004767
4768 @Override
4769 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004770 final long identity = Binder.clearCallingIdentity();
4771 try {
4772 // We query all subscriptions instead of just the active ones, because
4773 // this might be called early on in the provisioning flow when the
4774 // subscriptions potentially aren't active yet.
4775 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4776 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004777 return null;
4778 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004779
Malcolm Chend965c8b2018-02-28 15:00:40 -08004780 // This function may be called very early, say, from the setup wizard, at
4781 // which point we won't have a default subscription set. If that's the case
4782 // we just choose the first, which will be valid in "most cases".
4783 final int defaultSubId = getDefaultSubscription();
4784 SubscriptionInfo info = null;
4785 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4786 info = slist.get(0);
4787 } else {
4788 for (SubscriptionInfo item : slist) {
4789 if (item.getSubscriptionId() == defaultSubId) {
4790 info = item;
4791 break;
4792 }
4793 }
4794
4795 if (info == null) {
4796 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004797 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004798 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004799
Malcolm Chend965c8b2018-02-28 15:00:40 -08004800 // Try and fetch the locale from the carrier properties or from the SIM language
4801 // preferences (EF-PL and EF-LI)...
4802 final int mcc = info.getMcc();
4803 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4804 String simLanguage = null;
4805 if (defaultPhone != null) {
4806 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4807 if (localeFromDefaultSim != null) {
4808 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4809 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4810 return localeFromDefaultSim.toLanguageTag();
4811 } else {
4812 simLanguage = localeFromDefaultSim.getLanguage();
4813 }
4814 }
4815 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004816
Malcolm Chend965c8b2018-02-28 15:00:40 -08004817 // The SIM language preferences only store a language (e.g. fr = French), not an
4818 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4819 // the SIM and carrier preferences does not include a country we add the country
4820 // determined from the SIM MCC to provide an exact locale.
4821 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4822 simLanguage);
4823 if (mccLocale != null) {
4824 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4825 return mccLocale.toLanguageTag();
4826 }
4827
4828 if (DBG) log("No locale found - returning null");
4829 return null;
4830 } finally {
4831 Binder.restoreCallingIdentity(identity);
4832 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004833 }
4834
4835 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004836 return mSubscriptionController.getAllSubInfoList(
4837 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004838 }
4839
Malcolm Chend965c8b2018-02-28 15:00:40 -08004840 /**
4841 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4842 */
4843 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4844 return mSubscriptionController.getActiveSubscriptionInfoList(
4845 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004846 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004847
Chenjie Yu1ba97252018-01-11 18:16:20 -08004848 private final ModemActivityInfo mLastModemActivityInfo =
4849 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4850
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004851 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004852 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4853 * representing the state of the modem.
4854 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004855 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4856 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004857 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004858 */
4859 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004860 public void requestModemActivityInfo(ResultReceiver result) {
4861 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004862 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004863
4864 final long identity = Binder.clearCallingIdentity();
4865 try {
4866 ModemActivityInfo ret = null;
4867 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004868 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4869 CMD_GET_MODEM_ACTIVITY_INFO,
4870 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004871 if (isModemActivityInfoValid(info)) {
4872 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4873 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4874 mergedTxTimeMs[i] =
4875 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4876 }
4877 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4878 mLastModemActivityInfo.setSleepTimeMillis(
4879 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4880 mLastModemActivityInfo.setIdleTimeMillis(
4881 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4882 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4883 mLastModemActivityInfo.setRxTimeMillis(
4884 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4885 mLastModemActivityInfo.setEnergyUsed(
4886 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004887 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004888 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4889 mLastModemActivityInfo.getSleepTimeMillis(),
4890 mLastModemActivityInfo.getIdleTimeMillis(),
4891 mLastModemActivityInfo.getTxTimeMillis(),
4892 mLastModemActivityInfo.getRxTimeMillis(),
4893 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004894 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004895 Bundle bundle = new Bundle();
4896 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4897 result.send(0, bundle);
4898 } finally {
4899 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004900 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004901 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004902
Siddharth Rayf5d29552018-06-17 15:02:38 -07004903 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4904 // less than total activity duration.
4905 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4906 if (info == null) {
4907 return false;
4908 }
4909 int activityDurationMs =
4910 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4911 int totalTxTimeMs = 0;
4912 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4913 totalTxTimeMs += info.getTxTimeMillis()[i];
4914 }
4915 return (info.isValid()
4916 && (info.getSleepTimeMillis() <= activityDurationMs)
4917 && (info.getIdleTimeMillis() <= activityDurationMs)
4918 && (info.getRxTimeMillis() <= activityDurationMs)
4919 && (totalTxTimeMs <= activityDurationMs));
4920 }
4921
Jack Yu85bd38a2015-11-09 11:34:32 -08004922 /**
4923 * {@hide}
4924 * Returns the service state information on specified subscription.
4925 */
4926 @Override
4927 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004929 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004930 return null;
4931 }
4932
Malcolm Chend965c8b2018-02-28 15:00:40 -08004933 final long identity = Binder.clearCallingIdentity();
4934 try {
4935 final Phone phone = getPhone(subId);
4936 if (phone == null) {
4937 return null;
4938 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004939
Malcolm Chend965c8b2018-02-28 15:00:40 -08004940 return phone.getServiceState();
4941 } finally {
4942 Binder.restoreCallingIdentity(identity);
4943 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004944 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004945
4946 /**
4947 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4948 *
4949 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4950 * voicemail ringtone.
4951 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4952 * PhoneAccount.
4953 */
4954 @Override
4955 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4959 if (phone == null) {
4960 phone = mPhone;
4961 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004962
Malcolm Chend965c8b2018-02-28 15:00:40 -08004963 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004967 }
4968
4969 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004970 * Sets the per-account voicemail ringtone.
4971 *
4972 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4973 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4974 *
4975 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4976 * voicemail ringtone.
4977 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4978 * PhoneAccount.
4979 */
4980 @Override
4981 public void setVoicemailRingtoneUri(String callingPackage,
4982 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4983 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4984 if (!TextUtils.equals(callingPackage,
4985 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4987 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4988 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004989 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004990
4991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4994 if (phone == null) {
4995 phone = mPhone;
4996 }
4997 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4998 } finally {
4999 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005000 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005001 }
5002
5003 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005004 * Returns whether vibration is set for voicemail notification in Phone settings.
5005 *
5006 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5007 * voicemail vibration setting.
5008 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5009 */
5010 @Override
5011 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005012 final long identity = Binder.clearCallingIdentity();
5013 try {
5014 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5015 if (phone == null) {
5016 phone = mPhone;
5017 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005018
Malcolm Chend965c8b2018-02-28 15:00:40 -08005019 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005023 }
5024
Youhan Wange64578a2016-05-02 15:32:42 -07005025 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005026 * Sets the per-account voicemail vibration.
5027 *
5028 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5029 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5030 *
5031 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5032 * voicemail vibration setting.
5033 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5034 * specific PhoneAccount.
5035 */
5036 @Override
5037 public void setVoicemailVibrationEnabled(String callingPackage,
5038 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5040 if (!TextUtils.equals(callingPackage,
5041 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5043 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5044 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005045 }
5046
Malcolm Chend965c8b2018-02-28 15:00:40 -08005047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5050 if (phone == null) {
5051 phone = mPhone;
5052 }
5053 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005056 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005057 }
5058
5059 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005060 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5061 *
5062 * @throws SecurityException if the caller does not have the required permission
5063 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005064 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005065 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005066 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005067 }
5068
5069 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005070 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5071 * permission.
5072 *
5073 * @throws SecurityException if the caller does not have the required permission
5074 */
5075 private void enforceSendSmsPermission() {
5076 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5077 }
5078
5079 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005080 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005081 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005082 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005083 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005084 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005085 final long identity = Binder.clearCallingIdentity();
5086 try {
5087 ComponentName componentName =
5088 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5089 if (componentName == null) {
5090 throw new SecurityException(
5091 "Caller not current active visual voicemail package[null]");
5092 }
5093 String vvmPackage = componentName.getPackageName();
5094 if (!callingPackage.equals(vvmPackage)) {
5095 throw new SecurityException("Caller not current active visual voicemail package["
5096 + vvmPackage + "]");
5097 }
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005100 }
5101 }
5102
5103 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005104 * Return the application ID for the app type.
5105 *
5106 * @param subId the subscription ID that this request applies to.
5107 * @param appType the uicc app type.
5108 * @return Application ID for specificied app type, or null if no uicc.
5109 */
5110 @Override
5111 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005112 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005113 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005114
5115 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005116 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005117 if (phone == null) {
5118 return null;
5119 }
5120 String aid = null;
5121 try {
5122 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5123 .getApplicationByType(appType).getAid();
5124 } catch (Exception e) {
5125 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5126 }
5127 return aid;
5128 } finally {
5129 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005130 }
Youhan Wange64578a2016-05-02 15:32:42 -07005131 }
5132
Youhan Wang4001d252016-05-11 10:29:41 -07005133 /**
5134 * Return the Electronic Serial Number.
5135 *
5136 * @param subId the subscription ID that this request applies to.
5137 * @return ESN or null if error.
5138 */
5139 @Override
5140 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005141 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005142 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143
5144 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005145 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005146 if (phone == null) {
5147 return null;
5148 }
5149 String esn = null;
5150 try {
5151 esn = phone.getEsn();
5152 } catch (Exception e) {
5153 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5154 }
5155 return esn;
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005158 }
Youhan Wang4001d252016-05-11 10:29:41 -07005159 }
5160
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005161 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005162 * Return the Preferred Roaming List Version.
5163 *
5164 * @param subId the subscription ID that this request applies to.
5165 * @return PRLVersion or null if error.
5166 */
5167 @Override
5168 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005169 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005170 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005171
5172 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005173 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005174 if (phone == null) {
5175 return null;
5176 }
5177 String cdmaPrlVersion = null;
5178 try {
5179 cdmaPrlVersion = phone.getCdmaPrlVersion();
5180 } catch (Exception e) {
5181 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5182 }
5183 return cdmaPrlVersion;
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005186 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005187 }
5188
5189 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005190 * Get snapshot of Telephony histograms
5191 * @return List of Telephony histograms
5192 * @hide
5193 */
5194 @Override
5195 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5197 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005198
5199 final long identity = Binder.clearCallingIdentity();
5200 try {
5201 return RIL.getTelephonyRILTimingHistograms();
5202 } finally {
5203 Binder.restoreCallingIdentity(identity);
5204 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005205 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005206
5207 /**
5208 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005209 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005210 * Require system privileges. In the future we may add this to carrier APIs.
5211 *
5212 * @return The number of carriers set successfully, should match length of carriers
5213 */
5214 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005215 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005216 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005217 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005218
Meng Wang9b7c4e92017-02-17 11:41:27 -08005219 if (carriers == null) {
5220 throw new NullPointerException("carriers cannot be null");
5221 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005222
Malcolm Chend965c8b2018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005226 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5227 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005228 return retVal[0];
5229 } finally {
5230 Binder.restoreCallingIdentity(identity);
5231 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005232 }
5233
5234 /**
5235 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005236 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005237 * Require system privileges. In the future we may add this to carrier APIs.
5238 *
5239 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5240 * means all carriers are allowed.
5241 */
5242 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005243 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005244 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005245 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005246
5247 final long identity = Binder.clearCallingIdentity();
5248 try {
5249 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005250 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5251 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005255 }
5256
fionaxu59545b42016-05-25 15:53:37 -07005257 /**
5258 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5259 * @param subId the subscription ID that this action applies to.
5260 * @param enabled control enable or disable metered apns.
5261 * {@hide}
5262 */
5263 @Override
5264 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5265 enforceModifyPermission();
5266 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005267
5268 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005269 if (phone == null) {
5270 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5271 return;
5272 }
5273 try {
5274 phone.carrierActionSetMeteredApnsEnabled(enabled);
5275 } catch (Exception e) {
5276 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005277 } finally {
5278 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005279 }
5280 }
5281
5282 /**
5283 * Action set from carrier signalling broadcast receivers to enable/disable radio
5284 * @param subId the subscription ID that this action applies to.
5285 * @param enabled control enable or disable radio.
5286 * {@hide}
5287 */
5288 @Override
5289 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5290 enforceModifyPermission();
5291 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005292
5293 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005294 if (phone == null) {
5295 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5296 return;
5297 }
5298 try {
5299 phone.carrierActionSetRadioEnabled(enabled);
5300 } catch (Exception e) {
5301 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005302 } finally {
5303 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005304 }
5305 }
5306
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005307 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005308 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5309 * network status based on which carrier apps could apply actions accordingly,
5310 * enable/disable default url handler for example.
5311 *
5312 * @param subId the subscription ID that this action applies to.
5313 * @param report control start/stop reporting the default network status.
5314 * {@hide}
5315 */
5316 @Override
5317 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5318 enforceModifyPermission();
5319 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005320
5321 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005322 if (phone == null) {
5323 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5324 return;
5325 }
5326 try {
5327 phone.carrierActionReportDefaultNetworkStatus(report);
5328 } catch (Exception e) {
5329 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005330 } finally {
5331 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005332 }
5333 }
5334
5335 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005336 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5337 * bug report is being generated.
5338 */
5339 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005340 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005341 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5342 != PackageManager.PERMISSION_GRANTED) {
5343 writer.println("Permission Denial: can't dump Phone from pid="
5344 + Binder.getCallingPid()
5345 + ", uid=" + Binder.getCallingUid()
5346 + "without permission "
5347 + android.Manifest.permission.DUMP);
5348 return;
5349 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005350 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005351 }
Jack Yueb89b242016-06-22 13:27:47 -07005352
Brad Ebingerdac2f002018-04-03 15:17:52 -07005353 @Override
5354 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5355 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5356 throws RemoteException {
5357 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5358 }
5359
Jack Yueb89b242016-06-22 13:27:47 -07005360 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005361 * Get aggregated video call data usage since boot.
5362 *
5363 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5364 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005365 * {@hide}
5366 */
5367 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005368 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005369 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5370 null);
5371
Malcolm Chend965c8b2018-02-28 15:00:40 -08005372 final long identity = Binder.clearCallingIdentity();
5373 try {
5374 // NetworkStatsService keeps tracking the active network interface and identity. It
5375 // records the delta with the corresponding network identity.
5376 // We just return the total video call data usage snapshot since boot.
5377 Phone phone = getPhone(subId);
5378 if (phone != null) {
5379 return phone.getVtDataUsage(perUidStats);
5380 }
5381 return null;
5382 } finally {
5383 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005384 }
Jack Yueb89b242016-06-22 13:27:47 -07005385 }
Jack Yu75ab2952016-07-08 14:29:33 -07005386
5387 /**
5388 * Policy control of data connection. Usually used when data limit is passed.
5389 * @param enabled True if enabling the data, otherwise disabling.
5390 * @param subId Subscription index
5391 * {@hide}
5392 */
5393 @Override
5394 public void setPolicyDataEnabled(boolean enabled, int subId) {
5395 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005396
5397 final long identity = Binder.clearCallingIdentity();
5398 try {
5399 Phone phone = getPhone(subId);
5400 if (phone != null) {
5401 phone.setPolicyDataEnabled(enabled);
5402 }
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005405 }
5406 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005407
5408 /**
5409 * Get Client request stats
5410 * @return List of Client Request Stats
5411 * @hide
5412 */
5413 @Override
5414 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005415 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005416 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005417 return null;
5418 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005419 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005420
Malcolm Chend965c8b2018-02-28 15:00:40 -08005421 final long identity = Binder.clearCallingIdentity();
5422 try {
5423 if (phone != null) {
5424 return phone.getClientRequestStats();
5425 }
5426
5427 return null;
5428 } finally {
5429 Binder.restoreCallingIdentity(identity);
5430 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005431 }
5432
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005433 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005434 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005435 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005436 }
Jack Yueb4124c2017-02-16 15:32:43 -08005437
5438 /**
Grace Chen70990072017-03-24 17:21:30 -07005439 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005440 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005441 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005442 * @param state State of SIM (power down, power up, pass through)
5443 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5444 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5445 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005446 *
5447 **/
5448 @Override
Grace Chen70990072017-03-24 17:21:30 -07005449 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005450 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005451 Phone phone = PhoneFactory.getPhone(slotIndex);
5452
vagdevie435a3e2018-08-15 16:01:53 -07005453 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5454
Malcolm Chend965c8b2018-02-28 15:00:40 -08005455 final long identity = Binder.clearCallingIdentity();
5456 try {
5457 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005458 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005459 }
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005462 }
5463 }
Shuo Qiandd210312017-04-12 22:11:33 +00005464
Tyler Gunn65d45c22017-06-05 11:22:26 -07005465 private boolean isUssdApiAllowed(int subId) {
5466 CarrierConfigManager configManager =
5467 (CarrierConfigManager) mPhone.getContext().getSystemService(
5468 Context.CARRIER_CONFIG_SERVICE);
5469 if (configManager == null) {
5470 return false;
5471 }
5472 PersistableBundle pb = configManager.getConfigForSubId(subId);
5473 if (pb == null) {
5474 return false;
5475 }
5476 return pb.getBoolean(
5477 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5478 }
5479
Shuo Qiandd210312017-04-12 22:11:33 +00005480 /**
5481 * Check if phone is in emergency callback mode
5482 * @return true if phone is in emergency callback mode
5483 * @param subId sub id
5484 */
goneil9c5f4872017-12-05 14:07:56 -08005485 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005486 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005487 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005488 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005489
5490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 if (phone != null) {
5493 return phone.isInEcm();
5494 } else {
5495 return false;
5496 }
5497 } finally {
5498 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005499 }
5500 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005501
5502 /**
5503 * Get the current signal strength information for the given subscription.
5504 * Because this information is not updated when the device is in a low power state
5505 * it should not be relied-upon to be current.
5506 * @param subId Subscription index
5507 * @return the most recent cached signal strength info from the modem
5508 */
5509 @Override
5510 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005511 final long identity = Binder.clearCallingIdentity();
5512 try {
5513 Phone p = getPhone(subId);
5514 if (p == null) {
5515 return null;
5516 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005517
Malcolm Chend965c8b2018-02-28 15:00:40 -08005518 return p.getSignalStrength();
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
5521 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005522 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005523
Pengquan Meng9140aec2018-08-22 14:49:57 -07005524 /**
chen xu907e5a22018-10-11 13:21:04 -07005525 * Get the current modem radio state for the given slot.
5526 * @param slotIndex slot index.
5527 * @param callingPackage the name of the package making the call.
5528 * @return the current radio power state from the modem
5529 */
5530 @Override
5531 public int getRadioPowerState(int slotIndex, String callingPackage) {
5532 Phone phone = PhoneFactory.getPhone(slotIndex);
5533 if (phone != null) {
5534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5535 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5536 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5537 }
5538
5539 final long identity = Binder.clearCallingIdentity();
5540 try {
5541 return phone.getRadioPowerState();
5542 } finally {
5543 Binder.restoreCallingIdentity(identity);
5544 }
5545 }
5546 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5547 }
5548
5549 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005550 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5551 *
5552 * <p>Requires one of the following permissions:
5553 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5554 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5555 * privileges.
5556 *
5557 * @param subId subscription id
5558 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5559 * {@code false}.
5560 */
5561 @Override
5562 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005563 boolean isEnabled = false;
5564 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005565 try {
5566 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005567 null /* message */);
5568 Phone phone = getPhone(subId);
5569 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005570 } catch (Exception e) {
5571 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5572 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005573 } finally {
5574 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005575 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005576 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005577 }
5578
5579
5580 /**
5581 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5582 *
5583 * <p> Requires permission:
5584 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5585 * privileges.
5586 *
5587 * @param subId subscription id
5588 * @param isEnabled {@code true} means enable, {@code false} means disable.
5589 */
5590 @Override
5591 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005592 final long identity = Binder.clearCallingIdentity();
5593 try {
5594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5595 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005596
Pengquan Meng0c05b502018-09-06 09:59:22 -07005597 Phone phone = getPhone(subId);
5598 if (phone != null) {
5599 phone.setDataRoamingEnabled(isEnabled);
5600 }
5601 } finally {
5602 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005603 }
5604 }
5605
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005606 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005607 public boolean isManualNetworkSelectionAllowed(int subId) {
5608 boolean isAllowed = true;
5609 final long identity = Binder.clearCallingIdentity();
5610 try {
5611 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5612 mApp, subId, "isManualNetworkSelectionAllowed");
5613 Phone phone = getPhone(subId);
5614 if (phone != null) {
5615 isAllowed = phone.isCspPlmnEnabled();
5616 }
5617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
5620 return isAllowed;
5621 }
5622
5623 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005624 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005625 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005626
Malcolm Chend965c8b2018-02-28 15:00:40 -08005627 final long identity = Binder.clearCallingIdentity();
5628 try {
5629 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5630 if (slots == null) {
5631 Rlog.i(LOG_TAG, "slots is null.");
5632 return null;
5633 }
5634
5635 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5636 for (int i = 0; i < slots.length; i++) {
5637 UiccSlot slot = slots[i];
5638 if (slot == null) {
5639 continue;
5640 }
5641
5642 String cardId;
5643 UiccCard card = slot.getUiccCard();
5644 if (card != null) {
5645 cardId = card.getCardId();
5646 } else {
5647 cardId = slot.getIccId();
5648 }
5649
5650 int cardState = 0;
5651 switch (slot.getCardState()) {
5652 case CARDSTATE_ABSENT:
5653 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5654 break;
5655 case CARDSTATE_PRESENT:
5656 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5657 break;
5658 case CARDSTATE_ERROR:
5659 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5660 break;
5661 case CARDSTATE_RESTRICTED:
5662 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5663 break;
5664 default:
5665 break;
5666
5667 }
5668
5669 infos[i] = new UiccSlotInfo(
5670 slot.isActive(),
5671 slot.isEuicc(),
5672 cardId,
5673 cardState,
5674 slot.getPhoneId(),
5675 slot.isExtendedApduSupported());
5676 }
5677 return infos;
5678 } finally {
5679 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005680 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005681 }
5682
5683 @Override
5684 public boolean switchSlots(int[] physicalSlots) {
5685 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005686
5687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5690 } finally {
5691 Binder.restoreCallingIdentity(identity);
5692 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005693 }
Jack Yu4c988042018-02-27 15:30:01 -08005694
5695 @Override
5696 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5697 enforceModifyPermission();
5698 final Phone phone = getPhone(subId);
5699 if (phone == null) {
5700 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5701 return;
5702 }
5703
Malcolm Chend965c8b2018-02-28 15:00:40 -08005704 final long identity = Binder.clearCallingIdentity();
5705 try {
5706 phone.setRadioIndicationUpdateMode(filters, mode);
5707 } finally {
5708 Binder.restoreCallingIdentity(identity);
5709 }
Jack Yu4c988042018-02-27 15:30:01 -08005710 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005711
5712 /**
goneil47ffb6e2018-04-06 15:40:58 -07005713 * A test API to reload the UICC profile.
5714 *
5715 * <p>Requires that the calling app has permission
5716 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5717 * @hide
5718 */
5719 @Override
5720 public void refreshUiccProfile(int subId) {
5721 enforceModifyPermission();
5722
5723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 Phone phone = getPhone(subId);
5726 if (phone == null) {
5727 return;
5728 }
5729 UiccCard uiccCard = phone.getUiccCard();
5730 if (uiccCard == null) {
5731 return;
5732 }
5733 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5734 if (uiccProfile == null) {
5735 return;
5736 }
5737 uiccProfile.refresh();
5738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
5741 }
5742
5743 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005744 * Returns false if the mobile data is disabled by default, otherwise return true.
5745 */
5746 private boolean getDefaultDataEnabled() {
5747 return "true".equalsIgnoreCase(
5748 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5749 }
5750
5751 /**
5752 * Returns true if the data roaming is enabled by default, i.e the system property
5753 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5754 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5755 */
5756 private boolean getDefaultDataRoamingEnabled(int subId) {
5757 final CarrierConfigManager configMgr = (CarrierConfigManager)
5758 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5759 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5760 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5761 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5762 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5763 return isDataRoamingEnabled;
5764 }
5765
5766 /**
5767 * Returns the default network type for the given {@code subId}, if the default network type is
5768 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5769 */
5770 private int getDefaultNetworkType(int subId) {
5771 return Integer.parseInt(
5772 TelephonyManager.getTelephonyProperty(
5773 mSubscriptionController.getPhoneId(subId),
5774 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5775 String.valueOf(Phone.PREFERRED_NT_MODE)));
5776 }
fionaxua13278b2018-03-21 00:08:13 -07005777
5778 @Override
5779 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5780 gid1, String gid2, String plmn, String spn) {
5781 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005782
5783 final long identity = Binder.clearCallingIdentity();
5784 try {
5785 final Phone phone = getPhone(subId);
5786 if (phone == null) {
5787 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5788 return;
5789 }
5790 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5791 } finally {
5792 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005793 }
fionaxua13278b2018-03-21 00:08:13 -07005794 }
5795
5796 @Override
5797 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005798 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005799
5800 final long identity = Binder.clearCallingIdentity();
5801 try {
5802 final Phone phone = getPhone(subId);
5803 if (phone == null) {
5804 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5805 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5806 }
5807 return phone.getCarrierIdListVersion();
5808 } finally {
5809 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005810 }
fionaxua13278b2018-03-21 00:08:13 -07005811 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005812
5813 @Override
5814 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5816 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5817 return -1;
5818 }
5819
5820 final long identity = Binder.clearCallingIdentity();
5821 try {
5822 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
5826 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005827
5828 @Override
5829 public int getCdmaRoamingMode(int subId) {
5830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5831 mApp, subId, "getCdmaRoamingMode");
5832
5833 final long identity = Binder.clearCallingIdentity();
5834 try {
5835 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
5839 }
5840
5841 @Override
5842 public boolean setCdmaRoamingMode(int subId, int mode) {
5843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5844 mApp, subId, "setCdmaRoamingMode");
5845
5846 final long identity = Binder.clearCallingIdentity();
5847 try {
5848 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5849 } finally {
5850 Binder.restoreCallingIdentity(identity);
5851 }
5852 }
5853
5854 @Override
5855 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5857 mApp, subId, "setCdmaSubscriptionMode");
5858
5859 final long identity = Binder.clearCallingIdentity();
5860 try {
5861 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
5865 }
chen xu7ee67862018-10-30 22:27:10 -07005866
sqian2fff4a32018-11-05 14:18:37 -08005867 private void ensureUserRunning(int userId) {
5868 if (!mUserManager.isUserRunning(userId)) {
5869 throw new IllegalStateException("User " + userId + " does not exist or not running");
5870 }
5871 }
5872
5873 /**
5874 * Returns a list of SMS apps on a given user.
5875 *
5876 * Only the shell user (UID 2000 or 0) can call it.
5877 * Target user must be running.
5878 */
5879 @Override
5880 public String[] getSmsApps(int userId) {
5881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5882 ensureUserRunning(userId);
5883
5884 final Collection<SmsApplicationData> apps =
5885 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5886
5887 String[] ret = new String[apps.size()];
5888 int i = 0;
5889 for (SmsApplicationData app : apps) {
5890 ret[i++] = app.mPackageName;
5891 }
5892 return ret;
5893 }
5894
5895 /**
5896 * Returns the default SMS app package name on a given user.
5897 *
5898 * Only the shell user (UID 2000 or 0) can call it.
5899 * Target user must be running.
5900 */
5901 @Override
5902 public String getDefaultSmsApp(int userId) {
5903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5904 ensureUserRunning(userId);
5905
5906 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5907 /* updateIfNeeded= */ true, userId);
5908 return cn == null ? null : cn.getPackageName();
5909 }
5910
5911 /**
5912 * Set a package as the default SMS app on a given user.
5913 *
5914 * Only the shell user (UID 2000 or 0) can call it.
5915 * Target user must be running.
5916 */
5917 @Override
5918 public void setDefaultSmsApp(int userId, String packageName) {
5919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5920 ensureUserRunning(userId);
5921
5922 boolean found = false;
5923 for (String pkg : getSmsApps(userId)) {
5924 if (TextUtils.equals(packageName, pkg)) {
5925 found = true;
5926 break;
5927 }
5928 }
5929 if (!found) {
5930 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5931 }
5932
5933 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5934 }
5935
chen xu7ee67862018-10-30 22:27:10 -07005936 @Override
sqian04b86072018-11-07 14:02:21 -08005937 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5938 String callingPackage) {
5939 // TODO connect with internal content
5940 return null;
5941 }
5942
5943 @Override
5944 public boolean isCurrentEmergencyNumber(String number) {
5945 // TODO connect with internal content
5946 return false;
5947 }
5948
5949 @Override
chen xu7ee67862018-10-30 22:27:10 -07005950 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5951 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5952 Phone phone = getPhone(subId);
5953 if (phone == null) {
5954 return null;
5955 }
5956 final long identity = Binder.clearCallingIdentity();
5957 try {
5958 UiccProfile profile = UiccController.getInstance()
5959 .getUiccProfileForPhone(phone.getPhoneId());
5960 if (profile != null) {
5961 return profile.getCertsFromCarrierPrivilegeAccessRules();
5962 }
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
5966 return null;
5967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005968}