blob: 24e664228fc627c88612716a480907660e2e9272 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070028import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080043import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070046import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070047import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070049import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070050import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080052import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070053import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080054import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080055import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070056import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070057import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070059import android.telephony.CellInfoGsm;
60import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070061import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070063import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070064import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080065import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070066import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080067import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070068import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070069import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080072import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070073import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080074import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070076import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000078import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070081import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080082import android.telephony.data.ApnSetting;
83import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070084import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070085import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080086import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070087import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080088import android.telephony.ims.aidl.IImsMmTelFeature;
89import android.telephony.ims.aidl.IImsRcsFeature;
90import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070091import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080092import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080096import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080098
Brad Ebinger35c841c2018-10-01 10:40:55 -070099import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700100import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800101import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700102import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700103import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700104import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800105import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700106import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700107import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800110import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700111import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100112import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700113import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700114import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700116import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800117import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700118import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700119import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700120import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700121import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700122import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700123import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700124import com.android.internal.telephony.SmsApplication;
125import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800126import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800127import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700128import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.uicc.IccIoResult;
130import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800131import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700132import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800133import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700134import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800135import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000136import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700137import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700139import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800140import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700141import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700142import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700144import java.io.FileDescriptor;
145import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800146import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800148import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700149import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800150import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100151import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800152import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153
154/**
155 * Implementation of the ITelephony interface.
156 */
Santos Cordon117fee72014-05-16 17:56:12 -0700157public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 private static final String LOG_TAG = "PhoneInterfaceManager";
159 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
160 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800161 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162
163 // Message codes used with mMainThreadHandler
164 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700165 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
166 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167 private static final int CMD_OPEN_CHANNEL = 9;
168 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
169 private static final int CMD_CLOSE_CHANNEL = 11;
170 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800171 private static final int CMD_NV_READ_ITEM = 13;
172 private static final int EVENT_NV_READ_ITEM_DONE = 14;
173 private static final int CMD_NV_WRITE_ITEM = 15;
174 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
175 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
176 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700177 private static final int CMD_RESET_MODEM_CONFIG = 19;
178 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800179 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
180 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
181 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
182 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800183 private static final int CMD_SEND_ENVELOPE = 25;
184 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000185 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
186 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700187 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
188 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
189 private static final int CMD_EXCHANGE_SIM_IO = 31;
190 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800191 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
192 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700193 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
194 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700195 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
196 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700197 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
198 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
199 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
200 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700201 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
202 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
203 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
204 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700205 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800206 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
207 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000208 private static final int CMD_SWITCH_SLOTS = 50;
209 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700210 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
211 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
212 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
213 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
214 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
215 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
216 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
217 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700218 private static final int CMD_GET_ALL_CELL_INFO = 60;
219 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
220 private static final int CMD_GET_CELL_LOCATION = 62;
221 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700222 private static final int CMD_MODEM_REBOOT = 64;
223 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700224 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
225 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800227 // Parameters of select command.
228 private static final int SELECT_COMMAND = 0xA4;
229 private static final int SELECT_P1 = 0x04;
230 private static final int SELECT_P2 = 0;
231 private static final int SELECT_P3 = 0x10;
232
Pengquan Meng85728fb2018-03-12 16:31:21 -0700233 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
234 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
235 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
236
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237 /** The singleton instance. */
238 private static PhoneInterfaceManager sInstance;
239
Wink Saville3ab207e2014-11-20 13:07:20 -0800240 private PhoneGlobals mApp;
241 private Phone mPhone;
242 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700243 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800244 private AppOpsManager mAppOps;
245 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800246 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800247 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700248 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
Derek Tan97ebb422014-09-05 16:55:38 -0700250 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
251 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800252 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700253
Derek Tan740e1672017-06-27 14:56:27 -0700254 // The AID of ISD-R.
255 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
256
yinxub1bed742017-04-17 11:45:04 -0700257 private NetworkScanRequestTracker mNetworkScanRequestTracker;
258
David Kelly5e06a7f2018-03-12 14:10:59 +0000259 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
260 private static final int MANUFACTURER_CODE_LENGTH = 8;
261
Derek Tan89e89d42014-07-08 17:00:10 -0700262 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700263 * A request object to use for transmitting data to an ICC.
264 */
265 private static final class IccAPDUArgument {
266 public int channel, cla, command, p1, p2, p3;
267 public String data;
268
269 public IccAPDUArgument(int channel, int cla, int command,
270 int p1, int p2, int p3, String data) {
271 this.channel = channel;
272 this.cla = cla;
273 this.command = command;
274 this.p1 = p1;
275 this.p2 = p2;
276 this.p3 = p3;
277 this.data = data;
278 }
279 }
280
281 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700282 * A request object to use for transmitting data to an ICC.
283 */
284 private static final class ManualNetworkSelectionArgument {
285 public OperatorInfo operatorInfo;
286 public boolean persistSelection;
287
288 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
289 this.operatorInfo = operatorInfo;
290 this.persistSelection = persistSelection;
291 }
292 }
293
294 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
296 * request after sending. The main thread will notify the request when it is complete.
297 */
298 private static final class MainThreadRequest {
299 /** The argument to use for the request */
300 public Object argument;
301 /** The result of the request that is run on the main thread */
302 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800303 // The subscriber id that this request applies to. Defaults to
304 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
305 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306
Nathan Harold92bed182018-10-12 18:16:49 -0700307 // In cases where subId is unavailable, the caller needs to specify the phone.
308 public Phone phone;
309
vagdeviaf9a5b92018-08-15 16:01:53 -0700310 public WorkSource workSource;
311
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 public MainThreadRequest(Object argument) {
313 this.argument = argument;
314 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800315
Nathan Harold92bed182018-10-12 18:16:49 -0700316 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
317 this.argument = argument;
318 if (phone != null) {
319 this.phone = phone;
320 }
321 this.workSource = workSource;
322 }
323
vagdeviaf9a5b92018-08-15 16:01:53 -0700324 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800325 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800326 if (subId != null) {
327 this.subId = subId;
328 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700329 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 }
332
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800333 private static final class IncomingThirdPartyCallArgs {
334 public final ComponentName component;
335 public final String callId;
336 public final String callerDisplayName;
337
338 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
339 String callerDisplayName) {
340 this.component = component;
341 this.callId = callId;
342 this.callerDisplayName = callerDisplayName;
343 }
344 }
345
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 /**
347 * A handler that processes messages on the main thread in the phone process. Since many
348 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
349 * inbound binder threads to the main thread in the phone process. The Binder thread
350 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
351 * on, which will be notified when the operation completes and will contain the result of the
352 * request.
353 *
354 * <p>If a MainThreadRequest object is provided in the msg.obj field,
355 * note that request.result must be set to something non-null for the calling thread to
356 * unblock.
357 */
358 private final class MainThreadHandler extends Handler {
359 @Override
360 public void handleMessage(Message msg) {
361 MainThreadRequest request;
362 Message onCompleted;
363 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800364 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700365 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
367 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700368 case CMD_HANDLE_USSD_REQUEST: {
369 request = (MainThreadRequest) msg.obj;
370 final Phone phone = getPhoneFromRequest(request);
371 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
372 String ussdRequest = ussdObject.first;
373 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700374
Pengquan Menga1bb6272018-09-06 09:59:22 -0700375 if (!isUssdApiAllowed(request.subId)) {
376 // Carrier does not support use of this API, return failure.
377 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
378 UssdResponse response = new UssdResponse(ussdRequest, null);
379 Bundle returnData = new Bundle();
380 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
381 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700382
Pengquan Menga1bb6272018-09-06 09:59:22 -0700383 request.result = true;
384 notifyRequester(request);
385 return;
386 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700387
Pengquan Menga1bb6272018-09-06 09:59:22 -0700388 try {
389 request.result = phone != null
390 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
391 } catch (CallStateException cse) {
392 request.result = false;
393 }
394 // Wake up the requesting thread
395 notifyRequester(request);
396 break;
pkanwar32d516d2016-10-14 19:37:38 -0700397 }
398
Yorke Lee716f67e2015-06-17 15:39:16 -0700399 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700401 final Phone phone = getPhoneFromRequest(request);
402 request.result = phone != null ?
403 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
404 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700406 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700410 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700411 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800413 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700414 if (uiccCard == null) {
415 loge("iccTransmitApduLogicalChannel: No UICC");
416 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700417 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
420 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700421 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 iccArgument.channel, iccArgument.cla, iccArgument.command,
423 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700425 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 break;
427
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 ar = (AsyncResult) msg.obj;
430 request = (MainThreadRequest) ar.userObj;
431 if (ar.exception == null && ar.result != null) {
432 request.result = ar.result;
433 } else {
434 request.result = new IccIoResult(0x6F, 0, (byte[])null);
435 if (ar.result == null) {
436 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800437 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800439 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 } else {
441 loge("iccTransmitApduLogicalChannel: Unknown exception");
442 }
443 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700444 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 break;
446
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
448 request = (MainThreadRequest) msg.obj;
449 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800450 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 if (uiccCard == null) {
452 loge("iccTransmitApduBasicChannel: No UICC");
453 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 } else {
456 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
457 request);
458 uiccCard.iccTransmitApduBasicChannel(
459 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
460 iccArgument.p3, iccArgument.data, onCompleted);
461 }
462 break;
463
464 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
465 ar = (AsyncResult) msg.obj;
466 request = (MainThreadRequest) ar.userObj;
467 if (ar.exception == null && ar.result != null) {
468 request.result = ar.result;
469 } else {
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 if (ar.result == null) {
472 loge("iccTransmitApduBasicChannel: Empty response");
473 } else if (ar.exception instanceof CommandException) {
474 loge("iccTransmitApduBasicChannel: CommandException: " +
475 ar.exception);
476 } else {
477 loge("iccTransmitApduBasicChannel: Unknown exception");
478 }
479 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 break;
482
483 case CMD_EXCHANGE_SIM_IO:
484 request = (MainThreadRequest) msg.obj;
485 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 if (uiccCard == null) {
488 loge("iccExchangeSimIO: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 } else {
492 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
493 request);
494 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
495 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
496 iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_EXCHANGE_SIM_IO_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6f, 0, (byte[])null);
507 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 break;
510
Derek Tan4d5e5c12014-02-04 11:54:58 -0800511 case CMD_SEND_ENVELOPE:
512 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800513 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700514 if (uiccCard == null) {
515 loge("sendEnvelopeWithStatus: No UICC");
516 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 } else {
519 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
520 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
521 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800522 break;
523
524 case EVENT_SEND_ENVELOPE_DONE:
525 ar = (AsyncResult) msg.obj;
526 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700527 if (ar.exception == null && ar.result != null) {
528 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800529 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
531 if (ar.result == null) {
532 loge("sendEnvelopeWithStatus: Empty response");
533 } else if (ar.exception instanceof CommandException) {
534 loge("sendEnvelopeWithStatus: CommandException: " +
535 ar.exception);
536 } else {
537 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
538 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800541 break;
542
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 case CMD_OPEN_CHANNEL:
544 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800545 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800546 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 if (uiccCard == null) {
548 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800549 request.result = new IccOpenLogicalChannelResponse(-1,
550 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 } else {
553 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800554 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
555 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 break;
558
559 case EVENT_OPEN_CHANNEL_DONE:
560 ar = (AsyncResult) msg.obj;
561 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 int[] result = (int[]) ar.result;
565 int channelId = result[0];
566 byte[] selectResponse = null;
567 if (result.length > 1) {
568 selectResponse = new byte[result.length - 1];
569 for (int i = 1; i < result.length; ++i) {
570 selectResponse[i - 1] = (byte) result[i];
571 }
572 }
573 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700574 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 if (ar.result == null) {
577 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700579 if (ar.exception != null) {
580 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
581 }
582
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700583 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700584 if (ar.exception instanceof CommandException) {
585 CommandException.Error error =
586 ((CommandException) (ar.exception)).getCommandError();
587 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700588 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700589 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700590 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 }
592 }
593 openChannelResp = new IccOpenLogicalChannelResponse(
594 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700596 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 break;
599
600 case CMD_CLOSE_CHANNEL:
601 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800602 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 if (uiccCard == null) {
604 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900605 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 } else {
608 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
609 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
610 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 break;
612
613 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800614 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
615 break;
616
617 case CMD_NV_READ_ITEM:
618 request = (MainThreadRequest) msg.obj;
619 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700620 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800621 break;
622
623 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 ar = (AsyncResult) msg.obj;
625 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800626 if (ar.exception == null && ar.result != null) {
627 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800629 request.result = "";
630 if (ar.result == null) {
631 loge("nvReadItem: Empty response");
632 } else if (ar.exception instanceof CommandException) {
633 loge("nvReadItem: CommandException: " +
634 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800636 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 }
638 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 break;
641
Jake Hambye994d462014-02-03 13:10:13 -0800642 case CMD_NV_WRITE_ITEM:
643 request = (MainThreadRequest) msg.obj;
644 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
645 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700646 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
647 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800648 break;
649
650 case EVENT_NV_WRITE_ITEM_DONE:
651 handleNullReturnEvent(msg, "nvWriteItem");
652 break;
653
654 case CMD_NV_WRITE_CDMA_PRL:
655 request = (MainThreadRequest) msg.obj;
656 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
657 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
658 break;
659
660 case EVENT_NV_WRITE_CDMA_PRL_DONE:
661 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
662 break;
663
chen xu6dac5ab2018-10-26 17:39:23 -0700664 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800665 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700666 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
667 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800668 break;
669
chen xu6dac5ab2018-10-26 17:39:23 -0700670 case EVENT_RESET_MODEM_CONFIG_DONE:
671 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800672 break;
673
Jake Hamby7c27be32014-03-03 13:25:59 -0800674 case CMD_GET_PREFERRED_NETWORK_TYPE:
675 request = (MainThreadRequest) msg.obj;
676 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700677 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800678 break;
679
680 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
681 ar = (AsyncResult) msg.obj;
682 request = (MainThreadRequest) ar.userObj;
683 if (ar.exception == null && ar.result != null) {
684 request.result = ar.result; // Integer
685 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800686 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 if (ar.result == null) {
688 loge("getPreferredNetworkType: Empty response");
689 } else if (ar.exception instanceof CommandException) {
690 loge("getPreferredNetworkType: CommandException: " +
691 ar.exception);
692 } else {
693 loge("getPreferredNetworkType: Unknown exception");
694 }
695 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 break;
698
699 case CMD_SET_PREFERRED_NETWORK_TYPE:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
702 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700703 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
707 handleNullReturnEvent(msg, "setPreferredNetworkType");
708 break;
709
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000710 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
711 request = (MainThreadRequest)msg.obj;
712 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700713 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000714 break;
715
716 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
717 ar = (AsyncResult)msg.obj;
718 request = (MainThreadRequest)ar.userObj;
719 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700720 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000721 break;
722
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800723 case CMD_SET_VOICEMAIL_NUMBER:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
726 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800727 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
728 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800729 break;
730
731 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
732 handleNullReturnEvent(msg, "setVoicemailNumber");
733 break;
734
Stuart Scott54788802015-03-30 13:18:01 -0700735 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
738 request);
739 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
740 break;
741
742 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
743 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
744 break;
745
Shishir Agrawal302c8692015-06-19 13:49:39 -0700746 case CMD_PERFORM_NETWORK_SCAN:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
749 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
750 break;
751
752 case EVENT_PERFORM_NETWORK_SCAN_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 CellNetworkScanResult cellScanResult;
756 if (ar.exception == null && ar.result != null) {
757 cellScanResult = new CellNetworkScanResult(
758 CellNetworkScanResult.STATUS_SUCCESS,
759 (List<OperatorInfo>) ar.result);
760 } else {
761 if (ar.result == null) {
762 loge("getCellNetworkScanResults: Empty response");
763 }
764 if (ar.exception != null) {
765 loge("getCellNetworkScanResults: Exception: " + ar.exception);
766 }
767 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
768 if (ar.exception instanceof CommandException) {
769 CommandException.Error error =
770 ((CommandException) (ar.exception)).getCommandError();
771 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
772 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
773 } else if (error == CommandException.Error.GENERIC_FAILURE) {
774 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
775 }
776 }
777 cellScanResult = new CellNetworkScanResult(errorCode, null);
778 }
779 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700781 break;
782
783 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
784 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700785 ManualNetworkSelectionArgument selArg =
786 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700787 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
788 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700789 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
790 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 break;
792
793 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700794 ar = (AsyncResult) msg.obj;
795 request = (MainThreadRequest) ar.userObj;
796 if (ar.exception == null) {
797 request.result = true;
798 } else {
799 request.result = false;
800 loge("setNetworkSelectionModeManual " + ar.exception);
801 }
802 notifyRequester(request);
803 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700804 break;
805
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700806 case CMD_GET_MODEM_ACTIVITY_INFO:
807 request = (MainThreadRequest) msg.obj;
808 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700809 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700810 break;
811
812 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
815 if (ar.exception == null && ar.result != null) {
816 request.result = ar.result;
817 } else {
818 if (ar.result == null) {
819 loge("queryModemActivityInfo: Empty response");
820 } else if (ar.exception instanceof CommandException) {
821 loge("queryModemActivityInfo: CommandException: " +
822 ar.exception);
823 } else {
824 loge("queryModemActivityInfo: Unknown exception");
825 }
826 }
Amit Mahajand4766222016-01-28 15:28:28 -0800827 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
828 if (request.result == null) {
829 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
830 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700831 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700832 break;
833
Meng Wang1a7c35a2016-05-05 20:56:15 -0700834 case CMD_SET_ALLOWED_CARRIERS:
835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
837 mPhone.setAllowedCarriers(
838 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700839 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700840 break;
841
842 case EVENT_SET_ALLOWED_CARRIERS_DONE:
843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 if (ar.exception == null && ar.result != null) {
846 request.result = ar.result;
847 } else {
848 if (ar.result == null) {
849 loge("setAllowedCarriers: Empty response");
850 } else if (ar.exception instanceof CommandException) {
851 loge("setAllowedCarriers: CommandException: " +
852 ar.exception);
853 } else {
854 loge("setAllowedCarriers: Unknown exception");
855 }
856 }
857 // Result cannot be null. Return -1 on error.
858 if (request.result == null) {
859 request.result = new int[]{-1};
860 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700861 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700862 break;
863
864 case CMD_GET_ALLOWED_CARRIERS:
865 request = (MainThreadRequest) msg.obj;
866 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700867 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700868 break;
869
870 case EVENT_GET_ALLOWED_CARRIERS_DONE:
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null && ar.result != null) {
874 request.result = ar.result;
875 } else {
876 if (ar.result == null) {
877 loge("getAllowedCarriers: Empty response");
878 } else if (ar.exception instanceof CommandException) {
879 loge("getAllowedCarriers: CommandException: " +
880 ar.exception);
881 } else {
882 loge("getAllowedCarriers: Unknown exception");
883 }
884 }
885 // Result cannot be null. Return empty list of CarrierIdentifier.
886 if (request.result == null) {
887 request.result = new ArrayList<CarrierIdentifier>(0);
888 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700889 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 break;
891
Nathan Haroldb3014052017-01-25 15:57:32 -0800892 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result;
897 } else {
898 request.result = new IllegalArgumentException(
899 "Failed to retrieve Forbidden Plmns");
900 if (ar.result == null) {
901 loge("getForbiddenPlmns: Empty response");
902 } else {
903 loge("getForbiddenPlmns: Unknown exception");
904 }
905 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700906 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800907 break;
908
909 case CMD_GET_FORBIDDEN_PLMNS:
910 request = (MainThreadRequest) msg.obj;
911 uiccCard = getUiccCardFromRequest(request);
912 if (uiccCard == null) {
913 loge("getForbiddenPlmns() UiccCard is null");
914 request.result = new IllegalArgumentException(
915 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800917 break;
918 }
919 Integer appType = (Integer) request.argument;
920 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
921 if (uiccApp == null) {
922 loge("getForbiddenPlmns() no app with specified type -- "
923 + appType);
924 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700925 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800926 break;
927 } else {
928 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
929 + " specified type -- " + appType);
930 }
931 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
932 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
933 onCompleted);
934 break;
935
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000936 case CMD_SWITCH_SLOTS:
937 request = (MainThreadRequest) msg.obj;
938 int[] physicalSlots = (int[]) request.argument;
939 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
940 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
941 break;
942
943 case EVENT_SWITCH_SLOTS_DONE:
944 ar = (AsyncResult) msg.obj;
945 request = (MainThreadRequest) ar.userObj;
946 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700947 notifyRequester(request);
948 break;
949 case CMD_GET_NETWORK_SELECTION_MODE:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
952 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
953 break;
954
955 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
956 ar = (AsyncResult) msg.obj;
957 request = (MainThreadRequest) ar.userObj;
958 if (ar.exception != null) {
959 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
960 } else {
961 int mode = ((int[]) ar.result)[0];
962 if (mode == 0) {
963 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
964 } else {
965 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
966 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000967 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700968 notifyRequester(request);
969 break;
970 case CMD_GET_CDMA_ROAMING_MODE:
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
973 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
974 break;
975 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
976 ar = (AsyncResult) msg.obj;
977 request = (MainThreadRequest) ar.userObj;
978 if (ar.exception != null) {
979 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
980 } else {
981 request.result = ((int[]) ar.result)[0];
982 }
983 notifyRequester(request);
984 break;
985 case CMD_SET_CDMA_ROAMING_MODE:
986 request = (MainThreadRequest) msg.obj;
987 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
988 int mode = (int) request.argument;
989 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
990 break;
991 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
992 ar = (AsyncResult) msg.obj;
993 request = (MainThreadRequest) ar.userObj;
994 request.result = ar.exception == null;
995 notifyRequester(request);
996 break;
997 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
998 request = (MainThreadRequest) msg.obj;
999 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1000 int subscriptionMode = (int) request.argument;
1001 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1002 break;
1003 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1004 ar = (AsyncResult) msg.obj;
1005 request = (MainThreadRequest) ar.userObj;
1006 request.result = ar.exception == null;
1007 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001008 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001009 case CMD_GET_ALL_CELL_INFO:
1010 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001011 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001012 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001013 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001014 case EVENT_GET_ALL_CELL_INFO_DONE:
1015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001017 // If a timeout occurs, the response will be null
1018 request.result = (ar.exception == null && ar.result != null)
1019 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001020 synchronized (request) {
1021 request.notifyAll();
1022 }
1023 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001024 case CMD_REQUEST_CELL_INFO_UPDATE:
1025 request = (MainThreadRequest) msg.obj;
1026 request.phone.requestCellInfoUpdate(request.workSource,
1027 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1028 break;
1029 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1033 try {
1034 if (ar.exception != null) {
1035 // something went wrong... the response is null
1036 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1037 cb.onCellInfo(null);
1038 } else if (ar.result == null) {
1039 // timeout occurred, so force the result to non-null "empty"
1040 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1041 cb.onCellInfo(new ArrayList<CellInfo>());
1042 } else {
1043 // use the result as returned
1044 cb.onCellInfo((List<CellInfo>) ar.result);
1045 }
1046 } catch (RemoteException re) {
1047 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1048 }
1049 break;
1050 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 request = (MainThreadRequest) msg.obj;
1052 WorkSource ws = (WorkSource) request.argument;
1053 Phone phone = getPhoneFromRequest(request);
1054 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1055 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001056 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 if (ar.exception == null) {
1060 request.result = ar.result;
1061 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1064 ? new CdmaCellLocation() : new GsmCellLocation();
1065 }
1066
1067 synchronized (request) {
1068 request.notifyAll();
1069 }
1070 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001071 case CMD_MODEM_REBOOT:
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1074 mPhone.rebootModem(onCompleted);
1075 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001076 case EVENT_CMD_MODEM_REBOOT_DONE:
1077 handleNullReturnEvent(msg, "rebootModem");
1078 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001079 default:
1080 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1081 break;
1082 }
1083 }
Jake Hambye994d462014-02-03 13:10:13 -08001084
Pengquan Menga1bb6272018-09-06 09:59:22 -07001085 private void notifyRequester(MainThreadRequest request) {
1086 synchronized (request) {
1087 request.notifyAll();
1088 }
1089 }
1090
Jake Hambye994d462014-02-03 13:10:13 -08001091 private void handleNullReturnEvent(Message msg, String command) {
1092 AsyncResult ar = (AsyncResult) msg.obj;
1093 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null) {
1095 request.result = true;
1096 } else {
1097 request.result = false;
1098 if (ar.exception instanceof CommandException) {
1099 loge(command + ": CommandException: " + ar.exception);
1100 } else {
1101 loge(command + ": Unknown exception");
1102 }
1103 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001104 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001106 }
1107
1108 /**
1109 * Posts the specified command to be executed on the main thread,
1110 * waits for the request to complete, and returns the result.
1111 * @see #sendRequestAsync
1112 */
1113 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001114 return sendRequest(
1115 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001116 }
1117
1118 /**
1119 * Posts the specified command to be executed on the main thread,
1120 * waits for the request to complete, and returns the result.
1121 * @see #sendRequestAsync
1122 */
1123 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1124 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001125 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001126 }
1127
1128 /**
1129 * Posts the specified command to be executed on the main thread,
1130 * waits for the request to complete, and returns the result.
1131 * @see #sendRequestAsync
1132 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001133 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001134 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001135 }
1136
1137 /**
1138 * Posts the specified command to be executed on the main thread,
1139 * waits for the request to complete, and returns the result.
1140 * @see #sendRequestAsync
1141 */
Nathan Harold92bed182018-10-12 18:16:49 -07001142 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1143 return sendRequest(command, argument, subId, null, workSource);
1144 }
1145
1146 /**
1147 * Posts the specified command to be executed on the main thread,
1148 * waits for the request to complete, and returns the result.
1149 * @see #sendRequestAsync
1150 */
1151 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1152 return sendRequest(
1153 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1154 }
1155
1156 /**
1157 * Posts the specified command to be executed on the main thread,
1158 * waits for the request to complete, and returns the result.
1159 * @see #sendRequestAsync
1160 */
1161 private Object sendRequest(
1162 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001163 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1164 throw new RuntimeException("This method will deadlock if called from the main thread.");
1165 }
1166
Nathan Harold92bed182018-10-12 18:16:49 -07001167 MainThreadRequest request = null;
1168 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1169 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1170 } else if (phone != null) {
1171 request = new MainThreadRequest(argument, phone, workSource);
1172 } else {
1173 request = new MainThreadRequest(argument, subId, workSource);
1174 }
1175
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001176 Message msg = mMainThreadHandler.obtainMessage(command, request);
1177 msg.sendToTarget();
1178
1179 // Wait for the request to complete
1180 synchronized (request) {
1181 while (request.result == null) {
1182 try {
1183 request.wait();
1184 } catch (InterruptedException e) {
1185 // Do nothing, go back and wait until the request is complete
1186 }
1187 }
1188 }
1189 return request.result;
1190 }
1191
1192 /**
1193 * Asynchronous ("fire and forget") version of sendRequest():
1194 * Posts the specified command to be executed on the main thread, and
1195 * returns immediately.
1196 * @see #sendRequest
1197 */
1198 private void sendRequestAsync(int command) {
1199 mMainThreadHandler.sendEmptyMessage(command);
1200 }
1201
1202 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001203 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001204 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001205 */
1206 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001207 sendRequestAsync(command, argument, null, null);
1208 }
1209
1210 /**
1211 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1212 * @see {@link #sendRequest(int,Object)}
1213 */
1214 private void sendRequestAsync(
1215 int command, Object argument, Phone phone, WorkSource workSource) {
1216 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001217 Message msg = mMainThreadHandler.obtainMessage(command, request);
1218 msg.sendToTarget();
1219 }
1220
1221 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 * Initialize the singleton PhoneInterfaceManager instance.
1223 * This is only done once, at startup, from PhoneApp.onCreate().
1224 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001225 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 synchronized (PhoneInterfaceManager.class) {
1227 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001228 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 } else {
1230 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1231 }
1232 return sInstance;
1233 }
1234 }
1235
1236 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001237 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001238 mApp = app;
1239 mPhone = phone;
1240 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001241 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1243 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001244 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001245 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001246 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001247 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001248 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001249
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 publish();
1251 }
1252
1253 private void publish() {
1254 if (DBG) log("publish: " + this);
1255
1256 ServiceManager.addService("phone", this);
1257 }
1258
Stuart Scott584921c2015-01-15 17:10:34 -08001259 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001260 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1261 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001262 }
1263
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001264 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1265 Phone phone = getPhoneFromRequest(request);
1266 return phone == null ? null :
1267 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1268 }
1269
Wink Saville36469e72014-06-11 15:17:00 -07001270 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001271 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001272 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274
1275 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001276 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001277 }
1278
Wink Savilleb564aae2014-10-23 10:18:09 -07001279 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 if (DBG) log("dial: " + number);
1281 // No permission check needed here: This is just a wrapper around the
1282 // ACTION_DIAL intent, which is available to any app since it puts up
1283 // the UI before it does anything.
1284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001285 final long identity = Binder.clearCallingIdentity();
1286 try {
1287 String url = createTelUrl(number);
1288 if (url == null) {
1289 return;
1290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001292 // PENDING: should we just silently fail if phone is offhook or ringing?
1293 PhoneConstants.State state = mCM.getState(subId);
1294 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1295 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1296 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1297 mApp.startActivity(intent);
1298 }
1299 } finally {
1300 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 }
1302 }
1303
1304 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001305 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001306 }
1307
Wink Savilleb564aae2014-10-23 10:18:09 -07001308 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 if (DBG) log("call: " + number);
1310
1311 // This is just a wrapper around the ACTION_CALL intent, but we still
1312 // need to do a permission check since we're calling startActivity()
1313 // from the context of the phone app.
1314 enforceCallPermission();
1315
1316 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1317 != AppOpsManager.MODE_ALLOWED) {
1318 return;
1319 }
1320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001321 final long identity = Binder.clearCallingIdentity();
1322 try {
1323 String url = createTelUrl(number);
1324 if (url == null) {
1325 return;
1326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001328 boolean isValid = false;
1329 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1330 if (slist != null) {
1331 for (SubscriptionInfo subInfoRecord : slist) {
1332 if (subInfoRecord.getSubscriptionId() == subId) {
1333 isValid = true;
1334 break;
1335 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001336 }
Wink Saville08874612014-08-31 19:19:58 -07001337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001338 if (!isValid) {
1339 return;
1340 }
Wink Saville08874612014-08-31 19:19:58 -07001341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001342 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1343 intent.putExtra(SUBSCRIPTION_KEY, subId);
1344 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1345 mApp.startActivity(intent);
1346 } finally {
1347 Binder.restoreCallingIdentity(identity);
1348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 }
1350
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001352 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001353 }
1354
Wink Savilleb564aae2014-10-23 10:18:09 -07001355 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001357 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1358 }
1359
1360 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001361 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001362 }
1363
Wink Savilleb564aae2014-10-23 10:18:09 -07001364 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001365 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001366 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1367 }
1368
1369 /** {@hide} */
1370 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001371 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
1373
Wink Savilleb564aae2014-10-23 10:18:09 -07001374 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001376
1377 final long identity = Binder.clearCallingIdentity();
1378 try {
1379 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1380 checkSimPin.start();
1381 return checkSimPin.unlockSim(null, pin);
1382 } finally {
1383 Binder.restoreCallingIdentity(identity);
1384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 }
1386
Wink Saville9de0f752013-10-22 19:04:03 -07001387 /** {@hide} */
1388 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001389 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001390 }
1391
Wink Savilleb564aae2014-10-23 10:18:09 -07001392 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001394
1395 final long identity = Binder.clearCallingIdentity();
1396 try {
1397 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1398 checkSimPuk.start();
1399 return checkSimPuk.unlockSim(puk, pin);
1400 } finally {
1401 Binder.restoreCallingIdentity(identity);
1402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 }
1404
1405 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001406 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 * a synchronous one.
1408 */
1409 private static class UnlockSim extends Thread {
1410
1411 private final IccCard mSimCard;
1412
1413 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001414 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1415 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416
1417 // For replies from SimCard interface
1418 private Handler mHandler;
1419
1420 // For async handler to identify request type
1421 private static final int SUPPLY_PIN_COMPLETE = 100;
1422
1423 public UnlockSim(IccCard simCard) {
1424 mSimCard = simCard;
1425 }
1426
1427 @Override
1428 public void run() {
1429 Looper.prepare();
1430 synchronized (UnlockSim.this) {
1431 mHandler = new Handler() {
1432 @Override
1433 public void handleMessage(Message msg) {
1434 AsyncResult ar = (AsyncResult) msg.obj;
1435 switch (msg.what) {
1436 case SUPPLY_PIN_COMPLETE:
1437 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1438 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001439 mRetryCount = msg.arg1;
1440 if (ar.exception != null) {
1441 if (ar.exception instanceof CommandException &&
1442 ((CommandException)(ar.exception)).getCommandError()
1443 == CommandException.Error.PASSWORD_INCORRECT) {
1444 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1445 } else {
1446 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1447 }
1448 } else {
1449 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 mDone = true;
1452 UnlockSim.this.notifyAll();
1453 }
1454 break;
1455 }
1456 }
1457 };
1458 UnlockSim.this.notifyAll();
1459 }
1460 Looper.loop();
1461 }
1462
1463 /*
1464 * Use PIN or PUK to unlock SIM card
1465 *
1466 * If PUK is null, unlock SIM card with PIN
1467 *
1468 * If PUK is not null, unlock SIM card with PUK and set PIN code
1469 */
Wink Saville9de0f752013-10-22 19:04:03 -07001470 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471
1472 while (mHandler == null) {
1473 try {
1474 wait();
1475 } catch (InterruptedException e) {
1476 Thread.currentThread().interrupt();
1477 }
1478 }
1479 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1480
1481 if (puk == null) {
1482 mSimCard.supplyPin(pin, callback);
1483 } else {
1484 mSimCard.supplyPuk(puk, pin, callback);
1485 }
1486
1487 while (!mDone) {
1488 try {
1489 Log.d(LOG_TAG, "wait for done");
1490 wait();
1491 } catch (InterruptedException e) {
1492 // Restore the interrupted status
1493 Thread.currentThread().interrupt();
1494 }
1495 }
1496 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001497 int[] resultArray = new int[2];
1498 resultArray[0] = mResult;
1499 resultArray[1] = mRetryCount;
1500 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
1502 }
1503
1504 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001505 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001506
1507 }
1508
Wink Savilleb564aae2014-10-23 10:18:09 -07001509 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 // No permission check needed here: this call is harmless, and it's
1511 // needed for the ServiceState.requestStateUpdate() call (which is
1512 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001513 final long identity = Binder.clearCallingIdentity();
1514 try {
1515 final Phone phone = getPhone(subId);
1516 if (phone != null) {
1517 phone.updateServiceLocation();
1518 }
1519 } finally {
1520 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 }
1523
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001524 @Override
1525 public boolean isRadioOn(String callingPackage) {
1526 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001527 }
1528
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001529 @Override
1530 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001532 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001533 return false;
1534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001535
1536 final long identity = Binder.clearCallingIdentity();
1537 try {
1538 return isRadioOnForSubscriber(subId);
1539 } finally {
1540 Binder.restoreCallingIdentity(identity);
1541 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001542 }
1543
1544 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001545 final long identity = Binder.clearCallingIdentity();
1546 try {
1547 final Phone phone = getPhone(subId);
1548 if (phone != null) {
1549 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1550 } else {
1551 return false;
1552 }
1553 } finally {
1554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557
1558 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001559 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 }
Wink Saville36469e72014-06-11 15:17:00 -07001561
Wink Savilleb564aae2014-10-23 10:18:09 -07001562 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001564
1565 final long identity = Binder.clearCallingIdentity();
1566 try {
1567 final Phone phone = getPhone(subId);
1568 if (phone != null) {
1569 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1570 }
1571 } finally {
1572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 }
Wink Saville36469e72014-06-11 15:17:00 -07001574 }
1575
1576 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001577 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001578 }
1579
Wink Savilleb564aae2014-10-23 10:18:09 -07001580 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001582
1583 final long identity = Binder.clearCallingIdentity();
1584 try {
1585 final Phone phone = getPhone(subId);
1586 if (phone == null) {
1587 return false;
1588 }
1589 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1590 toggleRadioOnOffForSubscriber(subId);
1591 }
1592 return true;
1593 } finally {
1594 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001595 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 }
Wink Saville36469e72014-06-11 15:17:00 -07001597
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001598 public boolean needMobileRadioShutdown() {
1599 /*
1600 * If any of the Radios are available, it will need to be
1601 * shutdown. So return true if any Radio is available.
1602 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001603 final long identity = Binder.clearCallingIdentity();
1604 try {
1605 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1606 Phone phone = PhoneFactory.getPhone(i);
1607 if (phone != null && phone.isRadioAvailable()) return true;
1608 }
1609 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1610 return false;
1611 } finally {
1612 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001613 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001614 }
1615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001616 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001617 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001618 enforceModifyPermission();
1619
1620 final long identity = Binder.clearCallingIdentity();
1621 try {
1622 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1623 logv("Shutting down Phone " + i);
1624 shutdownRadioUsingPhoneId(i);
1625 }
1626 } finally {
1627 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001628 }
1629 }
1630
1631 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001632 Phone phone = PhoneFactory.getPhone(phoneId);
1633 if (phone != null && phone.isRadioAvailable()) {
1634 phone.shutdownRadio();
1635 }
1636 }
1637
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001639 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001640
1641 final long identity = Binder.clearCallingIdentity();
1642 try {
1643 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1644 if (defaultPhone != null) {
1645 defaultPhone.setRadioPower(turnOn);
1646 return true;
1647 } else {
1648 loge("There's no default phone.");
1649 return false;
1650 }
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001653 }
Wink Saville36469e72014-06-11 15:17:00 -07001654 }
1655
Wink Savilleb564aae2014-10-23 10:18:09 -07001656 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001658
1659 final long identity = Binder.clearCallingIdentity();
1660 try {
1661 final Phone phone = getPhone(subId);
1662 if (phone != null) {
1663 phone.setRadioPower(turnOn);
1664 return true;
1665 } else {
1666 return false;
1667 }
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 }
1672
Wink Saville36469e72014-06-11 15:17:00 -07001673 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001674 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 public boolean enableDataConnectivity() {
1676 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001677
1678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 int subId = mSubscriptionController.getDefaultDataSubId();
1681 final Phone phone = getPhone(subId);
1682 if (phone != null) {
1683 phone.setUserDataEnabled(true);
1684 return true;
1685 } else {
1686 return false;
1687 }
1688 } finally {
1689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 }
1692
Wink Saville36469e72014-06-11 15:17:00 -07001693 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001694 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 public boolean disableDataConnectivity() {
1696 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001697
1698 final long identity = Binder.clearCallingIdentity();
1699 try {
1700 int subId = mSubscriptionController.getDefaultDataSubId();
1701 final Phone phone = getPhone(subId);
1702 if (phone != null) {
1703 phone.setUserDataEnabled(false);
1704 return true;
1705 } else {
1706 return false;
1707 }
1708 } finally {
1709 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001710 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 }
1712
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001714 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 final Phone phone = getPhone(subId);
1718 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001719 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001720 } else {
1721 return false;
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
1728 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001729 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001730 }
1731
pkanwarae03a6b2016-11-06 20:37:09 -08001732 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733 enforceCallPermission();
1734
1735 final long identity = Binder.clearCallingIdentity();
1736 try {
1737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1738 return;
1739 }
1740 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1741 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
1744 }
pkanwar32d516d2016-10-14 19:37:38 -07001745 };
1746
Wink Savilleb564aae2014-10-23 10:18:09 -07001747 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001749
1750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1753 return false;
1754 }
1755 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 }
1760
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001762 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001763 }
1764
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001765 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001766 final long identity = Binder.clearCallingIdentity();
1767 try {
1768 Phone phone = PhoneFactory.getPhone(slotIndex);
1769 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1770 PhoneConstantConversions.convertCallState(phone.getState());
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
1773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
1775
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1781 if (phone != null) {
1782 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1783 } else {
1784 return PhoneConstantConversions.convertDataState(
1785 PhoneConstants.DataState.DISCONNECTED);
1786 }
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001794 final long identity = Binder.clearCallingIdentity();
1795 try {
1796 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1797 if (phone != null) {
1798 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1799 } else {
1800 return TelephonyManager.DATA_ACTIVITY_NONE;
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 }
1806
1807 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001808 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001809 mPhone.getContext().getSystemService(AppOpsManager.class)
1810 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001811 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001812 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001813 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 }
1815
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001816 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001817 final long identity = Binder.clearCallingIdentity();
1818 try {
1819 if (DBG_LOC) log("getCellLocation: is active user");
1820 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001821 int subId = mSubscriptionController.getDefaultDataSubId();
1822 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1823 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001824 return data;
1825 } finally {
1826 Binder.restoreCallingIdentity(identity);
1827 }
Svetoslav64fad262015-04-14 14:35:21 -07001828 }
1829
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001831 public String getNetworkCountryIsoForPhone(int phoneId) {
1832 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1833 // registered cell info, so return a NULL country instead.
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001836 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1837 // Get default phone in this case.
1838 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1839 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001840 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001841 // Todo: fix this when we can get the actual cellular network info when the device
1842 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001843 if (TelephonyManager.NETWORK_TYPE_IWLAN
1844 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1845 return "";
1846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847 Phone phone = PhoneFactory.getPhone(phoneId);
1848 if (phone != null) {
1849 ServiceStateTracker sst = phone.getServiceStateTracker();
1850 if (sst != null) {
1851 LocaleTracker lt = sst.getLocaleTracker();
1852 if (lt != null) {
1853 return lt.getCurrentCountry();
1854 }
1855 }
1856 }
1857 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001858 } finally {
1859 Binder.restoreCallingIdentity(identity);
1860 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001861 }
1862
1863 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001865 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001866 }
1867
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001869 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 mApp.enforceCallingOrSelfPermission(
1871 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001872
1873 final long identity = Binder.clearCallingIdentity();
1874 try {
1875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
1877 phone.enableLocationUpdates();
1878 }
1879 } finally {
1880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 }
1883
1884 @Override
1885 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001886 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001887 }
1888
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001890 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 mApp.enforceCallingOrSelfPermission(
1892 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001893
1894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
1898 phone.disableLocationUpdates();
1899 }
1900 } finally {
1901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
Nathan Harold31d7ff32018-10-15 20:20:30 -07001905 /**
1906 * Returns the target SDK version number for a given package name.
1907 *
1908 * @return target SDK if the package is found or INT_MAX.
1909 */
1910 private int getTargetSdk(String packageName) {
1911 try {
1912 final ApplicationInfo ai =
1913 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1914 if (ai != null) return ai.targetSdkVersion;
1915 } catch (PackageManager.NameNotFoundException unexpected) {
1916 }
1917 return Integer.MAX_VALUE;
1918 }
1919
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 @Override
1921 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001922 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1923 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001924 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1925 throw new SecurityException(
1926 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1927 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001928
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1930 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1931 return null;
1932 }
Svetoslav64fad262015-04-14 14:35:21 -07001933
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001934 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935
Nathan Haroldf180aac2018-06-01 18:43:55 -07001936 List<CellInfo> info = getAllCellInfo(callingPackage);
1937 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938
Nathan Haroldf180aac2018-06-01 18:43:55 -07001939 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1940 for (CellInfo ci : info) {
1941 if (ci instanceof CellInfoGsm) {
1942 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1943 } else if (ci instanceof CellInfoWcdma) {
1944 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001947 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 }
1949
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001950 private List<CellInfo> getCachedCellInfo() {
1951 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1952 for (Phone phone : PhoneFactory.getPhones()) {
1953 List<CellInfo> info = phone.getAllCellInfo();
1954 if (info != null) cellInfos.addAll(info);
1955 }
1956 return cellInfos;
1957 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958
1959 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001960 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001961 mPhone.getContext().getSystemService(AppOpsManager.class)
1962 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001963 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001964 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001965 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001968 final int targetSdk = getTargetSdk(callingPackage);
1969 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1970 return getCachedCellInfo();
1971 }
1972
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001973 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001974 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 final long identity = Binder.clearCallingIdentity();
1976 try {
1977 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1978 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001979 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001980 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001981 if (info != null) cellInfos.addAll(info);
1982 }
1983 return cellInfos;
1984 } finally {
1985 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001986 }
1987 }
1988
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001989 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001990 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
1991 requestCellInfoUpdateInternal(
1992 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
1993 }
1994
1995 @Override
1996 public void requestCellInfoUpdateWithWorkSource(
1997 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
1998 enforceModifyPermission();
1999 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2000 }
2001
2002 private void requestCellInfoUpdateInternal(
2003 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2004 mPhone.getContext().getSystemService(AppOpsManager.class)
2005 .checkPackage(Binder.getCallingUid(), callingPackage);
2006 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
2007 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
2008 return;
2009 }
2010
2011 final Phone phone = getPhone(subId);
2012 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2013
2014 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2015 }
2016
2017 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002019 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021
2022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 mPhone.setCellInfoListRate(rateInMillis, workSource);
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 }
2029
Shishir Agrawala9f32182016-04-12 12:00:16 -07002030 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002031 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002032 Phone phone = PhoneFactory.getPhone(slotIndex);
2033 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002034 return null;
2035 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002036 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002037 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2038 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002039 return null;
2040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 return phone.getImei();
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
2047 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002048 }
2049
2050 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002051 public String getTypeAllocationCodeForSlot(int slotIndex) {
2052 Phone phone = PhoneFactory.getPhone(slotIndex);
2053 String tac = null;
2054 if (phone != null) {
2055 String imei = phone.getImei();
2056 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2057 }
2058 return tac;
2059 }
2060
2061 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002062 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002063 Phone phone = PhoneFactory.getPhone(slotIndex);
2064 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002065 return null;
2066 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002067 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002068 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2069 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002070 return null;
2071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072
2073 final long identity = Binder.clearCallingIdentity();
2074 try {
2075 return phone.getMeid();
2076 } finally {
2077 Binder.restoreCallingIdentity(identity);
2078 }
Jack Yu2af8d712017-03-15 17:14:14 -07002079 }
2080
2081 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002082 public String getManufacturerCodeForSlot(int slotIndex) {
2083 Phone phone = PhoneFactory.getPhone(slotIndex);
2084 String manufacturerCode = null;
2085 if (phone != null) {
2086 String meid = phone.getMeid();
2087 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2088 }
2089 return manufacturerCode;
2090 }
2091
2092 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002093 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002094 Phone phone = PhoneFactory.getPhone(slotIndex);
2095 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002096 return null;
2097 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002098 int subId = phone.getSubId();
2099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2100 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2101 return null;
2102 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103
2104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 return phone.getDeviceSvn();
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
2109 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002110 }
2111
fionaxu43304da2017-11-27 22:51:16 -08002112 @Override
2113 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 final Phone phone = getPhone(subId);
2117 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
fionaxu43304da2017-11-27 22:51:16 -08002121 }
2122
2123 @Override
2124 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002125 final long identity = Binder.clearCallingIdentity();
2126 try {
2127 final Phone phone = getPhone(subId);
2128 return phone == null ? null : phone.getCarrierName();
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
2131 }
fionaxu43304da2017-11-27 22:51:16 -08002132 }
2133
calvinpanffe225e2018-11-01 19:43:06 +08002134 @Override
chen xu25637222018-11-04 17:17:00 -08002135 public int getSubscriptionPreciseCarrierId(int subId) {
2136 final long identity = Binder.clearCallingIdentity();
2137 try {
2138 final Phone phone = getPhone(subId);
2139 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2140 : phone.getPreciseCarrierId();
2141 } finally {
2142 Binder.restoreCallingIdentity(identity);
2143 }
2144 }
2145
2146 @Override
2147 public String getSubscriptionPreciseCarrierName(int subId) {
2148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 final Phone phone = getPhone(subId);
2151 return phone == null ? null : phone.getPreciseCarrierName();
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
2155 }
2156
chen xu651eec72018-11-11 19:03:44 -08002157 @Override
chen xu864e11c2018-12-06 22:10:03 -08002158 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2159 if (!isSubscriptionMccMnc) {
2160 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2161 }
chen xu651eec72018-11-11 19:03:44 -08002162 final Phone phone = PhoneFactory.getPhone(slotIndex);
2163 if (phone == null) {
2164 return TelephonyManager.UNKNOWN_CARRIER_ID;
2165 }
2166 final long identity = Binder.clearCallingIdentity();
2167 try {
2168 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2169 } finally {
2170 Binder.restoreCallingIdentity(identity);
2171 }
2172 }
2173
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 //
2175 // Internal helper methods.
2176 //
2177
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002178 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2180 *
2181 * @throws SecurityException if the caller does not have the required permission
2182 */
2183 private void enforceModifyPermission() {
2184 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2185 }
2186
2187 /**
2188 * Make sure the caller has the CALL_PHONE permission.
2189 *
2190 * @throws SecurityException if the caller does not have the required permission
2191 */
2192 private void enforceCallPermission() {
2193 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2194 }
2195
Stuart Scott8eef64f2015-04-08 15:13:54 -07002196 private void enforceConnectivityInternalPermission() {
2197 mApp.enforceCallingOrSelfPermission(
2198 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2199 "ConnectivityService");
2200 }
2201
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 private String createTelUrl(String number) {
2203 if (TextUtils.isEmpty(number)) {
2204 return null;
2205 }
2206
Jake Hambye994d462014-02-03 13:10:13 -08002207 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 }
2209
Ihab Awadf9e92732013-12-05 18:02:52 -08002210 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2212 }
2213
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002214 private static void logv(String msg) {
2215 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2216 }
2217
Ihab Awadf9e92732013-12-05 18:02:52 -08002218 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2220 }
2221
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002222 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002224 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002225 }
2226
Sanket Padawe356d7632015-06-22 14:03:32 -07002227 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002228 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229 final long identity = Binder.clearCallingIdentity();
2230 try {
2231 final Phone phone = PhoneFactory.getPhone(slotIndex);
2232 if (phone == null) {
2233 return PhoneConstants.PHONE_TYPE_NONE;
2234 } else {
2235 return phone.getPhoneType();
2236 }
2237 } finally {
2238 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 }
2241
2242 /**
2243 * Returns the CDMA ERI icon index to display
2244 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 @Override
2246 public int getCdmaEriIconIndex(String callingPackage) {
2247 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002248 }
2249
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002251 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002252 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002253 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002254 return -1;
2255 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002256
2257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 final Phone phone = getPhone(subId);
2260 if (phone != null) {
2261 return phone.getCdmaEriIconIndex();
2262 } else {
2263 return -1;
2264 }
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269
2270 /**
2271 * Returns the CDMA ERI icon mode,
2272 * 0 - ON
2273 * 1 - FLASHING
2274 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002275 @Override
2276 public int getCdmaEriIconMode(String callingPackage) {
2277 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002278 }
2279
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002281 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002283 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002284 return -1;
2285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 final Phone phone = getPhone(subId);
2290 if (phone != null) {
2291 return phone.getCdmaEriIconMode();
2292 } else {
2293 return -1;
2294 }
2295 } finally {
2296 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
2300 /**
2301 * Returns the CDMA ERI text,
2302 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002303 @Override
2304 public String getCdmaEriText(String callingPackage) {
2305 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002306 }
2307
Sanket Padawe356d7632015-06-22 14:03:32 -07002308 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002309 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002311 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002312 return null;
2313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002314
2315 final long identity = Binder.clearCallingIdentity();
2316 try {
2317 final Phone phone = getPhone(subId);
2318 if (phone != null) {
2319 return phone.getCdmaEriText();
2320 } else {
2321 return null;
2322 }
2323 } finally {
2324 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 }
2327
2328 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002329 * Returns the CDMA MDN.
2330 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002332 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2334 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002335
2336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 final Phone phone = getPhone(subId);
2339 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2340 return phone.getLine1Number();
2341 } else {
2342 return null;
2343 }
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002346 }
2347 }
2348
2349 /**
2350 * Returns the CDMA MIN.
2351 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002353 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2355 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 final Phone phone = getPhone(subId);
2360 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2361 return phone.getCdmaMin();
2362 } else {
2363 return null;
2364 }
2365 } finally {
2366 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002367 }
2368 }
2369
2370 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 * Returns true if CDMA provisioning needs to run.
2372 */
2373 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002374 final long identity = Binder.clearCallingIdentity();
2375 try {
2376 return mPhone.needsOtaServiceProvisioning();
2377 } finally {
2378 Binder.restoreCallingIdentity(identity);
2379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 }
2381
2382 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002383 * Sets the voice mail number of a given subId.
2384 */
2385 @Override
2386 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002387 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2392 new Pair<String, String>(alphaTag, number), new Integer(subId));
2393 return success;
2394 } finally {
2395 Binder.restoreCallingIdentity(identity);
2396 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002397 }
2398
Ta-wei Yen87c49842016-05-13 21:19:52 -07002399 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002400 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2401 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2402 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2403 if (!TextUtils.equals(callingPackage, systemDialer)) {
2404 throw new SecurityException("caller must be system dialer");
2405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002406
2407 final long identity = Binder.clearCallingIdentity();
2408 try {
2409 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2410 if (phoneAccountHandle == null) {
2411 return null;
2412 }
2413 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2414 } finally {
2415 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002416 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002417 }
2418
2419 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002420 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002421 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002422 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002423 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002424 return null;
2425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 return RemoteVvmTaskManager
2430 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2431 } finally {
2432 Binder.restoreCallingIdentity(identity);
2433 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002434 }
2435
2436 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002437 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2438 VisualVoicemailSmsFilterSettings settings) {
2439 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
2443 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2444 mPhone.getContext(), callingPackage, subId, settings);
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
2447 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002448 }
2449
2450 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002451 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453
2454 final long identity = Binder.clearCallingIdentity();
2455 try {
2456 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2457 mPhone.getContext(), callingPackage, subId);
2458 } finally {
2459 Binder.restoreCallingIdentity(identity);
2460 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002461 }
2462
2463 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002464 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2465 String callingPackage, int subId) {
2466 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467
2468 final long identity = Binder.clearCallingIdentity();
2469 try {
2470 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2471 mPhone.getContext(), callingPackage, subId);
2472 } finally {
2473 Binder.restoreCallingIdentity(identity);
2474 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002475 }
2476
2477 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002478 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002479 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480
2481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2484 mPhone.getContext(), subId);
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
2487 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002488 }
2489
2490 @Override
2491 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2492 String number, int port, String text, PendingIntent sentIntent) {
2493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002494 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002495 enforceSendSmsPermission();
2496 // Make the calls as the phone process.
2497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2500 if (port == 0) {
2501 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2502 sentIntent, null, false);
2503 } else {
2504 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2505 smsManager.sendDataMessageWithSelfPermissions(number, null,
2506 (short) port, data, sentIntent, null);
2507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002511 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002512 /**
fionaxu0152e512016-11-14 13:36:14 -08002513 * Sets the voice activation state of a given subId.
2514 */
2515 @Override
2516 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2518 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
2522 final Phone phone = getPhone(subId);
2523 if (phone != null) {
2524 phone.setVoiceActivationState(activationState);
2525 } else {
2526 loge("setVoiceActivationState fails with invalid subId: " + subId);
2527 }
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002530 }
2531 }
2532
2533 /**
2534 * Sets the data activation state of a given subId.
2535 */
2536 @Override
2537 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2539 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540
2541 final long identity = Binder.clearCallingIdentity();
2542 try {
2543 final Phone phone = getPhone(subId);
2544 if (phone != null) {
2545 phone.setDataActivationState(activationState);
2546 } else {
2547 loge("setVoiceActivationState fails with invalid subId: " + subId);
2548 }
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002551 }
2552 }
2553
2554 /**
2555 * Returns the voice activation state of a given subId.
2556 */
2557 @Override
2558 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002559 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560
fionaxu0152e512016-11-14 13:36:14 -08002561 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 final long identity = Binder.clearCallingIdentity();
2563 try {
2564 if (phone != null) {
2565 return phone.getVoiceActivationState();
2566 } else {
2567 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2568 }
2569 } finally {
2570 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002571 }
2572 }
2573
2574 /**
2575 * Returns the data activation state of a given subId.
2576 */
2577 @Override
2578 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002579 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580
fionaxu0152e512016-11-14 13:36:14 -08002581 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 if (phone != null) {
2585 return phone.getDataActivationState();
2586 } else {
2587 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2588 }
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002591 }
2592 }
2593
2594 /**
Wink Saville36469e72014-06-11 15:17:00 -07002595 * Returns the unread count of voicemails for a subId
2596 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002597 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002598 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2600 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2601 return 0;
2602 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 final Phone phone = getPhone(subId);
2606 if (phone != null) {
2607 return phone.getVoiceMessageCount();
2608 } else {
2609 return 0;
2610 }
2611 } finally {
2612 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 }
2615
2616 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002617 * returns true, if the device is in a state where both voice and data
2618 * are supported simultaneously. This can change based on location or network condition.
2619 */
2620 @Override
2621 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 final Phone phone = getPhone(subId);
2625 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
2628 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002629 }
2630
2631 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002632 * Send the dialer code if called from the current default dialer or the caller has
2633 * carrier privilege.
2634 * @param inputCode The dialer code to send
2635 */
2636 @Override
2637 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2638 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2639 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2640 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002641 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2642 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 mPhone.sendDialerSpecialCode(inputCode);
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
2650 }
fionaxu235cc5e2017-03-06 22:25:57 -08002651 }
2652
2653 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002654 * Returns the data network type.
2655 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 *
2657 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2658 */
2659 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002660 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 final Phone phone = getPhone(getDefaultSubscription());
2664 if (phone != null) {
2665 return phone.getServiceState().getDataNetworkType();
2666 } else {
2667 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2668 }
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002671 }
Wink Saville36469e72014-06-11 15:17:00 -07002672 }
2673
Pengquan Menga1bb6272018-09-06 09:59:22 -07002674 @Override
2675 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002676 if (!isActiveSubscription(subId)) {
2677 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2678 }
2679
Pengquan Menga1bb6272018-09-06 09:59:22 -07002680 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2681 }
2682
Brad Ebinger35c841c2018-10-01 10:40:55 -07002683 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002684 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2685 throws RemoteException {
2686 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002687 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2688 final long token = Binder.clearCallingIdentity();
2689 try {
2690 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2691 .addRegistrationCallbackForSubscription(c, subId);
2692 } finally {
2693 Binder.restoreCallingIdentity(token);
2694 }
2695 }
2696
2697 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002698 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2699 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002700 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2701 Binder.withCleanCallingIdentity(() ->
2702 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2703 .removeRegistrationCallbackForSubscription(c, subId));
2704 }
2705
2706 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002707 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2708 throws RemoteException {
2709 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002710 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2711 final long token = Binder.clearCallingIdentity();
2712 try {
2713 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2714 .addCapabilitiesCallbackForSubscription(c, subId);
2715 } finally {
2716 Binder.restoreCallingIdentity(token);
2717 }
2718 }
2719
2720 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002721 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2722 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2724 Binder.withCleanCallingIdentity(() ->
2725 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2726 .removeCapabilitiesCallbackForSubscription(c, subId));
2727 }
2728
2729 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002730 public boolean isCapable(int subId, int capability, int regTech) {
2731 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002732 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2733 final long token = Binder.clearCallingIdentity();
2734 try {
2735 return ImsManager.getInstance(mPhone.getContext(),
2736 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2737 } catch (ImsException e) {
2738 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2739 return false;
2740 } finally {
2741 Binder.restoreCallingIdentity(token);
2742 }
2743 }
2744
2745 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002746 public boolean isAvailable(int subId, int capability, int regTech) {
2747 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002748 final long token = Binder.clearCallingIdentity();
2749 try {
2750 Phone phone = getPhone(subId);
2751 if (phone == null) return false;
2752 return phone.isImsCapabilityAvailable(capability, regTech);
2753 } finally {
2754 Binder.restoreCallingIdentity(token);
2755 }
2756 }
2757
2758 @Override
2759 public boolean isAdvancedCallingSettingEnabled(int subId) {
2760 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2761 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2762 final long token = Binder.clearCallingIdentity();
2763 try {
2764 return ImsManager.getInstance(mPhone.getContext(),
2765 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2766 } finally {
2767 Binder.restoreCallingIdentity(token);
2768 }
2769 }
2770
2771 @Override
2772 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2774 "setAdvancedCallingSetting");
2775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2778 ImsManager.getInstance(mPhone.getContext(),
2779 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
2782 }
2783 }
2784
2785 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002786 public boolean isVtSettingEnabled(int subId) {
2787 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2791 return ImsManager.getInstance(mPhone.getContext(),
2792 getSlotIndexOrException(subId)).isVtEnabledByUser();
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
2795 }
2796 }
2797
2798 @Override
2799 public void setVtSetting(int subId, boolean isEnabled) {
2800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2801 "setVtSetting");
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2805 ImsManager.getInstance(mPhone.getContext(),
2806 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2807 } finally {
2808 Binder.restoreCallingIdentity(identity);
2809 }
2810 }
2811
2812 @Override
2813 public boolean isVoWiFiSettingEnabled(int subId) {
2814 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2818 return ImsManager.getInstance(mPhone.getContext(),
2819 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
2822 }
2823 }
2824
2825 @Override
2826 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2828 "setVoWiFiSetting");
2829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2832 ImsManager.getInstance(mPhone.getContext(),
2833 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2834 } finally {
2835 Binder.restoreCallingIdentity(identity);
2836 }
2837 }
2838
2839 @Override
2840 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2841 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2845 return ImsManager.getInstance(mPhone.getContext(),
2846 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
2849 }
2850 }
2851
2852 @Override
2853 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2855 "setVoWiFiRoamingSetting");
2856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2859 ImsManager.getInstance(mPhone.getContext(),
2860 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
2863 }
2864 }
2865
2866 @Override
2867 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2869 "setVoWiFiNonPersistent");
2870 final long identity = Binder.clearCallingIdentity();
2871 try {
2872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2873 ImsManager.getInstance(mPhone.getContext(),
2874 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
2877 }
2878 }
2879
2880 @Override
2881 public int getVoWiFiModeSetting(int subId) {
2882 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2886 return ImsManager.getInstance(mPhone.getContext(),
2887 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
2890 }
2891 }
2892
2893 @Override
2894 public void setVoWiFiModeSetting(int subId, int mode) {
2895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2896 "setVoWiFiModeSetting");
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2900 ImsManager.getInstance(mPhone.getContext(),
2901 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
2904 }
2905 }
2906
2907 @Override
2908 public int getVoWiFiRoamingModeSetting(int subId) {
2909 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2913 return ImsManager.getInstance(mPhone.getContext(),
2914 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
2917 }
2918 }
2919
2920 @Override
2921 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2923 "setVoWiFiRoamingModeSetting");
2924 final long identity = Binder.clearCallingIdentity();
2925 try {
2926 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2927 ImsManager.getInstance(mPhone.getContext(),
2928 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
2931 }
2932 }
2933
2934 @Override
2935 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2937 "setRttCapabilityEnabled");
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2941 ImsManager.getInstance(mPhone.getContext(),
2942 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
2946 }
2947
2948 @Override
2949 public boolean isTtyOverVolteEnabled(int subId) {
2950 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2954 return ImsManager.getInstance(mPhone.getContext(),
2955 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
2959 }
2960
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002961 @Override
2962 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2963 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2967 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2968 .getConfigInterface().addConfigCallback(callback);
2969 } catch (ImsException e) {
2970 throw new IllegalArgumentException(e.getMessage());
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
2973 }
2974 }
2975
2976 @Override
2977 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2978 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2982 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2983 .getConfigInterface().removeConfigCallback(callback);
2984 } catch (ImsException e) {
2985 throw new IllegalArgumentException(e.getMessage());
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
2989 }
2990
2991 @Override
2992 public int getImsProvisioningInt(int subId, int key) {
2993 enforceReadPrivilegedPermission("getImsProvisioningInt");
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2997 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2998 .getConfigInterface().getConfigInt(key);
2999 } catch (ImsException e) {
3000 throw new IllegalArgumentException(e.getMessage());
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
3004 }
3005
3006 @Override
3007 public String getImsProvisioningString(int subId, int key) {
3008 enforceReadPrivilegedPermission("getImsProvisioningString");
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3012 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3013 .getConfigInterface().getConfigString(key);
3014 } catch (ImsException e) {
3015 throw new IllegalArgumentException(e.getMessage());
3016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
3019 }
3020
3021 @Override
3022 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3024 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3028 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3029 .getConfigInterface().setConfig(key, value);
3030 } catch (ImsException e) {
3031 throw new IllegalArgumentException(e.getMessage());
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
3035 }
3036
3037 @Override
3038 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3040 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3044 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3045 .getConfigInterface().setConfig(key, value);
3046 } catch (ImsException e) {
3047 throw new IllegalArgumentException(e.getMessage());
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
3051 }
3052
Brad Ebinger35c841c2018-10-01 10:40:55 -07003053 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3054 int slotId = SubscriptionManager.getSlotIndex(subId);
3055 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3056 throw new IllegalArgumentException("Invalid Subscription Id.");
3057 }
3058 return slotId;
3059 }
3060
Wink Saville36469e72014-06-11 15:17:00 -07003061 /**
3062 * Returns the network type for a subId
3063 */
3064 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003065 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003067 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003068 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3069 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 final Phone phone = getPhone(subId);
3074 if (phone != null) {
3075 return phone.getServiceState().getDataNetworkType();
3076 } else {
3077 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3078 }
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082 }
3083
3084 /**
3085 * Returns the data network type
3086 */
3087 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003088 public int getDataNetworkType(String callingPackage) {
3089 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003090 }
3091
3092 /**
3093 * Returns the data network type for a subId
3094 */
3095 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003096 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003098 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003099 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3100 }
3101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 final Phone phone = getPhone(subId);
3105 if (phone != null) {
3106 return phone.getServiceState().getDataNetworkType();
3107 } else {
3108 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3109 }
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003113 }
3114
3115 /**
Wink Saville36469e72014-06-11 15:17:00 -07003116 * Returns the Voice network type for a subId
3117 */
3118 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003119 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003121 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003122 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3123 }
3124
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 final Phone phone = getPhone(subId);
3128 if (phone != null) {
3129 return phone.getServiceState().getVoiceNetworkType();
3130 } else {
3131 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3132 }
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003136 }
3137
3138 /**
3139 * @return true if a ICC card is present
3140 */
3141 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003142 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003143 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3144 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003145 }
3146
3147 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003148 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003149 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003150 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003151 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 final Phone phone = PhoneFactory.getPhone(slotIndex);
3155 if (phone != null) {
3156 return phone.getIccCard().hasIccCard();
3157 } else {
3158 return false;
3159 }
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003163 }
3164
3165 /**
3166 * Return if the current radio is LTE on CDMA. This
3167 * is a tri-state return value as for a period of time
3168 * the mode may be unknown.
3169 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003170 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003172 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003174 @Override
3175 public int getLteOnCdmaMode(String callingPackage) {
3176 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003177 }
3178
Sanket Padawe356d7632015-06-22 14:03:32 -07003179 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003180 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003182 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003183 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3184 }
3185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 final Phone phone = getPhone(subId);
3189 if (phone == null) {
3190 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3191 } else {
3192 return phone.getLteOnCdmaMode();
3193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003196 }
Wink Saville36469e72014-06-11 15:17:00 -07003197 }
3198
3199 public void setPhone(Phone phone) {
3200 mPhone = phone;
3201 }
3202
3203 /**
3204 * {@hide}
3205 * Returns Default subId, 0 in the case of single standby.
3206 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003207 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003208 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003209 }
3210
Shishir Agrawala9f32182016-04-12 12:00:16 -07003211 private int getSlotForDefaultSubscription() {
3212 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3213 }
3214
Wink Savilleb564aae2014-10-23 10:18:09 -07003215 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003216 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003217 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003218
Pengquan Menge92a50d2018-09-21 15:54:48 -07003219 private boolean isActiveSubscription(int subId) {
3220 return mSubscriptionController.isActiveSubId(subId);
3221 }
3222
Ihab Awadf2177b72013-11-25 13:33:23 -08003223 /**
3224 * @see android.telephony.TelephonyManager.WifiCallingChoices
3225 */
3226 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3230 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3231 getWhenToMakeWifiCallsDefaultPreference());
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003235 }
3236
3237 /**
3238 * @see android.telephony.TelephonyManager.WifiCallingChoices
3239 */
3240 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3244 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3245 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3246 } finally {
3247 Binder.restoreCallingIdentity(identity);
3248 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003249 }
3250
Sailesh Nepald1e68152013-12-12 19:08:02 -08003251 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003252 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003253 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003254 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003255
Shishir Agrawal566b7612013-10-28 14:41:00 -07003256 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003257 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3258 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3260 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 if (TextUtils.equals(ISDR_AID, aid)) {
3266 // Only allows LPA to open logical channel to ISD-R.
3267 ComponentInfo bestComponent =
3268 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3269 if (bestComponent == null
3270 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3271 loge("The calling package is not allowed to access ISD-R.");
3272 throw new SecurityException(
3273 "The calling package is not allowed to access ISD-R.");
3274 }
Derek Tan740e1672017-06-27 14:56:27 -07003275 }
Derek Tan740e1672017-06-27 14:56:27 -07003276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277 if (DBG) {
3278 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3279 }
3280 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3281 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3282 if (DBG) log("iccOpenLogicalChannel: " + response);
3283 return response;
3284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003287 }
3288
3289 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003290 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3292 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3297 if (channel < 0) {
3298 return false;
3299 }
3300 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3301 if (DBG) log("iccCloseLogicalChannel: " + success);
3302 return success;
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003305 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003306 }
3307
3308 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003309 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003310 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3312 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 if (DBG) {
3317 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3318 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3319 + p3 + " data=" + data);
3320 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322 if (channel < 0) {
3323 return "";
3324 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3327 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3328 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 // Append the returned status code to the end of the response payload.
3331 String s = Integer.toHexString(
3332 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3333 if (response.payload != null) {
3334 s = IccUtils.bytesToHexString(response.payload) + s;
3335 }
3336 return s;
3337 } finally {
3338 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003339 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003340 }
Jake Hambye994d462014-02-03 13:10:13 -08003341
Evan Charltonc66da362014-05-16 14:06:40 -07003342 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003343 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3344 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3346 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3352 && TextUtils.equals(ISDR_AID, data)) {
3353 // Only allows LPA to select ISD-R.
3354 ComponentInfo bestComponent =
3355 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3356 if (bestComponent == null
3357 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3358 loge("The calling package is not allowed to select ISD-R.");
3359 throw new SecurityException(
3360 "The calling package is not allowed to select ISD-R.");
3361 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003362 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364 if (DBG) {
3365 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3366 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3367 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003369 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3370 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3371 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003373 // Append the returned status code to the end of the response payload.
3374 String s = Integer.toHexString(
3375 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3376 if (response.payload != null) {
3377 s = IccUtils.bytesToHexString(response.payload) + s;
3378 }
3379 return s;
3380 } finally {
3381 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003382 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003383 }
3384
3385 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003386 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003387 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3389 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391 final long identity = Binder.clearCallingIdentity();
3392 try {
3393 if (DBG) {
3394 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3395 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3396 }
3397
3398 IccIoResult response =
3399 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3400 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3401 subId);
3402
3403 if (DBG) {
3404 log("Exchange SIM_IO [R]" + response);
3405 }
3406
3407 byte[] result = null;
3408 int length = 2;
3409 if (response.payload != null) {
3410 length = 2 + response.payload.length;
3411 result = new byte[length];
3412 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3413 } else {
3414 result = new byte[length];
3415 }
3416
3417 result[length - 1] = (byte) response.sw2;
3418 result[length - 2] = (byte) response.sw1;
3419 return result;
3420 } finally {
3421 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003422 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003423 }
3424
Nathan Haroldb3014052017-01-25 15:57:32 -08003425 /**
3426 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3427 * on a particular subscription
3428 */
sqianb6e41952018-03-12 14:54:01 -07003429 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3430 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3431 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3432 return null;
3433 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 if (appType != TelephonyManager.APPTYPE_USIM
3438 && appType != TelephonyManager.APPTYPE_SIM) {
3439 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3440 return null;
3441 }
3442 Object response = sendRequest(
3443 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3444 if (response instanceof String[]) {
3445 return (String[]) response;
3446 }
3447 // Response is an Exception of some kind,
3448 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003449 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003452 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003453 }
3454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003455 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003456 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3458 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003460 final long identity = Binder.clearCallingIdentity();
3461 try {
3462 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3463 if (response.payload == null) {
3464 return "";
3465 }
Evan Charltonc66da362014-05-16 14:06:40 -07003466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003467 // Append the returned status code to the end of the response payload.
3468 String s = Integer.toHexString(
3469 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3470 s = IccUtils.bytesToHexString(response.payload) + s;
3471 return s;
3472 } finally {
3473 Binder.restoreCallingIdentity(identity);
3474 }
Evan Charltonc66da362014-05-16 14:06:40 -07003475 }
3476
Jake Hambye994d462014-02-03 13:10:13 -08003477 /**
3478 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3479 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3480 *
3481 * @param itemID the ID of the item to read
3482 * @return the NV item as a String, or null on error.
3483 */
3484 @Override
3485 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003486 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3488 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003489
3490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003493 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003494 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3495 return value;
3496 } finally {
3497 Binder.restoreCallingIdentity(identity);
3498 }
Jake Hambye994d462014-02-03 13:10:13 -08003499 }
3500
3501 /**
3502 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3503 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3504 *
3505 * @param itemID the ID of the item to read
3506 * @param itemValue the value to write, as a String
3507 * @return true on success; false on any failure
3508 */
3509 @Override
3510 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3513 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514
3515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3518 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003519 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3521 return success;
3522 } finally {
3523 Binder.restoreCallingIdentity(identity);
3524 }
Jake Hambye994d462014-02-03 13:10:13 -08003525 }
3526
3527 /**
3528 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3529 * Used for device configuration by some CDMA operators.
3530 *
3531 * @param preferredRoamingList byte array containing the new PRL
3532 * @return true on success; false on any failure
3533 */
3534 @Override
3535 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3537 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538
3539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3542 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3543 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3544 return success;
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
Jake Hambye994d462014-02-03 13:10:13 -08003548 }
3549
3550 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003551 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003552 * Used for device configuration by some CDMA operators.
3553 *
chen xu6dac5ab2018-10-26 17:39:23 -07003554 * @param slotIndex - device slot.
3555 *
Jake Hambye994d462014-02-03 13:10:13 -08003556 * @return true on success; false on any failure
3557 */
3558 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003559 public boolean resetModemConfig(int slotIndex) {
3560 Phone phone = PhoneFactory.getPhone(slotIndex);
3561 if (phone != null) {
3562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3563 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564
chen xu6dac5ab2018-10-26 17:39:23 -07003565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3568 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3569 return success;
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
3572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 }
chen xu6dac5ab2018-10-26 17:39:23 -07003574 return false;
3575 }
3576
3577 /**
3578 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3579 *
3580 * @param slotIndex - device slot.
3581 *
3582 * @return true on success; false on any failure
3583 */
3584 @Override
3585 public boolean rebootModem(int slotIndex) {
3586 Phone phone = PhoneFactory.getPhone(slotIndex);
3587 if (phone != null) {
3588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3589 mApp, phone.getSubId(), "rebootModem");
3590
3591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3594 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3595 return success;
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
3598 }
3599 }
3600 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003601 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003602
Svet Ganovb320e182015-04-16 12:30:10 -07003603 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003605 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003606 return new String[0];
3607 }
3608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 return mPhone.getPcscfAddress(apnType);
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
3614 }
Wink Saville36469e72014-06-11 15:17:00 -07003615 }
3616
Brad Ebinger51f743a2017-01-23 13:50:20 -08003617 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003618 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3619 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003620 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003621 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003622 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 PhoneFactory.getImsResolver().enableIms(slotId);
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003630 }
3631
3632 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003633 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3634 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003635 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003636 public void disableIms(int slotId) {
3637 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638
3639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 PhoneFactory.getImsResolver().disableIms(slotId);
3642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003645 }
3646
3647 /**
3648 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3649 * feature or {@link null} if the service is not available. If the feature is available, the
3650 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3651 */
3652 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003653 IImsServiceFeatureCallback callback) {
3654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655
3656 final long identity = Binder.clearCallingIdentity();
3657 try {
3658 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003662 }
3663
3664 /**
3665 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3666 * feature during emergency calling or {@link null} if the service is not available. If the
3667 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3668 * listener for feature updates.
3669 */
3670 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003679 }
3680
Brad Ebinger5f64b052017-12-14 14:26:15 -08003681 /**
3682 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3683 * specified.
3684 */
3685 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3686 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003694 }
3695
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003696 /**
3697 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3698 * specified.
3699 */
3700 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003709 }
3710
Brad Ebinger884c07b2018-02-15 16:17:40 -08003711 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003712 * Sets the ImsService Package Name that Telephony will bind to.
3713 *
3714 * @param slotId the slot ID that the ImsService should bind for.
3715 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3716 * ImsService is the device default ImsService.
3717 * @param packageName The package name of the application that contains the ImsService to bind
3718 * to.
3719 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3720 * @hide
3721 */
3722 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003723 int[] subIds = SubscriptionManager.getSubId(slotId);
3724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3725 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3726 "setImsService");
3727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728 final long identity = Binder.clearCallingIdentity();
3729 try {
3730 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3731 isCarrierImsService, packageName);
3732 } finally {
3733 Binder.restoreCallingIdentity(identity);
3734 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003735 }
3736
3737 /**
3738 * Return the ImsService configuration.
3739 *
3740 * @param slotId The slot that the ImsService is associated with.
3741 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3742 * the device default.
3743 * @return the package name of the ImsService configuration.
3744 */
3745 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003746 int[] subIds = SubscriptionManager.getSubId(slotId);
3747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3748 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3749 "getImsService");
3750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3754 isCarrierImsService);
3755 } finally {
3756 Binder.restoreCallingIdentity(identity);
3757 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003758 }
3759
Wink Saville36469e72014-06-11 15:17:00 -07003760 public void setImsRegistrationState(boolean registered) {
3761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762
3763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 mPhone.setImsRegistrationState(registered);
3766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
Wink Saville36469e72014-06-11 15:17:00 -07003769 }
3770
3771 /**
Stuart Scott54788802015-03-30 13:18:01 -07003772 * Set the network selection mode to automatic.
3773 *
3774 */
3775 @Override
3776 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3778 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003779
Pengquan Menge92a50d2018-09-21 15:54:48 -07003780 if (!isActiveSubscription(subId)) {
3781 return;
3782 }
3783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784 final long identity = Binder.clearCallingIdentity();
3785 try {
3786 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3787 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
Stuart Scott54788802015-03-30 13:18:01 -07003791 }
3792
Pengquan Mengea84e042018-09-20 14:57:26 -07003793 /**
3794 * Ask the radio to connect to the input network and change selection mode to manual.
3795 *
3796 * @param subId the id of the subscription.
3797 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3798 * the operator to attach to.
3799 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3800 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3801 * normal network selection next time.
3802 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003803 */
3804 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003805 public boolean setNetworkSelectionModeManual(
3806 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3808 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003809
3810 if (!isActiveSubscription(subId)) {
3811 return false;
3812 }
3813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003816 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003818 if (DBG) {
3819 log("setNetworkSelectionModeManual: subId: " + subId
3820 + " operator: " + operatorInfo);
3821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003822 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3823 } finally {
3824 Binder.restoreCallingIdentity(identity);
3825 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003826 }
3827
3828 /**
3829 * Scans for available networks.
3830 */
3831 @Override
3832 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3834 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003835
Pengquan Menga1bb6272018-09-06 09:59:22 -07003836 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837 try {
3838 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003839 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003841 } finally {
3842 Binder.restoreCallingIdentity(identity);
3843 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003844 }
3845
3846 /**
yinxub1bed742017-04-17 11:45:04 -07003847 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003848 *
yinxub1bed742017-04-17 11:45:04 -07003849 * @param subId id of the subscription
3850 * @param request contains the radio access networks with bands/channels to scan
3851 * @param messenger callback messenger for scan results or errors
3852 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003853 * @return the id of the requested scan which can be used to stop the scan.
3854 */
3855 @Override
3856 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3857 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3859 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860
3861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 return mNetworkScanRequestTracker.startNetworkScan(
3864 request, messenger, binder, getPhone(subId));
3865 } finally {
3866 Binder.restoreCallingIdentity(identity);
3867 }
yinxu504e1392017-04-12 16:03:22 -07003868 }
3869
3870 /**
3871 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003872 *
3873 * @param subId id of the subscription
3874 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003875 */
3876 @Override
3877 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3879 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003880
3881 final long identity = Binder.clearCallingIdentity();
3882 try {
3883 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
3886 }
yinxu504e1392017-04-12 16:03:22 -07003887 }
3888
3889 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003890 * Get the calculated preferred network type.
3891 * Used for debugging incorrect network type.
3892 *
3893 * @return the preferred network type, defined in RILConstants.java.
3894 */
3895 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003896 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003898 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003899 return RILConstants.PREFERRED_NETWORK_MODE;
3900 }
3901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902 final long identity = Binder.clearCallingIdentity();
3903 try {
3904 // FIXME: need to get SubId from somewhere.
3905 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3906 } finally {
3907 Binder.restoreCallingIdentity(identity);
3908 }
Junda Liu84d15a22014-07-02 11:21:04 -07003909 }
3910
3911 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003912 * Get the preferred network type.
3913 * Used for device configuration by some CDMA operators.
3914 *
3915 * @return the preferred network type, defined in RILConstants.java.
3916 */
3917 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003918 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3920 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921
3922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 if (DBG) log("getPreferredNetworkType");
3925 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3926 int networkType = (result != null ? result[0] : -1);
3927 if (DBG) log("getPreferredNetworkType: " + networkType);
3928 return networkType;
3929 } finally {
3930 Binder.restoreCallingIdentity(identity);
3931 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003932 }
3933
3934 /**
3935 * Set the preferred network type.
3936 * Used for device configuration by some CDMA operators.
3937 *
3938 * @param networkType the preferred network type, defined in RILConstants.java.
3939 * @return true on success; false on any failure.
3940 */
3941 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003942 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3944 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945
3946 final long identity = Binder.clearCallingIdentity();
3947 try {
3948 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3949 Boolean success = (Boolean) sendRequest(
3950 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3951 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3952 if (success) {
3953 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3954 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3955 }
3956 return success;
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003959 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003960 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003961
3962 /**
Junda Liu475951f2014-11-07 16:45:03 -08003963 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07003964 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003965 * tethering.
3966 *
3967 * @return 0: Not required. 1: required. 2: Not set.
3968 * @hide
3969 */
3970 @Override
3971 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003972 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973
3974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3977 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07003978 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3980 dunRequired = 1;
3981 }
3982 return dunRequired;
3983 } finally {
3984 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003985 }
Junda Liu475951f2014-11-07 16:45:03 -08003986 }
3987
3988 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003989 * Set mobile data enabled
3990 * Used by the user through settings etc to turn on/off mobile data
3991 *
3992 * @param enable {@code true} turn turn data on, else {@code false}
3993 */
3994 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003995 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3997 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998
3999 final long identity = Binder.clearCallingIdentity();
4000 try {
4001 int phoneId = mSubscriptionController.getPhoneId(subId);
4002 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4003 Phone phone = PhoneFactory.getPhone(phoneId);
4004 if (phone != null) {
4005 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4006 phone.setUserDataEnabled(enable);
4007 } else {
4008 loge("setUserDataEnabled: no phone for subId=" + subId);
4009 }
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004012 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004013 }
4014
4015 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004016 * Get the user enabled state of Mobile Data.
4017 *
4018 * TODO: remove and use isUserDataEnabled.
4019 * This can't be removed now because some vendor codes
4020 * calls through ITelephony directly while they should
4021 * use TelephonyManager.
4022 *
4023 * @return true on enabled
4024 */
4025 @Override
4026 public boolean getDataEnabled(int subId) {
4027 return isUserDataEnabled(subId);
4028 }
4029
4030 /**
4031 * Get whether mobile data is enabled per user setting.
4032 *
4033 * There are other factors deciding whether mobile data is actually enabled, but they are
4034 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004035 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004036 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004037 *
4038 * @return {@code true} if data is enabled else {@code false}
4039 */
4040 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004041 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004042 try {
4043 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4044 null);
4045 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4047 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049
4050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 int phoneId = mSubscriptionController.getPhoneId(subId);
4053 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4054 Phone phone = PhoneFactory.getPhone(phoneId);
4055 if (phone != null) {
4056 boolean retVal = phone.isUserDataEnabled();
4057 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4058 return retVal;
4059 } else {
4060 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4061 return false;
4062 }
4063 } finally {
4064 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004065 }
4066 }
4067
4068 /**
4069 * Get whether mobile data is enabled.
4070 *
4071 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4072 * whether mobile data is actually enabled.
4073 *
4074 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4075 *
4076 * @return {@code true} if data is enabled else {@code false}
4077 */
4078 @Override
4079 public boolean isDataEnabled(int subId) {
4080 try {
4081 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4082 null);
4083 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4085 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087
4088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 int phoneId = mSubscriptionController.getPhoneId(subId);
4091 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4092 Phone phone = PhoneFactory.getPhone(phoneId);
4093 if (phone != null) {
4094 boolean retVal = phone.isDataEnabled();
4095 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4096 return retVal;
4097 } else {
4098 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4099 return false;
4100 }
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004103 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004104 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004105
4106 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004107 public int getCarrierPrivilegeStatus(int subId) {
4108 final Phone phone = getPhone(subId);
4109 if (phone == null) {
4110 loge("getCarrierPrivilegeStatus: Invalid subId");
4111 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4112 }
4113 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004114 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004115 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004116 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4117 }
4118 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004119 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004120 }
Junda Liu29340342014-07-10 15:23:27 -07004121
4122 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004123 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4124 final Phone phone = getPhone(subId);
4125 if (phone == null) {
4126 loge("getCarrierPrivilegeStatus: Invalid subId");
4127 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4128 }
4129 UiccProfile profile =
4130 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4131 if (profile == null) {
4132 loge("getCarrierPrivilegeStatus: No UICC");
4133 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4134 }
4135 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4136 }
4137
4138 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004139 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004140 if (TextUtils.isEmpty(pkgName))
4141 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004142 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004143 if (card == null) {
4144 loge("checkCarrierPrivilegesForPackage: No UICC");
4145 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4146 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004147 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4148 }
4149
4150 @Override
4151 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004152 if (TextUtils.isEmpty(pkgName))
4153 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004154 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4155 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4156 UiccCard card = UiccController.getInstance().getUiccCard(i);
4157 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004158 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004159 continue;
4160 }
4161
4162 result = card.getCarrierPrivilegeStatus(
4163 mPhone.getContext().getPackageManager(), pkgName);
4164 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4165 break;
4166 }
4167 }
4168
4169 return result;
Junda Liu29340342014-07-10 15:23:27 -07004170 }
Derek Tan89e89d42014-07-08 17:00:10 -07004171
4172 @Override
Junda Liue64de782015-04-16 17:19:16 -07004173 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4174 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4175 loge("phoneId " + phoneId + " is not valid.");
4176 return null;
4177 }
4178 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004179 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004180 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004181 return null ;
4182 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004183 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004184 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004185 }
4186
Amith Yamasani6e118872016-02-19 12:53:51 -08004187 @Override
4188 public List<String> getPackagesWithCarrierPrivileges() {
4189 PackageManager pm = mPhone.getContext().getPackageManager();
4190 List<String> privilegedPackages = new ArrayList<>();
4191 List<PackageInfo> packages = null;
4192 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4193 UiccCard card = UiccController.getInstance().getUiccCard(i);
4194 if (card == null) {
4195 // No UICC in that slot.
4196 continue;
4197 }
4198 if (card.hasCarrierPrivilegeRules()) {
4199 if (packages == null) {
4200 // Only check packages in user 0 for now
4201 packages = pm.getInstalledPackagesAsUser(
4202 PackageManager.MATCH_DISABLED_COMPONENTS
4203 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4204 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4205 }
4206 for (int p = packages.size() - 1; p >= 0; p--) {
4207 PackageInfo pkgInfo = packages.get(p);
4208 if (pkgInfo != null && pkgInfo.packageName != null
4209 && card.getCarrierPrivilegeStatus(pkgInfo)
4210 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4211 privilegedPackages.add(pkgInfo.packageName);
4212 }
4213 }
4214 }
4215 }
4216 return privilegedPackages;
4217 }
4218
Wink Savilleb564aae2014-10-23 10:18:09 -07004219 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004220 final Phone phone = getPhone(subId);
4221 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004222 if (card == null) {
4223 loge("getIccId: No UICC");
4224 return null;
4225 }
4226 String iccId = card.getIccId();
4227 if (TextUtils.isEmpty(iccId)) {
4228 loge("getIccId: ICC ID is null or empty.");
4229 return null;
4230 }
4231 return iccId;
4232 }
4233
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004234 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004235 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4236 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004237 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4238 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 final long identity = Binder.clearCallingIdentity();
4241 try {
4242 final String iccId = getIccId(subId);
4243 final Phone phone = getPhone(subId);
4244 if (phone == null) {
4245 return false;
4246 }
4247 final String subscriberId = phone.getSubscriberId();
4248
4249 if (DBG_MERGE) {
4250 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4251 + subscriberId + " to " + number);
4252 }
4253
4254 if (TextUtils.isEmpty(iccId)) {
4255 return false;
4256 }
4257
4258 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4259
4260 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4261 if (alphaTag == null) {
4262 editor.remove(alphaTagPrefKey);
4263 } else {
4264 editor.putString(alphaTagPrefKey, alphaTag);
4265 }
4266
4267 // Record both the line number and IMSI for this ICCID, since we need to
4268 // track all merged IMSIs based on line number
4269 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4270 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4271 if (number == null) {
4272 editor.remove(numberPrefKey);
4273 editor.remove(subscriberPrefKey);
4274 } else {
4275 editor.putString(numberPrefKey, number);
4276 editor.putString(subscriberPrefKey, subscriberId);
4277 }
4278
4279 editor.commit();
4280 return true;
4281 } finally {
4282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004283 }
Derek Tan7226c842014-07-02 17:42:23 -07004284 }
4285
4286 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004287 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004288 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004290 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004291 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004292 return null;
4293 }
Derek Tan97ebb422014-09-05 16:55:38 -07004294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295 final long identity = Binder.clearCallingIdentity();
4296 try {
4297 String iccId = getIccId(subId);
4298 if (iccId != null) {
4299 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4300 if (DBG_MERGE) {
4301 log("getLine1NumberForDisplay returning "
4302 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4303 }
4304 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004306 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4307 return null;
4308 } finally {
4309 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004310 }
Derek Tan7226c842014-07-02 17:42:23 -07004311 }
4312
4313 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004314 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004316 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004317 return null;
4318 }
Derek Tan97ebb422014-09-05 16:55:38 -07004319
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004320 final long identity = Binder.clearCallingIdentity();
4321 try {
4322 String iccId = getIccId(subId);
4323 if (iccId != null) {
4324 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4325 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4326 }
4327 return null;
4328 } finally {
4329 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004330 }
Derek Tan7226c842014-07-02 17:42:23 -07004331 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004332
4333 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004334 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004335 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4336 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004338 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4339 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004340 return null;
4341 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004342
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004343 final long identity = Binder.clearCallingIdentity();
4344 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 final Context context = mPhone.getContext();
4346 final TelephonyManager tele = TelephonyManager.from(context);
4347 final SubscriptionManager sub = SubscriptionManager.from(context);
4348
4349 // Figure out what subscribers are currently active
4350 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4351 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4352 // the process, where TelephonyManager was instantiated.
4353 // Otherwise AppOps check will fail.
4354
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004355 final int[] subIds = sub.getActiveSubscriptionIdList();
4356 for (int subId : subIds) {
4357 activeSubscriberIds.add(tele.getSubscriberId(subId));
4358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359
4360 // First pass, find a number override for an active subscriber
4361 String mergeNumber = null;
4362 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4363 for (String key : prefs.keySet()) {
4364 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4365 final String subscriberId = (String) prefs.get(key);
4366 if (activeSubscriberIds.contains(subscriberId)) {
4367 final String iccId = key.substring(
4368 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4369 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4370 mergeNumber = (String) prefs.get(numberKey);
4371 if (DBG_MERGE) {
4372 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4373 + " for active subscriber " + subscriberId);
4374 }
4375 if (!TextUtils.isEmpty(mergeNumber)) {
4376 break;
4377 }
4378 }
4379 }
4380 }
4381
4382 // Shortcut when no active merged subscribers
4383 if (TextUtils.isEmpty(mergeNumber)) {
4384 return null;
4385 }
4386
4387 // Second pass, find all subscribers under that line override
4388 final ArraySet<String> result = new ArraySet<>();
4389 for (String key : prefs.keySet()) {
4390 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4391 final String number = (String) prefs.get(key);
4392 if (mergeNumber.equals(number)) {
4393 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4394 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4395 final String subscriberId = (String) prefs.get(subscriberKey);
4396 if (!TextUtils.isEmpty(subscriberId)) {
4397 result.add(subscriberId);
4398 }
4399 }
4400 }
4401 }
4402
4403 final String[] resultArray = result.toArray(new String[result.size()]);
4404 Arrays.sort(resultArray);
4405 if (DBG_MERGE) {
4406 Slog.d(LOG_TAG,
4407 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4408 }
4409 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004410 } finally {
4411 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004412 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004413 }
4414
4415 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004416 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004417 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4418 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419
4420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 final Phone phone = getPhone(subId);
4423 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004427 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004428
4429 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004430 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004431 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4432 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004433 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434
4435 final long identity = Binder.clearCallingIdentity();
4436 try {
4437 final Phone phone = getPhone(subId);
4438 if (phone == null) {
4439 return false;
4440 }
4441 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4442 cdmaNonRoamingList);
4443 } finally {
4444 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004445 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004446 }
4447
4448 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004449 @Deprecated
4450 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4451 enforceModifyPermission();
4452
4453 int returnValue = 0;
4454 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004455 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004456 if(result.exception == null) {
4457 if (result.result != null) {
4458 byte[] responseData = (byte[])(result.result);
4459 if(responseData.length > oemResp.length) {
4460 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4461 responseData.length + "bytes. Buffer Size is " +
4462 oemResp.length + "bytes.");
4463 }
4464 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4465 returnValue = responseData.length;
4466 }
4467 } else {
4468 CommandException ex = (CommandException) result.exception;
4469 returnValue = ex.getCommandError().ordinal();
4470 if(returnValue > 0) returnValue *= -1;
4471 }
4472 } catch (RuntimeException e) {
4473 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4474 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4475 if(returnValue > 0) returnValue *= -1;
4476 }
4477
4478 return returnValue;
4479 }
4480
4481 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004482 public void setRadioCapability(RadioAccessFamily[] rafs) {
4483 try {
4484 ProxyController.getInstance().setRadioCapability(rafs);
4485 } catch (RuntimeException e) {
4486 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4487 }
4488 }
4489
4490 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004491 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004492 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004493 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004494 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004495 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497 final long identity = Binder.clearCallingIdentity();
4498 try {
chen xub97461a2018-10-26 14:17:57 -07004499 TelephonyPermissions
4500 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4501 mApp, phone.getSubId(), "getRadioAccessFamily");
4502 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
chen xub97461a2018-10-26 14:17:57 -07004506 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004507 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004508
4509 @Override
4510 public void enableVideoCalling(boolean enable) {
4511 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512
4513 final long identity = Binder.clearCallingIdentity();
4514 try {
4515 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004519 }
4520
4521 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004522 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4524 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4525 return false;
4526 }
Svet Ganovb320e182015-04-16 12:30:10 -07004527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 final long identity = Binder.clearCallingIdentity();
4529 try {
4530 // Check the user preference and the system-level IMS setting. Even if the user has
4531 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4532 // In the long run, we may instead need to check if there exists a connection service
4533 // which can support video calling.
4534 ImsManager imsManager =
4535 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4536 return imsManager.isVtEnabledByPlatform()
4537 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4538 && imsManager.isVtEnabledByUser();
4539 } finally {
4540 Binder.restoreCallingIdentity(identity);
4541 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004542 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004543
Andrew Leea1239f22015-03-02 17:44:07 -08004544 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4547 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4548 return false;
4549 }
4550
4551 final long identity = Binder.clearCallingIdentity();
4552 try {
4553 CarrierConfigManager configManager =
4554 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4555 return configManager.getConfigForSubId(mPhone.getSubId())
4556 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
Andrew Leea1239f22015-03-02 17:44:07 -08004560 }
4561
4562 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563 public boolean isWorldPhone(int subId, String callingPackage) {
4564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4565 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4566 return false;
4567 }
4568
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 CarrierConfigManager configManager =
4572 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4573 return configManager.getConfigForSubId(mPhone.getSubId())
4574 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Andrew Leea1239f22015-03-02 17:44:07 -08004578 }
4579
Andrew Lee9431b832015-03-09 18:46:45 -07004580 @Override
4581 public boolean isTtyModeSupported() {
4582 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004583 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004584 }
4585
4586 @Override
4587 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 final long identity = Binder.clearCallingIdentity();
4589 try {
4590 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4591 } finally {
4592 Binder.restoreCallingIdentity(identity);
4593 }
Andrew Lee9431b832015-03-09 18:46:45 -07004594 }
4595
Hall Liuf6668912018-10-31 17:05:23 -07004596 /**
4597 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4598 * support for the feature and device firmware support.
4599 *
4600 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4601 */
4602 @Override
4603 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4607 mPhone.getSubId()).getBoolean(
4608 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4609 boolean isDeviceSupported =
4610 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4611 return isCarrierSupported && isDeviceSupported;
4612 } finally {
4613 Binder.restoreCallingIdentity(identity);
4614 }
Hall Liu98187582018-01-22 19:15:32 -08004615 }
4616
Hall Liuf6668912018-10-31 17:05:23 -07004617 /**
4618 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4619 * both also support RTT.
4620 */
4621 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622 final long identity = Binder.clearCallingIdentity();
4623 try {
Hall Liuf6668912018-10-31 17:05:23 -07004624 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 mPhone.getContext().getContentResolver(),
4626 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004630 }
4631
Sanket Padawe7310cc72015-01-14 09:53:20 -08004632 /**
4633 * Returns the unique device ID of phone, for example, the IMEI for
4634 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4635 *
4636 * <p>Requires Permission:
4637 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4638 */
4639 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004640 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004641 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004642 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004643 return null;
4644 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004645 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004646 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4647 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004648 return null;
4649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650
4651 final long identity = Binder.clearCallingIdentity();
4652 try {
4653 return phone.getDeviceId();
4654 } finally {
4655 Binder.restoreCallingIdentity(identity);
4656 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004657 }
4658
Ping Sunc67b7c22016-03-02 19:16:45 +08004659 /**
4660 * {@hide}
4661 * Returns the IMS Registration Status on a particular subid
4662 *
4663 * @param subId
4664 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004665 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004666 Phone phone = getPhone(subId);
4667 if (phone != null) {
4668 return phone.isImsRegistered();
4669 } else {
4670 return false;
4671 }
4672 }
4673
Santos Cordon7a1885b2015-02-03 11:15:19 -08004674 @Override
4675 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004676 final long identity = Binder.clearCallingIdentity();
4677 try {
4678 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4679 } finally {
4680 Binder.restoreCallingIdentity(identity);
4681 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004682 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004683
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004684 /**
4685 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004686 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004687 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 final long identity = Binder.clearCallingIdentity();
4689 try {
4690 Phone phone = getPhone(subId);
4691 if (phone != null) {
4692 return phone.isWifiCallingEnabled();
4693 } else {
4694 return false;
4695 }
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004698 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004699 }
4700
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004701 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004702 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004703 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004704 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 Phone phone = getPhone(subId);
4708 if (phone != null) {
4709 return phone.isVideoEnabled();
4710 } else {
4711 return false;
4712 }
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004715 }
4716 }
4717
4718 /**
4719 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4720 * defined in {@link ImsRegistrationImplBase}.
4721 */
4722 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723 final long identity = Binder.clearCallingIdentity();
4724 try {
4725 Phone phone = getPhone(subId);
4726 if (phone != null) {
4727 return phone.getImsRegistrationTech();
4728 } else {
4729 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4730 }
4731 } finally {
4732 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004733 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004734 }
4735
Stuart Scott8eef64f2015-04-08 15:13:54 -07004736 @Override
4737 public void factoryReset(int subId) {
4738 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004739 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4740 return;
4741 }
4742
Svet Ganovcc087f82015-05-12 20:35:54 -07004743 final long identity = Binder.clearCallingIdentity();
4744 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004745 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4746 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004747 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004748 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004749 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4750 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004751 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004752 }
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004755 }
4756 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004757
4758 @Override
4759 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 final long identity = Binder.clearCallingIdentity();
4761 try {
4762 // We query all subscriptions instead of just the active ones, because
4763 // this might be called early on in the provisioning flow when the
4764 // subscriptions potentially aren't active yet.
4765 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4766 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004767 return null;
4768 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004770 // This function may be called very early, say, from the setup wizard, at
4771 // which point we won't have a default subscription set. If that's the case
4772 // we just choose the first, which will be valid in "most cases".
4773 final int defaultSubId = getDefaultSubscription();
4774 SubscriptionInfo info = null;
4775 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4776 info = slist.get(0);
4777 } else {
4778 for (SubscriptionInfo item : slist) {
4779 if (item.getSubscriptionId() == defaultSubId) {
4780 info = item;
4781 break;
4782 }
4783 }
4784
4785 if (info == null) {
4786 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004787 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004788 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 // Try and fetch the locale from the carrier properties or from the SIM language
4791 // preferences (EF-PL and EF-LI)...
4792 final int mcc = info.getMcc();
4793 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4794 String simLanguage = null;
4795 if (defaultPhone != null) {
4796 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4797 if (localeFromDefaultSim != null) {
4798 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4799 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4800 return localeFromDefaultSim.toLanguageTag();
4801 } else {
4802 simLanguage = localeFromDefaultSim.getLanguage();
4803 }
4804 }
4805 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004806
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807 // The SIM language preferences only store a language (e.g. fr = French), not an
4808 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4809 // the SIM and carrier preferences does not include a country we add the country
4810 // determined from the SIM MCC to provide an exact locale.
4811 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4812 simLanguage);
4813 if (mccLocale != null) {
4814 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4815 return mccLocale.toLanguageTag();
4816 }
4817
4818 if (DBG) log("No locale found - returning null");
4819 return null;
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004823 }
4824
4825 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826 return mSubscriptionController.getAllSubInfoList(
4827 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004828 }
4829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830 /**
4831 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4832 */
4833 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4834 return mSubscriptionController.getActiveSubscriptionInfoList(
4835 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004836 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004837
Chenjie Yu1ba97252018-01-11 18:16:20 -08004838 private final ModemActivityInfo mLastModemActivityInfo =
4839 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4840
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004841 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004842 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4843 * representing the state of the modem.
4844 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004845 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4846 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004847 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004848 */
4849 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004850 public void requestModemActivityInfo(ResultReceiver result) {
4851 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004852 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853
4854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 ModemActivityInfo ret = null;
4857 synchronized (mLastModemActivityInfo) {
4858 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4859 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004860 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004861 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4863 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4864 mergedTxTimeMs[i] =
4865 info.getTxTimeMillis()[i]
4866 + mLastModemActivityInfo.getTxTimeMillis()[i];
4867 }
4868 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4869 mLastModemActivityInfo.setSleepTimeMillis(
4870 info.getSleepTimeMillis()
4871 + mLastModemActivityInfo.getSleepTimeMillis());
4872 mLastModemActivityInfo.setIdleTimeMillis(
4873 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4874 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4875 mLastModemActivityInfo.setRxTimeMillis(
4876 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4877 mLastModemActivityInfo.setEnergyUsed(
4878 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4881 mLastModemActivityInfo.getSleepTimeMillis(),
4882 mLastModemActivityInfo.getIdleTimeMillis(),
4883 mLastModemActivityInfo.getTxTimeMillis(),
4884 mLastModemActivityInfo.getRxTimeMillis(),
4885 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004886 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 Bundle bundle = new Bundle();
4888 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4889 result.send(0, bundle);
4890 } finally {
4891 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004892 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004893 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004894
Siddharth Rayb8114062018-06-17 15:02:38 -07004895 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4896 // less than total activity duration.
4897 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4898 if (info == null) {
4899 return false;
4900 }
4901 int activityDurationMs =
4902 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4903 int totalTxTimeMs = 0;
4904 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4905 totalTxTimeMs += info.getTxTimeMillis()[i];
4906 }
4907 return (info.isValid()
4908 && (info.getSleepTimeMillis() <= activityDurationMs)
4909 && (info.getIdleTimeMillis() <= activityDurationMs)
4910 && (info.getRxTimeMillis() <= activityDurationMs)
4911 && (totalTxTimeMs <= activityDurationMs));
4912 }
4913
Jack Yu85bd38a2015-11-09 11:34:32 -08004914 /**
4915 * {@hide}
4916 * Returns the service state information on specified subscription.
4917 */
4918 @Override
4919 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004921 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004922 return null;
4923 }
4924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 final long identity = Binder.clearCallingIdentity();
4926 try {
4927 final Phone phone = getPhone(subId);
4928 if (phone == null) {
4929 return null;
4930 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 return phone.getServiceState();
4933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004936 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004937
4938 /**
4939 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4940 *
4941 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4942 * voicemail ringtone.
4943 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4944 * PhoneAccount.
4945 */
4946 @Override
4947 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 final long identity = Binder.clearCallingIdentity();
4949 try {
4950 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4951 if (phone == null) {
4952 phone = mPhone;
4953 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004955 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4956 } finally {
4957 Binder.restoreCallingIdentity(identity);
4958 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004959 }
4960
4961 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004962 * Sets the per-account voicemail ringtone.
4963 *
4964 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4965 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4966 *
4967 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4968 * voicemail ringtone.
4969 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4970 * PhoneAccount.
4971 */
4972 @Override
4973 public void setVoicemailRingtoneUri(String callingPackage,
4974 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4975 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4976 if (!TextUtils.equals(callingPackage,
4977 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4979 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4980 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982
4983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4986 if (phone == null) {
4987 phone = mPhone;
4988 }
4989 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004992 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004993 }
4994
4995 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004996 * Returns whether vibration is set for voicemail notification in Phone settings.
4997 *
4998 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4999 * voicemail vibration setting.
5000 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5001 */
5002 @Override
5003 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 final long identity = Binder.clearCallingIdentity();
5005 try {
5006 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5007 if (phone == null) {
5008 phone = mPhone;
5009 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005015 }
5016
Youhan Wange64578a2016-05-02 15:32:42 -07005017 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005018 * Sets the per-account voicemail vibration.
5019 *
5020 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5021 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5022 *
5023 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5024 * voicemail vibration setting.
5025 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5026 * specific PhoneAccount.
5027 */
5028 @Override
5029 public void setVoicemailVibrationEnabled(String callingPackage,
5030 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5032 if (!TextUtils.equals(callingPackage,
5033 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5035 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5036 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005037 }
5038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 final long identity = Binder.clearCallingIdentity();
5040 try {
5041 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5042 if (phone == null) {
5043 phone = mPhone;
5044 }
5045 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5046 } finally {
5047 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005048 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005049 }
5050
5051 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005052 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5053 *
5054 * @throws SecurityException if the caller does not have the required permission
5055 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005056 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005057 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005058 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005059 }
5060
5061 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005062 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5063 * permission.
5064 *
5065 * @throws SecurityException if the caller does not have the required permission
5066 */
5067 private void enforceSendSmsPermission() {
5068 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5069 }
5070
5071 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005072 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005073 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005074 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005075 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005076 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 ComponentName componentName =
5080 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5081 if (componentName == null) {
5082 throw new SecurityException(
5083 "Caller not current active visual voicemail package[null]");
5084 }
5085 String vvmPackage = componentName.getPackageName();
5086 if (!callingPackage.equals(vvmPackage)) {
5087 throw new SecurityException("Caller not current active visual voicemail package["
5088 + vvmPackage + "]");
5089 }
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005092 }
5093 }
5094
5095 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005096 * Return the application ID for the app type.
5097 *
5098 * @param subId the subscription ID that this request applies to.
5099 * @param appType the uicc app type.
5100 * @return Application ID for specificied app type, or null if no uicc.
5101 */
5102 @Override
5103 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005104 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005105 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106
5107 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005108 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 if (phone == null) {
5110 return null;
5111 }
5112 String aid = null;
5113 try {
5114 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5115 .getApplicationByType(appType).getAid();
5116 } catch (Exception e) {
5117 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5118 }
5119 return aid;
5120 } finally {
5121 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005122 }
Youhan Wange64578a2016-05-02 15:32:42 -07005123 }
5124
Youhan Wang4001d252016-05-11 10:29:41 -07005125 /**
5126 * Return the Electronic Serial Number.
5127 *
5128 * @param subId the subscription ID that this request applies to.
5129 * @return ESN or null if error.
5130 */
5131 @Override
5132 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005133 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005134 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135
5136 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005137 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 if (phone == null) {
5139 return null;
5140 }
5141 String esn = null;
5142 try {
5143 esn = phone.getEsn();
5144 } catch (Exception e) {
5145 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5146 }
5147 return esn;
5148 } finally {
5149 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005150 }
Youhan Wang4001d252016-05-11 10:29:41 -07005151 }
5152
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005153 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005154 * Return the Preferred Roaming List Version.
5155 *
5156 * @param subId the subscription ID that this request applies to.
5157 * @return PRLVersion or null if error.
5158 */
5159 @Override
5160 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005161 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005162 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163
5164 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005165 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 if (phone == null) {
5167 return null;
5168 }
5169 String cdmaPrlVersion = null;
5170 try {
5171 cdmaPrlVersion = phone.getCdmaPrlVersion();
5172 } catch (Exception e) {
5173 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5174 }
5175 return cdmaPrlVersion;
5176 } finally {
5177 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005178 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005179 }
5180
5181 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005182 * Get snapshot of Telephony histograms
5183 * @return List of Telephony histograms
5184 * @hide
5185 */
5186 @Override
5187 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5189 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190
5191 final long identity = Binder.clearCallingIdentity();
5192 try {
5193 return RIL.getTelephonyRILTimingHistograms();
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
5196 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005197 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005198
5199 /**
5200 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005201 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005202 * Require system privileges. In the future we may add this to carrier APIs.
5203 *
5204 * @return The number of carriers set successfully, should match length of carriers
5205 */
5206 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005207 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005208 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005210
Meng Wang9b7c4e92017-02-17 11:41:27 -08005211 if (carriers == null) {
5212 throw new NullPointerException("carriers cannot be null");
5213 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 final long identity = Binder.clearCallingIdentity();
5216 try {
5217 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005218 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5219 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 return retVal[0];
5221 } finally {
5222 Binder.restoreCallingIdentity(identity);
5223 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005224 }
5225
5226 /**
5227 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005228 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005229 * Require system privileges. In the future we may add this to carrier APIs.
5230 *
5231 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5232 * means all carriers are allowed.
5233 */
5234 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005235 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005236 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005237 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238
5239 final long identity = Binder.clearCallingIdentity();
5240 try {
5241 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005242 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5243 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005247 }
5248
fionaxu59545b42016-05-25 15:53:37 -07005249 /**
5250 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5251 * @param subId the subscription ID that this action applies to.
5252 * @param enabled control enable or disable metered apns.
5253 * {@hide}
5254 */
5255 @Override
5256 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5257 enforceModifyPermission();
5258 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259
5260 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005261 if (phone == null) {
5262 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5263 return;
5264 }
5265 try {
5266 phone.carrierActionSetMeteredApnsEnabled(enabled);
5267 } catch (Exception e) {
5268 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 } finally {
5270 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005271 }
5272 }
5273
5274 /**
5275 * Action set from carrier signalling broadcast receivers to enable/disable radio
5276 * @param subId the subscription ID that this action applies to.
5277 * @param enabled control enable or disable radio.
5278 * {@hide}
5279 */
5280 @Override
5281 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5282 enforceModifyPermission();
5283 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284
5285 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005286 if (phone == null) {
5287 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5288 return;
5289 }
5290 try {
5291 phone.carrierActionSetRadioEnabled(enabled);
5292 } catch (Exception e) {
5293 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 } finally {
5295 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005296 }
5297 }
5298
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005299 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005300 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5301 * network status based on which carrier apps could apply actions accordingly,
5302 * enable/disable default url handler for example.
5303 *
5304 * @param subId the subscription ID that this action applies to.
5305 * @param report control start/stop reporting the default network status.
5306 * {@hide}
5307 */
5308 @Override
5309 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5310 enforceModifyPermission();
5311 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312
5313 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005314 if (phone == null) {
5315 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5316 return;
5317 }
5318 try {
5319 phone.carrierActionReportDefaultNetworkStatus(report);
5320 } catch (Exception e) {
5321 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 } finally {
5323 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005324 }
5325 }
5326
5327 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005328 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5329 * bug report is being generated.
5330 */
5331 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005332 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005333 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5334 != PackageManager.PERMISSION_GRANTED) {
5335 writer.println("Permission Denial: can't dump Phone from pid="
5336 + Binder.getCallingPid()
5337 + ", uid=" + Binder.getCallingUid()
5338 + "without permission "
5339 + android.Manifest.permission.DUMP);
5340 return;
5341 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005342 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005343 }
Jack Yueb89b242016-06-22 13:27:47 -07005344
Brad Ebingerdac2f002018-04-03 15:17:52 -07005345 @Override
5346 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5347 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5348 throws RemoteException {
5349 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5350 }
5351
Jack Yueb89b242016-06-22 13:27:47 -07005352 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005353 * Get aggregated video call data usage since boot.
5354 *
5355 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5356 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005357 * {@hide}
5358 */
5359 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005360 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005361 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5362 null);
5363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 final long identity = Binder.clearCallingIdentity();
5365 try {
5366 // NetworkStatsService keeps tracking the active network interface and identity. It
5367 // records the delta with the corresponding network identity.
5368 // We just return the total video call data usage snapshot since boot.
5369 Phone phone = getPhone(subId);
5370 if (phone != null) {
5371 return phone.getVtDataUsage(perUidStats);
5372 }
5373 return null;
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005376 }
Jack Yueb89b242016-06-22 13:27:47 -07005377 }
Jack Yu75ab2952016-07-08 14:29:33 -07005378
5379 /**
5380 * Policy control of data connection. Usually used when data limit is passed.
5381 * @param enabled True if enabling the data, otherwise disabling.
5382 * @param subId Subscription index
5383 * {@hide}
5384 */
5385 @Override
5386 public void setPolicyDataEnabled(boolean enabled, int subId) {
5387 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388
5389 final long identity = Binder.clearCallingIdentity();
5390 try {
5391 Phone phone = getPhone(subId);
5392 if (phone != null) {
5393 phone.setPolicyDataEnabled(enabled);
5394 }
5395 } finally {
5396 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005397 }
5398 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005399
5400 /**
5401 * Get Client request stats
5402 * @return List of Client Request Stats
5403 * @hide
5404 */
5405 @Override
5406 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005408 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005409 return null;
5410 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005411 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 final long identity = Binder.clearCallingIdentity();
5414 try {
5415 if (phone != null) {
5416 return phone.getClientRequestStats();
5417 }
5418
5419 return null;
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005423 }
5424
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005425 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005426 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005427 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005428 }
Jack Yueb4124c2017-02-16 15:32:43 -08005429
5430 /**
Grace Chen70990072017-03-24 17:21:30 -07005431 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005432 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005433 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005434 * @param state State of SIM (power down, power up, pass through)
5435 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5436 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5437 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005438 *
5439 **/
5440 @Override
Grace Chen70990072017-03-24 17:21:30 -07005441 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005442 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005443 Phone phone = PhoneFactory.getPhone(slotIndex);
5444
vagdeviaf9a5b92018-08-15 16:01:53 -07005445 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 final long identity = Binder.clearCallingIdentity();
5448 try {
5449 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005450 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451 }
5452 } finally {
5453 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005454 }
5455 }
Shuo Qiandd210312017-04-12 22:11:33 +00005456
Tyler Gunn65d45c22017-06-05 11:22:26 -07005457 private boolean isUssdApiAllowed(int subId) {
5458 CarrierConfigManager configManager =
5459 (CarrierConfigManager) mPhone.getContext().getSystemService(
5460 Context.CARRIER_CONFIG_SERVICE);
5461 if (configManager == null) {
5462 return false;
5463 }
5464 PersistableBundle pb = configManager.getConfigForSubId(subId);
5465 if (pb == null) {
5466 return false;
5467 }
5468 return pb.getBoolean(
5469 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5470 }
5471
Shuo Qiandd210312017-04-12 22:11:33 +00005472 /**
5473 * Check if phone is in emergency callback mode
5474 * @return true if phone is in emergency callback mode
5475 * @param subId sub id
5476 */
goneil9c5f4872017-12-05 14:07:56 -08005477 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005478 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005479 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005480 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481
5482 final long identity = Binder.clearCallingIdentity();
5483 try {
5484 if (phone != null) {
5485 return phone.isInEcm();
5486 } else {
5487 return false;
5488 }
5489 } finally {
5490 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005491 }
5492 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005493
5494 /**
5495 * Get the current signal strength information for the given subscription.
5496 * Because this information is not updated when the device is in a low power state
5497 * it should not be relied-upon to be current.
5498 * @param subId Subscription index
5499 * @return the most recent cached signal strength info from the modem
5500 */
5501 @Override
5502 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503 final long identity = Binder.clearCallingIdentity();
5504 try {
5505 Phone p = getPhone(subId);
5506 if (p == null) {
5507 return null;
5508 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 return p.getSignalStrength();
5511 } finally {
5512 Binder.restoreCallingIdentity(identity);
5513 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005514 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005515
Pengquan Meng77b7f132018-08-22 14:49:57 -07005516 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005517 * Get the current modem radio state for the given slot.
5518 * @param slotIndex slot index.
5519 * @param callingPackage the name of the package making the call.
5520 * @return the current radio power state from the modem
5521 */
5522 @Override
5523 public int getRadioPowerState(int slotIndex, String callingPackage) {
5524 Phone phone = PhoneFactory.getPhone(slotIndex);
5525 if (phone != null) {
5526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5527 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5528 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5529 }
5530
5531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 return phone.getRadioPowerState();
5534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
5537 }
5538 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5539 }
5540
5541 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005542 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5543 *
5544 * <p>Requires one of the following permissions:
5545 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5546 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5547 * privileges.
5548 *
5549 * @param subId subscription id
5550 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5551 * {@code false}.
5552 */
5553 @Override
5554 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005555 boolean isEnabled = false;
5556 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005557 try {
5558 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005559 null /* message */);
5560 Phone phone = getPhone(subId);
5561 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005562 } catch (Exception e) {
5563 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5564 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005565 } finally {
5566 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005568 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005569 }
5570
5571
5572 /**
5573 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5574 *
5575 * <p> Requires permission:
5576 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5577 * privileges.
5578 *
5579 * @param subId subscription id
5580 * @param isEnabled {@code true} means enable, {@code false} means disable.
5581 */
5582 @Override
5583 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005584 final long identity = Binder.clearCallingIdentity();
5585 try {
5586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5587 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005588
Pengquan Menga1bb6272018-09-06 09:59:22 -07005589 Phone phone = getPhone(subId);
5590 if (phone != null) {
5591 phone.setDataRoamingEnabled(isEnabled);
5592 }
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005595 }
5596 }
5597
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005598 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005599 public boolean isManualNetworkSelectionAllowed(int subId) {
5600 boolean isAllowed = true;
5601 final long identity = Binder.clearCallingIdentity();
5602 try {
5603 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5604 mApp, subId, "isManualNetworkSelectionAllowed");
5605 Phone phone = getPhone(subId);
5606 if (phone != null) {
5607 isAllowed = phone.isCspPlmnEnabled();
5608 }
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
5611 }
5612 return isAllowed;
5613 }
5614
5615 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005616 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005617 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5622 if (slots == null) {
5623 Rlog.i(LOG_TAG, "slots is null.");
5624 return null;
5625 }
5626
5627 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5628 for (int i = 0; i < slots.length; i++) {
5629 UiccSlot slot = slots[i];
5630 if (slot == null) {
5631 continue;
5632 }
5633
5634 String cardId;
5635 UiccCard card = slot.getUiccCard();
5636 if (card != null) {
5637 cardId = card.getCardId();
5638 } else {
5639 cardId = slot.getIccId();
5640 }
5641
5642 int cardState = 0;
5643 switch (slot.getCardState()) {
5644 case CARDSTATE_ABSENT:
5645 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5646 break;
5647 case CARDSTATE_PRESENT:
5648 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5649 break;
5650 case CARDSTATE_ERROR:
5651 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5652 break;
5653 case CARDSTATE_RESTRICTED:
5654 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5655 break;
5656 default:
5657 break;
5658
5659 }
5660
5661 infos[i] = new UiccSlotInfo(
5662 slot.isActive(),
5663 slot.isEuicc(),
5664 cardId,
5665 cardState,
5666 slot.getPhoneId(),
5667 slot.isExtendedApduSupported());
5668 }
5669 return infos;
5670 } finally {
5671 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005672 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005673 }
5674
5675 @Override
5676 public boolean switchSlots(int[] physicalSlots) {
5677 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678
5679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005685 }
Jack Yu4c988042018-02-27 15:30:01 -08005686
5687 @Override
5688 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5689 enforceModifyPermission();
5690 final Phone phone = getPhone(subId);
5691 if (phone == null) {
5692 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5693 return;
5694 }
5695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 final long identity = Binder.clearCallingIdentity();
5697 try {
5698 phone.setRadioIndicationUpdateMode(filters, mode);
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
Jack Yu4c988042018-02-27 15:30:01 -08005702 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005703
5704 /**
goneil47ffb6e2018-04-06 15:40:58 -07005705 * A test API to reload the UICC profile.
5706 *
5707 * <p>Requires that the calling app has permission
5708 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5709 * @hide
5710 */
5711 @Override
5712 public void refreshUiccProfile(int subId) {
5713 enforceModifyPermission();
5714
5715 final long identity = Binder.clearCallingIdentity();
5716 try {
5717 Phone phone = getPhone(subId);
5718 if (phone == null) {
5719 return;
5720 }
5721 UiccCard uiccCard = phone.getUiccCard();
5722 if (uiccCard == null) {
5723 return;
5724 }
5725 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5726 if (uiccProfile == null) {
5727 return;
5728 }
5729 uiccProfile.refresh();
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
5733 }
5734
5735 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005736 * Returns false if the mobile data is disabled by default, otherwise return true.
5737 */
5738 private boolean getDefaultDataEnabled() {
5739 return "true".equalsIgnoreCase(
5740 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5741 }
5742
5743 /**
5744 * Returns true if the data roaming is enabled by default, i.e the system property
5745 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5746 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5747 */
5748 private boolean getDefaultDataRoamingEnabled(int subId) {
5749 final CarrierConfigManager configMgr = (CarrierConfigManager)
5750 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5751 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5752 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5753 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5754 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5755 return isDataRoamingEnabled;
5756 }
5757
5758 /**
5759 * Returns the default network type for the given {@code subId}, if the default network type is
5760 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5761 */
5762 private int getDefaultNetworkType(int subId) {
5763 return Integer.parseInt(
5764 TelephonyManager.getTelephonyProperty(
5765 mSubscriptionController.getPhoneId(subId),
5766 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5767 String.valueOf(Phone.PREFERRED_NT_MODE)));
5768 }
fionaxua13278b2018-03-21 00:08:13 -07005769
5770 @Override
5771 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5772 gid1, String gid2, String plmn, String spn) {
5773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 final Phone phone = getPhone(subId);
5778 if (phone == null) {
5779 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5780 return;
5781 }
5782 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5783 } finally {
5784 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005785 }
fionaxua13278b2018-03-21 00:08:13 -07005786 }
5787
5788 @Override
5789 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005790 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791
5792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 final Phone phone = getPhone(subId);
5795 if (phone == null) {
5796 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5797 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5798 }
5799 return phone.getCarrierIdListVersion();
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005802 }
fionaxua13278b2018-03-21 00:08:13 -07005803 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005804
5805 @Override
5806 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5808 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5809 return -1;
5810 }
5811
5812 final long identity = Binder.clearCallingIdentity();
5813 try {
5814 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
5818 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005819
5820 @Override
5821 public int getCdmaRoamingMode(int subId) {
5822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5823 mApp, subId, "getCdmaRoamingMode");
5824
5825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
5830 }
5831 }
5832
5833 @Override
5834 public boolean setCdmaRoamingMode(int subId, int mode) {
5835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5836 mApp, subId, "setCdmaRoamingMode");
5837
5838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
5844 }
5845
5846 @Override
5847 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5849 mApp, subId, "setCdmaSubscriptionMode");
5850
5851 final long identity = Binder.clearCallingIdentity();
5852 try {
5853 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5854 } finally {
5855 Binder.restoreCallingIdentity(identity);
5856 }
5857 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005858
5859 private void ensureUserRunning(int userId) {
5860 if (!mUserManager.isUserRunning(userId)) {
5861 throw new IllegalStateException("User " + userId + " does not exist or not running");
5862 }
5863 }
5864
5865 /**
5866 * Returns a list of SMS apps on a given user.
5867 *
5868 * Only the shell user (UID 2000 or 0) can call it.
5869 * Target user must be running.
5870 */
5871 @Override
5872 public String[] getSmsApps(int userId) {
5873 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5874 ensureUserRunning(userId);
5875
5876 final Collection<SmsApplicationData> apps =
5877 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5878
5879 String[] ret = new String[apps.size()];
5880 int i = 0;
5881 for (SmsApplicationData app : apps) {
5882 ret[i++] = app.mPackageName;
5883 }
5884 return ret;
5885 }
5886
5887 /**
5888 * Returns the default SMS app package name on a given user.
5889 *
5890 * Only the shell user (UID 2000 or 0) can call it.
5891 * Target user must be running.
5892 */
5893 @Override
5894 public String getDefaultSmsApp(int userId) {
5895 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5896 ensureUserRunning(userId);
5897
5898 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5899 /* updateIfNeeded= */ true, userId);
5900 return cn == null ? null : cn.getPackageName();
5901 }
5902
5903 /**
5904 * Set a package as the default SMS app on a given user.
5905 *
5906 * Only the shell user (UID 2000 or 0) can call it.
5907 * Target user must be running.
5908 */
5909 @Override
5910 public void setDefaultSmsApp(int userId, String packageName) {
5911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5912 ensureUserRunning(userId);
5913
5914 boolean found = false;
5915 for (String pkg : getSmsApps(userId)) {
5916 if (TextUtils.equals(packageName, pkg)) {
5917 found = true;
5918 break;
5919 }
5920 }
5921 if (!found) {
5922 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5923 }
5924
5925 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5926 }
sqianc5eccab2018-10-19 18:46:41 -07005927
5928 @Override
5929 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5930 String callingPackage) {
5931 // TODO connect with internal content
5932 return null;
5933 }
5934
5935 @Override
5936 public boolean isCurrentEmergencyNumber(String number) {
5937 // TODO connect with internal content
5938 return false;
5939 }
chen xud6b45bd2018-10-30 22:27:10 -07005940
5941 @Override
5942 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5943 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5944 Phone phone = getPhone(subId);
5945 if (phone == null) {
5946 return null;
5947 }
5948 final long identity = Binder.clearCallingIdentity();
5949 try {
5950 UiccProfile profile = UiccController.getInstance()
5951 .getUiccProfileForPhone(phone.getPhoneId());
5952 if (profile != null) {
5953 return profile.getCertsFromCarrierPrivilegeAccessRules();
5954 }
5955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
5958 return null;
5959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005960}