blob: c8453a62c09b7cdf6d03ae0efe30525c075057ee [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
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070055import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000081import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070082import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070083import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070084import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080085import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080086import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070087import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070088import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080089import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070090import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080091import android.telephony.ims.aidl.IImsMmTelFeature;
92import android.telephony.ims.aidl.IImsRcsFeature;
93import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070094import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080095import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080099import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800101
Brad Ebinger4c460712018-10-01 10:40:55 -0700102import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700103import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800104import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700105import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700106import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700107import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800108import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700109import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700110import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800112import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800114import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700115import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100116import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700117import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700118import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700120import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800121import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700122import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700123import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700124import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700125import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700126import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700127import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800128import com.android.internal.telephony.SmsApplication;
129import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800130import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800131import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700132import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700133import com.android.internal.telephony.uicc.IccIoResult;
134import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800135import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700136import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800137import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700138import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800139import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000140import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700141import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800142import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700143import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800144import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700145import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700146import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800147
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700148import java.io.FileDescriptor;
149import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800150import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800152import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800153import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800154import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100155import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800156import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157
158/**
159 * Implementation of the ITelephony interface.
160 */
Santos Cordon117fee72014-05-16 17:56:12 -0700161public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162 private static final String LOG_TAG = "PhoneInterfaceManager";
163 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
164 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800165 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166
167 // Message codes used with mMainThreadHandler
168 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700169 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
170 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700171 private static final int CMD_OPEN_CHANNEL = 9;
172 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
173 private static final int CMD_CLOSE_CHANNEL = 11;
174 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800175 private static final int CMD_NV_READ_ITEM = 13;
176 private static final int EVENT_NV_READ_ITEM_DONE = 14;
177 private static final int CMD_NV_WRITE_ITEM = 15;
178 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
179 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
180 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700181 private static final int CMD_RESET_MODEM_CONFIG = 19;
182 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800183 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
184 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
185 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
186 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800187 private static final int CMD_SEND_ENVELOPE = 25;
188 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000189 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
190 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700191 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
192 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
193 private static final int CMD_EXCHANGE_SIM_IO = 31;
194 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800195 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
196 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700197 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
198 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700199 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
200 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700201 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
202 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
203 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
204 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700205 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
206 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
207 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
208 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700209 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800210 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
211 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000212 private static final int CMD_SWITCH_SLOTS = 50;
213 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700214 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
215 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
216 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
217 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
218 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
219 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
220 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
221 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700222 private static final int CMD_GET_ALL_CELL_INFO = 60;
223 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
224 private static final int CMD_GET_CELL_LOCATION = 62;
225 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700226 private static final int CMD_MODEM_REBOOT = 64;
227 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700228 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
229 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800231 // Parameters of select command.
232 private static final int SELECT_COMMAND = 0xA4;
233 private static final int SELECT_P1 = 0x04;
234 private static final int SELECT_P2 = 0;
235 private static final int SELECT_P3 = 0x10;
236
Pengquan Meng85728fb2018-03-12 16:31:21 -0700237 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
238 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
239 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
240
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241 /** The singleton instance. */
242 private static PhoneInterfaceManager sInstance;
243
Wink Saville3ab207e2014-11-20 13:07:20 -0800244 private PhoneGlobals mApp;
245 private Phone mPhone;
246 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700247 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800248 private AppOpsManager mAppOps;
249 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800250 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800251 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700252 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253
Derek Tan97ebb422014-09-05 16:55:38 -0700254 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
255 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800256 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700257
Derek Tan740e1672017-06-27 14:56:27 -0700258 // The AID of ISD-R.
259 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
260
yinxub1bed742017-04-17 11:45:04 -0700261 private NetworkScanRequestTracker mNetworkScanRequestTracker;
262
David Kelly5e06a7f2018-03-12 14:10:59 +0000263 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
264 private static final int MANUFACTURER_CODE_LENGTH = 8;
265
Derek Tan89e89d42014-07-08 17:00:10 -0700266 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700267 * A request object to use for transmitting data to an ICC.
268 */
269 private static final class IccAPDUArgument {
270 public int channel, cla, command, p1, p2, p3;
271 public String data;
272
273 public IccAPDUArgument(int channel, int cla, int command,
274 int p1, int p2, int p3, String data) {
275 this.channel = channel;
276 this.cla = cla;
277 this.command = command;
278 this.p1 = p1;
279 this.p2 = p2;
280 this.p3 = p3;
281 this.data = data;
282 }
283 }
284
285 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700286 * A request object to use for transmitting data to an ICC.
287 */
288 private static final class ManualNetworkSelectionArgument {
289 public OperatorInfo operatorInfo;
290 public boolean persistSelection;
291
292 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
293 this.operatorInfo = operatorInfo;
294 this.persistSelection = persistSelection;
295 }
296 }
297
298 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
300 * request after sending. The main thread will notify the request when it is complete.
301 */
302 private static final class MainThreadRequest {
303 /** The argument to use for the request */
304 public Object argument;
305 /** The result of the request that is run on the main thread */
306 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800307 // The subscriber id that this request applies to. Defaults to
308 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
309 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310
Nathan Harold92bed182018-10-12 18:16:49 -0700311 // In cases where subId is unavailable, the caller needs to specify the phone.
312 public Phone phone;
313
vagdevie435a3e2018-08-15 16:01:53 -0700314 public WorkSource workSource;
315
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 public MainThreadRequest(Object argument) {
317 this.argument = argument;
318 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800319
Nathan Harold92bed182018-10-12 18:16:49 -0700320 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
321 this.argument = argument;
322 if (phone != null) {
323 this.phone = phone;
324 }
325 this.workSource = workSource;
326 }
327
vagdevie435a3e2018-08-15 16:01:53 -0700328 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800329 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800330 if (subId != null) {
331 this.subId = subId;
332 }
vagdevie435a3e2018-08-15 16:01:53 -0700333 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 }
336
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800337 private static final class IncomingThirdPartyCallArgs {
338 public final ComponentName component;
339 public final String callId;
340 public final String callerDisplayName;
341
342 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
343 String callerDisplayName) {
344 this.component = component;
345 this.callId = callId;
346 this.callerDisplayName = callerDisplayName;
347 }
348 }
349
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 /**
351 * A handler that processes messages on the main thread in the phone process. Since many
352 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
353 * inbound binder threads to the main thread in the phone process. The Binder thread
354 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
355 * on, which will be notified when the operation completes and will contain the result of the
356 * request.
357 *
358 * <p>If a MainThreadRequest object is provided in the msg.obj field,
359 * note that request.result must be set to something non-null for the calling thread to
360 * unblock.
361 */
362 private final class MainThreadHandler extends Handler {
363 @Override
364 public void handleMessage(Message msg) {
365 MainThreadRequest request;
366 Message onCompleted;
367 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800368 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700369 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
371 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700372 case CMD_HANDLE_USSD_REQUEST: {
373 request = (MainThreadRequest) msg.obj;
374 final Phone phone = getPhoneFromRequest(request);
375 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
376 String ussdRequest = ussdObject.first;
377 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700378
Pengquan Meng0c05b502018-09-06 09:59:22 -0700379 if (!isUssdApiAllowed(request.subId)) {
380 // Carrier does not support use of this API, return failure.
381 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
382 UssdResponse response = new UssdResponse(ussdRequest, null);
383 Bundle returnData = new Bundle();
384 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
385 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700386
Pengquan Meng0c05b502018-09-06 09:59:22 -0700387 request.result = true;
388 notifyRequester(request);
389 return;
390 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700391
Pengquan Meng0c05b502018-09-06 09:59:22 -0700392 try {
393 request.result = phone != null
394 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
395 } catch (CallStateException cse) {
396 request.result = false;
397 }
398 // Wake up the requesting thread
399 notifyRequester(request);
400 break;
pkanwar32d516d2016-10-14 19:37:38 -0700401 }
402
Yorke Lee716f67e2015-06-17 15:39:16 -0700403 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700405 final Phone phone = getPhoneFromRequest(request);
406 request.result = phone != null ?
407 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
408 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700410 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700415 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800417 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 if (uiccCard == null) {
419 loge("iccTransmitApduLogicalChannel: No UICC");
420 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700421 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
424 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700425 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 iccArgument.channel, iccArgument.cla, iccArgument.command,
427 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 break;
431
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 ar = (AsyncResult) msg.obj;
434 request = (MainThreadRequest) ar.userObj;
435 if (ar.exception == null && ar.result != null) {
436 request.result = ar.result;
437 } else {
438 request.result = new IccIoResult(0x6F, 0, (byte[])null);
439 if (ar.result == null) {
440 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800441 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800443 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 } else {
445 loge("iccTransmitApduLogicalChannel: Unknown exception");
446 }
447 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700448 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 break;
450
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
452 request = (MainThreadRequest) msg.obj;
453 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800454 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 if (uiccCard == null) {
456 loge("iccTransmitApduBasicChannel: No UICC");
457 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700458 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 } else {
460 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
461 request);
462 uiccCard.iccTransmitApduBasicChannel(
463 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
464 iccArgument.p3, iccArgument.data, onCompleted);
465 }
466 break;
467
468 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
469 ar = (AsyncResult) msg.obj;
470 request = (MainThreadRequest) ar.userObj;
471 if (ar.exception == null && ar.result != null) {
472 request.result = ar.result;
473 } else {
474 request.result = new IccIoResult(0x6F, 0, (byte[])null);
475 if (ar.result == null) {
476 loge("iccTransmitApduBasicChannel: Empty response");
477 } else if (ar.exception instanceof CommandException) {
478 loge("iccTransmitApduBasicChannel: CommandException: " +
479 ar.exception);
480 } else {
481 loge("iccTransmitApduBasicChannel: Unknown exception");
482 }
483 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700484 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 break;
486
487 case CMD_EXCHANGE_SIM_IO:
488 request = (MainThreadRequest) msg.obj;
489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 if (uiccCard == null) {
492 loge("iccExchangeSimIO: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 } else {
496 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
497 request);
498 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
499 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
500 iccArgument.data, onCompleted);
501 }
502 break;
503
504 case EVENT_EXCHANGE_SIM_IO_DONE:
505 ar = (AsyncResult) msg.obj;
506 request = (MainThreadRequest) ar.userObj;
507 if (ar.exception == null && ar.result != null) {
508 request.result = ar.result;
509 } else {
510 request.result = new IccIoResult(0x6f, 0, (byte[])null);
511 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 break;
514
Derek Tan4d5e5c12014-02-04 11:54:58 -0800515 case CMD_SEND_ENVELOPE:
516 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800517 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 if (uiccCard == null) {
519 loge("sendEnvelopeWithStatus: No UICC");
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 } else {
523 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
524 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
525 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 break;
527
528 case EVENT_SEND_ENVELOPE_DONE:
529 ar = (AsyncResult) msg.obj;
530 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700531 if (ar.exception == null && ar.result != null) {
532 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
535 if (ar.result == null) {
536 loge("sendEnvelopeWithStatus: Empty response");
537 } else if (ar.exception instanceof CommandException) {
538 loge("sendEnvelopeWithStatus: CommandException: " +
539 ar.exception);
540 } else {
541 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
542 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700544 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 break;
546
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 case CMD_OPEN_CHANNEL:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800550 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 if (uiccCard == null) {
552 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800553 request.result = new IccOpenLogicalChannelResponse(-1,
554 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 } else {
557 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800558 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
559 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 break;
562
563 case EVENT_OPEN_CHANNEL_DONE:
564 ar = (AsyncResult) msg.obj;
565 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 int[] result = (int[]) ar.result;
569 int channelId = result[0];
570 byte[] selectResponse = null;
571 if (result.length > 1) {
572 selectResponse = new byte[result.length - 1];
573 for (int i = 1; i < result.length; ++i) {
574 selectResponse[i - 1] = (byte) result[i];
575 }
576 }
577 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700578 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 if (ar.result == null) {
581 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 if (ar.exception != null) {
584 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
585 }
586
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700587 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700588 if (ar.exception instanceof CommandException) {
589 CommandException.Error error =
590 ((CommandException) (ar.exception)).getCommandError();
591 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700593 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 }
596 }
597 openChannelResp = new IccOpenLogicalChannelResponse(
598 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700600 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
604 case CMD_CLOSE_CHANNEL:
605 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800606 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 if (uiccCard == null) {
608 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900609 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 } else {
612 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
613 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
614 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 break;
616
617 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800618 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
619 break;
620
621 case CMD_NV_READ_ITEM:
622 request = (MainThreadRequest) msg.obj;
623 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700624 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800625 break;
626
627 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800630 if (ar.exception == null && ar.result != null) {
631 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800633 request.result = "";
634 if (ar.result == null) {
635 loge("nvReadItem: Empty response");
636 } else if (ar.exception instanceof CommandException) {
637 loge("nvReadItem: CommandException: " +
638 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800640 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 }
642 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 break;
645
Jake Hambye994d462014-02-03 13:10:13 -0800646 case CMD_NV_WRITE_ITEM:
647 request = (MainThreadRequest) msg.obj;
648 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
649 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700650 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
651 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800652 break;
653
654 case EVENT_NV_WRITE_ITEM_DONE:
655 handleNullReturnEvent(msg, "nvWriteItem");
656 break;
657
658 case CMD_NV_WRITE_CDMA_PRL:
659 request = (MainThreadRequest) msg.obj;
660 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
661 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
662 break;
663
664 case EVENT_NV_WRITE_CDMA_PRL_DONE:
665 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
666 break;
667
chen xu1cc0abe2018-10-26 17:39:23 -0700668 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800669 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700670 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
671 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800672 break;
673
chen xu1cc0abe2018-10-26 17:39:23 -0700674 case EVENT_RESET_MODEM_CONFIG_DONE:
675 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800676 break;
677
Jake Hamby7c27be32014-03-03 13:25:59 -0800678 case CMD_GET_PREFERRED_NETWORK_TYPE:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700681 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800682 break;
683
684 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
685 ar = (AsyncResult) msg.obj;
686 request = (MainThreadRequest) ar.userObj;
687 if (ar.exception == null && ar.result != null) {
688 request.result = ar.result; // Integer
689 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800690 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800691 if (ar.result == null) {
692 loge("getPreferredNetworkType: Empty response");
693 } else if (ar.exception instanceof CommandException) {
694 loge("getPreferredNetworkType: CommandException: " +
695 ar.exception);
696 } else {
697 loge("getPreferredNetworkType: Unknown exception");
698 }
699 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700700 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 break;
702
703 case CMD_SET_PREFERRED_NETWORK_TYPE:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
706 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700707 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800708 break;
709
710 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
711 handleNullReturnEvent(msg, "setPreferredNetworkType");
712 break;
713
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000714 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
715 request = (MainThreadRequest)msg.obj;
716 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700717 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000718 break;
719
720 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
721 ar = (AsyncResult)msg.obj;
722 request = (MainThreadRequest)ar.userObj;
723 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700724 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000725 break;
726
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800727 case CMD_SET_VOICEMAIL_NUMBER:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
730 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800731 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
732 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800733 break;
734
735 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
736 handleNullReturnEvent(msg, "setVoicemailNumber");
737 break;
738
Stuart Scott54788802015-03-30 13:18:01 -0700739 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
742 request);
743 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
744 break;
745
746 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
747 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
748 break;
749
Shishir Agrawal302c8692015-06-19 13:49:39 -0700750 case CMD_PERFORM_NETWORK_SCAN:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
753 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
754 break;
755
756 case EVENT_PERFORM_NETWORK_SCAN_DONE:
757 ar = (AsyncResult) msg.obj;
758 request = (MainThreadRequest) ar.userObj;
759 CellNetworkScanResult cellScanResult;
760 if (ar.exception == null && ar.result != null) {
761 cellScanResult = new CellNetworkScanResult(
762 CellNetworkScanResult.STATUS_SUCCESS,
763 (List<OperatorInfo>) ar.result);
764 } else {
765 if (ar.result == null) {
766 loge("getCellNetworkScanResults: Empty response");
767 }
768 if (ar.exception != null) {
769 loge("getCellNetworkScanResults: Exception: " + ar.exception);
770 }
771 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
772 if (ar.exception instanceof CommandException) {
773 CommandException.Error error =
774 ((CommandException) (ar.exception)).getCommandError();
775 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
776 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
777 } else if (error == CommandException.Error.GENERIC_FAILURE) {
778 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
779 }
780 }
781 cellScanResult = new CellNetworkScanResult(errorCode, null);
782 }
783 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700785 break;
786
787 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
788 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700789 ManualNetworkSelectionArgument selArg =
790 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
792 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700793 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
794 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 break;
796
797 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700798 ar = (AsyncResult) msg.obj;
799 request = (MainThreadRequest) ar.userObj;
800 if (ar.exception == null) {
801 request.result = true;
802 } else {
803 request.result = false;
804 loge("setNetworkSelectionModeManual " + ar.exception);
805 }
806 notifyRequester(request);
807 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700808 break;
809
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700810 case CMD_GET_MODEM_ACTIVITY_INFO:
811 request = (MainThreadRequest) msg.obj;
812 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700813 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700814 break;
815
816 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
817 ar = (AsyncResult) msg.obj;
818 request = (MainThreadRequest) ar.userObj;
819 if (ar.exception == null && ar.result != null) {
820 request.result = ar.result;
821 } else {
822 if (ar.result == null) {
823 loge("queryModemActivityInfo: Empty response");
824 } else if (ar.exception instanceof CommandException) {
825 loge("queryModemActivityInfo: CommandException: " +
826 ar.exception);
827 } else {
828 loge("queryModemActivityInfo: Unknown exception");
829 }
830 }
Amit Mahajand4766222016-01-28 15:28:28 -0800831 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
832 if (request.result == null) {
833 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
834 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700835 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700836 break;
837
Meng Wang1a7c35a2016-05-05 20:56:15 -0700838 case CMD_SET_ALLOWED_CARRIERS:
839 request = (MainThreadRequest) msg.obj;
840 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
841 mPhone.setAllowedCarriers(
842 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700843 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700844 break;
845
846 case EVENT_SET_ALLOWED_CARRIERS_DONE:
847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null && ar.result != null) {
850 request.result = ar.result;
851 } else {
852 if (ar.result == null) {
853 loge("setAllowedCarriers: Empty response");
854 } else if (ar.exception instanceof CommandException) {
855 loge("setAllowedCarriers: CommandException: " +
856 ar.exception);
857 } else {
858 loge("setAllowedCarriers: Unknown exception");
859 }
860 }
861 // Result cannot be null. Return -1 on error.
862 if (request.result == null) {
863 request.result = new int[]{-1};
864 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700865 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 break;
867
868 case CMD_GET_ALLOWED_CARRIERS:
869 request = (MainThreadRequest) msg.obj;
870 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700871 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700872 break;
873
874 case EVENT_GET_ALLOWED_CARRIERS_DONE:
875 ar = (AsyncResult) msg.obj;
876 request = (MainThreadRequest) ar.userObj;
877 if (ar.exception == null && ar.result != null) {
878 request.result = ar.result;
879 } else {
880 if (ar.result == null) {
881 loge("getAllowedCarriers: Empty response");
882 } else if (ar.exception instanceof CommandException) {
883 loge("getAllowedCarriers: CommandException: " +
884 ar.exception);
885 } else {
886 loge("getAllowedCarriers: Unknown exception");
887 }
888 }
889 // Result cannot be null. Return empty list of CarrierIdentifier.
890 if (request.result == null) {
891 request.result = new ArrayList<CarrierIdentifier>(0);
892 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700893 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 break;
895
Nathan Haroldb3014052017-01-25 15:57:32 -0800896 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result;
901 } else {
902 request.result = new IllegalArgumentException(
903 "Failed to retrieve Forbidden Plmns");
904 if (ar.result == null) {
905 loge("getForbiddenPlmns: Empty response");
906 } else {
907 loge("getForbiddenPlmns: Unknown exception");
908 }
909 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700910 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800911 break;
912
913 case CMD_GET_FORBIDDEN_PLMNS:
914 request = (MainThreadRequest) msg.obj;
915 uiccCard = getUiccCardFromRequest(request);
916 if (uiccCard == null) {
917 loge("getForbiddenPlmns() UiccCard is null");
918 request.result = new IllegalArgumentException(
919 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700920 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800921 break;
922 }
923 Integer appType = (Integer) request.argument;
924 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
925 if (uiccApp == null) {
926 loge("getForbiddenPlmns() no app with specified type -- "
927 + appType);
928 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700929 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800930 break;
931 } else {
932 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
933 + " specified type -- " + appType);
934 }
935 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
936 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
937 onCompleted);
938 break;
939
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000940 case CMD_SWITCH_SLOTS:
941 request = (MainThreadRequest) msg.obj;
942 int[] physicalSlots = (int[]) request.argument;
943 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
944 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
945 break;
946
947 case EVENT_SWITCH_SLOTS_DONE:
948 ar = (AsyncResult) msg.obj;
949 request = (MainThreadRequest) ar.userObj;
950 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700951 notifyRequester(request);
952 break;
953 case CMD_GET_NETWORK_SELECTION_MODE:
954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
956 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
957 break;
958
959 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
960 ar = (AsyncResult) msg.obj;
961 request = (MainThreadRequest) ar.userObj;
962 if (ar.exception != null) {
963 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
964 } else {
965 int mode = ((int[]) ar.result)[0];
966 if (mode == 0) {
967 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
968 } else {
969 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
970 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000971 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700972 notifyRequester(request);
973 break;
974 case CMD_GET_CDMA_ROAMING_MODE:
975 request = (MainThreadRequest) msg.obj;
976 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
977 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
978 break;
979 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 if (ar.exception != null) {
983 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
984 } else {
985 request.result = ((int[]) ar.result)[0];
986 }
987 notifyRequester(request);
988 break;
989 case CMD_SET_CDMA_ROAMING_MODE:
990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
992 int mode = (int) request.argument;
993 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
994 break;
995 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 request.result = ar.exception == null;
999 notifyRequester(request);
1000 break;
1001 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1002 request = (MainThreadRequest) msg.obj;
1003 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1004 int subscriptionMode = (int) request.argument;
1005 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1006 break;
1007 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
1010 request.result = ar.exception == null;
1011 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001012 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001013 case CMD_GET_ALL_CELL_INFO:
1014 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001015 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001016 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001017 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 case EVENT_GET_ALL_CELL_INFO_DONE:
1019 ar = (AsyncResult) msg.obj;
1020 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001021 // If a timeout occurs, the response will be null
1022 request.result = (ar.exception == null && ar.result != null)
1023 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001024 synchronized (request) {
1025 request.notifyAll();
1026 }
1027 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001028 case CMD_REQUEST_CELL_INFO_UPDATE:
1029 request = (MainThreadRequest) msg.obj;
1030 request.phone.requestCellInfoUpdate(request.workSource,
1031 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1032 break;
1033 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
1036 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1037 try {
1038 if (ar.exception != null) {
1039 // something went wrong... the response is null
1040 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1041 cb.onCellInfo(null);
1042 } else if (ar.result == null) {
1043 // timeout occurred, so force the result to non-null "empty"
1044 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1045 cb.onCellInfo(new ArrayList<CellInfo>());
1046 } else {
1047 // use the result as returned
1048 cb.onCellInfo((List<CellInfo>) ar.result);
1049 }
1050 } catch (RemoteException re) {
1051 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1052 }
1053 break;
1054 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 request = (MainThreadRequest) msg.obj;
1056 WorkSource ws = (WorkSource) request.argument;
1057 Phone phone = getPhoneFromRequest(request);
1058 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1059 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
1063 if (ar.exception == null) {
1064 request.result = ar.result;
1065 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001066 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1068 ? new CdmaCellLocation() : new GsmCellLocation();
1069 }
1070
1071 synchronized (request) {
1072 request.notifyAll();
1073 }
1074 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001075 case CMD_MODEM_REBOOT:
1076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1078 mPhone.rebootModem(onCompleted);
1079 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001080 case EVENT_CMD_MODEM_REBOOT_DONE:
1081 handleNullReturnEvent(msg, "rebootModem");
1082 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 default:
1084 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1085 break;
1086 }
1087 }
Jake Hambye994d462014-02-03 13:10:13 -08001088
Pengquan Meng0c05b502018-09-06 09:59:22 -07001089 private void notifyRequester(MainThreadRequest request) {
1090 synchronized (request) {
1091 request.notifyAll();
1092 }
1093 }
1094
Jake Hambye994d462014-02-03 13:10:13 -08001095 private void handleNullReturnEvent(Message msg, String command) {
1096 AsyncResult ar = (AsyncResult) msg.obj;
1097 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1098 if (ar.exception == null) {
1099 request.result = true;
1100 } else {
1101 request.result = false;
1102 if (ar.exception instanceof CommandException) {
1103 loge(command + ": CommandException: " + ar.exception);
1104 } else {
1105 loge(command + ": Unknown exception");
1106 }
1107 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001108 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 }
1111
1112 /**
1113 * Posts the specified command to be executed on the main thread,
1114 * waits for the request to complete, and returns the result.
1115 * @see #sendRequestAsync
1116 */
1117 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001118 return sendRequest(
1119 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001120 }
1121
1122 /**
1123 * Posts the specified command to be executed on the main thread,
1124 * waits for the request to complete, and returns the result.
1125 * @see #sendRequestAsync
1126 */
1127 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1128 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001129 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001130 }
1131
1132 /**
1133 * Posts the specified command to be executed on the main thread,
1134 * waits for the request to complete, and returns the result.
1135 * @see #sendRequestAsync
1136 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001137 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001138 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001139 }
1140
1141 /**
1142 * Posts the specified command to be executed on the main thread,
1143 * waits for the request to complete, and returns the result.
1144 * @see #sendRequestAsync
1145 */
Nathan Harold92bed182018-10-12 18:16:49 -07001146 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1147 return sendRequest(command, argument, subId, null, workSource);
1148 }
1149
1150 /**
1151 * Posts the specified command to be executed on the main thread,
1152 * waits for the request to complete, and returns the result.
1153 * @see #sendRequestAsync
1154 */
1155 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1156 return sendRequest(
1157 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1158 }
1159
1160 /**
1161 * Posts the specified command to be executed on the main thread,
1162 * waits for the request to complete, and returns the result.
1163 * @see #sendRequestAsync
1164 */
1165 private Object sendRequest(
1166 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001167 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1168 throw new RuntimeException("This method will deadlock if called from the main thread.");
1169 }
1170
Nathan Harold92bed182018-10-12 18:16:49 -07001171 MainThreadRequest request = null;
1172 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1173 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1174 } else if (phone != null) {
1175 request = new MainThreadRequest(argument, phone, workSource);
1176 } else {
1177 request = new MainThreadRequest(argument, subId, workSource);
1178 }
1179
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001180 Message msg = mMainThreadHandler.obtainMessage(command, request);
1181 msg.sendToTarget();
1182
1183 // Wait for the request to complete
1184 synchronized (request) {
1185 while (request.result == null) {
1186 try {
1187 request.wait();
1188 } catch (InterruptedException e) {
1189 // Do nothing, go back and wait until the request is complete
1190 }
1191 }
1192 }
1193 return request.result;
1194 }
1195
1196 /**
1197 * Asynchronous ("fire and forget") version of sendRequest():
1198 * Posts the specified command to be executed on the main thread, and
1199 * returns immediately.
1200 * @see #sendRequest
1201 */
1202 private void sendRequestAsync(int command) {
1203 mMainThreadHandler.sendEmptyMessage(command);
1204 }
1205
1206 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001207 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001208 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001209 */
1210 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001211 sendRequestAsync(command, argument, null, null);
1212 }
1213
1214 /**
1215 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1216 * @see {@link #sendRequest(int,Object)}
1217 */
1218 private void sendRequestAsync(
1219 int command, Object argument, Phone phone, WorkSource workSource) {
1220 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001221 Message msg = mMainThreadHandler.obtainMessage(command, request);
1222 msg.sendToTarget();
1223 }
1224
1225 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 * Initialize the singleton PhoneInterfaceManager instance.
1227 * This is only done once, at startup, from PhoneApp.onCreate().
1228 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001229 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 synchronized (PhoneInterfaceManager.class) {
1231 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001232 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 } else {
1234 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1235 }
1236 return sInstance;
1237 }
1238 }
1239
1240 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001241 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 mApp = app;
1243 mPhone = phone;
1244 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001245 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1247 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001248 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001249 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001250 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001251 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001252 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001253
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 publish();
1255 }
1256
1257 private void publish() {
1258 if (DBG) log("publish: " + this);
1259
1260 ServiceManager.addService("phone", this);
1261 }
1262
Stuart Scott584921c2015-01-15 17:10:34 -08001263 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001264 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1265 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001266 }
1267
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001268 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1269 Phone phone = getPhoneFromRequest(request);
1270 return phone == null ? null :
1271 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1272 }
1273
Wink Saville36469e72014-06-11 15:17:00 -07001274 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001275 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001276 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278
1279 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001280 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
Wink Savilleb564aae2014-10-23 10:18:09 -07001283 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 if (DBG) log("dial: " + number);
1285 // No permission check needed here: This is just a wrapper around the
1286 // ACTION_DIAL intent, which is available to any app since it puts up
1287 // the UI before it does anything.
1288
Malcolm Chend965c8b2018-02-28 15:00:40 -08001289 final long identity = Binder.clearCallingIdentity();
1290 try {
1291 String url = createTelUrl(number);
1292 if (url == null) {
1293 return;
1294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001295
Malcolm Chend965c8b2018-02-28 15:00:40 -08001296 // PENDING: should we just silently fail if phone is offhook or ringing?
1297 PhoneConstants.State state = mCM.getState(subId);
1298 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1299 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1300 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1301 mApp.startActivity(intent);
1302 }
1303 } finally {
1304 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 }
1306 }
1307
1308 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001309 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001310 }
1311
Wink Savilleb564aae2014-10-23 10:18:09 -07001312 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 if (DBG) log("call: " + number);
1314
1315 // This is just a wrapper around the ACTION_CALL intent, but we still
1316 // need to do a permission check since we're calling startActivity()
1317 // from the context of the phone app.
1318 enforceCallPermission();
1319
1320 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1321 != AppOpsManager.MODE_ALLOWED) {
1322 return;
1323 }
1324
Malcolm Chend965c8b2018-02-28 15:00:40 -08001325 final long identity = Binder.clearCallingIdentity();
1326 try {
1327 String url = createTelUrl(number);
1328 if (url == null) {
1329 return;
1330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331
Malcolm Chend965c8b2018-02-28 15:00:40 -08001332 boolean isValid = false;
1333 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1334 if (slist != null) {
1335 for (SubscriptionInfo subInfoRecord : slist) {
1336 if (subInfoRecord.getSubscriptionId() == subId) {
1337 isValid = true;
1338 break;
1339 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001340 }
Wink Saville08874612014-08-31 19:19:58 -07001341 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001342 if (!isValid) {
1343 return;
1344 }
Wink Saville08874612014-08-31 19:19:58 -07001345
Malcolm Chend965c8b2018-02-28 15:00:40 -08001346 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1347 intent.putExtra(SUBSCRIPTION_KEY, subId);
1348 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1349 mApp.startActivity(intent);
1350 } finally {
1351 Binder.restoreCallingIdentity(identity);
1352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001353 }
1354
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001355 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001357 }
1358
Wink Savilleb564aae2014-10-23 10:18:09 -07001359 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001360 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001361 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1362 }
1363
1364 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001365 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001366 }
1367
Wink Savilleb564aae2014-10-23 10:18:09 -07001368 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001369 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001370 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1371 }
1372
1373 /** {@hide} */
1374 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001380
1381 final long identity = Binder.clearCallingIdentity();
1382 try {
1383 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1384 checkSimPin.start();
1385 return checkSimPin.unlockSim(null, pin);
1386 } finally {
1387 Binder.restoreCallingIdentity(identity);
1388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389 }
1390
Wink Saville9de0f752013-10-22 19:04:03 -07001391 /** {@hide} */
1392 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001393 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001394 }
1395
Wink Savilleb564aae2014-10-23 10:18:09 -07001396 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001398
1399 final long identity = Binder.clearCallingIdentity();
1400 try {
1401 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1402 checkSimPuk.start();
1403 return checkSimPuk.unlockSim(puk, pin);
1404 } finally {
1405 Binder.restoreCallingIdentity(identity);
1406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 }
1408
1409 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001410 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 * a synchronous one.
1412 */
1413 private static class UnlockSim extends Thread {
1414
1415 private final IccCard mSimCard;
1416
1417 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001418 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1419 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420
1421 // For replies from SimCard interface
1422 private Handler mHandler;
1423
1424 // For async handler to identify request type
1425 private static final int SUPPLY_PIN_COMPLETE = 100;
1426
1427 public UnlockSim(IccCard simCard) {
1428 mSimCard = simCard;
1429 }
1430
1431 @Override
1432 public void run() {
1433 Looper.prepare();
1434 synchronized (UnlockSim.this) {
1435 mHandler = new Handler() {
1436 @Override
1437 public void handleMessage(Message msg) {
1438 AsyncResult ar = (AsyncResult) msg.obj;
1439 switch (msg.what) {
1440 case SUPPLY_PIN_COMPLETE:
1441 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1442 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001443 mRetryCount = msg.arg1;
1444 if (ar.exception != null) {
1445 if (ar.exception instanceof CommandException &&
1446 ((CommandException)(ar.exception)).getCommandError()
1447 == CommandException.Error.PASSWORD_INCORRECT) {
1448 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1449 } else {
1450 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1451 }
1452 } else {
1453 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 mDone = true;
1456 UnlockSim.this.notifyAll();
1457 }
1458 break;
1459 }
1460 }
1461 };
1462 UnlockSim.this.notifyAll();
1463 }
1464 Looper.loop();
1465 }
1466
1467 /*
1468 * Use PIN or PUK to unlock SIM card
1469 *
1470 * If PUK is null, unlock SIM card with PIN
1471 *
1472 * If PUK is not null, unlock SIM card with PUK and set PIN code
1473 */
Wink Saville9de0f752013-10-22 19:04:03 -07001474 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475
1476 while (mHandler == null) {
1477 try {
1478 wait();
1479 } catch (InterruptedException e) {
1480 Thread.currentThread().interrupt();
1481 }
1482 }
1483 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1484
1485 if (puk == null) {
1486 mSimCard.supplyPin(pin, callback);
1487 } else {
1488 mSimCard.supplyPuk(puk, pin, callback);
1489 }
1490
1491 while (!mDone) {
1492 try {
1493 Log.d(LOG_TAG, "wait for done");
1494 wait();
1495 } catch (InterruptedException e) {
1496 // Restore the interrupted status
1497 Thread.currentThread().interrupt();
1498 }
1499 }
1500 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001501 int[] resultArray = new int[2];
1502 resultArray[0] = mResult;
1503 resultArray[1] = mRetryCount;
1504 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 }
1506 }
1507
1508 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001509 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001510
1511 }
1512
Wink Savilleb564aae2014-10-23 10:18:09 -07001513 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514 // No permission check needed here: this call is harmless, and it's
1515 // needed for the ServiceState.requestStateUpdate() call (which is
1516 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001517 final long identity = Binder.clearCallingIdentity();
1518 try {
1519 final Phone phone = getPhone(subId);
1520 if (phone != null) {
1521 phone.updateServiceLocation();
1522 }
1523 } finally {
1524 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 }
1527
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001528 @Override
1529 public boolean isRadioOn(String callingPackage) {
1530 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001531 }
1532
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001533 @Override
1534 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001536 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001537 return false;
1538 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001539
1540 final long identity = Binder.clearCallingIdentity();
1541 try {
1542 return isRadioOnForSubscriber(subId);
1543 } finally {
1544 Binder.restoreCallingIdentity(identity);
1545 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001546 }
1547
1548 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001549 final long identity = Binder.clearCallingIdentity();
1550 try {
1551 final Phone phone = getPhone(subId);
1552 if (phone != null) {
1553 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1554 } else {
1555 return false;
1556 }
1557 } finally {
1558 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 }
1561
1562 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001563 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
Wink Saville36469e72014-06-11 15:17:00 -07001565
Wink Savilleb564aae2014-10-23 10:18:09 -07001566 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001568
1569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 final Phone phone = getPhone(subId);
1572 if (phone != null) {
1573 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1574 }
1575 } finally {
1576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001577 }
Wink Saville36469e72014-06-11 15:17:00 -07001578 }
1579
1580 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001581 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001582 }
1583
Wink Savilleb564aae2014-10-23 10:18:09 -07001584 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001585 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001586
1587 final long identity = Binder.clearCallingIdentity();
1588 try {
1589 final Phone phone = getPhone(subId);
1590 if (phone == null) {
1591 return false;
1592 }
1593 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1594 toggleRadioOnOffForSubscriber(subId);
1595 }
1596 return true;
1597 } finally {
1598 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
Wink Saville36469e72014-06-11 15:17:00 -07001601
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001602 public boolean needMobileRadioShutdown() {
1603 /*
1604 * If any of the Radios are available, it will need to be
1605 * shutdown. So return true if any Radio is available.
1606 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001607 final long identity = Binder.clearCallingIdentity();
1608 try {
1609 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1610 Phone phone = PhoneFactory.getPhone(i);
1611 if (phone != null && phone.isRadioAvailable()) return true;
1612 }
1613 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1614 return false;
1615 } finally {
1616 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001617 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001618 }
1619
Malcolm Chend965c8b2018-02-28 15:00:40 -08001620 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001621 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001622 enforceModifyPermission();
1623
1624 final long identity = Binder.clearCallingIdentity();
1625 try {
1626 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1627 logv("Shutting down Phone " + i);
1628 shutdownRadioUsingPhoneId(i);
1629 }
1630 } finally {
1631 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001632 }
1633 }
1634
1635 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001636 Phone phone = PhoneFactory.getPhone(phoneId);
1637 if (phone != null && phone.isRadioAvailable()) {
1638 phone.shutdownRadio();
1639 }
1640 }
1641
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001643 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001644
1645 final long identity = Binder.clearCallingIdentity();
1646 try {
1647 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1648 if (defaultPhone != null) {
1649 defaultPhone.setRadioPower(turnOn);
1650 return true;
1651 } else {
1652 loge("There's no default phone.");
1653 return false;
1654 }
1655 } finally {
1656 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001657 }
Wink Saville36469e72014-06-11 15:17:00 -07001658 }
1659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001662
1663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 final Phone phone = getPhone(subId);
1666 if (phone != null) {
1667 phone.setRadioPower(turnOn);
1668 return true;
1669 } else {
1670 return false;
1671 }
1672 } finally {
1673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 }
1676
Wink Saville36469e72014-06-11 15:17:00 -07001677 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001678 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 public boolean enableDataConnectivity() {
1680 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001681
1682 final long identity = Binder.clearCallingIdentity();
1683 try {
1684 int subId = mSubscriptionController.getDefaultDataSubId();
1685 final Phone phone = getPhone(subId);
1686 if (phone != null) {
1687 phone.setUserDataEnabled(true);
1688 return true;
1689 } else {
1690 return false;
1691 }
1692 } finally {
1693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 }
1696
Wink Saville36469e72014-06-11 15:17:00 -07001697 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 public boolean disableDataConnectivity() {
1700 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001701
1702 final long identity = Binder.clearCallingIdentity();
1703 try {
1704 int subId = mSubscriptionController.getDefaultDataSubId();
1705 final Phone phone = getPhone(subId);
1706 if (phone != null) {
1707 phone.setUserDataEnabled(false);
1708 return true;
1709 } else {
1710 return false;
1711 }
1712 } finally {
1713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 }
1716
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001718 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001719 final long identity = Binder.clearCallingIdentity();
1720 try {
1721 final Phone phone = getPhone(subId);
1722 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001723 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001724 } else {
1725 return false;
1726 }
1727 } finally {
1728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 }
1731
1732 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001733 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001734 }
1735
pkanwarae03a6b2016-11-06 20:37:09 -08001736 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001737 enforceCallPermission();
1738
1739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1742 return;
1743 }
1744 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1745 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
1748 }
pkanwar32d516d2016-10-14 19:37:38 -07001749 };
1750
Wink Savilleb564aae2014-10-23 10:18:09 -07001751 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001753
1754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1757 return false;
1758 }
1759 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
1764
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001766 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
1768
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001769 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001770 final long identity = Binder.clearCallingIdentity();
1771 try {
1772 Phone phone = PhoneFactory.getPhone(slotIndex);
1773 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1774 PhoneConstantConversions.convertCallState(phone.getState());
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
1777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Sanket Padawe356d7632015-06-22 14:03:32 -07001780 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001782 final long identity = Binder.clearCallingIdentity();
1783 try {
1784 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1785 if (phone != null) {
1786 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1787 } else {
1788 return PhoneConstantConversions.convertDataState(
1789 PhoneConstants.DataState.DISCONNECTED);
1790 }
1791 } finally {
1792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 }
1795
Sanket Padawe356d7632015-06-22 14:03:32 -07001796 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001798 final long identity = Binder.clearCallingIdentity();
1799 try {
1800 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1801 if (phone != null) {
1802 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1803 } else {
1804 return TelephonyManager.DATA_ACTIVITY_NONE;
1805 }
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
1811 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001812 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001813 mPhone.getContext().getSystemService(AppOpsManager.class)
1814 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001815 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001816 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001817 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 }
1819
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001820 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 if (DBG_LOC) log("getCellLocation: is active user");
1824 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001825 int subId = mSubscriptionController.getDefaultDataSubId();
1826 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1827 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001828 return data;
1829 } finally {
1830 Binder.restoreCallingIdentity(identity);
1831 }
Svetoslav64fad262015-04-14 14:35:21 -07001832 }
1833
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001835 public String getNetworkCountryIsoForPhone(int phoneId) {
1836 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1837 // registered cell info, so return a NULL country instead.
1838 final long identity = Binder.clearCallingIdentity();
1839 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001840 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1841 // Get default phone in this case.
1842 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1843 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001844 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001845 // Todo: fix this when we can get the actual cellular network info when the device
1846 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001847 if (TelephonyManager.NETWORK_TYPE_IWLAN
1848 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1849 return "";
1850 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001851 Phone phone = PhoneFactory.getPhone(phoneId);
1852 if (phone != null) {
1853 ServiceStateTracker sst = phone.getServiceStateTracker();
1854 if (sst != null) {
1855 LocaleTracker lt = sst.getLocaleTracker();
1856 if (lt != null) {
1857 return lt.getCurrentCountry();
1858 }
1859 }
1860 }
1861 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001862 } finally {
1863 Binder.restoreCallingIdentity(identity);
1864 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001865 }
1866
1867 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001869 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001870 }
1871
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001873 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 mApp.enforceCallingOrSelfPermission(
1875 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001876
1877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 final Phone phone = getPhone(subId);
1880 if (phone != null) {
1881 phone.enableLocationUpdates();
1882 }
1883 } finally {
1884 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 }
1887
1888 @Override
1889 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001890 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001891 }
1892
Sanket Padawe356d7632015-06-22 14:03:32 -07001893 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001894 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 mApp.enforceCallingOrSelfPermission(
1896 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001897
1898 final long identity = Binder.clearCallingIdentity();
1899 try {
1900 final Phone phone = getPhone(subId);
1901 if (phone != null) {
1902 phone.disableLocationUpdates();
1903 }
1904 } finally {
1905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
Nathan Harold31d7ff32018-10-15 20:20:30 -07001909 /**
1910 * Returns the target SDK version number for a given package name.
1911 *
1912 * @return target SDK if the package is found or INT_MAX.
1913 */
1914 private int getTargetSdk(String packageName) {
1915 try {
1916 final ApplicationInfo ai =
1917 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1918 if (ai != null) return ai.targetSdkVersion;
1919 } catch (PackageManager.NameNotFoundException unexpected) {
1920 }
1921 return Integer.MAX_VALUE;
1922 }
1923
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 @Override
1925 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001926 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1927 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001928 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1929 throw new SecurityException(
1930 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1931 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001932
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1934 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1935 return null;
1936 }
Svetoslav64fad262015-04-14 14:35:21 -07001937
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001938 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939
Nathan Haroldf180aac2018-06-01 18:43:55 -07001940 List<CellInfo> info = getAllCellInfo(callingPackage);
1941 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942
Nathan Haroldf180aac2018-06-01 18:43:55 -07001943 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1944 for (CellInfo ci : info) {
1945 if (ci instanceof CellInfoGsm) {
1946 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1947 } else if (ci instanceof CellInfoWcdma) {
1948 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001951 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001954 private List<CellInfo> getCachedCellInfo() {
1955 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1956 for (Phone phone : PhoneFactory.getPhones()) {
1957 List<CellInfo> info = phone.getAllCellInfo();
1958 if (info != null) cellInfos.addAll(info);
1959 }
1960 return cellInfos;
1961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962
1963 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001964 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001965 mPhone.getContext().getSystemService(AppOpsManager.class)
1966 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001967 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001968 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001969 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001972 final int targetSdk = getTargetSdk(callingPackage);
1973 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1974 return getCachedCellInfo();
1975 }
1976
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001977 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001978 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001979 final long identity = Binder.clearCallingIdentity();
1980 try {
1981 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1982 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001983 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001984 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001985 if (info != null) cellInfos.addAll(info);
1986 }
1987 return cellInfos;
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 }
1991 }
1992
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001993 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001994 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
1995 requestCellInfoUpdateInternal(
1996 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
1997 }
1998
1999 @Override
2000 public void requestCellInfoUpdateWithWorkSource(
2001 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2002 enforceModifyPermission();
2003 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2004 }
2005
2006 private void requestCellInfoUpdateInternal(
2007 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2008 mPhone.getContext().getSystemService(AppOpsManager.class)
2009 .checkPackage(Binder.getCallingUid(), callingPackage);
2010 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
2011 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
2012 return;
2013 }
2014
2015 final Phone phone = getPhone(subId);
2016 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2017
2018 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2019 }
2020
2021 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002022 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002023 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002024 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002025
2026 final long identity = Binder.clearCallingIdentity();
2027 try {
2028 mPhone.setCellInfoListRate(rateInMillis, workSource);
2029 } finally {
2030 Binder.restoreCallingIdentity(identity);
2031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 }
2033
Shishir Agrawala9f32182016-04-12 12:00:16 -07002034 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002035 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002036 Phone phone = PhoneFactory.getPhone(slotIndex);
2037 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002038 return null;
2039 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002040 int subId = phone.getSubId();
2041 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2042 mApp, subId, callingPackage, "getImeiForSlot")) {
2043 return null;
2044 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002045
2046 final long identity = Binder.clearCallingIdentity();
2047 try {
2048 return phone.getImei();
2049 } finally {
2050 Binder.restoreCallingIdentity(identity);
2051 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002052 }
2053
2054 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002055 public String getTypeAllocationCodeForSlot(int slotIndex) {
2056 Phone phone = PhoneFactory.getPhone(slotIndex);
2057 String tac = null;
2058 if (phone != null) {
2059 String imei = phone.getImei();
2060 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2061 }
2062 return tac;
2063 }
2064
2065 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002066 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002067 Phone phone = PhoneFactory.getPhone(slotIndex);
2068 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002069 return null;
2070 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002071 int subId = phone.getSubId();
2072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2073 mApp, subId, callingPackage, "getMeidForSlot")) {
2074 return null;
2075 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002076
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 return phone.getMeid();
2080 } finally {
2081 Binder.restoreCallingIdentity(identity);
2082 }
Jack Yu2af8d712017-03-15 17:14:14 -07002083 }
2084
2085 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002086 public String getManufacturerCodeForSlot(int slotIndex) {
2087 Phone phone = PhoneFactory.getPhone(slotIndex);
2088 String manufacturerCode = null;
2089 if (phone != null) {
2090 String meid = phone.getMeid();
2091 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2092 }
2093 return manufacturerCode;
2094 }
2095
2096 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002097 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002098 Phone phone = PhoneFactory.getPhone(slotIndex);
2099 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002100 return null;
2101 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002102 int subId = phone.getSubId();
2103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2104 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2105 return null;
2106 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002107
2108 final long identity = Binder.clearCallingIdentity();
2109 try {
2110 return phone.getDeviceSvn();
2111 } finally {
2112 Binder.restoreCallingIdentity(identity);
2113 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002114 }
2115
fionaxu43304da2017-11-27 22:51:16 -08002116 @Override
2117 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002118 final long identity = Binder.clearCallingIdentity();
2119 try {
2120 final Phone phone = getPhone(subId);
2121 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
2124 }
fionaxu43304da2017-11-27 22:51:16 -08002125 }
2126
2127 @Override
2128 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002129 final long identity = Binder.clearCallingIdentity();
2130 try {
2131 final Phone phone = getPhone(subId);
2132 return phone == null ? null : phone.getCarrierName();
2133 } finally {
2134 Binder.restoreCallingIdentity(identity);
2135 }
fionaxu43304da2017-11-27 22:51:16 -08002136 }
2137
calvinpaneed9ae82018-11-01 19:43:06 +08002138 @Override
2139 public int getSubscriptionMNOCarrierId(int subId) {
2140 final long identity = Binder.clearCallingIdentity();
2141 try {
2142 final Phone phone = getPhone(subId);
2143 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2144 } finally {
2145 Binder.restoreCallingIdentity(identity);
2146 }
2147 }
2148
chen xuc93cc282018-11-04 17:17:00 -08002149 @Override
2150 public int getSubscriptionPreciseCarrierId(int subId) {
2151 final long identity = Binder.clearCallingIdentity();
2152 try {
2153 final Phone phone = getPhone(subId);
2154 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2155 : phone.getPreciseCarrierId();
2156 } finally {
2157 Binder.restoreCallingIdentity(identity);
2158 }
2159 }
2160
2161 @Override
2162 public String getSubscriptionPreciseCarrierName(int subId) {
2163 final long identity = Binder.clearCallingIdentity();
2164 try {
2165 final Phone phone = getPhone(subId);
2166 return phone == null ? null : phone.getPreciseCarrierName();
2167 } finally {
2168 Binder.restoreCallingIdentity(identity);
2169 }
2170 }
2171
chen xu02581692018-11-11 19:03:44 -08002172 @Override
2173 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc) {
2174 final Phone phone = PhoneFactory.getPhone(slotIndex);
2175 if (phone == null) {
2176 return TelephonyManager.UNKNOWN_CARRIER_ID;
2177 }
2178 final long identity = Binder.clearCallingIdentity();
2179 try {
2180 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2181 } finally {
2182 Binder.restoreCallingIdentity(identity);
2183 }
2184 }
2185
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 //
2187 // Internal helper methods.
2188 //
2189
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002190 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2192 *
2193 * @throws SecurityException if the caller does not have the required permission
2194 */
2195 private void enforceModifyPermission() {
2196 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2197 }
2198
2199 /**
2200 * Make sure the caller has the CALL_PHONE permission.
2201 *
2202 * @throws SecurityException if the caller does not have the required permission
2203 */
2204 private void enforceCallPermission() {
2205 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2206 }
2207
Stuart Scott8eef64f2015-04-08 15:13:54 -07002208 private void enforceConnectivityInternalPermission() {
2209 mApp.enforceCallingOrSelfPermission(
2210 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2211 "ConnectivityService");
2212 }
2213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 private String createTelUrl(String number) {
2215 if (TextUtils.isEmpty(number)) {
2216 return null;
2217 }
2218
Jake Hambye994d462014-02-03 13:10:13 -08002219 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221
Ihab Awadf9e92732013-12-05 18:02:52 -08002222 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2224 }
2225
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002226 private static void logv(String msg) {
2227 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2228 }
2229
Ihab Awadf9e92732013-12-05 18:02:52 -08002230 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2232 }
2233
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002234 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002236 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002237 }
2238
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002240 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 final Phone phone = PhoneFactory.getPhone(slotIndex);
2244 if (phone == null) {
2245 return PhoneConstants.PHONE_TYPE_NONE;
2246 } else {
2247 return phone.getPhoneType();
2248 }
2249 } finally {
2250 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 }
2253
2254 /**
2255 * Returns the CDMA ERI icon index to display
2256 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002257 @Override
2258 public int getCdmaEriIconIndex(String callingPackage) {
2259 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002260 }
2261
Sanket Padawe356d7632015-06-22 14:03:32 -07002262 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002263 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002265 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002266 return -1;
2267 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002268
2269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 final Phone phone = getPhone(subId);
2272 if (phone != null) {
2273 return phone.getCdmaEriIconIndex();
2274 } else {
2275 return -1;
2276 }
2277 } finally {
2278 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281
2282 /**
2283 * Returns the CDMA ERI icon mode,
2284 * 0 - ON
2285 * 1 - FLASHING
2286 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002287 @Override
2288 public int getCdmaEriIconMode(String callingPackage) {
2289 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002290 }
2291
Sanket Padawe356d7632015-06-22 14:03:32 -07002292 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002293 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002294 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002295 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002296 return -1;
2297 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002298
2299 final long identity = Binder.clearCallingIdentity();
2300 try {
2301 final Phone phone = getPhone(subId);
2302 if (phone != null) {
2303 return phone.getCdmaEriIconMode();
2304 } else {
2305 return -1;
2306 }
2307 } finally {
2308 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 }
2311
2312 /**
2313 * Returns the CDMA ERI text,
2314 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002315 @Override
2316 public String getCdmaEriText(String callingPackage) {
2317 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002318 }
2319
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002321 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002323 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002324 return null;
2325 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 final Phone phone = getPhone(subId);
2330 if (phone != null) {
2331 return phone.getCdmaEriText();
2332 } else {
2333 return null;
2334 }
2335 } finally {
2336 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 }
2339
2340 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002341 * Returns the CDMA MDN.
2342 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002343 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002344 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2346 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
2351 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2352 return phone.getLine1Number();
2353 } else {
2354 return null;
2355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002358 }
2359 }
2360
2361 /**
2362 * Returns the CDMA MIN.
2363 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002365 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2367 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002368
2369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 final Phone phone = getPhone(subId);
2372 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2373 return phone.getCdmaMin();
2374 } else {
2375 return null;
2376 }
2377 } finally {
2378 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002379 }
2380 }
2381
Hall Liud892bec2018-11-30 14:51:45 -08002382 @Override
2383 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2384 INumberVerificationCallback callback, String callingPackage) {
2385 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2386 != PERMISSION_GRANTED) {
2387 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2388 }
2389 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2390
2391 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2392 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2393 throw new SecurityException("Calling package must be configured in the device config");
2394 }
2395
2396 if (range == null) {
2397 throw new NullPointerException("Range must be non-null");
2398 }
2399
2400 timeoutMillis = Math.min(timeoutMillis,
2401 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2402
2403 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2404 }
2405
Junda Liuca05d5d2014-08-14 22:36:34 -07002406 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 * Returns true if CDMA provisioning needs to run.
2408 */
2409 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 return mPhone.needsOtaServiceProvisioning();
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417
2418 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002419 * Sets the voice mail number of a given subId.
2420 */
2421 @Override
2422 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002423 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002424
2425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2428 new Pair<String, String>(alphaTag, number), new Integer(subId));
2429 return success;
2430 } finally {
2431 Binder.restoreCallingIdentity(identity);
2432 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002433 }
2434
Ta-wei Yen87c49842016-05-13 21:19:52 -07002435 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002436 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2437 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2438 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2439 if (!TextUtils.equals(callingPackage, systemDialer)) {
2440 throw new SecurityException("caller must be system dialer");
2441 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002442
2443 final long identity = Binder.clearCallingIdentity();
2444 try {
2445 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2446 if (phoneAccountHandle == null) {
2447 return null;
2448 }
2449 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002452 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002453 }
2454
2455 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002456 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002459 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002460 return null;
2461 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002462
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 return RemoteVvmTaskManager
2466 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
2469 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002470 }
2471
2472 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002473 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2474 VisualVoicemailSmsFilterSettings settings) {
2475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002476
2477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2480 mPhone.getContext(), callingPackage, subId, settings);
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
2483 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002484 }
2485
2486 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002487 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2488 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002489
2490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2493 mPhone.getContext(), callingPackage, subId);
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
2496 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002497 }
2498
2499 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002500 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2501 String callingPackage, int subId) {
2502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2507 mPhone.getContext(), callingPackage, subId);
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002511 }
2512
2513 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002514 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002515 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002516
2517 final long identity = Binder.clearCallingIdentity();
2518 try {
2519 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2520 mPhone.getContext(), subId);
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
2523 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002524 }
2525
2526 @Override
2527 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2528 String number, int port, String text, PendingIntent sentIntent) {
2529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002530 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002531 enforceSendSmsPermission();
2532 // Make the calls as the phone process.
2533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2536 if (port == 0) {
2537 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2538 sentIntent, null, false);
2539 } else {
2540 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2541 smsManager.sendDataMessageWithSelfPermissions(number, null,
2542 (short) port, data, sentIntent, null);
2543 }
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
2546 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002547 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002548 /**
fionaxu0152e512016-11-14 13:36:14 -08002549 * Sets the voice activation state of a given subId.
2550 */
2551 @Override
2552 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2554 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002555
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 final Phone phone = getPhone(subId);
2559 if (phone != null) {
2560 phone.setVoiceActivationState(activationState);
2561 } else {
2562 loge("setVoiceActivationState fails with invalid subId: " + subId);
2563 }
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002566 }
2567 }
2568
2569 /**
2570 * Sets the data activation state of a given subId.
2571 */
2572 @Override
2573 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2575 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 final Phone phone = getPhone(subId);
2580 if (phone != null) {
2581 phone.setDataActivationState(activationState);
2582 } else {
2583 loge("setVoiceActivationState fails with invalid subId: " + subId);
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002587 }
2588 }
2589
2590 /**
2591 * Returns the voice activation state of a given subId.
2592 */
2593 @Override
2594 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002595 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002596
fionaxu0152e512016-11-14 13:36:14 -08002597 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 if (phone != null) {
2601 return phone.getVoiceActivationState();
2602 } else {
2603 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002607 }
2608 }
2609
2610 /**
2611 * Returns the data activation state of a given subId.
2612 */
2613 @Override
2614 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002615 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002616
fionaxu0152e512016-11-14 13:36:14 -08002617 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 if (phone != null) {
2621 return phone.getDataActivationState();
2622 } else {
2623 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002627 }
2628 }
2629
2630 /**
Wink Saville36469e72014-06-11 15:17:00 -07002631 * Returns the unread count of voicemails for a subId
2632 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002634 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2636 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2637 return 0;
2638 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 final Phone phone = getPhone(subId);
2642 if (phone != null) {
2643 return phone.getVoiceMessageCount();
2644 } else {
2645 return 0;
2646 }
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 }
2651
2652 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002653 * returns true, if the device is in a state where both voice and data
2654 * are supported simultaneously. This can change based on location or network condition.
2655 */
2656 @Override
2657 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 final Phone phone = getPhone(subId);
2661 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
2664 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002665 }
2666
2667 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002668 * Send the dialer code if called from the current default dialer or the caller has
2669 * carrier privilege.
2670 * @param inputCode The dialer code to send
2671 */
2672 @Override
2673 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2674 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2675 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2676 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002677 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2678 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002679 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002680
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 mPhone.sendDialerSpecialCode(inputCode);
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
2686 }
fionaxu235cc5e2017-03-06 22:25:57 -08002687 }
2688
2689 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002690 * Returns the data network type.
2691 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 *
2693 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2694 */
2695 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002696 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 final Phone phone = getPhone(getDefaultSubscription());
2700 if (phone != null) {
2701 return phone.getServiceState().getDataNetworkType();
2702 } else {
2703 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002707 }
Wink Saville36469e72014-06-11 15:17:00 -07002708 }
2709
Pengquan Meng0c05b502018-09-06 09:59:22 -07002710 @Override
2711 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002712 if (!isActiveSubscription(subId)) {
2713 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2714 }
2715
Pengquan Meng0c05b502018-09-06 09:59:22 -07002716 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2717 }
2718
Brad Ebinger4c460712018-10-01 10:40:55 -07002719 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002720 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2721 throws RemoteException {
2722 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2724 final long token = Binder.clearCallingIdentity();
2725 try {
2726 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2727 .addRegistrationCallbackForSubscription(c, subId);
2728 } finally {
2729 Binder.restoreCallingIdentity(token);
2730 }
2731 }
2732
2733 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002734 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2735 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002736 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2737 Binder.withCleanCallingIdentity(() ->
2738 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2739 .removeRegistrationCallbackForSubscription(c, subId));
2740 }
2741
2742 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002743 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2744 throws RemoteException {
2745 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002746 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2747 final long token = Binder.clearCallingIdentity();
2748 try {
2749 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2750 .addCapabilitiesCallbackForSubscription(c, subId);
2751 } finally {
2752 Binder.restoreCallingIdentity(token);
2753 }
2754 }
2755
2756 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002757 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2758 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2760 Binder.withCleanCallingIdentity(() ->
2761 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2762 .removeCapabilitiesCallbackForSubscription(c, subId));
2763 }
2764
2765 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002766 public boolean isCapable(int subId, int capability, int regTech) {
2767 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002768 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2769 final long token = Binder.clearCallingIdentity();
2770 try {
2771 return ImsManager.getInstance(mPhone.getContext(),
2772 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2773 } catch (ImsException e) {
2774 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2775 return false;
2776 } finally {
2777 Binder.restoreCallingIdentity(token);
2778 }
2779 }
2780
2781 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002782 public boolean isAvailable(int subId, int capability, int regTech) {
2783 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002784 final long token = Binder.clearCallingIdentity();
2785 try {
2786 Phone phone = getPhone(subId);
2787 if (phone == null) return false;
2788 return phone.isImsCapabilityAvailable(capability, regTech);
2789 } finally {
2790 Binder.restoreCallingIdentity(token);
2791 }
2792 }
2793
2794 @Override
2795 public boolean isAdvancedCallingSettingEnabled(int subId) {
2796 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2797 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2798 final long token = Binder.clearCallingIdentity();
2799 try {
2800 return ImsManager.getInstance(mPhone.getContext(),
2801 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2802 } finally {
2803 Binder.restoreCallingIdentity(token);
2804 }
2805 }
2806
2807 @Override
2808 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2810 "setAdvancedCallingSetting");
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
2813 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2814 ImsManager.getInstance(mPhone.getContext(),
2815 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
2818 }
2819 }
2820
2821 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002822 public boolean isVtSettingEnabled(int subId) {
2823 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2827 return ImsManager.getInstance(mPhone.getContext(),
2828 getSlotIndexOrException(subId)).isVtEnabledByUser();
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
2831 }
2832 }
2833
2834 @Override
2835 public void setVtSetting(int subId, boolean isEnabled) {
2836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2837 "setVtSetting");
2838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2841 ImsManager.getInstance(mPhone.getContext(),
2842 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
2845 }
2846 }
2847
2848 @Override
2849 public boolean isVoWiFiSettingEnabled(int subId) {
2850 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2854 return ImsManager.getInstance(mPhone.getContext(),
2855 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
2859 }
2860
2861 @Override
2862 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2864 "setVoWiFiSetting");
2865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2868 ImsManager.getInstance(mPhone.getContext(),
2869 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2870 } finally {
2871 Binder.restoreCallingIdentity(identity);
2872 }
2873 }
2874
2875 @Override
2876 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2877 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2881 return ImsManager.getInstance(mPhone.getContext(),
2882 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
2885 }
2886 }
2887
2888 @Override
2889 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2891 "setVoWiFiRoamingSetting");
2892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2895 ImsManager.getInstance(mPhone.getContext(),
2896 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
2899 }
2900 }
2901
2902 @Override
2903 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2905 "setVoWiFiNonPersistent");
2906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2909 ImsManager.getInstance(mPhone.getContext(),
2910 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
2913 }
2914 }
2915
2916 @Override
2917 public int getVoWiFiModeSetting(int subId) {
2918 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2922 return ImsManager.getInstance(mPhone.getContext(),
2923 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
2927 }
2928
2929 @Override
2930 public void setVoWiFiModeSetting(int subId, int mode) {
2931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2932 "setVoWiFiModeSetting");
2933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2936 ImsManager.getInstance(mPhone.getContext(),
2937 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
2941 }
2942
2943 @Override
2944 public int getVoWiFiRoamingModeSetting(int subId) {
2945 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2949 return ImsManager.getInstance(mPhone.getContext(),
2950 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
2954 }
2955
2956 @Override
2957 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2959 "setVoWiFiRoamingModeSetting");
2960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2963 ImsManager.getInstance(mPhone.getContext(),
2964 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
2968 }
2969
2970 @Override
2971 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2973 "setRttCapabilityEnabled");
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(),
2978 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
2985 public boolean isTtyOverVolteEnabled(int subId) {
2986 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2990 return ImsManager.getInstance(mPhone.getContext(),
2991 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002997 @Override
2998 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2999 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3003 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3004 .getConfigInterface().addConfigCallback(callback);
3005 } catch (ImsException e) {
3006 throw new IllegalArgumentException(e.getMessage());
3007 } finally {
3008 Binder.restoreCallingIdentity(identity);
3009 }
3010 }
3011
3012 @Override
3013 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3014 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3018 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3019 .getConfigInterface().removeConfigCallback(callback);
3020 } catch (ImsException e) {
3021 throw new IllegalArgumentException(e.getMessage());
3022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
3025 }
3026
3027 @Override
3028 public int getImsProvisioningInt(int subId, int key) {
3029 enforceReadPrivilegedPermission("getImsProvisioningInt");
3030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3033 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3034 .getConfigInterface().getConfigInt(key);
3035 } catch (ImsException e) {
3036 throw new IllegalArgumentException(e.getMessage());
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
3040 }
3041
3042 @Override
3043 public String getImsProvisioningString(int subId, int key) {
3044 enforceReadPrivilegedPermission("getImsProvisioningString");
3045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3048 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3049 .getConfigInterface().getConfigString(key);
3050 } catch (ImsException e) {
3051 throw new IllegalArgumentException(e.getMessage());
3052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
3055 }
3056
3057 @Override
3058 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3060 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3064 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3065 .getConfigInterface().setConfig(key, value);
3066 } catch (ImsException e) {
3067 throw new IllegalArgumentException(e.getMessage());
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
3071 }
3072
3073 @Override
3074 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3076 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003077 final long identity = Binder.clearCallingIdentity();
3078 try {
3079 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3080 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3081 .getConfigInterface().setConfig(key, value);
3082 } catch (ImsException e) {
3083 throw new IllegalArgumentException(e.getMessage());
3084 } finally {
3085 Binder.restoreCallingIdentity(identity);
3086 }
3087 }
3088
Brad Ebinger4c460712018-10-01 10:40:55 -07003089 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3090 int slotId = SubscriptionManager.getSlotIndex(subId);
3091 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3092 throw new IllegalArgumentException("Invalid Subscription Id.");
3093 }
3094 return slotId;
3095 }
3096
Wink Saville36469e72014-06-11 15:17:00 -07003097 /**
3098 * Returns the network type for a subId
3099 */
3100 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003101 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003103 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003104 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3105 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003106
Malcolm Chend965c8b2018-02-28 15:00:40 -08003107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 final Phone phone = getPhone(subId);
3110 if (phone != null) {
3111 return phone.getServiceState().getDataNetworkType();
3112 } else {
3113 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3114 }
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003118 }
3119
3120 /**
3121 * Returns the data network type
3122 */
3123 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003124 public int getDataNetworkType(String callingPackage) {
3125 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003126 }
3127
3128 /**
3129 * Returns the data network type for a subId
3130 */
3131 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003132 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003134 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003135 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3136 }
3137
Malcolm Chend965c8b2018-02-28 15:00:40 -08003138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 final Phone phone = getPhone(subId);
3141 if (phone != null) {
3142 return phone.getServiceState().getDataNetworkType();
3143 } else {
3144 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3145 }
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 }
3150
3151 /**
Wink Saville36469e72014-06-11 15:17:00 -07003152 * Returns the Voice network type for a subId
3153 */
3154 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003155 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003157 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003158 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3159 }
3160
Malcolm Chend965c8b2018-02-28 15:00:40 -08003161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 final Phone phone = getPhone(subId);
3164 if (phone != null) {
3165 return phone.getServiceState().getVoiceNetworkType();
3166 } else {
3167 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3168 }
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 }
3173
3174 /**
3175 * @return true if a ICC card is present
3176 */
3177 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003178 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003179 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3180 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003181 }
3182
3183 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003184 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003185 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003186 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003187 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 final Phone phone = PhoneFactory.getPhone(slotIndex);
3191 if (phone != null) {
3192 return phone.getIccCard().hasIccCard();
3193 } else {
3194 return false;
3195 }
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 }
3200
3201 /**
3202 * Return if the current radio is LTE on CDMA. This
3203 * is a tri-state return value as for a period of time
3204 * the mode may be unknown.
3205 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003206 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003208 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003210 @Override
3211 public int getLteOnCdmaMode(String callingPackage) {
3212 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003213 }
3214
Sanket Padawe356d7632015-06-22 14:03:32 -07003215 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003216 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003218 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003219 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3220 }
3221
Malcolm Chend965c8b2018-02-28 15:00:40 -08003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 final Phone phone = getPhone(subId);
3225 if (phone == null) {
3226 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3227 } else {
3228 return phone.getLteOnCdmaMode();
3229 }
3230 } finally {
3231 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003232 }
Wink Saville36469e72014-06-11 15:17:00 -07003233 }
3234
3235 public void setPhone(Phone phone) {
3236 mPhone = phone;
3237 }
3238
3239 /**
3240 * {@hide}
3241 * Returns Default subId, 0 in the case of single standby.
3242 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003243 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003244 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003245 }
3246
Shishir Agrawala9f32182016-04-12 12:00:16 -07003247 private int getSlotForDefaultSubscription() {
3248 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3249 }
3250
Wink Savilleb564aae2014-10-23 10:18:09 -07003251 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003252 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003254
Pengquan Meng466e2482018-09-21 15:54:48 -07003255 private boolean isActiveSubscription(int subId) {
3256 return mSubscriptionController.isActiveSubId(subId);
3257 }
3258
Ihab Awadf2177b72013-11-25 13:33:23 -08003259 /**
3260 * @see android.telephony.TelephonyManager.WifiCallingChoices
3261 */
3262 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3266 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3267 getWhenToMakeWifiCallsDefaultPreference());
3268 } finally {
3269 Binder.restoreCallingIdentity(identity);
3270 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003271 }
3272
3273 /**
3274 * @see android.telephony.TelephonyManager.WifiCallingChoices
3275 */
3276 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003277 final long identity = Binder.clearCallingIdentity();
3278 try {
3279 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3280 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3281 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003285 }
3286
Sailesh Nepald1e68152013-12-12 19:08:02 -08003287 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003288 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003289 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003290 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003291
Shishir Agrawal566b7612013-10-28 14:41:00 -07003292 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003293 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3294 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3296 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003297 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003298
Malcolm Chend965c8b2018-02-28 15:00:40 -08003299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 if (TextUtils.equals(ISDR_AID, aid)) {
3302 // Only allows LPA to open logical channel to ISD-R.
3303 ComponentInfo bestComponent =
3304 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3305 if (bestComponent == null
3306 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3307 loge("The calling package is not allowed to access ISD-R.");
3308 throw new SecurityException(
3309 "The calling package is not allowed to access ISD-R.");
3310 }
Derek Tan740e1672017-06-27 14:56:27 -07003311 }
Derek Tan740e1672017-06-27 14:56:27 -07003312
Malcolm Chend965c8b2018-02-28 15:00:40 -08003313 if (DBG) {
3314 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3315 }
3316 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3317 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3318 if (DBG) log("iccOpenLogicalChannel: " + response);
3319 return response;
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
3322 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003323 }
3324
3325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003326 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3328 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003329
Malcolm Chend965c8b2018-02-28 15:00:40 -08003330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3333 if (channel < 0) {
3334 return false;
3335 }
3336 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3337 if (DBG) log("iccCloseLogicalChannel: " + success);
3338 return success;
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003341 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003342 }
3343
3344 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003345 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003346 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3348 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003349
Malcolm Chend965c8b2018-02-28 15:00:40 -08003350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 if (DBG) {
3353 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3354 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3355 + p3 + " data=" + data);
3356 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003357
Malcolm Chend965c8b2018-02-28 15:00:40 -08003358 if (channel < 0) {
3359 return "";
3360 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003361
Malcolm Chend965c8b2018-02-28 15:00:40 -08003362 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3363 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3364 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003365
Malcolm Chend965c8b2018-02-28 15:00:40 -08003366 // Append the returned status code to the end of the response payload.
3367 String s = Integer.toHexString(
3368 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3369 if (response.payload != null) {
3370 s = IccUtils.bytesToHexString(response.payload) + s;
3371 }
3372 return s;
3373 } finally {
3374 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003375 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003376 }
Jake Hambye994d462014-02-03 13:10:13 -08003377
Evan Charltonc66da362014-05-16 14:06:40 -07003378 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003379 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3380 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3382 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003383 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003384
Malcolm Chend965c8b2018-02-28 15:00:40 -08003385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3388 && TextUtils.equals(ISDR_AID, data)) {
3389 // Only allows LPA to select ISD-R.
3390 ComponentInfo bestComponent =
3391 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3392 if (bestComponent == null
3393 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3394 loge("The calling package is not allowed to select ISD-R.");
3395 throw new SecurityException(
3396 "The calling package is not allowed to select ISD-R.");
3397 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003398 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003399
Malcolm Chend965c8b2018-02-28 15:00:40 -08003400 if (DBG) {
3401 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3402 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3403 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003404
Malcolm Chend965c8b2018-02-28 15:00:40 -08003405 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3406 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3407 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003408
Malcolm Chend965c8b2018-02-28 15:00:40 -08003409 // Append the returned status code to the end of the response payload.
3410 String s = Integer.toHexString(
3411 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3412 if (response.payload != null) {
3413 s = IccUtils.bytesToHexString(response.payload) + s;
3414 }
3415 return s;
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003418 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003419 }
3420
3421 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003422 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003423 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3425 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003426
Malcolm Chend965c8b2018-02-28 15:00:40 -08003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 if (DBG) {
3430 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3431 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3432 }
3433
3434 IccIoResult response =
3435 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3436 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3437 subId);
3438
3439 if (DBG) {
3440 log("Exchange SIM_IO [R]" + response);
3441 }
3442
3443 byte[] result = null;
3444 int length = 2;
3445 if (response.payload != null) {
3446 length = 2 + response.payload.length;
3447 result = new byte[length];
3448 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3449 } else {
3450 result = new byte[length];
3451 }
3452
3453 result[length - 1] = (byte) response.sw2;
3454 result[length - 2] = (byte) response.sw1;
3455 return result;
3456 } finally {
3457 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003458 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003459 }
3460
Nathan Haroldb3014052017-01-25 15:57:32 -08003461 /**
3462 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3463 * on a particular subscription
3464 */
sqianb6e41952018-03-12 14:54:01 -07003465 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3467 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3468 return null;
3469 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003470
3471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 if (appType != TelephonyManager.APPTYPE_USIM
3474 && appType != TelephonyManager.APPTYPE_SIM) {
3475 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3476 return null;
3477 }
3478 Object response = sendRequest(
3479 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3480 if (response instanceof String[]) {
3481 return (String[]) response;
3482 }
3483 // Response is an Exception of some kind,
3484 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003485 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003486 } finally {
3487 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003488 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003489 }
3490
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003491 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003492 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3494 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003495
Malcolm Chend965c8b2018-02-28 15:00:40 -08003496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3499 if (response.payload == null) {
3500 return "";
3501 }
Evan Charltonc66da362014-05-16 14:06:40 -07003502
Malcolm Chend965c8b2018-02-28 15:00:40 -08003503 // Append the returned status code to the end of the response payload.
3504 String s = Integer.toHexString(
3505 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3506 s = IccUtils.bytesToHexString(response.payload) + s;
3507 return s;
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
3510 }
Evan Charltonc66da362014-05-16 14:06:40 -07003511 }
3512
Jake Hambye994d462014-02-03 13:10:13 -08003513 /**
3514 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3515 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3516 *
3517 * @param itemID the ID of the item to read
3518 * @return the NV item as a String, or null on error.
3519 */
3520 @Override
3521 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003522 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3524 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003525
3526 final long identity = Binder.clearCallingIdentity();
3527 try {
3528 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003529 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003530 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3531 return value;
3532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
Jake Hambye994d462014-02-03 13:10:13 -08003535 }
3536
3537 /**
3538 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3539 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3540 *
3541 * @param itemID the ID of the item to read
3542 * @param itemValue the value to write, as a String
3543 * @return true on success; false on any failure
3544 */
3545 @Override
3546 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003547 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3549 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003550
3551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3554 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003555 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003556 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3557 return success;
3558 } finally {
3559 Binder.restoreCallingIdentity(identity);
3560 }
Jake Hambye994d462014-02-03 13:10:13 -08003561 }
3562
3563 /**
3564 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3565 * Used for device configuration by some CDMA operators.
3566 *
3567 * @param preferredRoamingList byte array containing the new PRL
3568 * @return true on success; false on any failure
3569 */
3570 @Override
3571 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3573 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003574
3575 final long identity = Binder.clearCallingIdentity();
3576 try {
3577 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3578 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3579 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3580 return success;
3581 } finally {
3582 Binder.restoreCallingIdentity(identity);
3583 }
Jake Hambye994d462014-02-03 13:10:13 -08003584 }
3585
3586 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003587 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003588 * Used for device configuration by some CDMA operators.
3589 *
chen xu1cc0abe2018-10-26 17:39:23 -07003590 * @param slotIndex - device slot.
3591 *
Jake Hambye994d462014-02-03 13:10:13 -08003592 * @return true on success; false on any failure
3593 */
3594 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003595 public boolean resetModemConfig(int slotIndex) {
3596 Phone phone = PhoneFactory.getPhone(slotIndex);
3597 if (phone != null) {
3598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3599 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003600
chen xu1cc0abe2018-10-26 17:39:23 -07003601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3604 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3605 return success;
3606 } finally {
3607 Binder.restoreCallingIdentity(identity);
3608 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003609 }
chen xu1cc0abe2018-10-26 17:39:23 -07003610 return false;
3611 }
3612
3613 /**
3614 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3615 *
3616 * @param slotIndex - device slot.
3617 *
3618 * @return true on success; false on any failure
3619 */
3620 @Override
3621 public boolean rebootModem(int slotIndex) {
3622 Phone phone = PhoneFactory.getPhone(slotIndex);
3623 if (phone != null) {
3624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3625 mApp, phone.getSubId(), "rebootModem");
3626
3627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3630 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3631 return success;
3632 } finally {
3633 Binder.restoreCallingIdentity(identity);
3634 }
3635 }
3636 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003637 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003638
Svet Ganovb320e182015-04-16 12:30:10 -07003639 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003641 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003642 return new String[0];
3643 }
3644
Malcolm Chend965c8b2018-02-28 15:00:40 -08003645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 return mPhone.getPcscfAddress(apnType);
3648 } finally {
3649 Binder.restoreCallingIdentity(identity);
3650 }
Wink Saville36469e72014-06-11 15:17:00 -07003651 }
3652
Brad Ebinger51f743a2017-01-23 13:50:20 -08003653 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003654 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3655 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003656 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003657 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003658 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003659
3660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 PhoneFactory.getImsResolver().enableIms(slotId);
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003666 }
3667
3668 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003669 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3670 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003671 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003672 public void disableIms(int slotId) {
3673 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003674
3675 final long identity = Binder.clearCallingIdentity();
3676 try {
3677 PhoneFactory.getImsResolver().disableIms(slotId);
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003681 }
3682
3683 /**
3684 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3685 * feature or {@link null} if the service is not available. If the feature is available, the
3686 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3687 */
3688 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003689 IImsServiceFeatureCallback callback) {
3690 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003691
3692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003698 }
3699
3700 /**
3701 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3702 * feature during emergency calling or {@link null} if the service is not available. If the
3703 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3704 * listener for feature updates.
3705 */
3706 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3707 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003708
3709 final long identity = Binder.clearCallingIdentity();
3710 try {
3711 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003715 }
3716
Brad Ebinger5f64b052017-12-14 14:26:15 -08003717 /**
3718 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3719 * specified.
3720 */
3721 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3722 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003723
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003730 }
3731
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003732 /**
3733 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3734 * specified.
3735 */
3736 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3737 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003738
3739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3742 } finally {
3743 Binder.restoreCallingIdentity(identity);
3744 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003745 }
3746
Brad Ebinger884c07b2018-02-15 16:17:40 -08003747 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003748 * Sets the ImsService Package Name that Telephony will bind to.
3749 *
3750 * @param slotId the slot ID that the ImsService should bind for.
3751 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3752 * ImsService is the device default ImsService.
3753 * @param packageName The package name of the application that contains the ImsService to bind
3754 * to.
3755 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3756 * @hide
3757 */
3758 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003759 int[] subIds = SubscriptionManager.getSubId(slotId);
3760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3761 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3762 "setImsService");
3763
Malcolm Chend965c8b2018-02-28 15:00:40 -08003764 final long identity = Binder.clearCallingIdentity();
3765 try {
3766 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3767 isCarrierImsService, packageName);
3768 } finally {
3769 Binder.restoreCallingIdentity(identity);
3770 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003771 }
3772
3773 /**
3774 * Return the ImsService configuration.
3775 *
3776 * @param slotId The slot that the ImsService is associated with.
3777 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3778 * the device default.
3779 * @return the package name of the ImsService configuration.
3780 */
3781 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003782 int[] subIds = SubscriptionManager.getSubId(slotId);
3783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3784 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3785 "getImsService");
3786
Malcolm Chend965c8b2018-02-28 15:00:40 -08003787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3790 isCarrierImsService);
3791 } finally {
3792 Binder.restoreCallingIdentity(identity);
3793 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003794 }
3795
Wink Saville36469e72014-06-11 15:17:00 -07003796 public void setImsRegistrationState(boolean registered) {
3797 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003798
3799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 mPhone.setImsRegistrationState(registered);
3802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
Wink Saville36469e72014-06-11 15:17:00 -07003805 }
3806
3807 /**
Stuart Scott54788802015-03-30 13:18:01 -07003808 * Set the network selection mode to automatic.
3809 *
3810 */
3811 @Override
3812 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3814 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003815
Pengquan Meng466e2482018-09-21 15:54:48 -07003816 if (!isActiveSubscription(subId)) {
3817 return;
3818 }
3819
Malcolm Chend965c8b2018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3823 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3824 } finally {
3825 Binder.restoreCallingIdentity(identity);
3826 }
Stuart Scott54788802015-03-30 13:18:01 -07003827 }
3828
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003829 /**
3830 * Ask the radio to connect to the input network and change selection mode to manual.
3831 *
3832 * @param subId the id of the subscription.
3833 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3834 * the operator to attach to.
3835 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3836 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3837 * normal network selection next time.
3838 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003839 */
3840 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003841 public boolean setNetworkSelectionModeManual(
3842 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3844 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003845
3846 if (!isActiveSubscription(subId)) {
3847 return false;
3848 }
3849
Malcolm Chend965c8b2018-02-28 15:00:40 -08003850 final long identity = Binder.clearCallingIdentity();
3851 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003852 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003853 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003854 if (DBG) {
3855 log("setNetworkSelectionModeManual: subId: " + subId
3856 + " operator: " + operatorInfo);
3857 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003858 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003862 }
3863
3864 /**
3865 * Scans for available networks.
3866 */
3867 @Override
3868 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3870 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003871
Pengquan Meng0c05b502018-09-06 09:59:22 -07003872 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003873 try {
3874 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003875 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003876 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003877 } finally {
3878 Binder.restoreCallingIdentity(identity);
3879 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003880 }
3881
3882 /**
yinxub1bed742017-04-17 11:45:04 -07003883 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003884 *
yinxub1bed742017-04-17 11:45:04 -07003885 * @param subId id of the subscription
3886 * @param request contains the radio access networks with bands/channels to scan
3887 * @param messenger callback messenger for scan results or errors
3888 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003889 * @return the id of the requested scan which can be used to stop the scan.
3890 */
3891 @Override
3892 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3893 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3895 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003896
3897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 return mNetworkScanRequestTracker.startNetworkScan(
3900 request, messenger, binder, getPhone(subId));
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
3903 }
yinxu504e1392017-04-12 16:03:22 -07003904 }
3905
3906 /**
3907 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003908 *
3909 * @param subId id of the subscription
3910 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003911 */
3912 @Override
3913 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3915 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003916
3917 final long identity = Binder.clearCallingIdentity();
3918 try {
3919 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3920 } finally {
3921 Binder.restoreCallingIdentity(identity);
3922 }
yinxu504e1392017-04-12 16:03:22 -07003923 }
3924
3925 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003926 * Get the calculated preferred network type.
3927 * Used for debugging incorrect network type.
3928 *
3929 * @return the preferred network type, defined in RILConstants.java.
3930 */
3931 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003932 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003934 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003935 return RILConstants.PREFERRED_NETWORK_MODE;
3936 }
3937
Malcolm Chend965c8b2018-02-28 15:00:40 -08003938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 // FIXME: need to get SubId from somewhere.
3941 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3942 } finally {
3943 Binder.restoreCallingIdentity(identity);
3944 }
Junda Liu84d15a22014-07-02 11:21:04 -07003945 }
3946
3947 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003948 * Get the preferred network type.
3949 * Used for device configuration by some CDMA operators.
3950 *
3951 * @return the preferred network type, defined in RILConstants.java.
3952 */
3953 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003954 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3956 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 if (DBG) log("getPreferredNetworkType");
3961 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3962 int networkType = (result != null ? result[0] : -1);
3963 if (DBG) log("getPreferredNetworkType: " + networkType);
3964 return networkType;
3965 } finally {
3966 Binder.restoreCallingIdentity(identity);
3967 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003968 }
3969
3970 /**
3971 * Set the preferred network type.
3972 * Used for device configuration by some CDMA operators.
3973 *
3974 * @param networkType the preferred network type, defined in RILConstants.java.
3975 * @return true on success; false on any failure.
3976 */
3977 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003978 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3980 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003981
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3985 Boolean success = (Boolean) sendRequest(
3986 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3987 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3988 if (success) {
3989 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3990 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3991 }
3992 return success;
3993 } finally {
3994 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003995 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003996 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003997
3998 /**
Junda Liu475951f2014-11-07 16:45:03 -08003999 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004000 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004001 * tethering.
4002 *
4003 * @return 0: Not required. 1: required. 2: Not set.
4004 * @hide
4005 */
4006 @Override
4007 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004008 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004009
4010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
4013 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004014 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08004015 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
4016 dunRequired = 1;
4017 }
4018 return dunRequired;
4019 } finally {
4020 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004021 }
Junda Liu475951f2014-11-07 16:45:03 -08004022 }
4023
4024 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004025 * Set mobile data enabled
4026 * Used by the user through settings etc to turn on/off mobile data
4027 *
4028 * @param enable {@code true} turn turn data on, else {@code false}
4029 */
4030 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004031 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4033 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004034
4035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 int phoneId = mSubscriptionController.getPhoneId(subId);
4038 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4039 Phone phone = PhoneFactory.getPhone(phoneId);
4040 if (phone != null) {
4041 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4042 phone.setUserDataEnabled(enable);
4043 } else {
4044 loge("setUserDataEnabled: no phone for subId=" + subId);
4045 }
4046 } finally {
4047 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004048 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004049 }
4050
4051 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004052 * Get the user enabled state of Mobile Data.
4053 *
4054 * TODO: remove and use isUserDataEnabled.
4055 * This can't be removed now because some vendor codes
4056 * calls through ITelephony directly while they should
4057 * use TelephonyManager.
4058 *
4059 * @return true on enabled
4060 */
4061 @Override
4062 public boolean getDataEnabled(int subId) {
4063 return isUserDataEnabled(subId);
4064 }
4065
4066 /**
4067 * Get whether mobile data is enabled per user setting.
4068 *
4069 * There are other factors deciding whether mobile data is actually enabled, but they are
4070 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004071 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004072 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004073 *
4074 * @return {@code true} if data is enabled else {@code false}
4075 */
4076 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004077 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004078 try {
4079 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4080 null);
4081 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4083 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004084 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004085
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 int phoneId = mSubscriptionController.getPhoneId(subId);
4089 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4090 Phone phone = PhoneFactory.getPhone(phoneId);
4091 if (phone != null) {
4092 boolean retVal = phone.isUserDataEnabled();
4093 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4094 return retVal;
4095 } else {
4096 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4097 return false;
4098 }
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004101 }
4102 }
4103
4104 /**
4105 * Get whether mobile data is enabled.
4106 *
4107 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4108 * whether mobile data is actually enabled.
4109 *
4110 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4111 *
4112 * @return {@code true} if data is enabled else {@code false}
4113 */
4114 @Override
4115 public boolean isDataEnabled(int subId) {
4116 try {
4117 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4118 null);
4119 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4121 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004122 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004123
4124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 int phoneId = mSubscriptionController.getPhoneId(subId);
4127 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4128 Phone phone = PhoneFactory.getPhone(phoneId);
4129 if (phone != null) {
4130 boolean retVal = phone.isDataEnabled();
4131 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4132 return retVal;
4133 } else {
4134 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4135 return false;
4136 }
4137 } finally {
4138 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004139 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004140 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004141
4142 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004143 public int getCarrierPrivilegeStatus(int subId) {
4144 final Phone phone = getPhone(subId);
4145 if (phone == null) {
4146 loge("getCarrierPrivilegeStatus: Invalid subId");
4147 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4148 }
4149 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004150 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004151 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004152 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4153 }
4154 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004155 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004156 }
Junda Liu29340342014-07-10 15:23:27 -07004157
4158 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004159 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4160 final Phone phone = getPhone(subId);
4161 if (phone == null) {
4162 loge("getCarrierPrivilegeStatus: Invalid subId");
4163 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4164 }
4165 UiccProfile profile =
4166 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4167 if (profile == null) {
4168 loge("getCarrierPrivilegeStatus: No UICC");
4169 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4170 }
4171 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4172 }
4173
4174 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004175 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004176 if (TextUtils.isEmpty(pkgName))
4177 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004178 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004179 if (card == null) {
4180 loge("checkCarrierPrivilegesForPackage: No UICC");
4181 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4182 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004183 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4184 }
4185
4186 @Override
4187 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004188 if (TextUtils.isEmpty(pkgName))
4189 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004190 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4191 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4192 UiccCard card = UiccController.getInstance().getUiccCard(i);
4193 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004194 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004195 continue;
4196 }
4197
4198 result = card.getCarrierPrivilegeStatus(
4199 mPhone.getContext().getPackageManager(), pkgName);
4200 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4201 break;
4202 }
4203 }
4204
4205 return result;
Junda Liu29340342014-07-10 15:23:27 -07004206 }
Derek Tan89e89d42014-07-08 17:00:10 -07004207
4208 @Override
Junda Liue64de782015-04-16 17:19:16 -07004209 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4210 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4211 loge("phoneId " + phoneId + " is not valid.");
4212 return null;
4213 }
4214 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004215 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004216 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004217 return null ;
4218 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004219 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004220 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004221 }
4222
Amith Yamasani6e118872016-02-19 12:53:51 -08004223 @Override
4224 public List<String> getPackagesWithCarrierPrivileges() {
4225 PackageManager pm = mPhone.getContext().getPackageManager();
4226 List<String> privilegedPackages = new ArrayList<>();
4227 List<PackageInfo> packages = null;
4228 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4229 UiccCard card = UiccController.getInstance().getUiccCard(i);
4230 if (card == null) {
4231 // No UICC in that slot.
4232 continue;
4233 }
4234 if (card.hasCarrierPrivilegeRules()) {
4235 if (packages == null) {
4236 // Only check packages in user 0 for now
4237 packages = pm.getInstalledPackagesAsUser(
4238 PackageManager.MATCH_DISABLED_COMPONENTS
4239 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4240 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4241 }
4242 for (int p = packages.size() - 1; p >= 0; p--) {
4243 PackageInfo pkgInfo = packages.get(p);
4244 if (pkgInfo != null && pkgInfo.packageName != null
4245 && card.getCarrierPrivilegeStatus(pkgInfo)
4246 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4247 privilegedPackages.add(pkgInfo.packageName);
4248 }
4249 }
4250 }
4251 }
4252 return privilegedPackages;
4253 }
4254
Wink Savilleb564aae2014-10-23 10:18:09 -07004255 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004256 final Phone phone = getPhone(subId);
4257 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004258 if (card == null) {
4259 loge("getIccId: No UICC");
4260 return null;
4261 }
4262 String iccId = card.getIccId();
4263 if (TextUtils.isEmpty(iccId)) {
4264 loge("getIccId: ICC ID is null or empty.");
4265 return null;
4266 }
4267 return iccId;
4268 }
4269
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004270 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004271 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4272 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004273 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4274 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004275
Malcolm Chend965c8b2018-02-28 15:00:40 -08004276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 final String iccId = getIccId(subId);
4279 final Phone phone = getPhone(subId);
4280 if (phone == null) {
4281 return false;
4282 }
4283 final String subscriberId = phone.getSubscriberId();
4284
4285 if (DBG_MERGE) {
4286 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4287 + subscriberId + " to " + number);
4288 }
4289
4290 if (TextUtils.isEmpty(iccId)) {
4291 return false;
4292 }
4293
4294 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4295
4296 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4297 if (alphaTag == null) {
4298 editor.remove(alphaTagPrefKey);
4299 } else {
4300 editor.putString(alphaTagPrefKey, alphaTag);
4301 }
4302
4303 // Record both the line number and IMSI for this ICCID, since we need to
4304 // track all merged IMSIs based on line number
4305 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4306 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4307 if (number == null) {
4308 editor.remove(numberPrefKey);
4309 editor.remove(subscriberPrefKey);
4310 } else {
4311 editor.putString(numberPrefKey, number);
4312 editor.putString(subscriberPrefKey, subscriberId);
4313 }
4314
4315 editor.commit();
4316 return true;
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004319 }
Derek Tan7226c842014-07-02 17:42:23 -07004320 }
4321
4322 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004323 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004324 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004326 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004327 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004328 return null;
4329 }
Derek Tan97ebb422014-09-05 16:55:38 -07004330
Malcolm Chend965c8b2018-02-28 15:00:40 -08004331 final long identity = Binder.clearCallingIdentity();
4332 try {
4333 String iccId = getIccId(subId);
4334 if (iccId != null) {
4335 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4336 if (DBG_MERGE) {
4337 log("getLine1NumberForDisplay returning "
4338 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4339 }
4340 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004341 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004342 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4343 return null;
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004346 }
Derek Tan7226c842014-07-02 17:42:23 -07004347 }
4348
4349 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004350 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004352 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004353 return null;
4354 }
Derek Tan97ebb422014-09-05 16:55:38 -07004355
Malcolm Chend965c8b2018-02-28 15:00:40 -08004356 final long identity = Binder.clearCallingIdentity();
4357 try {
4358 String iccId = getIccId(subId);
4359 if (iccId != null) {
4360 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4361 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4362 }
4363 return null;
4364 } finally {
4365 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004366 }
Derek Tan7226c842014-07-02 17:42:23 -07004367 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004368
4369 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004370 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004371 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4372 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004374 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4375 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004376 return null;
4377 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004378
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004379 final long identity = Binder.clearCallingIdentity();
4380 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004381 final Context context = mPhone.getContext();
4382 final TelephonyManager tele = TelephonyManager.from(context);
4383 final SubscriptionManager sub = SubscriptionManager.from(context);
4384
4385 // Figure out what subscribers are currently active
4386 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4387 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4388 // the process, where TelephonyManager was instantiated.
4389 // Otherwise AppOps check will fail.
4390
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004391 final int[] subIds = sub.getActiveSubscriptionIdList();
4392 for (int subId : subIds) {
4393 activeSubscriberIds.add(tele.getSubscriberId(subId));
4394 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004395
4396 // First pass, find a number override for an active subscriber
4397 String mergeNumber = null;
4398 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4399 for (String key : prefs.keySet()) {
4400 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4401 final String subscriberId = (String) prefs.get(key);
4402 if (activeSubscriberIds.contains(subscriberId)) {
4403 final String iccId = key.substring(
4404 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4405 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4406 mergeNumber = (String) prefs.get(numberKey);
4407 if (DBG_MERGE) {
4408 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4409 + " for active subscriber " + subscriberId);
4410 }
4411 if (!TextUtils.isEmpty(mergeNumber)) {
4412 break;
4413 }
4414 }
4415 }
4416 }
4417
4418 // Shortcut when no active merged subscribers
4419 if (TextUtils.isEmpty(mergeNumber)) {
4420 return null;
4421 }
4422
4423 // Second pass, find all subscribers under that line override
4424 final ArraySet<String> result = new ArraySet<>();
4425 for (String key : prefs.keySet()) {
4426 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4427 final String number = (String) prefs.get(key);
4428 if (mergeNumber.equals(number)) {
4429 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4430 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4431 final String subscriberId = (String) prefs.get(subscriberKey);
4432 if (!TextUtils.isEmpty(subscriberId)) {
4433 result.add(subscriberId);
4434 }
4435 }
4436 }
4437 }
4438
4439 final String[] resultArray = result.toArray(new String[result.size()]);
4440 Arrays.sort(resultArray);
4441 if (DBG_MERGE) {
4442 Slog.d(LOG_TAG,
4443 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4444 }
4445 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004446 } finally {
4447 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004448 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004449 }
4450
4451 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004452 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004453 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4454 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004455
4456 final long identity = Binder.clearCallingIdentity();
4457 try {
4458 final Phone phone = getPhone(subId);
4459 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4460 } finally {
4461 Binder.restoreCallingIdentity(identity);
4462 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004463 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004464
4465 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004466 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004467 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4468 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004469 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004470
4471 final long identity = Binder.clearCallingIdentity();
4472 try {
4473 final Phone phone = getPhone(subId);
4474 if (phone == null) {
4475 return false;
4476 }
4477 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4478 cdmaNonRoamingList);
4479 } finally {
4480 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004481 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004482 }
4483
4484 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004485 @Deprecated
4486 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4487 enforceModifyPermission();
4488
4489 int returnValue = 0;
4490 try {
vagdevie435a3e2018-08-15 16:01:53 -07004491 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004492 if(result.exception == null) {
4493 if (result.result != null) {
4494 byte[] responseData = (byte[])(result.result);
4495 if(responseData.length > oemResp.length) {
4496 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4497 responseData.length + "bytes. Buffer Size is " +
4498 oemResp.length + "bytes.");
4499 }
4500 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4501 returnValue = responseData.length;
4502 }
4503 } else {
4504 CommandException ex = (CommandException) result.exception;
4505 returnValue = ex.getCommandError().ordinal();
4506 if(returnValue > 0) returnValue *= -1;
4507 }
4508 } catch (RuntimeException e) {
4509 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4510 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4511 if(returnValue > 0) returnValue *= -1;
4512 }
4513
4514 return returnValue;
4515 }
4516
4517 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004518 public void setRadioCapability(RadioAccessFamily[] rafs) {
4519 try {
4520 ProxyController.getInstance().setRadioCapability(rafs);
4521 } catch (RuntimeException e) {
4522 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4523 }
4524 }
4525
4526 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004527 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004528 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004529 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004530 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004531 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004532 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004533 final long identity = Binder.clearCallingIdentity();
4534 try {
chen xufeeed752018-10-26 14:17:57 -07004535 TelephonyPermissions
4536 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4537 mApp, phone.getSubId(), "getRadioAccessFamily");
4538 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004539 } finally {
4540 Binder.restoreCallingIdentity(identity);
4541 }
chen xufeeed752018-10-26 14:17:57 -07004542 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004543 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004544
4545 @Override
4546 public void enableVideoCalling(boolean enable) {
4547 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004548
4549 final long identity = Binder.clearCallingIdentity();
4550 try {
4551 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4552 } finally {
4553 Binder.restoreCallingIdentity(identity);
4554 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004555 }
4556
4557 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004558 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4560 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4561 return false;
4562 }
Svet Ganovb320e182015-04-16 12:30:10 -07004563
Malcolm Chend965c8b2018-02-28 15:00:40 -08004564 final long identity = Binder.clearCallingIdentity();
4565 try {
4566 // Check the user preference and the system-level IMS setting. Even if the user has
4567 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4568 // In the long run, we may instead need to check if there exists a connection service
4569 // which can support video calling.
4570 ImsManager imsManager =
4571 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4572 return imsManager.isVtEnabledByPlatform()
4573 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4574 && imsManager.isVtEnabledByUser();
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004578 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004579
Andrew Leea1239f22015-03-02 17:44:07 -08004580 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004581 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4583 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4584 return false;
4585 }
4586
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
4589 CarrierConfigManager configManager =
4590 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4591 return configManager.getConfigForSubId(mPhone.getSubId())
4592 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4593 } finally {
4594 Binder.restoreCallingIdentity(identity);
4595 }
Andrew Leea1239f22015-03-02 17:44:07 -08004596 }
4597
4598 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004599 public boolean isWorldPhone(int subId, String callingPackage) {
4600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4601 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4602 return false;
4603 }
4604
4605 final long identity = Binder.clearCallingIdentity();
4606 try {
4607 CarrierConfigManager configManager =
4608 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4609 return configManager.getConfigForSubId(mPhone.getSubId())
4610 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4611 } finally {
4612 Binder.restoreCallingIdentity(identity);
4613 }
Andrew Leea1239f22015-03-02 17:44:07 -08004614 }
4615
Andrew Lee9431b832015-03-09 18:46:45 -07004616 @Override
4617 public boolean isTtyModeSupported() {
4618 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004619 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004620 }
4621
4622 @Override
4623 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004624 final long identity = Binder.clearCallingIdentity();
4625 try {
4626 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
Andrew Lee9431b832015-03-09 18:46:45 -07004630 }
4631
Hall Liuf6668912018-10-31 17:05:23 -07004632 /**
4633 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4634 * support for the feature and device firmware support.
4635 *
4636 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4637 */
4638 @Override
4639 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004640 final long identity = Binder.clearCallingIdentity();
4641 try {
4642 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4643 mPhone.getSubId()).getBoolean(
4644 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4645 boolean isDeviceSupported =
4646 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4647 return isCarrierSupported && isDeviceSupported;
4648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
Hall Liu98187582018-01-22 19:15:32 -08004651 }
4652
Hall Liuf6668912018-10-31 17:05:23 -07004653 /**
4654 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4655 * both also support RTT.
4656 */
4657 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004658 final long identity = Binder.clearCallingIdentity();
4659 try {
Hall Liuf6668912018-10-31 17:05:23 -07004660 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004661 mPhone.getContext().getContentResolver(),
4662 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004666 }
4667
Sanket Padawe7310cc72015-01-14 09:53:20 -08004668 /**
4669 * Returns the unique device ID of phone, for example, the IMEI for
4670 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4671 *
4672 * <p>Requires Permission:
4673 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4674 */
4675 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004676 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004677 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004678 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004679 return null;
4680 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004681 int subId = phone.getSubId();
4682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4683 mApp, subId, callingPackage, "getDeviceId")) {
4684 return null;
4685 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004686
4687 final long identity = Binder.clearCallingIdentity();
4688 try {
4689 return phone.getDeviceId();
4690 } finally {
4691 Binder.restoreCallingIdentity(identity);
4692 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004693 }
4694
Ping Sunc67b7c22016-03-02 19:16:45 +08004695 /**
4696 * {@hide}
4697 * Returns the IMS Registration Status on a particular subid
4698 *
4699 * @param subId
4700 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004701 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004702 Phone phone = getPhone(subId);
4703 if (phone != null) {
4704 return phone.isImsRegistered();
4705 } else {
4706 return false;
4707 }
4708 }
4709
Santos Cordon7a1885b2015-02-03 11:15:19 -08004710 @Override
4711 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004712 final long identity = Binder.clearCallingIdentity();
4713 try {
4714 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
4717 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004718 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004719
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004720 /**
4721 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004722 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004723 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004724 final long identity = Binder.clearCallingIdentity();
4725 try {
4726 Phone phone = getPhone(subId);
4727 if (phone != null) {
4728 return phone.isWifiCallingEnabled();
4729 } else {
4730 return false;
4731 }
4732 } finally {
4733 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004734 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004735 }
4736
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004737 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004738 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004739 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004740 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004741 final long identity = Binder.clearCallingIdentity();
4742 try {
4743 Phone phone = getPhone(subId);
4744 if (phone != null) {
4745 return phone.isVideoEnabled();
4746 } else {
4747 return false;
4748 }
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004751 }
4752 }
4753
4754 /**
4755 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4756 * defined in {@link ImsRegistrationImplBase}.
4757 */
4758 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 Phone phone = getPhone(subId);
4762 if (phone != null) {
4763 return phone.getImsRegistrationTech();
4764 } else {
4765 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4766 }
4767 } finally {
4768 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004769 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004770 }
4771
Stuart Scott8eef64f2015-04-08 15:13:54 -07004772 @Override
4773 public void factoryReset(int subId) {
4774 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004775 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4776 return;
4777 }
4778
Svet Ganovcc087f82015-05-12 20:35:54 -07004779 final long identity = Binder.clearCallingIdentity();
4780 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004781 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4782 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004783 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004784 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004785 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4786 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004787 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004788 }
4789 } finally {
4790 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004791 }
4792 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004793
4794 @Override
4795 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004796 final long identity = Binder.clearCallingIdentity();
4797 try {
4798 // We query all subscriptions instead of just the active ones, because
4799 // this might be called early on in the provisioning flow when the
4800 // subscriptions potentially aren't active yet.
4801 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4802 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004803 return null;
4804 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004805
Malcolm Chend965c8b2018-02-28 15:00:40 -08004806 // This function may be called very early, say, from the setup wizard, at
4807 // which point we won't have a default subscription set. If that's the case
4808 // we just choose the first, which will be valid in "most cases".
4809 final int defaultSubId = getDefaultSubscription();
4810 SubscriptionInfo info = null;
4811 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4812 info = slist.get(0);
4813 } else {
4814 for (SubscriptionInfo item : slist) {
4815 if (item.getSubscriptionId() == defaultSubId) {
4816 info = item;
4817 break;
4818 }
4819 }
4820
4821 if (info == null) {
4822 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004823 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004824 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004825
Malcolm Chend965c8b2018-02-28 15:00:40 -08004826 // Try and fetch the locale from the carrier properties or from the SIM language
4827 // preferences (EF-PL and EF-LI)...
4828 final int mcc = info.getMcc();
4829 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4830 String simLanguage = null;
4831 if (defaultPhone != null) {
4832 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4833 if (localeFromDefaultSim != null) {
4834 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4835 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4836 return localeFromDefaultSim.toLanguageTag();
4837 } else {
4838 simLanguage = localeFromDefaultSim.getLanguage();
4839 }
4840 }
4841 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004842
Malcolm Chend965c8b2018-02-28 15:00:40 -08004843 // The SIM language preferences only store a language (e.g. fr = French), not an
4844 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4845 // the SIM and carrier preferences does not include a country we add the country
4846 // determined from the SIM MCC to provide an exact locale.
4847 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4848 simLanguage);
4849 if (mccLocale != null) {
4850 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4851 return mccLocale.toLanguageTag();
4852 }
4853
4854 if (DBG) log("No locale found - returning null");
4855 return null;
4856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004859 }
4860
4861 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004862 return mSubscriptionController.getAllSubInfoList(
4863 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004864 }
4865
Malcolm Chend965c8b2018-02-28 15:00:40 -08004866 /**
4867 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4868 */
4869 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4870 return mSubscriptionController.getActiveSubscriptionInfoList(
4871 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004872 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004873
Chenjie Yu1ba97252018-01-11 18:16:20 -08004874 private final ModemActivityInfo mLastModemActivityInfo =
4875 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4876
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004877 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004878 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4879 * representing the state of the modem.
4880 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004881 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4882 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004883 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004884 */
4885 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004886 public void requestModemActivityInfo(ResultReceiver result) {
4887 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004889
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 ModemActivityInfo ret = null;
4893 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004894 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4895 CMD_GET_MODEM_ACTIVITY_INFO,
4896 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004897 if (isModemActivityInfoValid(info)) {
4898 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4899 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4900 mergedTxTimeMs[i] =
4901 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4902 }
4903 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4904 mLastModemActivityInfo.setSleepTimeMillis(
4905 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4906 mLastModemActivityInfo.setIdleTimeMillis(
4907 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4908 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4909 mLastModemActivityInfo.setRxTimeMillis(
4910 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4911 mLastModemActivityInfo.setEnergyUsed(
4912 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004913 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004914 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4915 mLastModemActivityInfo.getSleepTimeMillis(),
4916 mLastModemActivityInfo.getIdleTimeMillis(),
4917 mLastModemActivityInfo.getTxTimeMillis(),
4918 mLastModemActivityInfo.getRxTimeMillis(),
4919 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004920 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004921 Bundle bundle = new Bundle();
4922 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4923 result.send(0, bundle);
4924 } finally {
4925 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004926 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004927 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004928
Siddharth Rayf5d29552018-06-17 15:02:38 -07004929 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4930 // less than total activity duration.
4931 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4932 if (info == null) {
4933 return false;
4934 }
4935 int activityDurationMs =
4936 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4937 int totalTxTimeMs = 0;
4938 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4939 totalTxTimeMs += info.getTxTimeMillis()[i];
4940 }
4941 return (info.isValid()
4942 && (info.getSleepTimeMillis() <= activityDurationMs)
4943 && (info.getIdleTimeMillis() <= activityDurationMs)
4944 && (info.getRxTimeMillis() <= activityDurationMs)
4945 && (totalTxTimeMs <= activityDurationMs));
4946 }
4947
Jack Yu85bd38a2015-11-09 11:34:32 -08004948 /**
4949 * {@hide}
4950 * Returns the service state information on specified subscription.
4951 */
4952 @Override
4953 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004955 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004956 return null;
4957 }
4958
Malcolm Chend965c8b2018-02-28 15:00:40 -08004959 final long identity = Binder.clearCallingIdentity();
4960 try {
4961 final Phone phone = getPhone(subId);
4962 if (phone == null) {
4963 return null;
4964 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004965
Malcolm Chend965c8b2018-02-28 15:00:40 -08004966 return phone.getServiceState();
4967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004970 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004971
4972 /**
4973 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4974 *
4975 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4976 * voicemail ringtone.
4977 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4978 * PhoneAccount.
4979 */
4980 @Override
4981 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004982 final long identity = Binder.clearCallingIdentity();
4983 try {
4984 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4985 if (phone == null) {
4986 phone = mPhone;
4987 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004988
Malcolm Chend965c8b2018-02-28 15:00:40 -08004989 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004993 }
4994
4995 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004996 * Sets the per-account voicemail ringtone.
4997 *
4998 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4999 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5000 *
5001 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5002 * voicemail ringtone.
5003 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5004 * PhoneAccount.
5005 */
5006 @Override
5007 public void setVoicemailRingtoneUri(String callingPackage,
5008 PhoneAccountHandle phoneAccountHandle, Uri uri) {
5009 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5010 if (!TextUtils.equals(callingPackage,
5011 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5013 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5014 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005015 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005016
5017 final long identity = Binder.clearCallingIdentity();
5018 try {
5019 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5020 if (phone == null) {
5021 phone = mPhone;
5022 }
5023 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5024 } finally {
5025 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005026 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005027 }
5028
5029 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005030 * Returns whether vibration is set for voicemail notification in Phone settings.
5031 *
5032 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5033 * voicemail vibration setting.
5034 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5035 */
5036 @Override
5037 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005038 final long identity = Binder.clearCallingIdentity();
5039 try {
5040 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5041 if (phone == null) {
5042 phone = mPhone;
5043 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005044
Malcolm Chend965c8b2018-02-28 15:00:40 -08005045 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005049 }
5050
Youhan Wange64578a2016-05-02 15:32:42 -07005051 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005052 * Sets the per-account voicemail vibration.
5053 *
5054 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5055 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5056 *
5057 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5058 * voicemail vibration setting.
5059 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5060 * specific PhoneAccount.
5061 */
5062 @Override
5063 public void setVoicemailVibrationEnabled(String callingPackage,
5064 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5066 if (!TextUtils.equals(callingPackage,
5067 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5069 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5070 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005071 }
5072
Malcolm Chend965c8b2018-02-28 15:00:40 -08005073 final long identity = Binder.clearCallingIdentity();
5074 try {
5075 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5076 if (phone == null) {
5077 phone = mPhone;
5078 }
5079 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5080 } finally {
5081 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005082 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005083 }
5084
5085 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005086 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5087 *
5088 * @throws SecurityException if the caller does not have the required permission
5089 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005090 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005091 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005092 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005093 }
5094
5095 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005096 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5097 * permission.
5098 *
5099 * @throws SecurityException if the caller does not have the required permission
5100 */
5101 private void enforceSendSmsPermission() {
5102 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5103 }
5104
5105 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005106 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005107 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005108 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005109 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005110 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
5113 ComponentName componentName =
5114 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5115 if (componentName == null) {
5116 throw new SecurityException(
5117 "Caller not current active visual voicemail package[null]");
5118 }
5119 String vvmPackage = componentName.getPackageName();
5120 if (!callingPackage.equals(vvmPackage)) {
5121 throw new SecurityException("Caller not current active visual voicemail package["
5122 + vvmPackage + "]");
5123 }
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005126 }
5127 }
5128
5129 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005130 * Return the application ID for the app type.
5131 *
5132 * @param subId the subscription ID that this request applies to.
5133 * @param appType the uicc app type.
5134 * @return Application ID for specificied app type, or null if no uicc.
5135 */
5136 @Override
5137 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005138 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005139 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005140
5141 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005142 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143 if (phone == null) {
5144 return null;
5145 }
5146 String aid = null;
5147 try {
5148 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5149 .getApplicationByType(appType).getAid();
5150 } catch (Exception e) {
5151 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5152 }
5153 return aid;
5154 } finally {
5155 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005156 }
Youhan Wange64578a2016-05-02 15:32:42 -07005157 }
5158
Youhan Wang4001d252016-05-11 10:29:41 -07005159 /**
5160 * Return the Electronic Serial Number.
5161 *
5162 * @param subId the subscription ID that this request applies to.
5163 * @return ESN or null if error.
5164 */
5165 @Override
5166 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005167 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005168 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005169
5170 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005171 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005172 if (phone == null) {
5173 return null;
5174 }
5175 String esn = null;
5176 try {
5177 esn = phone.getEsn();
5178 } catch (Exception e) {
5179 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5180 }
5181 return esn;
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005184 }
Youhan Wang4001d252016-05-11 10:29:41 -07005185 }
5186
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005187 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005188 * Return the Preferred Roaming List Version.
5189 *
5190 * @param subId the subscription ID that this request applies to.
5191 * @return PRLVersion or null if error.
5192 */
5193 @Override
5194 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005195 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005196 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005197
5198 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005199 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005200 if (phone == null) {
5201 return null;
5202 }
5203 String cdmaPrlVersion = null;
5204 try {
5205 cdmaPrlVersion = phone.getCdmaPrlVersion();
5206 } catch (Exception e) {
5207 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5208 }
5209 return cdmaPrlVersion;
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005212 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005213 }
5214
5215 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005216 * Get snapshot of Telephony histograms
5217 * @return List of Telephony histograms
5218 * @hide
5219 */
5220 @Override
5221 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5223 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005224
5225 final long identity = Binder.clearCallingIdentity();
5226 try {
5227 return RIL.getTelephonyRILTimingHistograms();
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005231 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005232
5233 /**
5234 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005235 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005236 * Require system privileges. In the future we may add this to carrier APIs.
5237 *
5238 * @return The number of carriers set successfully, should match length of carriers
5239 */
5240 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005241 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005242 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005243 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005244
Meng Wang9b7c4e92017-02-17 11:41:27 -08005245 if (carriers == null) {
5246 throw new NullPointerException("carriers cannot be null");
5247 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005248
Malcolm Chend965c8b2018-02-28 15:00:40 -08005249 final long identity = Binder.clearCallingIdentity();
5250 try {
5251 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005252 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5253 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005254 return retVal[0];
5255 } finally {
5256 Binder.restoreCallingIdentity(identity);
5257 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005258 }
5259
5260 /**
5261 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005262 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005263 * Require system privileges. In the future we may add this to carrier APIs.
5264 *
5265 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5266 * means all carriers are allowed.
5267 */
5268 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005269 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005270 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005272
5273 final long identity = Binder.clearCallingIdentity();
5274 try {
5275 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005276 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5277 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005278 } finally {
5279 Binder.restoreCallingIdentity(identity);
5280 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005281 }
5282
fionaxu59545b42016-05-25 15:53:37 -07005283 /**
5284 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5285 * @param subId the subscription ID that this action applies to.
5286 * @param enabled control enable or disable metered apns.
5287 * {@hide}
5288 */
5289 @Override
5290 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5291 enforceModifyPermission();
5292 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005293
5294 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005295 if (phone == null) {
5296 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5297 return;
5298 }
5299 try {
5300 phone.carrierActionSetMeteredApnsEnabled(enabled);
5301 } catch (Exception e) {
5302 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005303 } finally {
5304 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005305 }
5306 }
5307
5308 /**
5309 * Action set from carrier signalling broadcast receivers to enable/disable radio
5310 * @param subId the subscription ID that this action applies to.
5311 * @param enabled control enable or disable radio.
5312 * {@hide}
5313 */
5314 @Override
5315 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5316 enforceModifyPermission();
5317 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005318
5319 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005320 if (phone == null) {
5321 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5322 return;
5323 }
5324 try {
5325 phone.carrierActionSetRadioEnabled(enabled);
5326 } catch (Exception e) {
5327 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005328 } finally {
5329 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005330 }
5331 }
5332
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005333 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005334 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5335 * network status based on which carrier apps could apply actions accordingly,
5336 * enable/disable default url handler for example.
5337 *
5338 * @param subId the subscription ID that this action applies to.
5339 * @param report control start/stop reporting the default network status.
5340 * {@hide}
5341 */
5342 @Override
5343 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5344 enforceModifyPermission();
5345 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005346
5347 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005348 if (phone == null) {
5349 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5350 return;
5351 }
5352 try {
5353 phone.carrierActionReportDefaultNetworkStatus(report);
5354 } catch (Exception e) {
5355 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005356 } finally {
5357 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005358 }
5359 }
5360
5361 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005362 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5363 * bug report is being generated.
5364 */
5365 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005366 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005367 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Hall Liud892bec2018-11-30 14:51:45 -08005368 != PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005369 writer.println("Permission Denial: can't dump Phone from pid="
5370 + Binder.getCallingPid()
5371 + ", uid=" + Binder.getCallingUid()
5372 + "without permission "
5373 + android.Manifest.permission.DUMP);
5374 return;
5375 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005376 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005377 }
Jack Yueb89b242016-06-22 13:27:47 -07005378
Brad Ebingerdac2f002018-04-03 15:17:52 -07005379 @Override
5380 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5381 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5382 throws RemoteException {
5383 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5384 }
5385
Jack Yueb89b242016-06-22 13:27:47 -07005386 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005387 * Get aggregated video call data usage since boot.
5388 *
5389 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5390 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005391 * {@hide}
5392 */
5393 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005394 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005395 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5396 null);
5397
Malcolm Chend965c8b2018-02-28 15:00:40 -08005398 final long identity = Binder.clearCallingIdentity();
5399 try {
5400 // NetworkStatsService keeps tracking the active network interface and identity. It
5401 // records the delta with the corresponding network identity.
5402 // We just return the total video call data usage snapshot since boot.
5403 Phone phone = getPhone(subId);
5404 if (phone != null) {
5405 return phone.getVtDataUsage(perUidStats);
5406 }
5407 return null;
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005410 }
Jack Yueb89b242016-06-22 13:27:47 -07005411 }
Jack Yu75ab2952016-07-08 14:29:33 -07005412
5413 /**
5414 * Policy control of data connection. Usually used when data limit is passed.
5415 * @param enabled True if enabling the data, otherwise disabling.
5416 * @param subId Subscription index
5417 * {@hide}
5418 */
5419 @Override
5420 public void setPolicyDataEnabled(boolean enabled, int subId) {
5421 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005422
5423 final long identity = Binder.clearCallingIdentity();
5424 try {
5425 Phone phone = getPhone(subId);
5426 if (phone != null) {
5427 phone.setPolicyDataEnabled(enabled);
5428 }
5429 } finally {
5430 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005431 }
5432 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005433
5434 /**
5435 * Get Client request stats
5436 * @return List of Client Request Stats
5437 * @hide
5438 */
5439 @Override
5440 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005442 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005443 return null;
5444 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005445 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005446
Malcolm Chend965c8b2018-02-28 15:00:40 -08005447 final long identity = Binder.clearCallingIdentity();
5448 try {
5449 if (phone != null) {
5450 return phone.getClientRequestStats();
5451 }
5452
5453 return null;
5454 } finally {
5455 Binder.restoreCallingIdentity(identity);
5456 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005457 }
5458
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005459 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005460 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005461 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005462 }
Jack Yueb4124c2017-02-16 15:32:43 -08005463
5464 /**
Grace Chen70990072017-03-24 17:21:30 -07005465 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005466 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005467 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005468 * @param state State of SIM (power down, power up, pass through)
5469 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5470 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5471 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005472 *
5473 **/
5474 @Override
Grace Chen70990072017-03-24 17:21:30 -07005475 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005476 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005477 Phone phone = PhoneFactory.getPhone(slotIndex);
5478
vagdevie435a3e2018-08-15 16:01:53 -07005479 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5480
Malcolm Chend965c8b2018-02-28 15:00:40 -08005481 final long identity = Binder.clearCallingIdentity();
5482 try {
5483 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005484 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005485 }
5486 } finally {
5487 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005488 }
5489 }
Shuo Qiandd210312017-04-12 22:11:33 +00005490
Tyler Gunn65d45c22017-06-05 11:22:26 -07005491 private boolean isUssdApiAllowed(int subId) {
5492 CarrierConfigManager configManager =
5493 (CarrierConfigManager) mPhone.getContext().getSystemService(
5494 Context.CARRIER_CONFIG_SERVICE);
5495 if (configManager == null) {
5496 return false;
5497 }
5498 PersistableBundle pb = configManager.getConfigForSubId(subId);
5499 if (pb == null) {
5500 return false;
5501 }
5502 return pb.getBoolean(
5503 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5504 }
5505
Shuo Qiandd210312017-04-12 22:11:33 +00005506 /**
5507 * Check if phone is in emergency callback mode
5508 * @return true if phone is in emergency callback mode
5509 * @param subId sub id
5510 */
goneil9c5f4872017-12-05 14:07:56 -08005511 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005512 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005513 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005514 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005515
5516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 if (phone != null) {
5519 return phone.isInEcm();
5520 } else {
5521 return false;
5522 }
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005525 }
5526 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005527
5528 /**
5529 * Get the current signal strength information for the given subscription.
5530 * Because this information is not updated when the device is in a low power state
5531 * it should not be relied-upon to be current.
5532 * @param subId Subscription index
5533 * @return the most recent cached signal strength info from the modem
5534 */
5535 @Override
5536 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 Phone p = getPhone(subId);
5540 if (p == null) {
5541 return null;
5542 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005543
Malcolm Chend965c8b2018-02-28 15:00:40 -08005544 return p.getSignalStrength();
5545 } finally {
5546 Binder.restoreCallingIdentity(identity);
5547 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005548 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005549
Pengquan Meng9140aec2018-08-22 14:49:57 -07005550 /**
chen xu907e5a22018-10-11 13:21:04 -07005551 * Get the current modem radio state for the given slot.
5552 * @param slotIndex slot index.
5553 * @param callingPackage the name of the package making the call.
5554 * @return the current radio power state from the modem
5555 */
5556 @Override
5557 public int getRadioPowerState(int slotIndex, String callingPackage) {
5558 Phone phone = PhoneFactory.getPhone(slotIndex);
5559 if (phone != null) {
5560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5561 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5562 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5563 }
5564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 return phone.getRadioPowerState();
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
5571 }
5572 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5573 }
5574
5575 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005576 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5577 *
5578 * <p>Requires one of the following permissions:
5579 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5580 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5581 * privileges.
5582 *
5583 * @param subId subscription id
5584 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5585 * {@code false}.
5586 */
5587 @Override
5588 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005589 boolean isEnabled = false;
5590 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005591 try {
5592 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005593 null /* message */);
5594 Phone phone = getPhone(subId);
5595 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005596 } catch (Exception e) {
5597 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5598 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005599 } finally {
5600 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005601 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005602 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005603 }
5604
5605
5606 /**
5607 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5608 *
5609 * <p> Requires permission:
5610 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5611 * privileges.
5612 *
5613 * @param subId subscription id
5614 * @param isEnabled {@code true} means enable, {@code false} means disable.
5615 */
5616 @Override
5617 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005618 final long identity = Binder.clearCallingIdentity();
5619 try {
5620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5621 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005622
Pengquan Meng0c05b502018-09-06 09:59:22 -07005623 Phone phone = getPhone(subId);
5624 if (phone != null) {
5625 phone.setDataRoamingEnabled(isEnabled);
5626 }
5627 } finally {
5628 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005629 }
5630 }
5631
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005632 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005633 public boolean isManualNetworkSelectionAllowed(int subId) {
5634 boolean isAllowed = true;
5635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5638 mApp, subId, "isManualNetworkSelectionAllowed");
5639 Phone phone = getPhone(subId);
5640 if (phone != null) {
5641 isAllowed = phone.isCspPlmnEnabled();
5642 }
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
5646 return isAllowed;
5647 }
5648
5649 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005650 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005651 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005652
Malcolm Chend965c8b2018-02-28 15:00:40 -08005653 final long identity = Binder.clearCallingIdentity();
5654 try {
5655 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5656 if (slots == null) {
5657 Rlog.i(LOG_TAG, "slots is null.");
5658 return null;
5659 }
5660
5661 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5662 for (int i = 0; i < slots.length; i++) {
5663 UiccSlot slot = slots[i];
5664 if (slot == null) {
5665 continue;
5666 }
5667
5668 String cardId;
5669 UiccCard card = slot.getUiccCard();
5670 if (card != null) {
5671 cardId = card.getCardId();
5672 } else {
5673 cardId = slot.getIccId();
5674 }
5675
5676 int cardState = 0;
5677 switch (slot.getCardState()) {
5678 case CARDSTATE_ABSENT:
5679 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5680 break;
5681 case CARDSTATE_PRESENT:
5682 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5683 break;
5684 case CARDSTATE_ERROR:
5685 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5686 break;
5687 case CARDSTATE_RESTRICTED:
5688 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5689 break;
5690 default:
5691 break;
5692
5693 }
5694
5695 infos[i] = new UiccSlotInfo(
5696 slot.isActive(),
5697 slot.isEuicc(),
5698 cardId,
5699 cardState,
5700 slot.getPhoneId(),
5701 slot.isExtendedApduSupported());
5702 }
5703 return infos;
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005706 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005707 }
5708
5709 @Override
5710 public boolean switchSlots(int[] physicalSlots) {
5711 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005712
5713 final long identity = Binder.clearCallingIdentity();
5714 try {
5715 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005719 }
Jack Yu4c988042018-02-27 15:30:01 -08005720
5721 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005722 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5724 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5725 return TelephonyManager.INVALID_CARD_ID;
5726 }
5727
5728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 return UiccController.getInstance().getCardIdForDefaultEuicc();
5731 } finally {
5732 Binder.restoreCallingIdentity(identity);
5733 }
5734 }
5735
5736 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005737 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5738 enforceModifyPermission();
5739 final Phone phone = getPhone(subId);
5740 if (phone == null) {
5741 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5742 return;
5743 }
5744
Malcolm Chend965c8b2018-02-28 15:00:40 -08005745 final long identity = Binder.clearCallingIdentity();
5746 try {
5747 phone.setRadioIndicationUpdateMode(filters, mode);
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
Jack Yu4c988042018-02-27 15:30:01 -08005751 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005752
5753 /**
goneil47ffb6e2018-04-06 15:40:58 -07005754 * A test API to reload the UICC profile.
5755 *
5756 * <p>Requires that the calling app has permission
5757 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5758 * @hide
5759 */
5760 @Override
5761 public void refreshUiccProfile(int subId) {
5762 enforceModifyPermission();
5763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 Phone phone = getPhone(subId);
5767 if (phone == null) {
5768 return;
5769 }
5770 UiccCard uiccCard = phone.getUiccCard();
5771 if (uiccCard == null) {
5772 return;
5773 }
5774 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5775 if (uiccProfile == null) {
5776 return;
5777 }
5778 uiccProfile.refresh();
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
5781 }
5782 }
5783
5784 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005785 * Returns false if the mobile data is disabled by default, otherwise return true.
5786 */
5787 private boolean getDefaultDataEnabled() {
5788 return "true".equalsIgnoreCase(
5789 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5790 }
5791
5792 /**
5793 * Returns true if the data roaming is enabled by default, i.e the system property
5794 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5795 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5796 */
5797 private boolean getDefaultDataRoamingEnabled(int subId) {
5798 final CarrierConfigManager configMgr = (CarrierConfigManager)
5799 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5800 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5801 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5802 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5803 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5804 return isDataRoamingEnabled;
5805 }
5806
5807 /**
5808 * Returns the default network type for the given {@code subId}, if the default network type is
5809 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5810 */
5811 private int getDefaultNetworkType(int subId) {
5812 return Integer.parseInt(
5813 TelephonyManager.getTelephonyProperty(
5814 mSubscriptionController.getPhoneId(subId),
5815 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5816 String.valueOf(Phone.PREFERRED_NT_MODE)));
5817 }
fionaxua13278b2018-03-21 00:08:13 -07005818
5819 @Override
5820 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5821 gid1, String gid2, String plmn, String spn) {
5822 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005823
5824 final long identity = Binder.clearCallingIdentity();
5825 try {
5826 final Phone phone = getPhone(subId);
5827 if (phone == null) {
5828 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5829 return;
5830 }
5831 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5832 } finally {
5833 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005834 }
fionaxua13278b2018-03-21 00:08:13 -07005835 }
5836
5837 @Override
5838 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005839 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005840
5841 final long identity = Binder.clearCallingIdentity();
5842 try {
5843 final Phone phone = getPhone(subId);
5844 if (phone == null) {
5845 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5846 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5847 }
5848 return phone.getCarrierIdListVersion();
5849 } finally {
5850 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005851 }
fionaxua13278b2018-03-21 00:08:13 -07005852 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005853
5854 @Override
5855 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5857 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5858 return -1;
5859 }
5860
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
5863 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
5867 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005868
5869 @Override
5870 public int getCdmaRoamingMode(int subId) {
5871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5872 mApp, subId, "getCdmaRoamingMode");
5873
5874 final long identity = Binder.clearCallingIdentity();
5875 try {
5876 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
5880 }
5881
5882 @Override
5883 public boolean setCdmaRoamingMode(int subId, int mode) {
5884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5885 mApp, subId, "setCdmaRoamingMode");
5886
5887 final long identity = Binder.clearCallingIdentity();
5888 try {
5889 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
5893 }
5894
5895 @Override
5896 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5898 mApp, subId, "setCdmaSubscriptionMode");
5899
5900 final long identity = Binder.clearCallingIdentity();
5901 try {
5902 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
5906 }
chen xu7ee67862018-10-30 22:27:10 -07005907
sqian2fff4a32018-11-05 14:18:37 -08005908 private void ensureUserRunning(int userId) {
5909 if (!mUserManager.isUserRunning(userId)) {
5910 throw new IllegalStateException("User " + userId + " does not exist or not running");
5911 }
5912 }
5913
5914 /**
5915 * Returns a list of SMS apps on a given user.
5916 *
5917 * Only the shell user (UID 2000 or 0) can call it.
5918 * Target user must be running.
5919 */
5920 @Override
5921 public String[] getSmsApps(int userId) {
5922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5923 ensureUserRunning(userId);
5924
5925 final Collection<SmsApplicationData> apps =
5926 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5927
5928 String[] ret = new String[apps.size()];
5929 int i = 0;
5930 for (SmsApplicationData app : apps) {
5931 ret[i++] = app.mPackageName;
5932 }
5933 return ret;
5934 }
5935
5936 /**
5937 * Returns the default SMS app package name on a given user.
5938 *
5939 * Only the shell user (UID 2000 or 0) can call it.
5940 * Target user must be running.
5941 */
5942 @Override
5943 public String getDefaultSmsApp(int userId) {
5944 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5945 ensureUserRunning(userId);
5946
5947 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5948 /* updateIfNeeded= */ true, userId);
5949 return cn == null ? null : cn.getPackageName();
5950 }
5951
5952 /**
5953 * Set a package as the default SMS app on a given user.
5954 *
5955 * Only the shell user (UID 2000 or 0) can call it.
5956 * Target user must be running.
5957 */
5958 @Override
5959 public void setDefaultSmsApp(int userId, String packageName) {
5960 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5961 ensureUserRunning(userId);
5962
5963 boolean found = false;
5964 for (String pkg : getSmsApps(userId)) {
5965 if (TextUtils.equals(packageName, pkg)) {
5966 found = true;
5967 break;
5968 }
5969 }
5970 if (!found) {
5971 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5972 }
5973
5974 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5975 }
5976
chen xu7ee67862018-10-30 22:27:10 -07005977 @Override
sqian04b86072018-11-07 14:02:21 -08005978 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5979 String callingPackage) {
5980 // TODO connect with internal content
5981 return null;
5982 }
5983
5984 @Override
5985 public boolean isCurrentEmergencyNumber(String number) {
5986 // TODO connect with internal content
5987 return false;
5988 }
5989
5990 @Override
chen xu7ee67862018-10-30 22:27:10 -07005991 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5992 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5993 Phone phone = getPhone(subId);
5994 if (phone == null) {
5995 return null;
5996 }
5997 final long identity = Binder.clearCallingIdentity();
5998 try {
5999 UiccProfile profile = UiccController.getInstance()
6000 .getUiccProfileForPhone(phone.getPhoneId());
6001 if (profile != null) {
6002 return profile.getCertsFromCarrierPrivilegeAccessRules();
6003 }
6004 } finally {
6005 Binder.restoreCallingIdentity(identity);
6006 }
6007 return null;
6008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006009}