blob: ce805ed0b88f200e70acbcc299f6848f3010b1a9 [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;
sqianc5eccab2018-10-19 18:46:41 -070057import android.telephony.emergency.EmergencyNumber;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070060import android.telephony.CellInfoGsm;
61import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070062import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070063import android.telephony.ClientRequestStats;
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;
82import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070083import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080084import android.telephony.ims.aidl.IImsConfig;
85import android.telephony.ims.aidl.IImsMmTelFeature;
86import android.telephony.ims.aidl.IImsRcsFeature;
87import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070088import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080089import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080095
Brad Ebinger35c841c2018-10-01 10:40:55 -070096import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070097import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080098import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070099import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700100import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700101import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700102import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700103import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800106import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700107import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100108import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700109import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700112import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800113import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700114import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700115import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700116import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700117import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700118import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700119import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700120import com.android.internal.telephony.SmsApplication;
121import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800122import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800123import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700124import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.uicc.IccIoResult;
126import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800127import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700128import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800129import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800131import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000132import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700133import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700135import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800136import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700137import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700138import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800139
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700140import java.io.FileDescriptor;
141import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800144import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700145import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800146import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100147import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800148import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149
150/**
151 * Implementation of the ITelephony interface.
152 */
Santos Cordon117fee72014-05-16 17:56:12 -0700153public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154 private static final String LOG_TAG = "PhoneInterfaceManager";
155 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
156 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800157 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158
159 // Message codes used with mMainThreadHandler
160 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700161 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
162 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163 private static final int CMD_OPEN_CHANNEL = 9;
164 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
165 private static final int CMD_CLOSE_CHANNEL = 11;
166 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800167 private static final int CMD_NV_READ_ITEM = 13;
168 private static final int EVENT_NV_READ_ITEM_DONE = 14;
169 private static final int CMD_NV_WRITE_ITEM = 15;
170 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
171 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
172 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700173 private static final int CMD_RESET_MODEM_CONFIG = 19;
174 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800175 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
176 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
177 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
178 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800179 private static final int CMD_SEND_ENVELOPE = 25;
180 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000181 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
182 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700183 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
184 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
185 private static final int CMD_EXCHANGE_SIM_IO = 31;
186 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800187 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
188 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700189 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
190 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700191 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
192 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700193 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
194 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
195 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
196 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700197 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
198 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
199 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
200 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700201 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
203 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000204 private static final int CMD_SWITCH_SLOTS = 50;
205 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700206 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
207 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
208 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
209 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
210 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
211 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
212 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
213 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700214 private static final int CMD_GET_ALL_CELL_INFO = 60;
215 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
216 private static final int CMD_GET_CELL_LOCATION = 62;
217 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700218 private static final int CMD_MODEM_REBOOT = 64;
219 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800221 // Parameters of select command.
222 private static final int SELECT_COMMAND = 0xA4;
223 private static final int SELECT_P1 = 0x04;
224 private static final int SELECT_P2 = 0;
225 private static final int SELECT_P3 = 0x10;
226
Pengquan Meng85728fb2018-03-12 16:31:21 -0700227 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
228 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
229 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
230
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 /** The singleton instance. */
232 private static PhoneInterfaceManager sInstance;
233
Wink Saville3ab207e2014-11-20 13:07:20 -0800234 private PhoneGlobals mApp;
235 private Phone mPhone;
236 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700237 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800238 private AppOpsManager mAppOps;
239 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800240 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800241 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700242 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243
Derek Tan97ebb422014-09-05 16:55:38 -0700244 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
245 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800246 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700247
Derek Tan740e1672017-06-27 14:56:27 -0700248 // The AID of ISD-R.
249 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
250
yinxub1bed742017-04-17 11:45:04 -0700251 private NetworkScanRequestTracker mNetworkScanRequestTracker;
252
David Kelly5e06a7f2018-03-12 14:10:59 +0000253 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
254 private static final int MANUFACTURER_CODE_LENGTH = 8;
255
Derek Tan89e89d42014-07-08 17:00:10 -0700256 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700257 * A request object to use for transmitting data to an ICC.
258 */
259 private static final class IccAPDUArgument {
260 public int channel, cla, command, p1, p2, p3;
261 public String data;
262
263 public IccAPDUArgument(int channel, int cla, int command,
264 int p1, int p2, int p3, String data) {
265 this.channel = channel;
266 this.cla = cla;
267 this.command = command;
268 this.p1 = p1;
269 this.p2 = p2;
270 this.p3 = p3;
271 this.data = data;
272 }
273 }
274
275 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700276 * A request object to use for transmitting data to an ICC.
277 */
278 private static final class ManualNetworkSelectionArgument {
279 public OperatorInfo operatorInfo;
280 public boolean persistSelection;
281
282 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
283 this.operatorInfo = operatorInfo;
284 this.persistSelection = persistSelection;
285 }
286 }
287
288 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
290 * request after sending. The main thread will notify the request when it is complete.
291 */
292 private static final class MainThreadRequest {
293 /** The argument to use for the request */
294 public Object argument;
295 /** The result of the request that is run on the main thread */
296 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800297 // The subscriber id that this request applies to. Defaults to
298 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
299 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
Nathan Harold92bed182018-10-12 18:16:49 -0700301 // In cases where subId is unavailable, the caller needs to specify the phone.
302 public Phone phone;
303
vagdeviaf9a5b92018-08-15 16:01:53 -0700304 public WorkSource workSource;
305
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306 public MainThreadRequest(Object argument) {
307 this.argument = argument;
308 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800309
Nathan Harold92bed182018-10-12 18:16:49 -0700310 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
311 this.argument = argument;
312 if (phone != null) {
313 this.phone = phone;
314 }
315 this.workSource = workSource;
316 }
317
vagdeviaf9a5b92018-08-15 16:01:53 -0700318 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800319 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800320 if (subId != null) {
321 this.subId = subId;
322 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700323 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 }
326
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800327 private static final class IncomingThirdPartyCallArgs {
328 public final ComponentName component;
329 public final String callId;
330 public final String callerDisplayName;
331
332 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
333 String callerDisplayName) {
334 this.component = component;
335 this.callId = callId;
336 this.callerDisplayName = callerDisplayName;
337 }
338 }
339
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340 /**
341 * A handler that processes messages on the main thread in the phone process. Since many
342 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
343 * inbound binder threads to the main thread in the phone process. The Binder thread
344 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
345 * on, which will be notified when the operation completes and will contain the result of the
346 * request.
347 *
348 * <p>If a MainThreadRequest object is provided in the msg.obj field,
349 * note that request.result must be set to something non-null for the calling thread to
350 * unblock.
351 */
352 private final class MainThreadHandler extends Handler {
353 @Override
354 public void handleMessage(Message msg) {
355 MainThreadRequest request;
356 Message onCompleted;
357 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800358 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700359 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
361 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700362 case CMD_HANDLE_USSD_REQUEST: {
363 request = (MainThreadRequest) msg.obj;
364 final Phone phone = getPhoneFromRequest(request);
365 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
366 String ussdRequest = ussdObject.first;
367 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700368
Pengquan Menga1bb6272018-09-06 09:59:22 -0700369 if (!isUssdApiAllowed(request.subId)) {
370 // Carrier does not support use of this API, return failure.
371 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
372 UssdResponse response = new UssdResponse(ussdRequest, null);
373 Bundle returnData = new Bundle();
374 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
375 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700376
Pengquan Menga1bb6272018-09-06 09:59:22 -0700377 request.result = true;
378 notifyRequester(request);
379 return;
380 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700381
Pengquan Menga1bb6272018-09-06 09:59:22 -0700382 try {
383 request.result = phone != null
384 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
385 } catch (CallStateException cse) {
386 request.result = false;
387 }
388 // Wake up the requesting thread
389 notifyRequester(request);
390 break;
pkanwar32d516d2016-10-14 19:37:38 -0700391 }
392
Yorke Lee716f67e2015-06-17 15:39:16 -0700393 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700395 final Phone phone = getPhoneFromRequest(request);
396 request.result = phone != null ?
397 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
398 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700400 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700406 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800407 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700408 if (uiccCard == null) {
409 loge("iccTransmitApduLogicalChannel: No UICC");
410 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700412 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
414 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700415 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 iccArgument.channel, iccArgument.cla, iccArgument.command,
417 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700419 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700420 break;
421
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 ar = (AsyncResult) msg.obj;
424 request = (MainThreadRequest) ar.userObj;
425 if (ar.exception == null && ar.result != null) {
426 request.result = ar.result;
427 } else {
428 request.result = new IccIoResult(0x6F, 0, (byte[])null);
429 if (ar.result == null) {
430 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800431 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800433 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 } else {
435 loge("iccTransmitApduLogicalChannel: Unknown exception");
436 }
437 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 break;
440
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
442 request = (MainThreadRequest) msg.obj;
443 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800444 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 if (uiccCard == null) {
446 loge("iccTransmitApduBasicChannel: No UICC");
447 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700448 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 } else {
450 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
451 request);
452 uiccCard.iccTransmitApduBasicChannel(
453 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
454 iccArgument.p3, iccArgument.data, onCompleted);
455 }
456 break;
457
458 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
459 ar = (AsyncResult) msg.obj;
460 request = (MainThreadRequest) ar.userObj;
461 if (ar.exception == null && ar.result != null) {
462 request.result = ar.result;
463 } else {
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
465 if (ar.result == null) {
466 loge("iccTransmitApduBasicChannel: Empty response");
467 } else if (ar.exception instanceof CommandException) {
468 loge("iccTransmitApduBasicChannel: CommandException: " +
469 ar.exception);
470 } else {
471 loge("iccTransmitApduBasicChannel: Unknown exception");
472 }
473 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700474 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 break;
476
477 case CMD_EXCHANGE_SIM_IO:
478 request = (MainThreadRequest) msg.obj;
479 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800480 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 if (uiccCard == null) {
482 loge("iccExchangeSimIO: No UICC");
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 } else {
486 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
487 request);
488 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
489 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
490 iccArgument.data, onCompleted);
491 }
492 break;
493
494 case EVENT_EXCHANGE_SIM_IO_DONE:
495 ar = (AsyncResult) msg.obj;
496 request = (MainThreadRequest) ar.userObj;
497 if (ar.exception == null && ar.result != null) {
498 request.result = ar.result;
499 } else {
500 request.result = new IccIoResult(0x6f, 0, (byte[])null);
501 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 break;
504
Derek Tan4d5e5c12014-02-04 11:54:58 -0800505 case CMD_SEND_ENVELOPE:
506 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800507 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700508 if (uiccCard == null) {
509 loge("sendEnvelopeWithStatus: No UICC");
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700512 } else {
513 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
514 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
515 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800516 break;
517
518 case EVENT_SEND_ENVELOPE_DONE:
519 ar = (AsyncResult) msg.obj;
520 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700521 if (ar.exception == null && ar.result != null) {
522 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800523 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
525 if (ar.result == null) {
526 loge("sendEnvelopeWithStatus: Empty response");
527 } else if (ar.exception instanceof CommandException) {
528 loge("sendEnvelopeWithStatus: CommandException: " +
529 ar.exception);
530 } else {
531 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
532 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700534 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 break;
536
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 case CMD_OPEN_CHANNEL:
538 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800539 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800540 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 if (uiccCard == null) {
542 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800543 request.result = new IccOpenLogicalChannelResponse(-1,
544 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 } else {
547 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800548 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
549 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 break;
552
553 case EVENT_OPEN_CHANNEL_DONE:
554 ar = (AsyncResult) msg.obj;
555 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 int[] result = (int[]) ar.result;
559 int channelId = result[0];
560 byte[] selectResponse = null;
561 if (result.length > 1) {
562 selectResponse = new byte[result.length - 1];
563 for (int i = 1; i < result.length; ++i) {
564 selectResponse[i - 1] = (byte) result[i];
565 }
566 }
567 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700568 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 if (ar.result == null) {
571 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 if (ar.exception != null) {
574 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
575 }
576
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700577 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700578 if (ar.exception instanceof CommandException) {
579 CommandException.Error error =
580 ((CommandException) (ar.exception)).getCommandError();
581 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700583 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700584 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 }
586 }
587 openChannelResp = new IccOpenLogicalChannelResponse(
588 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700590 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 break;
593
594 case CMD_CLOSE_CHANNEL:
595 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800596 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 if (uiccCard == null) {
598 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900599 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 } else {
602 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
603 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
604 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 break;
606
607 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800608 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
609 break;
610
611 case CMD_NV_READ_ITEM:
612 request = (MainThreadRequest) msg.obj;
613 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700614 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800615 break;
616
617 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 ar = (AsyncResult) msg.obj;
619 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800620 if (ar.exception == null && ar.result != null) {
621 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800623 request.result = "";
624 if (ar.result == null) {
625 loge("nvReadItem: Empty response");
626 } else if (ar.exception instanceof CommandException) {
627 loge("nvReadItem: CommandException: " +
628 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800630 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 }
632 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
Jake Hambye994d462014-02-03 13:10:13 -0800636 case CMD_NV_WRITE_ITEM:
637 request = (MainThreadRequest) msg.obj;
638 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
639 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700640 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
641 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800642 break;
643
644 case EVENT_NV_WRITE_ITEM_DONE:
645 handleNullReturnEvent(msg, "nvWriteItem");
646 break;
647
648 case CMD_NV_WRITE_CDMA_PRL:
649 request = (MainThreadRequest) msg.obj;
650 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
651 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
652 break;
653
654 case EVENT_NV_WRITE_CDMA_PRL_DONE:
655 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
656 break;
657
chen xu6dac5ab2018-10-26 17:39:23 -0700658 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800659 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700660 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
661 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800662 break;
663
chen xu6dac5ab2018-10-26 17:39:23 -0700664 case EVENT_RESET_MODEM_CONFIG_DONE:
665 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800666 break;
667
Jake Hamby7c27be32014-03-03 13:25:59 -0800668 case CMD_GET_PREFERRED_NETWORK_TYPE:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700671 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800672 break;
673
674 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result; // Integer
679 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800680 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800681 if (ar.result == null) {
682 loge("getPreferredNetworkType: Empty response");
683 } else if (ar.exception instanceof CommandException) {
684 loge("getPreferredNetworkType: CommandException: " +
685 ar.exception);
686 } else {
687 loge("getPreferredNetworkType: Unknown exception");
688 }
689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800691 break;
692
693 case CMD_SET_PREFERRED_NETWORK_TYPE:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
696 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700697 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800698 break;
699
700 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
701 handleNullReturnEvent(msg, "setPreferredNetworkType");
702 break;
703
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000704 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
705 request = (MainThreadRequest)msg.obj;
706 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700707 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000708 break;
709
710 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
711 ar = (AsyncResult)msg.obj;
712 request = (MainThreadRequest)ar.userObj;
713 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000715 break;
716
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800717 case CMD_SET_VOICEMAIL_NUMBER:
718 request = (MainThreadRequest) msg.obj;
719 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
720 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800721 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
722 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800723 break;
724
725 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
726 handleNullReturnEvent(msg, "setVoicemailNumber");
727 break;
728
Stuart Scott54788802015-03-30 13:18:01 -0700729 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
732 request);
733 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
734 break;
735
736 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
737 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
738 break;
739
Shishir Agrawal302c8692015-06-19 13:49:39 -0700740 case CMD_PERFORM_NETWORK_SCAN:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
743 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
744 break;
745
746 case EVENT_PERFORM_NETWORK_SCAN_DONE:
747 ar = (AsyncResult) msg.obj;
748 request = (MainThreadRequest) ar.userObj;
749 CellNetworkScanResult cellScanResult;
750 if (ar.exception == null && ar.result != null) {
751 cellScanResult = new CellNetworkScanResult(
752 CellNetworkScanResult.STATUS_SUCCESS,
753 (List<OperatorInfo>) ar.result);
754 } else {
755 if (ar.result == null) {
756 loge("getCellNetworkScanResults: Empty response");
757 }
758 if (ar.exception != null) {
759 loge("getCellNetworkScanResults: Exception: " + ar.exception);
760 }
761 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
762 if (ar.exception instanceof CommandException) {
763 CommandException.Error error =
764 ((CommandException) (ar.exception)).getCommandError();
765 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
766 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
767 } else if (error == CommandException.Error.GENERIC_FAILURE) {
768 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
769 }
770 }
771 cellScanResult = new CellNetworkScanResult(errorCode, null);
772 }
773 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700775 break;
776
777 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
778 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700779 ManualNetworkSelectionArgument selArg =
780 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700781 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
782 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700783 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
784 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700785 break;
786
787 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
790 if (ar.exception == null) {
791 request.result = true;
792 } else {
793 request.result = false;
794 loge("setNetworkSelectionModeManual " + ar.exception);
795 }
796 notifyRequester(request);
797 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 break;
799
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700800 case CMD_GET_MODEM_ACTIVITY_INFO:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700803 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700804 break;
805
806 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null && ar.result != null) {
810 request.result = ar.result;
811 } else {
812 if (ar.result == null) {
813 loge("queryModemActivityInfo: Empty response");
814 } else if (ar.exception instanceof CommandException) {
815 loge("queryModemActivityInfo: CommandException: " +
816 ar.exception);
817 } else {
818 loge("queryModemActivityInfo: Unknown exception");
819 }
820 }
Amit Mahajand4766222016-01-28 15:28:28 -0800821 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
822 if (request.result == null) {
823 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
824 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700825 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700826 break;
827
Meng Wang1a7c35a2016-05-05 20:56:15 -0700828 case CMD_SET_ALLOWED_CARRIERS:
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
831 mPhone.setAllowedCarriers(
832 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700833 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700834 break;
835
836 case EVENT_SET_ALLOWED_CARRIERS_DONE:
837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null && ar.result != null) {
840 request.result = ar.result;
841 } else {
842 if (ar.result == null) {
843 loge("setAllowedCarriers: Empty response");
844 } else if (ar.exception instanceof CommandException) {
845 loge("setAllowedCarriers: CommandException: " +
846 ar.exception);
847 } else {
848 loge("setAllowedCarriers: Unknown exception");
849 }
850 }
851 // Result cannot be null. Return -1 on error.
852 if (request.result == null) {
853 request.result = new int[]{-1};
854 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700855 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700856 break;
857
858 case CMD_GET_ALLOWED_CARRIERS:
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700861 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700862 break;
863
864 case EVENT_GET_ALLOWED_CARRIERS_DONE:
865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
867 if (ar.exception == null && ar.result != null) {
868 request.result = ar.result;
869 } else {
870 if (ar.result == null) {
871 loge("getAllowedCarriers: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("getAllowedCarriers: CommandException: " +
874 ar.exception);
875 } else {
876 loge("getAllowedCarriers: Unknown exception");
877 }
878 }
879 // Result cannot be null. Return empty list of CarrierIdentifier.
880 if (request.result == null) {
881 request.result = new ArrayList<CarrierIdentifier>(0);
882 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 break;
885
Nathan Haroldb3014052017-01-25 15:57:32 -0800886 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result;
891 } else {
892 request.result = new IllegalArgumentException(
893 "Failed to retrieve Forbidden Plmns");
894 if (ar.result == null) {
895 loge("getForbiddenPlmns: Empty response");
896 } else {
897 loge("getForbiddenPlmns: Unknown exception");
898 }
899 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700900 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800901 break;
902
903 case CMD_GET_FORBIDDEN_PLMNS:
904 request = (MainThreadRequest) msg.obj;
905 uiccCard = getUiccCardFromRequest(request);
906 if (uiccCard == null) {
907 loge("getForbiddenPlmns() UiccCard is null");
908 request.result = new IllegalArgumentException(
909 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700910 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800911 break;
912 }
913 Integer appType = (Integer) request.argument;
914 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
915 if (uiccApp == null) {
916 loge("getForbiddenPlmns() no app with specified type -- "
917 + appType);
918 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700919 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800920 break;
921 } else {
922 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
923 + " specified type -- " + appType);
924 }
925 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
926 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
927 onCompleted);
928 break;
929
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000930 case CMD_SWITCH_SLOTS:
931 request = (MainThreadRequest) msg.obj;
932 int[] physicalSlots = (int[]) request.argument;
933 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
934 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
935 break;
936
937 case EVENT_SWITCH_SLOTS_DONE:
938 ar = (AsyncResult) msg.obj;
939 request = (MainThreadRequest) ar.userObj;
940 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700941 notifyRequester(request);
942 break;
943 case CMD_GET_NETWORK_SELECTION_MODE:
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
946 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
947 break;
948
949 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
950 ar = (AsyncResult) msg.obj;
951 request = (MainThreadRequest) ar.userObj;
952 if (ar.exception != null) {
953 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
954 } else {
955 int mode = ((int[]) ar.result)[0];
956 if (mode == 0) {
957 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
958 } else {
959 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
960 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000961 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700962 notifyRequester(request);
963 break;
964 case CMD_GET_CDMA_ROAMING_MODE:
965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
967 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
968 break;
969 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
972 if (ar.exception != null) {
973 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
974 } else {
975 request.result = ((int[]) ar.result)[0];
976 }
977 notifyRequester(request);
978 break;
979 case CMD_SET_CDMA_ROAMING_MODE:
980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
982 int mode = (int) request.argument;
983 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
984 break;
985 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 request.result = ar.exception == null;
989 notifyRequester(request);
990 break;
991 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
992 request = (MainThreadRequest) msg.obj;
993 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
994 int subscriptionMode = (int) request.argument;
995 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
996 break;
997 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 request.result = ar.exception == null;
1001 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001002 break;
1003
Nathan Harold3ff88932018-08-14 10:19:49 -07001004 case CMD_GET_ALL_CELL_INFO:
1005 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001006 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001007 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001008 break;
1009
1010 case EVENT_GET_ALL_CELL_INFO_DONE:
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001013 // If a timeout occurs, the response will be null
1014 request.result = (ar.exception == null && ar.result != null)
1015 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001016 synchronized (request) {
1017 request.notifyAll();
1018 }
1019 break;
1020
1021 case CMD_GET_CELL_LOCATION: {
1022 request = (MainThreadRequest) msg.obj;
1023 WorkSource ws = (WorkSource) request.argument;
1024 Phone phone = getPhoneFromRequest(request);
1025 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1026 break;
1027 }
1028
1029 case EVENT_GET_CELL_LOCATION_DONE: {
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 if (ar.exception == null) {
1033 request.result = ar.result;
1034 } else {
1035 Phone phone = getPhoneFromRequest(request);
1036 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1037 ? new CdmaCellLocation() : new GsmCellLocation();
1038 }
1039
1040 synchronized (request) {
1041 request.notifyAll();
1042 }
1043 break;
1044 }
1045
chen xu6dac5ab2018-10-26 17:39:23 -07001046 case CMD_MODEM_REBOOT:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1049 mPhone.rebootModem(onCompleted);
1050 break;
1051
1052 case EVENT_CMD_MODEM_REBOOT_DONE:
1053 handleNullReturnEvent(msg, "rebootModem");
1054 break;
1055
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001056 default:
1057 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1058 break;
1059 }
1060 }
Jake Hambye994d462014-02-03 13:10:13 -08001061
Pengquan Menga1bb6272018-09-06 09:59:22 -07001062 private void notifyRequester(MainThreadRequest request) {
1063 synchronized (request) {
1064 request.notifyAll();
1065 }
1066 }
1067
Jake Hambye994d462014-02-03 13:10:13 -08001068 private void handleNullReturnEvent(Message msg, String command) {
1069 AsyncResult ar = (AsyncResult) msg.obj;
1070 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1071 if (ar.exception == null) {
1072 request.result = true;
1073 } else {
1074 request.result = false;
1075 if (ar.exception instanceof CommandException) {
1076 loge(command + ": CommandException: " + ar.exception);
1077 } else {
1078 loge(command + ": Unknown exception");
1079 }
1080 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001081 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 }
1084
1085 /**
1086 * Posts the specified command to be executed on the main thread,
1087 * waits for the request to complete, and returns the result.
1088 * @see #sendRequestAsync
1089 */
1090 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001091 return sendRequest(
1092 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001093 }
1094
1095 /**
1096 * Posts the specified command to be executed on the main thread,
1097 * waits for the request to complete, and returns the result.
1098 * @see #sendRequestAsync
1099 */
1100 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1101 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001102 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001103 }
1104
1105 /**
1106 * Posts the specified command to be executed on the main thread,
1107 * waits for the request to complete, and returns the result.
1108 * @see #sendRequestAsync
1109 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001110 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001111 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001112 }
1113
1114 /**
1115 * Posts the specified command to be executed on the main thread,
1116 * waits for the request to complete, and returns the result.
1117 * @see #sendRequestAsync
1118 */
Nathan Harold92bed182018-10-12 18:16:49 -07001119 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1120 return sendRequest(command, argument, subId, null, workSource);
1121 }
1122
1123 /**
1124 * Posts the specified command to be executed on the main thread,
1125 * waits for the request to complete, and returns the result.
1126 * @see #sendRequestAsync
1127 */
1128 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1129 return sendRequest(
1130 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1131 }
1132
1133 /**
1134 * Posts the specified command to be executed on the main thread,
1135 * waits for the request to complete, and returns the result.
1136 * @see #sendRequestAsync
1137 */
1138 private Object sendRequest(
1139 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1141 throw new RuntimeException("This method will deadlock if called from the main thread.");
1142 }
1143
Nathan Harold92bed182018-10-12 18:16:49 -07001144 MainThreadRequest request = null;
1145 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1146 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1147 } else if (phone != null) {
1148 request = new MainThreadRequest(argument, phone, workSource);
1149 } else {
1150 request = new MainThreadRequest(argument, subId, workSource);
1151 }
1152
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001153 Message msg = mMainThreadHandler.obtainMessage(command, request);
1154 msg.sendToTarget();
1155
1156 // Wait for the request to complete
1157 synchronized (request) {
1158 while (request.result == null) {
1159 try {
1160 request.wait();
1161 } catch (InterruptedException e) {
1162 // Do nothing, go back and wait until the request is complete
1163 }
1164 }
1165 }
1166 return request.result;
1167 }
1168
1169 /**
1170 * Asynchronous ("fire and forget") version of sendRequest():
1171 * Posts the specified command to be executed on the main thread, and
1172 * returns immediately.
1173 * @see #sendRequest
1174 */
1175 private void sendRequestAsync(int command) {
1176 mMainThreadHandler.sendEmptyMessage(command);
1177 }
1178
1179 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001180 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1181 * @see {@link #sendRequest(int,Object)}
1182 */
1183 private void sendRequestAsync(int command, Object argument) {
1184 MainThreadRequest request = new MainThreadRequest(argument);
1185 Message msg = mMainThreadHandler.obtainMessage(command, request);
1186 msg.sendToTarget();
1187 }
1188
1189 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 * Initialize the singleton PhoneInterfaceManager instance.
1191 * This is only done once, at startup, from PhoneApp.onCreate().
1192 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001193 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 synchronized (PhoneInterfaceManager.class) {
1195 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001196 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 } else {
1198 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1199 }
1200 return sInstance;
1201 }
1202 }
1203
1204 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001205 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 mApp = app;
1207 mPhone = phone;
1208 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001209 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001210 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1211 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001212 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001213 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001214 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001215 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001216 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001217
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 publish();
1219 }
1220
1221 private void publish() {
1222 if (DBG) log("publish: " + this);
1223
1224 ServiceManager.addService("phone", this);
1225 }
1226
Stuart Scott584921c2015-01-15 17:10:34 -08001227 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001228 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1229 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001230 }
1231
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001232 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1233 Phone phone = getPhoneFromRequest(request);
1234 return phone == null ? null :
1235 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1236 }
1237
Wink Saville36469e72014-06-11 15:17:00 -07001238 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001239 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001240 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242
1243 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001244 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001245 }
1246
Wink Savilleb564aae2014-10-23 10:18:09 -07001247 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 if (DBG) log("dial: " + number);
1249 // No permission check needed here: This is just a wrapper around the
1250 // ACTION_DIAL intent, which is available to any app since it puts up
1251 // the UI before it does anything.
1252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001253 final long identity = Binder.clearCallingIdentity();
1254 try {
1255 String url = createTelUrl(number);
1256 if (url == null) {
1257 return;
1258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001260 // PENDING: should we just silently fail if phone is offhook or ringing?
1261 PhoneConstants.State state = mCM.getState(subId);
1262 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1263 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1264 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1265 mApp.startActivity(intent);
1266 }
1267 } finally {
1268 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001269 }
1270 }
1271
1272 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001273 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001274 }
1275
Wink Savilleb564aae2014-10-23 10:18:09 -07001276 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 if (DBG) log("call: " + number);
1278
1279 // This is just a wrapper around the ACTION_CALL intent, but we still
1280 // need to do a permission check since we're calling startActivity()
1281 // from the context of the phone app.
1282 enforceCallPermission();
1283
1284 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1285 != AppOpsManager.MODE_ALLOWED) {
1286 return;
1287 }
1288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001289 final long identity = Binder.clearCallingIdentity();
1290 try {
1291 String url = createTelUrl(number);
1292 if (url == null) {
1293 return;
1294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001296 boolean isValid = false;
1297 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1298 if (slist != null) {
1299 for (SubscriptionInfo subInfoRecord : slist) {
1300 if (subInfoRecord.getSubscriptionId() == subId) {
1301 isValid = true;
1302 break;
1303 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001304 }
Wink Saville08874612014-08-31 19:19:58 -07001305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001306 if (!isValid) {
1307 return;
1308 }
Wink Saville08874612014-08-31 19:19:58 -07001309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001310 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1311 intent.putExtra(SUBSCRIPTION_KEY, subId);
1312 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1313 mApp.startActivity(intent);
1314 } finally {
1315 Binder.restoreCallingIdentity(identity);
1316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 }
1318
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001321 }
1322
Wink Savilleb564aae2014-10-23 10:18:09 -07001323 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001324 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001325 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1326 }
1327
1328 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001329 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001330 }
1331
Wink Savilleb564aae2014-10-23 10:18:09 -07001332 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001333 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001334 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1335 }
1336
1337 /** {@hide} */
1338 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001339 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001340 }
1341
Wink Savilleb564aae2014-10-23 10:18:09 -07001342 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001344
1345 final long identity = Binder.clearCallingIdentity();
1346 try {
1347 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1348 checkSimPin.start();
1349 return checkSimPin.unlockSim(null, pin);
1350 } finally {
1351 Binder.restoreCallingIdentity(identity);
1352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001353 }
1354
Wink Saville9de0f752013-10-22 19:04:03 -07001355 /** {@hide} */
1356 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001357 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001358 }
1359
Wink Savilleb564aae2014-10-23 10:18:09 -07001360 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001362
1363 final long identity = Binder.clearCallingIdentity();
1364 try {
1365 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1366 checkSimPuk.start();
1367 return checkSimPuk.unlockSim(puk, pin);
1368 } finally {
1369 Binder.restoreCallingIdentity(identity);
1370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371 }
1372
1373 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001374 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 * a synchronous one.
1376 */
1377 private static class UnlockSim extends Thread {
1378
1379 private final IccCard mSimCard;
1380
1381 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001382 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1383 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384
1385 // For replies from SimCard interface
1386 private Handler mHandler;
1387
1388 // For async handler to identify request type
1389 private static final int SUPPLY_PIN_COMPLETE = 100;
1390
1391 public UnlockSim(IccCard simCard) {
1392 mSimCard = simCard;
1393 }
1394
1395 @Override
1396 public void run() {
1397 Looper.prepare();
1398 synchronized (UnlockSim.this) {
1399 mHandler = new Handler() {
1400 @Override
1401 public void handleMessage(Message msg) {
1402 AsyncResult ar = (AsyncResult) msg.obj;
1403 switch (msg.what) {
1404 case SUPPLY_PIN_COMPLETE:
1405 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1406 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001407 mRetryCount = msg.arg1;
1408 if (ar.exception != null) {
1409 if (ar.exception instanceof CommandException &&
1410 ((CommandException)(ar.exception)).getCommandError()
1411 == CommandException.Error.PASSWORD_INCORRECT) {
1412 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1413 } else {
1414 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1415 }
1416 } else {
1417 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 mDone = true;
1420 UnlockSim.this.notifyAll();
1421 }
1422 break;
1423 }
1424 }
1425 };
1426 UnlockSim.this.notifyAll();
1427 }
1428 Looper.loop();
1429 }
1430
1431 /*
1432 * Use PIN or PUK to unlock SIM card
1433 *
1434 * If PUK is null, unlock SIM card with PIN
1435 *
1436 * If PUK is not null, unlock SIM card with PUK and set PIN code
1437 */
Wink Saville9de0f752013-10-22 19:04:03 -07001438 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439
1440 while (mHandler == null) {
1441 try {
1442 wait();
1443 } catch (InterruptedException e) {
1444 Thread.currentThread().interrupt();
1445 }
1446 }
1447 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1448
1449 if (puk == null) {
1450 mSimCard.supplyPin(pin, callback);
1451 } else {
1452 mSimCard.supplyPuk(puk, pin, callback);
1453 }
1454
1455 while (!mDone) {
1456 try {
1457 Log.d(LOG_TAG, "wait for done");
1458 wait();
1459 } catch (InterruptedException e) {
1460 // Restore the interrupted status
1461 Thread.currentThread().interrupt();
1462 }
1463 }
1464 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001465 int[] resultArray = new int[2];
1466 resultArray[0] = mResult;
1467 resultArray[1] = mRetryCount;
1468 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 }
1470 }
1471
1472 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001473 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001474
1475 }
1476
Wink Savilleb564aae2014-10-23 10:18:09 -07001477 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 // No permission check needed here: this call is harmless, and it's
1479 // needed for the ServiceState.requestStateUpdate() call (which is
1480 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001481 final long identity = Binder.clearCallingIdentity();
1482 try {
1483 final Phone phone = getPhone(subId);
1484 if (phone != null) {
1485 phone.updateServiceLocation();
1486 }
1487 } finally {
1488 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 }
1491
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001492 @Override
1493 public boolean isRadioOn(String callingPackage) {
1494 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001495 }
1496
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001497 @Override
1498 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001500 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001501 return false;
1502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001503
1504 final long identity = Binder.clearCallingIdentity();
1505 try {
1506 return isRadioOnForSubscriber(subId);
1507 } finally {
1508 Binder.restoreCallingIdentity(identity);
1509 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001510 }
1511
1512 private boolean isRadioOnForSubscriber(int subId) {
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 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1518 } else {
1519 return false;
1520 }
1521 } finally {
1522 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 }
1525
1526 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001527 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 }
Wink Saville36469e72014-06-11 15:17:00 -07001529
Wink Savilleb564aae2014-10-23 10:18:09 -07001530 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001532
1533 final long identity = Binder.clearCallingIdentity();
1534 try {
1535 final Phone phone = getPhone(subId);
1536 if (phone != null) {
1537 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1538 }
1539 } finally {
1540 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001541 }
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
1544 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001546 }
1547
Wink Savilleb564aae2014-10-23 10:18:09 -07001548 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001550
1551 final long identity = Binder.clearCallingIdentity();
1552 try {
1553 final Phone phone = getPhone(subId);
1554 if (phone == null) {
1555 return false;
1556 }
1557 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1558 toggleRadioOnOffForSubscriber(subId);
1559 }
1560 return true;
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
Wink Saville36469e72014-06-11 15:17:00 -07001565
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001566 public boolean needMobileRadioShutdown() {
1567 /*
1568 * If any of the Radios are available, it will need to be
1569 * shutdown. So return true if any Radio is available.
1570 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001571 final long identity = Binder.clearCallingIdentity();
1572 try {
1573 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1574 Phone phone = PhoneFactory.getPhone(i);
1575 if (phone != null && phone.isRadioAvailable()) return true;
1576 }
1577 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1578 return false;
1579 } finally {
1580 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001581 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001582 }
1583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001584 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001585 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001586 enforceModifyPermission();
1587
1588 final long identity = Binder.clearCallingIdentity();
1589 try {
1590 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1591 logv("Shutting down Phone " + i);
1592 shutdownRadioUsingPhoneId(i);
1593 }
1594 } finally {
1595 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001596 }
1597 }
1598
1599 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001600 Phone phone = PhoneFactory.getPhone(phoneId);
1601 if (phone != null && phone.isRadioAvailable()) {
1602 phone.shutdownRadio();
1603 }
1604 }
1605
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001608
1609 final long identity = Binder.clearCallingIdentity();
1610 try {
1611 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1612 if (defaultPhone != null) {
1613 defaultPhone.setRadioPower(turnOn);
1614 return true;
1615 } else {
1616 loge("There's no default phone.");
1617 return false;
1618 }
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001621 }
Wink Saville36469e72014-06-11 15:17:00 -07001622 }
1623
Wink Savilleb564aae2014-10-23 10:18:09 -07001624 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001626
1627 final long identity = Binder.clearCallingIdentity();
1628 try {
1629 final Phone phone = getPhone(subId);
1630 if (phone != null) {
1631 phone.setRadioPower(turnOn);
1632 return true;
1633 } else {
1634 return false;
1635 }
1636 } finally {
1637 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 }
1640
Wink Saville36469e72014-06-11 15:17:00 -07001641 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001642 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 public boolean enableDataConnectivity() {
1644 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001645
1646 final long identity = Binder.clearCallingIdentity();
1647 try {
1648 int subId = mSubscriptionController.getDefaultDataSubId();
1649 final Phone phone = getPhone(subId);
1650 if (phone != null) {
1651 phone.setUserDataEnabled(true);
1652 return true;
1653 } else {
1654 return false;
1655 }
1656 } finally {
1657 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
1660
Wink Saville36469e72014-06-11 15:17:00 -07001661 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001662 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 public boolean disableDataConnectivity() {
1664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001665
1666 final long identity = Binder.clearCallingIdentity();
1667 try {
1668 int subId = mSubscriptionController.getDefaultDataSubId();
1669 final Phone phone = getPhone(subId);
1670 if (phone != null) {
1671 phone.setUserDataEnabled(false);
1672 return true;
1673 } else {
1674 return false;
1675 }
1676 } finally {
1677 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 }
1680
Sanket Padawe356d7632015-06-22 14:03:32 -07001681 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001682 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001683 final long identity = Binder.clearCallingIdentity();
1684 try {
1685 final Phone phone = getPhone(subId);
1686 if (phone != null) {
1687 return phone.isDataAllowed();
1688 } else {
1689 return false;
1690 }
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
1695
1696 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001697 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001698 }
1699
pkanwarae03a6b2016-11-06 20:37:09 -08001700 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001701 enforceCallPermission();
1702
1703 final long identity = Binder.clearCallingIdentity();
1704 try {
1705 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1706 return;
1707 }
1708 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1709 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1710 } finally {
1711 Binder.restoreCallingIdentity(identity);
1712 }
pkanwar32d516d2016-10-14 19:37:38 -07001713 };
1714
Wink Savilleb564aae2014-10-23 10:18:09 -07001715 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1721 return false;
1722 }
1723 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 }
1728
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001730 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001731 }
1732
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001733 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 Phone phone = PhoneFactory.getPhone(slotIndex);
1737 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1738 PhoneConstantConversions.convertCallState(phone.getState());
1739 } finally {
1740 Binder.restoreCallingIdentity(identity);
1741 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 }
1743
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746 final long identity = Binder.clearCallingIdentity();
1747 try {
1748 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1749 if (phone != null) {
1750 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1751 } else {
1752 return PhoneConstantConversions.convertDataState(
1753 PhoneConstants.DataState.DISCONNECTED);
1754 }
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759
Sanket Padawe356d7632015-06-22 14:03:32 -07001760 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762 final long identity = Binder.clearCallingIdentity();
1763 try {
1764 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1765 if (phone != null) {
1766 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1767 } else {
1768 return TelephonyManager.DATA_ACTIVITY_NONE;
1769 }
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
1775 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001776 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001777 mPhone.getContext().getSystemService(AppOpsManager.class)
1778 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001779 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001780 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001781 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 }
1783
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001784 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 if (DBG_LOC) log("getCellLocation: is active user");
1788 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001789 int subId = mSubscriptionController.getDefaultDataSubId();
1790 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1791 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001792 return data;
1793 } finally {
1794 Binder.restoreCallingIdentity(identity);
1795 }
Svetoslav64fad262015-04-14 14:35:21 -07001796 }
1797
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001799 public String getNetworkCountryIsoForPhone(int phoneId) {
1800 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1801 // registered cell info, so return a NULL country instead.
1802 final long identity = Binder.clearCallingIdentity();
1803 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001804 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1805 // Get default phone in this case.
1806 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1807 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001808 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001809 // Todo: fix this when we can get the actual cellular network info when the device
1810 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001811 if (TelephonyManager.NETWORK_TYPE_IWLAN
1812 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1813 return "";
1814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001815 Phone phone = PhoneFactory.getPhone(phoneId);
1816 if (phone != null) {
1817 ServiceStateTracker sst = phone.getServiceStateTracker();
1818 if (sst != null) {
1819 LocaleTracker lt = sst.getLocaleTracker();
1820 if (lt != null) {
1821 return lt.getCurrentCountry();
1822 }
1823 }
1824 }
1825 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001826 } finally {
1827 Binder.restoreCallingIdentity(identity);
1828 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001829 }
1830
1831 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001833 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001834 }
1835
Sanket Padawe356d7632015-06-22 14:03:32 -07001836 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001837 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 mApp.enforceCallingOrSelfPermission(
1839 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001840
1841 final long identity = Binder.clearCallingIdentity();
1842 try {
1843 final Phone phone = getPhone(subId);
1844 if (phone != null) {
1845 phone.enableLocationUpdates();
1846 }
1847 } finally {
1848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 }
1851
1852 @Override
1853 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001854 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001855 }
1856
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001858 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 mApp.enforceCallingOrSelfPermission(
1860 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001861
1862 final long identity = Binder.clearCallingIdentity();
1863 try {
1864 final Phone phone = getPhone(subId);
1865 if (phone != null) {
1866 phone.disableLocationUpdates();
1867 }
1868 } finally {
1869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 }
1872
Nathan Harold31d7ff32018-10-15 20:20:30 -07001873 /**
1874 * Returns the target SDK version number for a given package name.
1875 *
1876 * @return target SDK if the package is found or INT_MAX.
1877 */
1878 private int getTargetSdk(String packageName) {
1879 try {
1880 final ApplicationInfo ai =
1881 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1882 if (ai != null) return ai.targetSdkVersion;
1883 } catch (PackageManager.NameNotFoundException unexpected) {
1884 }
1885 return Integer.MAX_VALUE;
1886 }
1887
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 @Override
1889 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001890 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1891 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001892 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1893 throw new SecurityException(
1894 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1895 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001896
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1898 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1899 return null;
1900 }
Svetoslav64fad262015-04-14 14:35:21 -07001901
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001902 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903
Nathan Haroldf180aac2018-06-01 18:43:55 -07001904 List<CellInfo> info = getAllCellInfo(callingPackage);
1905 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906
Nathan Haroldf180aac2018-06-01 18:43:55 -07001907 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1908 for (CellInfo ci : info) {
1909 if (ci instanceof CellInfoGsm) {
1910 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1911 } else if (ci instanceof CellInfoWcdma) {
1912 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001915 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 }
1917
1918
1919 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001920 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001921 mPhone.getContext().getSystemService(AppOpsManager.class)
1922 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001923 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001924 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001925 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 }
1927
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001928 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001929 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1933 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001934 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001935 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001936 if (info != null) cellInfos.addAll(info);
1937 }
1938 return cellInfos;
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942 }
1943
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001944 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001946 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001947 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948
1949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 mPhone.setCellInfoListRate(rateInMillis, workSource);
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
Shishir Agrawala9f32182016-04-12 12:00:16 -07001957 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001958 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001959 Phone phone = PhoneFactory.getPhone(slotIndex);
1960 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001961 return null;
1962 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001963 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001964 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1965 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001966 return null;
1967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968
1969 final long identity = Binder.clearCallingIdentity();
1970 try {
1971 return phone.getImei();
1972 } finally {
1973 Binder.restoreCallingIdentity(identity);
1974 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001975 }
1976
1977 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001978 public String getTypeAllocationCodeForSlot(int slotIndex) {
1979 Phone phone = PhoneFactory.getPhone(slotIndex);
1980 String tac = null;
1981 if (phone != null) {
1982 String imei = phone.getImei();
1983 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1984 }
1985 return tac;
1986 }
1987
1988 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001989 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001990 Phone phone = PhoneFactory.getPhone(slotIndex);
1991 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001992 return null;
1993 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001994 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001995 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1996 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001997 return null;
1998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999
2000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 return phone.getMeid();
2003 } finally {
2004 Binder.restoreCallingIdentity(identity);
2005 }
Jack Yu2af8d712017-03-15 17:14:14 -07002006 }
2007
2008 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002009 public String getManufacturerCodeForSlot(int slotIndex) {
2010 Phone phone = PhoneFactory.getPhone(slotIndex);
2011 String manufacturerCode = null;
2012 if (phone != null) {
2013 String meid = phone.getMeid();
2014 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2015 }
2016 return manufacturerCode;
2017 }
2018
2019 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002020 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002021 Phone phone = PhoneFactory.getPhone(slotIndex);
2022 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002023 return null;
2024 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002025 int subId = phone.getSubId();
2026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2027 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2028 return null;
2029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030
2031 final long identity = Binder.clearCallingIdentity();
2032 try {
2033 return phone.getDeviceSvn();
2034 } finally {
2035 Binder.restoreCallingIdentity(identity);
2036 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002037 }
2038
fionaxu43304da2017-11-27 22:51:16 -08002039 @Override
2040 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041 final long identity = Binder.clearCallingIdentity();
2042 try {
2043 final Phone phone = getPhone(subId);
2044 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
2047 }
fionaxu43304da2017-11-27 22:51:16 -08002048 }
2049
2050 @Override
2051 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002052 final long identity = Binder.clearCallingIdentity();
2053 try {
2054 final Phone phone = getPhone(subId);
2055 return phone == null ? null : phone.getCarrierName();
2056 } finally {
2057 Binder.restoreCallingIdentity(identity);
2058 }
fionaxu43304da2017-11-27 22:51:16 -08002059 }
2060
calvinpanffe225e2018-11-01 19:43:06 +08002061 @Override
2062 public int getSubscriptionMNOCarrierId(int subId) {
2063 final long identity = Binder.clearCallingIdentity();
2064 try {
2065 final Phone phone = getPhone(subId);
2066 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2067 } finally {
2068 Binder.restoreCallingIdentity(identity);
2069 }
2070 }
2071
chen xu25637222018-11-04 17:17:00 -08002072 @Override
2073 public int getSubscriptionPreciseCarrierId(int subId) {
2074 final long identity = Binder.clearCallingIdentity();
2075 try {
2076 final Phone phone = getPhone(subId);
2077 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2078 : phone.getPreciseCarrierId();
2079 } finally {
2080 Binder.restoreCallingIdentity(identity);
2081 }
2082 }
2083
2084 @Override
2085 public String getSubscriptionPreciseCarrierName(int subId) {
2086 final long identity = Binder.clearCallingIdentity();
2087 try {
2088 final Phone phone = getPhone(subId);
2089 return phone == null ? null : phone.getPreciseCarrierName();
2090 } finally {
2091 Binder.restoreCallingIdentity(identity);
2092 }
2093 }
2094
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 //
2096 // Internal helper methods.
2097 //
2098
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002099 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2101 *
2102 * @throws SecurityException if the caller does not have the required permission
2103 */
2104 private void enforceModifyPermission() {
2105 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2106 }
2107
2108 /**
2109 * Make sure the caller has the CALL_PHONE permission.
2110 *
2111 * @throws SecurityException if the caller does not have the required permission
2112 */
2113 private void enforceCallPermission() {
2114 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2115 }
2116
Stuart Scott8eef64f2015-04-08 15:13:54 -07002117 private void enforceConnectivityInternalPermission() {
2118 mApp.enforceCallingOrSelfPermission(
2119 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2120 "ConnectivityService");
2121 }
2122
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 private String createTelUrl(String number) {
2124 if (TextUtils.isEmpty(number)) {
2125 return null;
2126 }
2127
Jake Hambye994d462014-02-03 13:10:13 -08002128 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
2130
Ihab Awadf9e92732013-12-05 18:02:52 -08002131 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2133 }
2134
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002135 private static void logv(String msg) {
2136 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2137 }
2138
Ihab Awadf9e92732013-12-05 18:02:52 -08002139 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2141 }
2142
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002143 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002145 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002146 }
2147
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002149 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002150 final long identity = Binder.clearCallingIdentity();
2151 try {
2152 final Phone phone = PhoneFactory.getPhone(slotIndex);
2153 if (phone == null) {
2154 return PhoneConstants.PHONE_TYPE_NONE;
2155 } else {
2156 return phone.getPhoneType();
2157 }
2158 } finally {
2159 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 }
2162
2163 /**
2164 * Returns the CDMA ERI icon index to display
2165 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002166 @Override
2167 public int getCdmaEriIconIndex(String callingPackage) {
2168 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002169 }
2170
Sanket Padawe356d7632015-06-22 14:03:32 -07002171 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002172 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002174 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002175 return -1;
2176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002177
2178 final long identity = Binder.clearCallingIdentity();
2179 try {
2180 final Phone phone = getPhone(subId);
2181 if (phone != null) {
2182 return phone.getCdmaEriIconIndex();
2183 } else {
2184 return -1;
2185 }
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 }
2190
2191 /**
2192 * Returns the CDMA ERI icon mode,
2193 * 0 - ON
2194 * 1 - FLASHING
2195 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002196 @Override
2197 public int getCdmaEriIconMode(String callingPackage) {
2198 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002199 }
2200
Sanket Padawe356d7632015-06-22 14:03:32 -07002201 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002202 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002203 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002204 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002205 return -1;
2206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207
2208 final long identity = Binder.clearCallingIdentity();
2209 try {
2210 final Phone phone = getPhone(subId);
2211 if (phone != null) {
2212 return phone.getCdmaEriIconMode();
2213 } else {
2214 return -1;
2215 }
2216 } finally {
2217 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220
2221 /**
2222 * Returns the CDMA ERI text,
2223 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002224 @Override
2225 public String getCdmaEriText(String callingPackage) {
2226 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002227 }
2228
Sanket Padawe356d7632015-06-22 14:03:32 -07002229 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002232 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 return null;
2234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235
2236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 final Phone phone = getPhone(subId);
2239 if (phone != null) {
2240 return phone.getCdmaEriText();
2241 } else {
2242 return null;
2243 }
2244 } finally {
2245 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 }
2248
2249 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002250 * Returns the CDMA MDN.
2251 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002253 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2255 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002256
2257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 final Phone phone = getPhone(subId);
2260 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2261 return phone.getLine1Number();
2262 } else {
2263 return null;
2264 }
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002267 }
2268 }
2269
2270 /**
2271 * Returns the CDMA MIN.
2272 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002273 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002274 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2276 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277
2278 final long identity = Binder.clearCallingIdentity();
2279 try {
2280 final Phone phone = getPhone(subId);
2281 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2282 return phone.getCdmaMin();
2283 } else {
2284 return null;
2285 }
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002288 }
2289 }
2290
2291 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 * Returns true if CDMA provisioning needs to run.
2293 */
2294 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 final long identity = Binder.clearCallingIdentity();
2296 try {
2297 return mPhone.needsOtaServiceProvisioning();
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
2300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002304 * Sets the voice mail number of a given subId.
2305 */
2306 @Override
2307 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002308 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002309
2310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2313 new Pair<String, String>(alphaTag, number), new Integer(subId));
2314 return success;
2315 } finally {
2316 Binder.restoreCallingIdentity(identity);
2317 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002318 }
2319
Ta-wei Yen87c49842016-05-13 21:19:52 -07002320 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002321 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2322 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2323 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2324 if (!TextUtils.equals(callingPackage, systemDialer)) {
2325 throw new SecurityException("caller must be system dialer");
2326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2331 if (phoneAccountHandle == null) {
2332 return null;
2333 }
2334 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2335 } finally {
2336 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002337 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002338 }
2339
2340 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002341 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002342 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002344 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002345 return null;
2346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 return RemoteVvmTaskManager
2351 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2352 } finally {
2353 Binder.restoreCallingIdentity(identity);
2354 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002355 }
2356
2357 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002358 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2359 VisualVoicemailSmsFilterSettings settings) {
2360 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002361
2362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2365 mPhone.getContext(), callingPackage, subId, settings);
2366 } finally {
2367 Binder.restoreCallingIdentity(identity);
2368 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002369 }
2370
2371 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002372 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002374
2375 final long identity = Binder.clearCallingIdentity();
2376 try {
2377 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2378 mPhone.getContext(), callingPackage, subId);
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
2381 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002382 }
2383
2384 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002385 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2386 String callingPackage, int subId) {
2387 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2392 mPhone.getContext(), callingPackage, subId);
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
2395 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002396 }
2397
2398 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002399 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002400 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002401
2402 final long identity = Binder.clearCallingIdentity();
2403 try {
2404 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2405 mPhone.getContext(), subId);
2406 } finally {
2407 Binder.restoreCallingIdentity(identity);
2408 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002409 }
2410
2411 @Override
2412 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2413 String number, int port, String text, PendingIntent sentIntent) {
2414 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002415 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002416 enforceSendSmsPermission();
2417 // Make the calls as the phone process.
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2421 if (port == 0) {
2422 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2423 sentIntent, null, false);
2424 } else {
2425 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2426 smsManager.sendDataMessageWithSelfPermissions(number, null,
2427 (short) port, data, sentIntent, null);
2428 }
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
2431 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002432 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002433 /**
fionaxu0152e512016-11-14 13:36:14 -08002434 * Sets the voice activation state of a given subId.
2435 */
2436 @Override
2437 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2439 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
2443 final Phone phone = getPhone(subId);
2444 if (phone != null) {
2445 phone.setVoiceActivationState(activationState);
2446 } else {
2447 loge("setVoiceActivationState fails with invalid subId: " + subId);
2448 }
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002451 }
2452 }
2453
2454 /**
2455 * Sets the data activation state of a given subId.
2456 */
2457 @Override
2458 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2460 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461
2462 final long identity = Binder.clearCallingIdentity();
2463 try {
2464 final Phone phone = getPhone(subId);
2465 if (phone != null) {
2466 phone.setDataActivationState(activationState);
2467 } else {
2468 loge("setVoiceActivationState fails with invalid subId: " + subId);
2469 }
2470 } finally {
2471 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002472 }
2473 }
2474
2475 /**
2476 * Returns the voice activation state of a given subId.
2477 */
2478 @Override
2479 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002480 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481
fionaxu0152e512016-11-14 13:36:14 -08002482 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 final long identity = Binder.clearCallingIdentity();
2484 try {
2485 if (phone != null) {
2486 return phone.getVoiceActivationState();
2487 } else {
2488 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2489 }
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002492 }
2493 }
2494
2495 /**
2496 * Returns the data activation state of a given subId.
2497 */
2498 @Override
2499 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002500 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501
fionaxu0152e512016-11-14 13:36:14 -08002502 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 if (phone != null) {
2506 return phone.getDataActivationState();
2507 } else {
2508 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2509 }
2510 } finally {
2511 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002512 }
2513 }
2514
2515 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 * Returns the unread count of voicemails
2517 */
2518 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002519 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002520 }
2521
2522 /**
2523 * Returns the unread count of voicemails for a subId
2524 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002526 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 final Phone phone = getPhone(subId);
2530 if (phone != null) {
2531 return phone.getVoiceMessageCount();
2532 } else {
2533 return 0;
2534 }
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 }
2539
2540 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002541 * returns true, if the device is in a state where both voice and data
2542 * are supported simultaneously. This can change based on location or network condition.
2543 */
2544 @Override
2545 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 final Phone phone = getPhone(subId);
2549 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
2552 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002553 }
2554
2555 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002556 * Send the dialer code if called from the current default dialer or the caller has
2557 * carrier privilege.
2558 * @param inputCode The dialer code to send
2559 */
2560 @Override
2561 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2562 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2563 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2564 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002565 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2566 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002567 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 mPhone.sendDialerSpecialCode(inputCode);
2572 } finally {
2573 Binder.restoreCallingIdentity(identity);
2574 }
fionaxu235cc5e2017-03-06 22:25:57 -08002575 }
2576
2577 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002578 * Returns the data network type.
2579 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 *
2581 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2582 */
2583 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002584 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 final Phone phone = getPhone(getDefaultSubscription());
2588 if (phone != null) {
2589 return phone.getServiceState().getDataNetworkType();
2590 } else {
2591 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2592 }
2593 } finally {
2594 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002595 }
Wink Saville36469e72014-06-11 15:17:00 -07002596 }
2597
Pengquan Menga1bb6272018-09-06 09:59:22 -07002598 @Override
2599 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002600 if (!isActiveSubscription(subId)) {
2601 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2602 }
2603
Pengquan Menga1bb6272018-09-06 09:59:22 -07002604 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2605 }
2606
Brad Ebinger35c841c2018-10-01 10:40:55 -07002607 @Override
2608 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2609 String callingPackage) throws RemoteException {
2610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2611 "addImsRegistrationCallback")) {
2612 return;
2613 }
2614 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2615 final long token = Binder.clearCallingIdentity();
2616 try {
2617 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2618 .addRegistrationCallbackForSubscription(c, subId);
2619 } finally {
2620 Binder.restoreCallingIdentity(token);
2621 }
2622 }
2623
2624 @Override
2625 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2626 String callingPackage) {
2627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2628 "removeImsRegistrationCallback")) {
2629 return;
2630 }
2631 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2632 Binder.withCleanCallingIdentity(() ->
2633 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2634 .removeRegistrationCallbackForSubscription(c, subId));
2635 }
2636
2637 @Override
2638 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2639 String callingPackage) throws RemoteException {
2640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2641 "addMmTelCapabilityCallback")) {
2642 return;
2643 }
2644 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2645 final long token = Binder.clearCallingIdentity();
2646 try {
2647 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2648 .addCapabilitiesCallbackForSubscription(c, subId);
2649 } finally {
2650 Binder.restoreCallingIdentity(token);
2651 }
2652 }
2653
2654 @Override
2655 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2656 String callingPackage) {
2657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2658 "removeMmTelCapabilityCallback")) {
2659 return;
2660 }
2661 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2662 Binder.withCleanCallingIdentity(() ->
2663 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2664 .removeCapabilitiesCallbackForSubscription(c, subId));
2665 }
2666
2667 @Override
2668 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2670 "isCapable")) {
2671 return false;
2672 }
2673 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2674 final long token = Binder.clearCallingIdentity();
2675 try {
2676 return ImsManager.getInstance(mPhone.getContext(),
2677 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2678 } catch (ImsException e) {
2679 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2680 return false;
2681 } finally {
2682 Binder.restoreCallingIdentity(token);
2683 }
2684 }
2685
2686 @Override
2687 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2689 "isAvailable")) {
2690 return false;
2691 }
2692 final long token = Binder.clearCallingIdentity();
2693 try {
2694 Phone phone = getPhone(subId);
2695 if (phone == null) return false;
2696 return phone.isImsCapabilityAvailable(capability, regTech);
2697 } finally {
2698 Binder.restoreCallingIdentity(token);
2699 }
2700 }
2701
2702 @Override
2703 public boolean isAdvancedCallingSettingEnabled(int subId) {
2704 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2705 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2706 final long token = Binder.clearCallingIdentity();
2707 try {
2708 return ImsManager.getInstance(mPhone.getContext(),
2709 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2710 } finally {
2711 Binder.restoreCallingIdentity(token);
2712 }
2713 }
2714
2715 @Override
2716 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2718 "setAdvancedCallingSetting");
2719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2722 ImsManager.getInstance(mPhone.getContext(),
2723 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
2726 }
2727 }
2728
2729 @Override
2730 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2731 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2732 "isVtSettingEnabled")) {
2733 return false;
2734 }
2735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2738 return ImsManager.getInstance(mPhone.getContext(),
2739 getSlotIndexOrException(subId)).isVtEnabledByUser();
2740 } finally {
2741 Binder.restoreCallingIdentity(identity);
2742 }
2743 }
2744
2745 @Override
2746 public void setVtSetting(int subId, boolean isEnabled) {
2747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2748 "setVtSetting");
2749 final long identity = Binder.clearCallingIdentity();
2750 try {
2751 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2752 ImsManager.getInstance(mPhone.getContext(),
2753 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
2757 }
2758
2759 @Override
2760 public boolean isVoWiFiSettingEnabled(int subId) {
2761 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2765 return ImsManager.getInstance(mPhone.getContext(),
2766 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
2769 }
2770 }
2771
2772 @Override
2773 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2775 "setVoWiFiSetting");
2776 final long identity = Binder.clearCallingIdentity();
2777 try {
2778 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2779 ImsManager.getInstance(mPhone.getContext(),
2780 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2781 } finally {
2782 Binder.restoreCallingIdentity(identity);
2783 }
2784 }
2785
2786 @Override
2787 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2788 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2792 return ImsManager.getInstance(mPhone.getContext(),
2793 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
2796 }
2797 }
2798
2799 @Override
2800 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2802 "setVoWiFiRoamingSetting");
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2806 ImsManager.getInstance(mPhone.getContext(),
2807 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
2810 }
2811 }
2812
2813 @Override
2814 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2816 "setVoWiFiNonPersistent");
2817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2820 ImsManager.getInstance(mPhone.getContext(),
2821 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2822 } finally {
2823 Binder.restoreCallingIdentity(identity);
2824 }
2825 }
2826
2827 @Override
2828 public int getVoWiFiModeSetting(int subId) {
2829 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2833 return ImsManager.getInstance(mPhone.getContext(),
2834 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
2837 }
2838 }
2839
2840 @Override
2841 public void setVoWiFiModeSetting(int subId, int mode) {
2842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2843 "setVoWiFiModeSetting");
2844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2847 ImsManager.getInstance(mPhone.getContext(),
2848 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
2851 }
2852 }
2853
2854 @Override
2855 public int getVoWiFiRoamingModeSetting(int subId) {
2856 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2857 final long identity = Binder.clearCallingIdentity();
2858 try {
2859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2860 return ImsManager.getInstance(mPhone.getContext(),
2861 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
2865 }
2866
2867 @Override
2868 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2870 "setVoWiFiRoamingModeSetting");
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2874 ImsManager.getInstance(mPhone.getContext(),
2875 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2876 } finally {
2877 Binder.restoreCallingIdentity(identity);
2878 }
2879 }
2880
2881 @Override
2882 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2884 "setRttCapabilityEnabled");
2885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2888 ImsManager.getInstance(mPhone.getContext(),
2889 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
2892 }
2893 }
2894
2895 @Override
2896 public boolean isTtyOverVolteEnabled(int subId) {
2897 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2898 final long identity = Binder.clearCallingIdentity();
2899 try {
2900 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2901 return ImsManager.getInstance(mPhone.getContext(),
2902 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
2905 }
2906 }
2907
2908 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2909 int slotId = SubscriptionManager.getSlotIndex(subId);
2910 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2911 throw new IllegalArgumentException("Invalid Subscription Id.");
2912 }
2913 return slotId;
2914 }
2915
Wink Saville36469e72014-06-11 15:17:00 -07002916 /**
2917 * Returns the network type for a subId
2918 */
2919 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002920 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002922 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002923 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2924 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 final Phone phone = getPhone(subId);
2929 if (phone != null) {
2930 return phone.getServiceState().getDataNetworkType();
2931 } else {
2932 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2933 }
2934 } finally {
2935 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 }
2938
2939 /**
2940 * Returns the data network type
2941 */
2942 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002943 public int getDataNetworkType(String callingPackage) {
2944 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002945 }
2946
2947 /**
2948 * Returns the data network type for a subId
2949 */
2950 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002951 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002953 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002954 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2955 }
2956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 final Phone phone = getPhone(subId);
2960 if (phone != null) {
2961 return phone.getServiceState().getDataNetworkType();
2962 } else {
2963 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2964 }
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002968 }
2969
2970 /**
Wink Saville36469e72014-06-11 15:17:00 -07002971 * Returns the Voice network type for a subId
2972 */
2973 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002974 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002975 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002976 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002977 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2978 }
2979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 final Phone phone = getPhone(subId);
2983 if (phone != null) {
2984 return phone.getServiceState().getVoiceNetworkType();
2985 } else {
2986 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2987 }
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
2992
2993 /**
2994 * @return true if a ICC card is present
2995 */
2996 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002997 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002998 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2999 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003000 }
3001
3002 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003003 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003004 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003005 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003006 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007 final long identity = Binder.clearCallingIdentity();
3008 try {
3009 final Phone phone = PhoneFactory.getPhone(slotIndex);
3010 if (phone != null) {
3011 return phone.getIccCard().hasIccCard();
3012 } else {
3013 return false;
3014 }
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003017 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003018 }
3019
3020 /**
3021 * Return if the current radio is LTE on CDMA. This
3022 * is a tri-state return value as for a period of time
3023 * the mode may be unknown.
3024 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003025 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003027 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003029 @Override
3030 public int getLteOnCdmaMode(String callingPackage) {
3031 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003032 }
3033
Sanket Padawe356d7632015-06-22 14:03:32 -07003034 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003035 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003037 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003038 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3039 }
3040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 final Phone phone = getPhone(subId);
3044 if (phone == null) {
3045 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3046 } else {
3047 return phone.getLteOnCdmaMode();
3048 }
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003051 }
Wink Saville36469e72014-06-11 15:17:00 -07003052 }
3053
3054 public void setPhone(Phone phone) {
3055 mPhone = phone;
3056 }
3057
3058 /**
3059 * {@hide}
3060 * Returns Default subId, 0 in the case of single standby.
3061 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003062 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003063 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003064 }
3065
Shishir Agrawala9f32182016-04-12 12:00:16 -07003066 private int getSlotForDefaultSubscription() {
3067 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3068 }
3069
Wink Savilleb564aae2014-10-23 10:18:09 -07003070 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003071 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003073
Pengquan Menge92a50d2018-09-21 15:54:48 -07003074 private boolean isActiveSubscription(int subId) {
3075 return mSubscriptionController.isActiveSubId(subId);
3076 }
3077
Ihab Awadf2177b72013-11-25 13:33:23 -08003078 /**
3079 * @see android.telephony.TelephonyManager.WifiCallingChoices
3080 */
3081 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3085 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3086 getWhenToMakeWifiCallsDefaultPreference());
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003090 }
3091
3092 /**
3093 * @see android.telephony.TelephonyManager.WifiCallingChoices
3094 */
3095 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3099 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3100 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003104 }
3105
Sailesh Nepald1e68152013-12-12 19:08:02 -08003106 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003107 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003108 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003109 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003110
Shishir Agrawal566b7612013-10-28 14:41:00 -07003111 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003112 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3113 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3115 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 if (TextUtils.equals(ISDR_AID, aid)) {
3121 // Only allows LPA to open logical channel to ISD-R.
3122 ComponentInfo bestComponent =
3123 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3124 if (bestComponent == null
3125 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3126 loge("The calling package is not allowed to access ISD-R.");
3127 throw new SecurityException(
3128 "The calling package is not allowed to access ISD-R.");
3129 }
Derek Tan740e1672017-06-27 14:56:27 -07003130 }
Derek Tan740e1672017-06-27 14:56:27 -07003131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 if (DBG) {
3133 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3134 }
3135 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3136 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3137 if (DBG) log("iccOpenLogicalChannel: " + response);
3138 return response;
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
3141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003142 }
3143
3144 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003145 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3147 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3152 if (channel < 0) {
3153 return false;
3154 }
3155 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3156 if (DBG) log("iccCloseLogicalChannel: " + success);
3157 return success;
3158 } finally {
3159 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003160 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003161 }
3162
3163 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003164 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003165 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3167 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 if (DBG) {
3172 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3173 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3174 + p3 + " data=" + data);
3175 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177 if (channel < 0) {
3178 return "";
3179 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3182 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3183 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185 // Append the returned status code to the end of the response payload.
3186 String s = Integer.toHexString(
3187 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3188 if (response.payload != null) {
3189 s = IccUtils.bytesToHexString(response.payload) + s;
3190 }
3191 return s;
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003194 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003195 }
Jake Hambye994d462014-02-03 13:10:13 -08003196
Evan Charltonc66da362014-05-16 14:06:40 -07003197 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003198 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3199 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3201 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3207 && TextUtils.equals(ISDR_AID, data)) {
3208 // Only allows LPA to select ISD-R.
3209 ComponentInfo bestComponent =
3210 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3211 if (bestComponent == null
3212 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3213 loge("The calling package is not allowed to select ISD-R.");
3214 throw new SecurityException(
3215 "The calling package is not allowed to select ISD-R.");
3216 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003217 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 if (DBG) {
3220 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3221 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3222 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3225 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3226 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 // Append the returned status code to the end of the response payload.
3229 String s = Integer.toHexString(
3230 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3231 if (response.payload != null) {
3232 s = IccUtils.bytesToHexString(response.payload) + s;
3233 }
3234 return s;
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003237 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003238 }
3239
3240 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003241 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003242 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3244 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 if (DBG) {
3249 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3250 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3251 }
3252
3253 IccIoResult response =
3254 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3255 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3256 subId);
3257
3258 if (DBG) {
3259 log("Exchange SIM_IO [R]" + response);
3260 }
3261
3262 byte[] result = null;
3263 int length = 2;
3264 if (response.payload != null) {
3265 length = 2 + response.payload.length;
3266 result = new byte[length];
3267 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3268 } else {
3269 result = new byte[length];
3270 }
3271
3272 result[length - 1] = (byte) response.sw2;
3273 result[length - 2] = (byte) response.sw1;
3274 return result;
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003277 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003278 }
3279
Nathan Haroldb3014052017-01-25 15:57:32 -08003280 /**
3281 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3282 * on a particular subscription
3283 */
sqianb6e41952018-03-12 14:54:01 -07003284 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3286 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3287 return null;
3288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289
3290 final long identity = Binder.clearCallingIdentity();
3291 try {
3292 if (appType != TelephonyManager.APPTYPE_USIM
3293 && appType != TelephonyManager.APPTYPE_SIM) {
3294 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3295 return null;
3296 }
3297 Object response = sendRequest(
3298 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3299 if (response instanceof String[]) {
3300 return (String[]) response;
3301 }
3302 // Response is an Exception of some kind,
3303 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003304 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305 } finally {
3306 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003307 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003308 }
3309
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003310 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003311 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3313 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3318 if (response.payload == null) {
3319 return "";
3320 }
Evan Charltonc66da362014-05-16 14:06:40 -07003321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322 // Append the returned status code to the end of the response payload.
3323 String s = Integer.toHexString(
3324 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3325 s = IccUtils.bytesToHexString(response.payload) + s;
3326 return s;
3327 } finally {
3328 Binder.restoreCallingIdentity(identity);
3329 }
Evan Charltonc66da362014-05-16 14:06:40 -07003330 }
3331
Jake Hambye994d462014-02-03 13:10:13 -08003332 /**
3333 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3334 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3335 *
3336 * @param itemID the ID of the item to read
3337 * @return the NV item as a String, or null on error.
3338 */
3339 @Override
3340 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003341 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3343 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003348 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3350 return value;
3351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
Jake Hambye994d462014-02-03 13:10:13 -08003354 }
3355
3356 /**
3357 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3358 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3359 *
3360 * @param itemID the ID of the item to read
3361 * @param itemValue the value to write, as a String
3362 * @return true on success; false on any failure
3363 */
3364 @Override
3365 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003366 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3368 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003369
3370 final long identity = Binder.clearCallingIdentity();
3371 try {
3372 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3373 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003374 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3376 return success;
3377 } finally {
3378 Binder.restoreCallingIdentity(identity);
3379 }
Jake Hambye994d462014-02-03 13:10:13 -08003380 }
3381
3382 /**
3383 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3384 * Used for device configuration by some CDMA operators.
3385 *
3386 * @param preferredRoamingList byte array containing the new PRL
3387 * @return true on success; false on any failure
3388 */
3389 @Override
3390 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3392 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393
3394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3397 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3398 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3399 return success;
3400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
Jake Hambye994d462014-02-03 13:10:13 -08003403 }
3404
3405 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003406 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003407 * Used for device configuration by some CDMA operators.
3408 *
chen xu6dac5ab2018-10-26 17:39:23 -07003409 * @param slotIndex - device slot.
3410 *
Jake Hambye994d462014-02-03 13:10:13 -08003411 * @return true on success; false on any failure
3412 */
3413 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003414 public boolean resetModemConfig(int slotIndex) {
3415 Phone phone = PhoneFactory.getPhone(slotIndex);
3416 if (phone != null) {
3417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3418 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419
chen xu6dac5ab2018-10-26 17:39:23 -07003420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3423 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3424 return success;
3425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003428 }
chen xu6dac5ab2018-10-26 17:39:23 -07003429 return false;
3430 }
3431
3432 /**
3433 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3434 *
3435 * @param slotIndex - device slot.
3436 *
3437 * @return true on success; false on any failure
3438 */
3439 @Override
3440 public boolean rebootModem(int slotIndex) {
3441 Phone phone = PhoneFactory.getPhone(slotIndex);
3442 if (phone != null) {
3443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3444 mApp, phone.getSubId(), "rebootModem");
3445
3446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3449 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3450 return success;
3451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
3454 }
3455 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003456 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003457
Svet Ganovb320e182015-04-16 12:30:10 -07003458 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003460 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003461 return new String[0];
3462 }
3463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464 final long identity = Binder.clearCallingIdentity();
3465 try {
3466 return mPhone.getPcscfAddress(apnType);
3467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
Wink Saville36469e72014-06-11 15:17:00 -07003470 }
3471
Brad Ebinger51f743a2017-01-23 13:50:20 -08003472 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003473 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3474 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003475 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003476 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003477 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478
3479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 PhoneFactory.getImsResolver().enableIms(slotId);
3482 } finally {
3483 Binder.restoreCallingIdentity(identity);
3484 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003485 }
3486
3487 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003488 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3489 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003490 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003491 public void disableIms(int slotId) {
3492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493
3494 final long identity = Binder.clearCallingIdentity();
3495 try {
3496 PhoneFactory.getImsResolver().disableIms(slotId);
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003500 }
3501
3502 /**
3503 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3504 * feature or {@link null} if the service is not available. If the feature is available, the
3505 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3506 */
3507 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003508 IImsServiceFeatureCallback callback) {
3509 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003510
3511 final long identity = Binder.clearCallingIdentity();
3512 try {
3513 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3514 } finally {
3515 Binder.restoreCallingIdentity(identity);
3516 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003517 }
3518
3519 /**
3520 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3521 * feature during emergency calling or {@link null} if the service is not available. If the
3522 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3523 * listener for feature updates.
3524 */
3525 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527
3528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
3533 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003534 }
3535
Brad Ebinger5f64b052017-12-14 14:26:15 -08003536 /**
3537 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3538 * specified.
3539 */
3540 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
3548 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003549 }
3550
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003551 /**
3552 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3553 * specified.
3554 */
3555 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003564 }
3565
Brad Ebinger884c07b2018-02-15 16:17:40 -08003566 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003567 * Sets the ImsService Package Name that Telephony will bind to.
3568 *
3569 * @param slotId the slot ID that the ImsService should bind for.
3570 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3571 * ImsService is the device default ImsService.
3572 * @param packageName The package name of the application that contains the ImsService to bind
3573 * to.
3574 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3575 * @hide
3576 */
3577 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003578 int[] subIds = SubscriptionManager.getSubId(slotId);
3579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3580 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3581 "setImsService");
3582
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3586 isCarrierImsService, packageName);
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003590 }
3591
3592 /**
3593 * Return the ImsService configuration.
3594 *
3595 * @param slotId The slot that the ImsService is associated with.
3596 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3597 * the device default.
3598 * @return the package name of the ImsService configuration.
3599 */
3600 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003601 int[] subIds = SubscriptionManager.getSubId(slotId);
3602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3603 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3604 "getImsService");
3605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3609 isCarrierImsService);
3610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003613 }
3614
Wink Saville36469e72014-06-11 15:17:00 -07003615 public void setImsRegistrationState(boolean registered) {
3616 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003617
3618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 mPhone.setImsRegistrationState(registered);
3621 } finally {
3622 Binder.restoreCallingIdentity(identity);
3623 }
Wink Saville36469e72014-06-11 15:17:00 -07003624 }
3625
3626 /**
Stuart Scott54788802015-03-30 13:18:01 -07003627 * Set the network selection mode to automatic.
3628 *
3629 */
3630 @Override
3631 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3633 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003634
Pengquan Menge92a50d2018-09-21 15:54:48 -07003635 if (!isActiveSubscription(subId)) {
3636 return;
3637 }
3638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3642 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
Stuart Scott54788802015-03-30 13:18:01 -07003646 }
3647
Pengquan Mengea84e042018-09-20 14:57:26 -07003648 /**
3649 * Ask the radio to connect to the input network and change selection mode to manual.
3650 *
3651 * @param subId the id of the subscription.
3652 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3653 * the operator to attach to.
3654 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3655 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3656 * normal network selection next time.
3657 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003658 */
3659 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003660 public boolean setNetworkSelectionModeManual(
3661 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3663 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003664
3665 if (!isActiveSubscription(subId)) {
3666 return false;
3667 }
3668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 final long identity = Binder.clearCallingIdentity();
3670 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003671 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003673 if (DBG) {
3674 log("setNetworkSelectionModeManual: subId: " + subId
3675 + " operator: " + operatorInfo);
3676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003681 }
3682
3683 /**
3684 * Scans for available networks.
3685 */
3686 @Override
3687 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3689 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690
Pengquan Menga1bb6272018-09-06 09:59:22 -07003691 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003692 try {
3693 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003694 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003695 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003699 }
3700
3701 /**
yinxub1bed742017-04-17 11:45:04 -07003702 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003703 *
yinxub1bed742017-04-17 11:45:04 -07003704 * @param subId id of the subscription
3705 * @param request contains the radio access networks with bands/channels to scan
3706 * @param messenger callback messenger for scan results or errors
3707 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003708 * @return the id of the requested scan which can be used to stop the scan.
3709 */
3710 @Override
3711 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3712 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3714 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 return mNetworkScanRequestTracker.startNetworkScan(
3719 request, messenger, binder, getPhone(subId));
3720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
yinxu504e1392017-04-12 16:03:22 -07003723 }
3724
3725 /**
3726 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003727 *
3728 * @param subId id of the subscription
3729 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003730 */
3731 @Override
3732 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3734 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
yinxu504e1392017-04-12 16:03:22 -07003742 }
3743
3744 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003745 * Get the calculated preferred network type.
3746 * Used for debugging incorrect network type.
3747 *
3748 * @return the preferred network type, defined in RILConstants.java.
3749 */
3750 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003751 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003753 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003754 return RILConstants.PREFERRED_NETWORK_MODE;
3755 }
3756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003757 final long identity = Binder.clearCallingIdentity();
3758 try {
3759 // FIXME: need to get SubId from somewhere.
3760 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
Junda Liu84d15a22014-07-02 11:21:04 -07003764 }
3765
3766 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003767 * Get the preferred network type.
3768 * Used for device configuration by some CDMA operators.
3769 *
3770 * @return the preferred network type, defined in RILConstants.java.
3771 */
3772 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003773 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3775 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776
3777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 if (DBG) log("getPreferredNetworkType");
3780 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3781 int networkType = (result != null ? result[0] : -1);
3782 if (DBG) log("getPreferredNetworkType: " + networkType);
3783 return networkType;
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
3786 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003787 }
3788
3789 /**
3790 * Set the preferred network type.
3791 * Used for device configuration by some CDMA operators.
3792 *
3793 * @param networkType the preferred network type, defined in RILConstants.java.
3794 * @return true on success; false on any failure.
3795 */
3796 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003797 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3799 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800
3801 final long identity = Binder.clearCallingIdentity();
3802 try {
3803 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3804 Boolean success = (Boolean) sendRequest(
3805 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3806 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3807 if (success) {
3808 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3809 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3810 }
3811 return success;
3812 } finally {
3813 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003814 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003815 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003816
3817 /**
Junda Liu475951f2014-11-07 16:45:03 -08003818 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07003819 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003820 * tethering.
3821 *
3822 * @return 0: Not required. 1: required. 2: Not set.
3823 * @hide
3824 */
3825 @Override
3826 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828
3829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3832 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07003833 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3835 dunRequired = 1;
3836 }
3837 return dunRequired;
3838 } finally {
3839 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003840 }
Junda Liu475951f2014-11-07 16:45:03 -08003841 }
3842
3843 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003844 * Set mobile data enabled
3845 * Used by the user through settings etc to turn on/off mobile data
3846 *
3847 * @param enable {@code true} turn turn data on, else {@code false}
3848 */
3849 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003850 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3852 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853
3854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 int phoneId = mSubscriptionController.getPhoneId(subId);
3857 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3858 Phone phone = PhoneFactory.getPhone(phoneId);
3859 if (phone != null) {
3860 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3861 phone.setUserDataEnabled(enable);
3862 } else {
3863 loge("setUserDataEnabled: no phone for subId=" + subId);
3864 }
3865 } finally {
3866 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003867 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003868 }
3869
3870 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003871 * Get the user enabled state of Mobile Data.
3872 *
3873 * TODO: remove and use isUserDataEnabled.
3874 * This can't be removed now because some vendor codes
3875 * calls through ITelephony directly while they should
3876 * use TelephonyManager.
3877 *
3878 * @return true on enabled
3879 */
3880 @Override
3881 public boolean getDataEnabled(int subId) {
3882 return isUserDataEnabled(subId);
3883 }
3884
3885 /**
3886 * Get whether mobile data is enabled per user setting.
3887 *
3888 * There are other factors deciding whether mobile data is actually enabled, but they are
3889 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003890 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003891 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003892 *
3893 * @return {@code true} if data is enabled else {@code false}
3894 */
3895 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003896 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003897 try {
3898 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3899 null);
3900 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3902 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003903 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904
3905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 int phoneId = mSubscriptionController.getPhoneId(subId);
3908 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3909 Phone phone = PhoneFactory.getPhone(phoneId);
3910 if (phone != null) {
3911 boolean retVal = phone.isUserDataEnabled();
3912 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3913 return retVal;
3914 } else {
3915 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3916 return false;
3917 }
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003920 }
3921 }
3922
3923 /**
3924 * Get whether mobile data is enabled.
3925 *
3926 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3927 * whether mobile data is actually enabled.
3928 *
3929 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3930 *
3931 * @return {@code true} if data is enabled else {@code false}
3932 */
3933 @Override
3934 public boolean isDataEnabled(int subId) {
3935 try {
3936 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3937 null);
3938 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3940 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942
3943 final long identity = Binder.clearCallingIdentity();
3944 try {
3945 int phoneId = mSubscriptionController.getPhoneId(subId);
3946 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3947 Phone phone = PhoneFactory.getPhone(phoneId);
3948 if (phone != null) {
3949 boolean retVal = phone.isDataEnabled();
3950 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3951 return retVal;
3952 } else {
3953 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3954 return false;
3955 }
3956 } finally {
3957 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003958 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003959 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003960
3961 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003962 public int getCarrierPrivilegeStatus(int subId) {
3963 final Phone phone = getPhone(subId);
3964 if (phone == null) {
3965 loge("getCarrierPrivilegeStatus: Invalid subId");
3966 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3967 }
3968 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003969 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003970 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003971 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3972 }
3973 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003974 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003975 }
Junda Liu29340342014-07-10 15:23:27 -07003976
3977 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003978 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3979 final Phone phone = getPhone(subId);
3980 if (phone == null) {
3981 loge("getCarrierPrivilegeStatus: Invalid subId");
3982 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3983 }
3984 UiccProfile profile =
3985 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3986 if (profile == null) {
3987 loge("getCarrierPrivilegeStatus: No UICC");
3988 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3989 }
3990 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3991 }
3992
3993 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003994 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003995 if (TextUtils.isEmpty(pkgName))
3996 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003997 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003998 if (card == null) {
3999 loge("checkCarrierPrivilegesForPackage: No UICC");
4000 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4001 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004002 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4003 }
4004
4005 @Override
4006 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004007 if (TextUtils.isEmpty(pkgName))
4008 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004009 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4010 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4011 UiccCard card = UiccController.getInstance().getUiccCard(i);
4012 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004013 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004014 continue;
4015 }
4016
4017 result = card.getCarrierPrivilegeStatus(
4018 mPhone.getContext().getPackageManager(), pkgName);
4019 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4020 break;
4021 }
4022 }
4023
4024 return result;
Junda Liu29340342014-07-10 15:23:27 -07004025 }
Derek Tan89e89d42014-07-08 17:00:10 -07004026
4027 @Override
Junda Liue64de782015-04-16 17:19:16 -07004028 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4029 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4030 loge("phoneId " + phoneId + " is not valid.");
4031 return null;
4032 }
4033 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004034 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004035 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004036 return null ;
4037 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004038 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004039 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004040 }
4041
Amith Yamasani6e118872016-02-19 12:53:51 -08004042 @Override
4043 public List<String> getPackagesWithCarrierPrivileges() {
4044 PackageManager pm = mPhone.getContext().getPackageManager();
4045 List<String> privilegedPackages = new ArrayList<>();
4046 List<PackageInfo> packages = null;
4047 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4048 UiccCard card = UiccController.getInstance().getUiccCard(i);
4049 if (card == null) {
4050 // No UICC in that slot.
4051 continue;
4052 }
4053 if (card.hasCarrierPrivilegeRules()) {
4054 if (packages == null) {
4055 // Only check packages in user 0 for now
4056 packages = pm.getInstalledPackagesAsUser(
4057 PackageManager.MATCH_DISABLED_COMPONENTS
4058 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4059 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4060 }
4061 for (int p = packages.size() - 1; p >= 0; p--) {
4062 PackageInfo pkgInfo = packages.get(p);
4063 if (pkgInfo != null && pkgInfo.packageName != null
4064 && card.getCarrierPrivilegeStatus(pkgInfo)
4065 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4066 privilegedPackages.add(pkgInfo.packageName);
4067 }
4068 }
4069 }
4070 }
4071 return privilegedPackages;
4072 }
4073
Wink Savilleb564aae2014-10-23 10:18:09 -07004074 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004075 final Phone phone = getPhone(subId);
4076 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004077 if (card == null) {
4078 loge("getIccId: No UICC");
4079 return null;
4080 }
4081 String iccId = card.getIccId();
4082 if (TextUtils.isEmpty(iccId)) {
4083 loge("getIccId: ICC ID is null or empty.");
4084 return null;
4085 }
4086 return iccId;
4087 }
4088
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004089 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004090 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4091 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004092 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4093 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 final String iccId = getIccId(subId);
4098 final Phone phone = getPhone(subId);
4099 if (phone == null) {
4100 return false;
4101 }
4102 final String subscriberId = phone.getSubscriberId();
4103
4104 if (DBG_MERGE) {
4105 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4106 + subscriberId + " to " + number);
4107 }
4108
4109 if (TextUtils.isEmpty(iccId)) {
4110 return false;
4111 }
4112
4113 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4114
4115 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4116 if (alphaTag == null) {
4117 editor.remove(alphaTagPrefKey);
4118 } else {
4119 editor.putString(alphaTagPrefKey, alphaTag);
4120 }
4121
4122 // Record both the line number and IMSI for this ICCID, since we need to
4123 // track all merged IMSIs based on line number
4124 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4125 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4126 if (number == null) {
4127 editor.remove(numberPrefKey);
4128 editor.remove(subscriberPrefKey);
4129 } else {
4130 editor.putString(numberPrefKey, number);
4131 editor.putString(subscriberPrefKey, subscriberId);
4132 }
4133
4134 editor.commit();
4135 return true;
4136 } finally {
4137 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004138 }
Derek Tan7226c842014-07-02 17:42:23 -07004139 }
4140
4141 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004142 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004143 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004145 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004146 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004147 return null;
4148 }
Derek Tan97ebb422014-09-05 16:55:38 -07004149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 String iccId = getIccId(subId);
4153 if (iccId != null) {
4154 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4155 if (DBG_MERGE) {
4156 log("getLine1NumberForDisplay returning "
4157 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4158 }
4159 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004161 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4162 return null;
4163 } finally {
4164 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004165 }
Derek Tan7226c842014-07-02 17:42:23 -07004166 }
4167
4168 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004169 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004171 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004172 return null;
4173 }
Derek Tan97ebb422014-09-05 16:55:38 -07004174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004175 final long identity = Binder.clearCallingIdentity();
4176 try {
4177 String iccId = getIccId(subId);
4178 if (iccId != null) {
4179 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4180 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4181 }
4182 return null;
4183 } finally {
4184 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004185 }
Derek Tan7226c842014-07-02 17:42:23 -07004186 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004187
4188 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004189 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004190 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4191 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004193 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4194 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004195 return null;
4196 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004197
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004198 final long identity = Binder.clearCallingIdentity();
4199 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 final Context context = mPhone.getContext();
4201 final TelephonyManager tele = TelephonyManager.from(context);
4202 final SubscriptionManager sub = SubscriptionManager.from(context);
4203
4204 // Figure out what subscribers are currently active
4205 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4206 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4207 // the process, where TelephonyManager was instantiated.
4208 // Otherwise AppOps check will fail.
4209
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004210 final int[] subIds = sub.getActiveSubscriptionIdList();
4211 for (int subId : subIds) {
4212 activeSubscriberIds.add(tele.getSubscriberId(subId));
4213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214
4215 // First pass, find a number override for an active subscriber
4216 String mergeNumber = null;
4217 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4218 for (String key : prefs.keySet()) {
4219 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4220 final String subscriberId = (String) prefs.get(key);
4221 if (activeSubscriberIds.contains(subscriberId)) {
4222 final String iccId = key.substring(
4223 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4224 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4225 mergeNumber = (String) prefs.get(numberKey);
4226 if (DBG_MERGE) {
4227 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4228 + " for active subscriber " + subscriberId);
4229 }
4230 if (!TextUtils.isEmpty(mergeNumber)) {
4231 break;
4232 }
4233 }
4234 }
4235 }
4236
4237 // Shortcut when no active merged subscribers
4238 if (TextUtils.isEmpty(mergeNumber)) {
4239 return null;
4240 }
4241
4242 // Second pass, find all subscribers under that line override
4243 final ArraySet<String> result = new ArraySet<>();
4244 for (String key : prefs.keySet()) {
4245 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4246 final String number = (String) prefs.get(key);
4247 if (mergeNumber.equals(number)) {
4248 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4249 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4250 final String subscriberId = (String) prefs.get(subscriberKey);
4251 if (!TextUtils.isEmpty(subscriberId)) {
4252 result.add(subscriberId);
4253 }
4254 }
4255 }
4256 }
4257
4258 final String[] resultArray = result.toArray(new String[result.size()]);
4259 Arrays.sort(resultArray);
4260 if (DBG_MERGE) {
4261 Slog.d(LOG_TAG,
4262 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4263 }
4264 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004265 } finally {
4266 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004267 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004268 }
4269
4270 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004271 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004272 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4273 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004274
4275 final long identity = Binder.clearCallingIdentity();
4276 try {
4277 final Phone phone = getPhone(subId);
4278 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004282 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004283
4284 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004285 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004286 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4287 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004288 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289
4290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 final Phone phone = getPhone(subId);
4293 if (phone == null) {
4294 return false;
4295 }
4296 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4297 cdmaNonRoamingList);
4298 } finally {
4299 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004300 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004301 }
4302
4303 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004304 @Deprecated
4305 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4306 enforceModifyPermission();
4307
4308 int returnValue = 0;
4309 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004310 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004311 if(result.exception == null) {
4312 if (result.result != null) {
4313 byte[] responseData = (byte[])(result.result);
4314 if(responseData.length > oemResp.length) {
4315 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4316 responseData.length + "bytes. Buffer Size is " +
4317 oemResp.length + "bytes.");
4318 }
4319 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4320 returnValue = responseData.length;
4321 }
4322 } else {
4323 CommandException ex = (CommandException) result.exception;
4324 returnValue = ex.getCommandError().ordinal();
4325 if(returnValue > 0) returnValue *= -1;
4326 }
4327 } catch (RuntimeException e) {
4328 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4329 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4330 if(returnValue > 0) returnValue *= -1;
4331 }
4332
4333 return returnValue;
4334 }
4335
4336 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004337 public void setRadioCapability(RadioAccessFamily[] rafs) {
4338 try {
4339 ProxyController.getInstance().setRadioCapability(rafs);
4340 } catch (RuntimeException e) {
4341 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4342 }
4343 }
4344
4345 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004346 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004347 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004348 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004349 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004350 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352 final long identity = Binder.clearCallingIdentity();
4353 try {
chen xub97461a2018-10-26 14:17:57 -07004354 TelephonyPermissions
4355 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4356 mApp, phone.getSubId(), "getRadioAccessFamily");
4357 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
chen xub97461a2018-10-26 14:17:57 -07004361 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004362 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004363
4364 @Override
4365 public void enableVideoCalling(boolean enable) {
4366 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367
4368 final long identity = Binder.clearCallingIdentity();
4369 try {
4370 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004374 }
4375
4376 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004377 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4379 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4380 return false;
4381 }
Svet Ganovb320e182015-04-16 12:30:10 -07004382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383 final long identity = Binder.clearCallingIdentity();
4384 try {
4385 // Check the user preference and the system-level IMS setting. Even if the user has
4386 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4387 // In the long run, we may instead need to check if there exists a connection service
4388 // which can support video calling.
4389 ImsManager imsManager =
4390 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4391 return imsManager.isVtEnabledByPlatform()
4392 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4393 && imsManager.isVtEnabledByUser();
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
4396 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004397 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004398
Andrew Leea1239f22015-03-02 17:44:07 -08004399 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4402 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4403 return false;
4404 }
4405
4406 final long identity = Binder.clearCallingIdentity();
4407 try {
4408 CarrierConfigManager configManager =
4409 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4410 return configManager.getConfigForSubId(mPhone.getSubId())
4411 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
Andrew Leea1239f22015-03-02 17:44:07 -08004415 }
4416
4417 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418 public boolean isWorldPhone(int subId, String callingPackage) {
4419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4420 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4421 return false;
4422 }
4423
4424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 CarrierConfigManager configManager =
4427 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4428 return configManager.getConfigForSubId(mPhone.getSubId())
4429 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
Andrew Leea1239f22015-03-02 17:44:07 -08004433 }
4434
Andrew Lee9431b832015-03-09 18:46:45 -07004435 @Override
4436 public boolean isTtyModeSupported() {
4437 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004438 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004439 }
4440
4441 @Override
4442 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 final long identity = Binder.clearCallingIdentity();
4444 try {
4445 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
Andrew Lee9431b832015-03-09 18:46:45 -07004449 }
4450
Hall Liuf6668912018-10-31 17:05:23 -07004451 /**
4452 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4453 * support for the feature and device firmware support.
4454 *
4455 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4456 */
4457 @Override
4458 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004459 final long identity = Binder.clearCallingIdentity();
4460 try {
4461 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4462 mPhone.getSubId()).getBoolean(
4463 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4464 boolean isDeviceSupported =
4465 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4466 return isCarrierSupported && isDeviceSupported;
4467 } finally {
4468 Binder.restoreCallingIdentity(identity);
4469 }
Hall Liu98187582018-01-22 19:15:32 -08004470 }
4471
Hall Liuf6668912018-10-31 17:05:23 -07004472 /**
4473 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4474 * both also support RTT.
4475 */
4476 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 final long identity = Binder.clearCallingIdentity();
4478 try {
Hall Liuf6668912018-10-31 17:05:23 -07004479 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 mPhone.getContext().getContentResolver(),
4481 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004485 }
4486
Sanket Padawe7310cc72015-01-14 09:53:20 -08004487 /**
4488 * Returns the unique device ID of phone, for example, the IMEI for
4489 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4490 *
4491 * <p>Requires Permission:
4492 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4493 */
4494 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004495 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004496 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004497 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004498 return null;
4499 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004500 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004501 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4502 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004503 return null;
4504 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004505
4506 final long identity = Binder.clearCallingIdentity();
4507 try {
4508 return phone.getDeviceId();
4509 } finally {
4510 Binder.restoreCallingIdentity(identity);
4511 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004512 }
4513
Ping Sunc67b7c22016-03-02 19:16:45 +08004514 /**
4515 * {@hide}
4516 * Returns the IMS Registration Status on a particular subid
4517 *
4518 * @param subId
4519 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004520 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004521 Phone phone = getPhone(subId);
4522 if (phone != null) {
4523 return phone.isImsRegistered();
4524 } else {
4525 return false;
4526 }
4527 }
4528
Santos Cordon7a1885b2015-02-03 11:15:19 -08004529 @Override
4530 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004531 final long identity = Binder.clearCallingIdentity();
4532 try {
4533 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4534 } finally {
4535 Binder.restoreCallingIdentity(identity);
4536 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004537 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004538
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004539 /**
4540 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004541 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004542 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543 final long identity = Binder.clearCallingIdentity();
4544 try {
4545 Phone phone = getPhone(subId);
4546 if (phone != null) {
4547 return phone.isWifiCallingEnabled();
4548 } else {
4549 return false;
4550 }
4551 } finally {
4552 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004553 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004554 }
4555
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004556 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004557 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004558 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004559 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 final long identity = Binder.clearCallingIdentity();
4561 try {
4562 Phone phone = getPhone(subId);
4563 if (phone != null) {
4564 return phone.isVideoEnabled();
4565 } else {
4566 return false;
4567 }
4568 } finally {
4569 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004570 }
4571 }
4572
4573 /**
4574 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4575 * defined in {@link ImsRegistrationImplBase}.
4576 */
4577 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004578 final long identity = Binder.clearCallingIdentity();
4579 try {
4580 Phone phone = getPhone(subId);
4581 if (phone != null) {
4582 return phone.getImsRegistrationTech();
4583 } else {
4584 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4585 }
4586 } finally {
4587 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004588 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004589 }
4590
Stuart Scott8eef64f2015-04-08 15:13:54 -07004591 @Override
4592 public void factoryReset(int subId) {
4593 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004594 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4595 return;
4596 }
4597
Svet Ganovcc087f82015-05-12 20:35:54 -07004598 final long identity = Binder.clearCallingIdentity();
4599 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004600 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4601 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004602 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004603 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004604 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4605 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004606 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004607 }
4608 } finally {
4609 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004610 }
4611 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004612
4613 @Override
4614 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 final long identity = Binder.clearCallingIdentity();
4616 try {
4617 // We query all subscriptions instead of just the active ones, because
4618 // this might be called early on in the provisioning flow when the
4619 // subscriptions potentially aren't active yet.
4620 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4621 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004622 return null;
4623 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 // This function may be called very early, say, from the setup wizard, at
4626 // which point we won't have a default subscription set. If that's the case
4627 // we just choose the first, which will be valid in "most cases".
4628 final int defaultSubId = getDefaultSubscription();
4629 SubscriptionInfo info = null;
4630 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4631 info = slist.get(0);
4632 } else {
4633 for (SubscriptionInfo item : slist) {
4634 if (item.getSubscriptionId() == defaultSubId) {
4635 info = item;
4636 break;
4637 }
4638 }
4639
4640 if (info == null) {
4641 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004642 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004643 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645 // Try and fetch the locale from the carrier properties or from the SIM language
4646 // preferences (EF-PL and EF-LI)...
4647 final int mcc = info.getMcc();
4648 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4649 String simLanguage = null;
4650 if (defaultPhone != null) {
4651 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4652 if (localeFromDefaultSim != null) {
4653 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4654 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4655 return localeFromDefaultSim.toLanguageTag();
4656 } else {
4657 simLanguage = localeFromDefaultSim.getLanguage();
4658 }
4659 }
4660 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 // The SIM language preferences only store a language (e.g. fr = French), not an
4663 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4664 // the SIM and carrier preferences does not include a country we add the country
4665 // determined from the SIM MCC to provide an exact locale.
4666 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4667 simLanguage);
4668 if (mccLocale != null) {
4669 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4670 return mccLocale.toLanguageTag();
4671 }
4672
4673 if (DBG) log("No locale found - returning null");
4674 return null;
4675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004678 }
4679
4680 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 return mSubscriptionController.getAllSubInfoList(
4682 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004683 }
4684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 /**
4686 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4687 */
4688 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4689 return mSubscriptionController.getActiveSubscriptionInfoList(
4690 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004691 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004692
Chenjie Yu1ba97252018-01-11 18:16:20 -08004693 private final ModemActivityInfo mLastModemActivityInfo =
4694 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4695
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004696 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004697 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4698 * representing the state of the modem.
4699 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004700 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4701 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004702 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004703 */
4704 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004705 public void requestModemActivityInfo(ResultReceiver result) {
4706 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004707 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004708
4709 final long identity = Binder.clearCallingIdentity();
4710 try {
4711 ModemActivityInfo ret = null;
4712 synchronized (mLastModemActivityInfo) {
4713 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4714 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004715 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004716 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4718 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4719 mergedTxTimeMs[i] =
4720 info.getTxTimeMillis()[i]
4721 + mLastModemActivityInfo.getTxTimeMillis()[i];
4722 }
4723 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4724 mLastModemActivityInfo.setSleepTimeMillis(
4725 info.getSleepTimeMillis()
4726 + mLastModemActivityInfo.getSleepTimeMillis());
4727 mLastModemActivityInfo.setIdleTimeMillis(
4728 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4729 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4730 mLastModemActivityInfo.setRxTimeMillis(
4731 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4732 mLastModemActivityInfo.setEnergyUsed(
4733 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004734 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4736 mLastModemActivityInfo.getSleepTimeMillis(),
4737 mLastModemActivityInfo.getIdleTimeMillis(),
4738 mLastModemActivityInfo.getTxTimeMillis(),
4739 mLastModemActivityInfo.getRxTimeMillis(),
4740 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004741 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 Bundle bundle = new Bundle();
4743 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4744 result.send(0, bundle);
4745 } finally {
4746 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004747 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004748 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004749
Siddharth Rayb8114062018-06-17 15:02:38 -07004750 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4751 // less than total activity duration.
4752 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4753 if (info == null) {
4754 return false;
4755 }
4756 int activityDurationMs =
4757 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4758 int totalTxTimeMs = 0;
4759 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4760 totalTxTimeMs += info.getTxTimeMillis()[i];
4761 }
4762 return (info.isValid()
4763 && (info.getSleepTimeMillis() <= activityDurationMs)
4764 && (info.getIdleTimeMillis() <= activityDurationMs)
4765 && (info.getRxTimeMillis() <= activityDurationMs)
4766 && (totalTxTimeMs <= activityDurationMs));
4767 }
4768
Jack Yu85bd38a2015-11-09 11:34:32 -08004769 /**
4770 * {@hide}
4771 * Returns the service state information on specified subscription.
4772 */
4773 @Override
4774 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004775 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004776 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004777 return null;
4778 }
4779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 final long identity = Binder.clearCallingIdentity();
4781 try {
4782 final Phone phone = getPhone(subId);
4783 if (phone == null) {
4784 return null;
4785 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004787 return phone.getServiceState();
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
4790 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004791 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004792
4793 /**
4794 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4795 *
4796 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4797 * voicemail ringtone.
4798 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4799 * PhoneAccount.
4800 */
4801 @Override
4802 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803 final long identity = Binder.clearCallingIdentity();
4804 try {
4805 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4806 if (phone == null) {
4807 phone = mPhone;
4808 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4811 } finally {
4812 Binder.restoreCallingIdentity(identity);
4813 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004814 }
4815
4816 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004817 * Sets the per-account voicemail ringtone.
4818 *
4819 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4820 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4821 *
4822 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4823 * voicemail ringtone.
4824 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4825 * PhoneAccount.
4826 */
4827 @Override
4828 public void setVoicemailRingtoneUri(String callingPackage,
4829 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4830 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4831 if (!TextUtils.equals(callingPackage,
4832 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4834 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4835 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837
4838 final long identity = Binder.clearCallingIdentity();
4839 try {
4840 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4841 if (phone == null) {
4842 phone = mPhone;
4843 }
4844 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4845 } finally {
4846 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004847 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004848 }
4849
4850 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004851 * Returns whether vibration is set for voicemail notification in Phone settings.
4852 *
4853 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4854 * voicemail vibration setting.
4855 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4856 */
4857 @Override
4858 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 final long identity = Binder.clearCallingIdentity();
4860 try {
4861 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4862 if (phone == null) {
4863 phone = mPhone;
4864 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004870 }
4871
Youhan Wange64578a2016-05-02 15:32:42 -07004872 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004873 * Sets the per-account voicemail vibration.
4874 *
4875 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4876 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4877 *
4878 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4879 * voicemail vibration setting.
4880 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4881 * specific PhoneAccount.
4882 */
4883 @Override
4884 public void setVoicemailVibrationEnabled(String callingPackage,
4885 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4886 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4887 if (!TextUtils.equals(callingPackage,
4888 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4890 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4891 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004892 }
4893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4897 if (phone == null) {
4898 phone = mPhone;
4899 }
4900 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4901 } finally {
4902 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004903 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004904 }
4905
4906 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004907 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4908 *
4909 * @throws SecurityException if the caller does not have the required permission
4910 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004911 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004912 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004913 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004914 }
4915
4916 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004917 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4918 * permission.
4919 *
4920 * @throws SecurityException if the caller does not have the required permission
4921 */
4922 private void enforceSendSmsPermission() {
4923 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4924 }
4925
4926 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004927 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004928 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004929 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004930 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004931 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 ComponentName componentName =
4935 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4936 if (componentName == null) {
4937 throw new SecurityException(
4938 "Caller not current active visual voicemail package[null]");
4939 }
4940 String vvmPackage = componentName.getPackageName();
4941 if (!callingPackage.equals(vvmPackage)) {
4942 throw new SecurityException("Caller not current active visual voicemail package["
4943 + vvmPackage + "]");
4944 }
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004947 }
4948 }
4949
4950 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004951 * Return the application ID for the app type.
4952 *
4953 * @param subId the subscription ID that this request applies to.
4954 * @param appType the uicc app type.
4955 * @return Application ID for specificied app type, or null if no uicc.
4956 */
4957 @Override
4958 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004959 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07004960 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961
4962 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004963 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 if (phone == null) {
4965 return null;
4966 }
4967 String aid = null;
4968 try {
4969 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4970 .getApplicationByType(appType).getAid();
4971 } catch (Exception e) {
4972 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4973 }
4974 return aid;
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004977 }
Youhan Wange64578a2016-05-02 15:32:42 -07004978 }
4979
Youhan Wang4001d252016-05-11 10:29:41 -07004980 /**
4981 * Return the Electronic Serial Number.
4982 *
4983 * @param subId the subscription ID that this request applies to.
4984 * @return ESN or null if error.
4985 */
4986 @Override
4987 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004988 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07004989 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990
4991 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004992 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 if (phone == null) {
4994 return null;
4995 }
4996 String esn = null;
4997 try {
4998 esn = phone.getEsn();
4999 } catch (Exception e) {
5000 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5001 }
5002 return esn;
5003 } finally {
5004 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005005 }
Youhan Wang4001d252016-05-11 10:29:41 -07005006 }
5007
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005008 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005009 * Return the Preferred Roaming List Version.
5010 *
5011 * @param subId the subscription ID that this request applies to.
5012 * @return PRLVersion or null if error.
5013 */
5014 @Override
5015 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005016 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005017 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018
5019 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005020 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021 if (phone == null) {
5022 return null;
5023 }
5024 String cdmaPrlVersion = null;
5025 try {
5026 cdmaPrlVersion = phone.getCdmaPrlVersion();
5027 } catch (Exception e) {
5028 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5029 }
5030 return cdmaPrlVersion;
5031 } finally {
5032 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005033 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005034 }
5035
5036 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005037 * Get snapshot of Telephony histograms
5038 * @return List of Telephony histograms
5039 * @hide
5040 */
5041 @Override
5042 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5044 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045
5046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 return RIL.getTelephonyRILTimingHistograms();
5049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005052 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005053
5054 /**
5055 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005056 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005057 * Require system privileges. In the future we may add this to carrier APIs.
5058 *
5059 * @return The number of carriers set successfully, should match length of carriers
5060 */
5061 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005062 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005063 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005064 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005065
Meng Wang9b7c4e92017-02-17 11:41:27 -08005066 if (carriers == null) {
5067 throw new NullPointerException("carriers cannot be null");
5068 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005073 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5074 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005075 return retVal[0];
5076 } finally {
5077 Binder.restoreCallingIdentity(identity);
5078 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005079 }
5080
5081 /**
5082 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005083 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005084 * Require system privileges. In the future we may add this to carrier APIs.
5085 *
5086 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5087 * means all carriers are allowed.
5088 */
5089 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005090 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005091 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005092 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093
5094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005097 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5098 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005099 } finally {
5100 Binder.restoreCallingIdentity(identity);
5101 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005102 }
5103
fionaxu59545b42016-05-25 15:53:37 -07005104 /**
5105 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5106 * @param subId the subscription ID that this action applies to.
5107 * @param enabled control enable or disable metered apns.
5108 * {@hide}
5109 */
5110 @Override
5111 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5112 enforceModifyPermission();
5113 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114
5115 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005116 if (phone == null) {
5117 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5118 return;
5119 }
5120 try {
5121 phone.carrierActionSetMeteredApnsEnabled(enabled);
5122 } catch (Exception e) {
5123 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 } finally {
5125 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005126 }
5127 }
5128
5129 /**
5130 * Action set from carrier signalling broadcast receivers to enable/disable radio
5131 * @param subId the subscription ID that this action applies to.
5132 * @param enabled control enable or disable radio.
5133 * {@hide}
5134 */
5135 @Override
5136 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5137 enforceModifyPermission();
5138 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139
5140 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005141 if (phone == null) {
5142 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5143 return;
5144 }
5145 try {
5146 phone.carrierActionSetRadioEnabled(enabled);
5147 } catch (Exception e) {
5148 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 } finally {
5150 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005151 }
5152 }
5153
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005154 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005155 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5156 * network status based on which carrier apps could apply actions accordingly,
5157 * enable/disable default url handler for example.
5158 *
5159 * @param subId the subscription ID that this action applies to.
5160 * @param report control start/stop reporting the default network status.
5161 * {@hide}
5162 */
5163 @Override
5164 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5165 enforceModifyPermission();
5166 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167
5168 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005169 if (phone == null) {
5170 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5171 return;
5172 }
5173 try {
5174 phone.carrierActionReportDefaultNetworkStatus(report);
5175 } catch (Exception e) {
5176 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177 } finally {
5178 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005179 }
5180 }
5181
5182 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005183 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5184 * bug report is being generated.
5185 */
5186 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005187 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005188 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5189 != PackageManager.PERMISSION_GRANTED) {
5190 writer.println("Permission Denial: can't dump Phone from pid="
5191 + Binder.getCallingPid()
5192 + ", uid=" + Binder.getCallingUid()
5193 + "without permission "
5194 + android.Manifest.permission.DUMP);
5195 return;
5196 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005197 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005198 }
Jack Yueb89b242016-06-22 13:27:47 -07005199
Brad Ebingerdac2f002018-04-03 15:17:52 -07005200 @Override
5201 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5202 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5203 throws RemoteException {
5204 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5205 }
5206
Jack Yueb89b242016-06-22 13:27:47 -07005207 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005208 * Get aggregated video call data usage since boot.
5209 *
5210 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5211 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005212 * {@hide}
5213 */
5214 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005215 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005216 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5217 null);
5218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 final long identity = Binder.clearCallingIdentity();
5220 try {
5221 // NetworkStatsService keeps tracking the active network interface and identity. It
5222 // records the delta with the corresponding network identity.
5223 // We just return the total video call data usage snapshot since boot.
5224 Phone phone = getPhone(subId);
5225 if (phone != null) {
5226 return phone.getVtDataUsage(perUidStats);
5227 }
5228 return null;
5229 } finally {
5230 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005231 }
Jack Yueb89b242016-06-22 13:27:47 -07005232 }
Jack Yu75ab2952016-07-08 14:29:33 -07005233
5234 /**
5235 * Policy control of data connection. Usually used when data limit is passed.
5236 * @param enabled True if enabling the data, otherwise disabling.
5237 * @param subId Subscription index
5238 * {@hide}
5239 */
5240 @Override
5241 public void setPolicyDataEnabled(boolean enabled, int subId) {
5242 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243
5244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 Phone phone = getPhone(subId);
5247 if (phone != null) {
5248 phone.setPolicyDataEnabled(enabled);
5249 }
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005252 }
5253 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005254
5255 /**
5256 * Get Client request stats
5257 * @return List of Client Request Stats
5258 * @hide
5259 */
5260 @Override
5261 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005263 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005264 return null;
5265 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005266 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 final long identity = Binder.clearCallingIdentity();
5269 try {
5270 if (phone != null) {
5271 return phone.getClientRequestStats();
5272 }
5273
5274 return null;
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005278 }
5279
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005280 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005281 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005282 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005283 }
Jack Yueb4124c2017-02-16 15:32:43 -08005284
5285 /**
Grace Chen70990072017-03-24 17:21:30 -07005286 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005287 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005288 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005289 * @param state State of SIM (power down, power up, pass through)
5290 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5291 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5292 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005293 *
5294 **/
5295 @Override
Grace Chen70990072017-03-24 17:21:30 -07005296 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005297 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005298 Phone phone = PhoneFactory.getPhone(slotIndex);
5299
vagdeviaf9a5b92018-08-15 16:01:53 -07005300 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005305 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306 }
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005309 }
5310 }
Shuo Qiandd210312017-04-12 22:11:33 +00005311
Tyler Gunn65d45c22017-06-05 11:22:26 -07005312 private boolean isUssdApiAllowed(int subId) {
5313 CarrierConfigManager configManager =
5314 (CarrierConfigManager) mPhone.getContext().getSystemService(
5315 Context.CARRIER_CONFIG_SERVICE);
5316 if (configManager == null) {
5317 return false;
5318 }
5319 PersistableBundle pb = configManager.getConfigForSubId(subId);
5320 if (pb == null) {
5321 return false;
5322 }
5323 return pb.getBoolean(
5324 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5325 }
5326
Shuo Qiandd210312017-04-12 22:11:33 +00005327 /**
5328 * Check if phone is in emergency callback mode
5329 * @return true if phone is in emergency callback mode
5330 * @param subId sub id
5331 */
goneil9c5f4872017-12-05 14:07:56 -08005332 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005333 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005334 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005335 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336
5337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 if (phone != null) {
5340 return phone.isInEcm();
5341 } else {
5342 return false;
5343 }
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005346 }
5347 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005348
5349 /**
5350 * Get the current signal strength information for the given subscription.
5351 * Because this information is not updated when the device is in a low power state
5352 * it should not be relied-upon to be current.
5353 * @param subId Subscription index
5354 * @return the most recent cached signal strength info from the modem
5355 */
5356 @Override
5357 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 final long identity = Binder.clearCallingIdentity();
5359 try {
5360 Phone p = getPhone(subId);
5361 if (p == null) {
5362 return null;
5363 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 return p.getSignalStrength();
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
5368 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005369 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005370
Pengquan Meng77b7f132018-08-22 14:49:57 -07005371 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005372 * Get the current modem radio state for the given slot.
5373 * @param slotIndex slot index.
5374 * @param callingPackage the name of the package making the call.
5375 * @return the current radio power state from the modem
5376 */
5377 @Override
5378 public int getRadioPowerState(int slotIndex, String callingPackage) {
5379 Phone phone = PhoneFactory.getPhone(slotIndex);
5380 if (phone != null) {
5381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5382 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5383 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5384 }
5385
5386 final long identity = Binder.clearCallingIdentity();
5387 try {
5388 return phone.getRadioPowerState();
5389 } finally {
5390 Binder.restoreCallingIdentity(identity);
5391 }
5392 }
5393 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5394 }
5395
5396 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005397 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5398 *
5399 * <p>Requires one of the following permissions:
5400 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5401 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5402 * privileges.
5403 *
5404 * @param subId subscription id
5405 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5406 * {@code false}.
5407 */
5408 @Override
5409 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005410 boolean isEnabled = false;
5411 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005412 try {
5413 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005414 null /* message */);
5415 Phone phone = getPhone(subId);
5416 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005417 } catch (Exception e) {
5418 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5419 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005420 } finally {
5421 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005422 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005423 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005424 }
5425
5426
5427 /**
5428 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5429 *
5430 * <p> Requires permission:
5431 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5432 * privileges.
5433 *
5434 * @param subId subscription id
5435 * @param isEnabled {@code true} means enable, {@code false} means disable.
5436 */
5437 @Override
5438 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005439 final long identity = Binder.clearCallingIdentity();
5440 try {
5441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5442 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005443
Pengquan Menga1bb6272018-09-06 09:59:22 -07005444 Phone phone = getPhone(subId);
5445 if (phone != null) {
5446 phone.setDataRoamingEnabled(isEnabled);
5447 }
5448 } finally {
5449 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005450 }
5451 }
5452
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005453 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005454 public boolean isManualNetworkSelectionAllowed(int subId) {
5455 boolean isAllowed = true;
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
5458 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5459 mApp, subId, "isManualNetworkSelectionAllowed");
5460 Phone phone = getPhone(subId);
5461 if (phone != null) {
5462 isAllowed = phone.isCspPlmnEnabled();
5463 }
5464 } finally {
5465 Binder.restoreCallingIdentity(identity);
5466 }
5467 return isAllowed;
5468 }
5469
5470 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005471 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005472 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 final long identity = Binder.clearCallingIdentity();
5475 try {
5476 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5477 if (slots == null) {
5478 Rlog.i(LOG_TAG, "slots is null.");
5479 return null;
5480 }
5481
5482 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5483 for (int i = 0; i < slots.length; i++) {
5484 UiccSlot slot = slots[i];
5485 if (slot == null) {
5486 continue;
5487 }
5488
5489 String cardId;
5490 UiccCard card = slot.getUiccCard();
5491 if (card != null) {
5492 cardId = card.getCardId();
5493 } else {
5494 cardId = slot.getIccId();
5495 }
5496
5497 int cardState = 0;
5498 switch (slot.getCardState()) {
5499 case CARDSTATE_ABSENT:
5500 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5501 break;
5502 case CARDSTATE_PRESENT:
5503 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5504 break;
5505 case CARDSTATE_ERROR:
5506 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5507 break;
5508 case CARDSTATE_RESTRICTED:
5509 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5510 break;
5511 default:
5512 break;
5513
5514 }
5515
5516 infos[i] = new UiccSlotInfo(
5517 slot.isActive(),
5518 slot.isEuicc(),
5519 cardId,
5520 cardState,
5521 slot.getPhoneId(),
5522 slot.isExtendedApduSupported());
5523 }
5524 return infos;
5525 } finally {
5526 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005527 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005528 }
5529
5530 @Override
5531 public boolean switchSlots(int[] physicalSlots) {
5532 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533
5534 final long identity = Binder.clearCallingIdentity();
5535 try {
5536 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
5539 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005540 }
Jack Yu4c988042018-02-27 15:30:01 -08005541
5542 @Override
5543 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5544 enforceModifyPermission();
5545 final Phone phone = getPhone(subId);
5546 if (phone == null) {
5547 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5548 return;
5549 }
5550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 final long identity = Binder.clearCallingIdentity();
5552 try {
5553 phone.setRadioIndicationUpdateMode(filters, mode);
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556 }
Jack Yu4c988042018-02-27 15:30:01 -08005557 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005558
5559 /**
goneil47ffb6e2018-04-06 15:40:58 -07005560 * A test API to reload the UICC profile.
5561 *
5562 * <p>Requires that the calling app has permission
5563 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5564 * @hide
5565 */
5566 @Override
5567 public void refreshUiccProfile(int subId) {
5568 enforceModifyPermission();
5569
5570 final long identity = Binder.clearCallingIdentity();
5571 try {
5572 Phone phone = getPhone(subId);
5573 if (phone == null) {
5574 return;
5575 }
5576 UiccCard uiccCard = phone.getUiccCard();
5577 if (uiccCard == null) {
5578 return;
5579 }
5580 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5581 if (uiccProfile == null) {
5582 return;
5583 }
5584 uiccProfile.refresh();
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
5588 }
5589
5590 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005591 * Returns false if the mobile data is disabled by default, otherwise return true.
5592 */
5593 private boolean getDefaultDataEnabled() {
5594 return "true".equalsIgnoreCase(
5595 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5596 }
5597
5598 /**
5599 * Returns true if the data roaming is enabled by default, i.e the system property
5600 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5601 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5602 */
5603 private boolean getDefaultDataRoamingEnabled(int subId) {
5604 final CarrierConfigManager configMgr = (CarrierConfigManager)
5605 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5606 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5607 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5608 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5609 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5610 return isDataRoamingEnabled;
5611 }
5612
5613 /**
5614 * Returns the default network type for the given {@code subId}, if the default network type is
5615 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5616 */
5617 private int getDefaultNetworkType(int subId) {
5618 return Integer.parseInt(
5619 TelephonyManager.getTelephonyProperty(
5620 mSubscriptionController.getPhoneId(subId),
5621 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5622 String.valueOf(Phone.PREFERRED_NT_MODE)));
5623 }
fionaxua13278b2018-03-21 00:08:13 -07005624
5625 @Override
5626 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5627 gid1, String gid2, String plmn, String spn) {
5628 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629
5630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 final Phone phone = getPhone(subId);
5633 if (phone == null) {
5634 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5635 return;
5636 }
5637 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5638 } finally {
5639 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005640 }
fionaxua13278b2018-03-21 00:08:13 -07005641 }
5642
5643 @Override
5644 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005645 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646
5647 final long identity = Binder.clearCallingIdentity();
5648 try {
5649 final Phone phone = getPhone(subId);
5650 if (phone == null) {
5651 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5652 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5653 }
5654 return phone.getCarrierIdListVersion();
5655 } finally {
5656 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005657 }
fionaxua13278b2018-03-21 00:08:13 -07005658 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005659
5660 @Override
5661 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5662 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5663 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5664 return -1;
5665 }
5666
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5670 } finally {
5671 Binder.restoreCallingIdentity(identity);
5672 }
5673 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005674
5675 @Override
5676 public int getCdmaRoamingMode(int subId) {
5677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5678 mApp, subId, "getCdmaRoamingMode");
5679
5680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
5686 }
5687
5688 @Override
5689 public boolean setCdmaRoamingMode(int subId, int mode) {
5690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, subId, "setCdmaRoamingMode");
5692
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
5699 }
5700
5701 @Override
5702 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5704 mApp, subId, "setCdmaSubscriptionMode");
5705
5706 final long identity = Binder.clearCallingIdentity();
5707 try {
5708 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
5712 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005713
5714 private void ensureUserRunning(int userId) {
5715 if (!mUserManager.isUserRunning(userId)) {
5716 throw new IllegalStateException("User " + userId + " does not exist or not running");
5717 }
5718 }
5719
5720 /**
5721 * Returns a list of SMS apps on a given user.
5722 *
5723 * Only the shell user (UID 2000 or 0) can call it.
5724 * Target user must be running.
5725 */
5726 @Override
5727 public String[] getSmsApps(int userId) {
5728 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5729 ensureUserRunning(userId);
5730
5731 final Collection<SmsApplicationData> apps =
5732 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5733
5734 String[] ret = new String[apps.size()];
5735 int i = 0;
5736 for (SmsApplicationData app : apps) {
5737 ret[i++] = app.mPackageName;
5738 }
5739 return ret;
5740 }
5741
5742 /**
5743 * Returns the default SMS app package name on a given user.
5744 *
5745 * Only the shell user (UID 2000 or 0) can call it.
5746 * Target user must be running.
5747 */
5748 @Override
5749 public String getDefaultSmsApp(int userId) {
5750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5751 ensureUserRunning(userId);
5752
5753 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5754 /* updateIfNeeded= */ true, userId);
5755 return cn == null ? null : cn.getPackageName();
5756 }
5757
5758 /**
5759 * Set a package as the default SMS app on a given user.
5760 *
5761 * Only the shell user (UID 2000 or 0) can call it.
5762 * Target user must be running.
5763 */
5764 @Override
5765 public void setDefaultSmsApp(int userId, String packageName) {
5766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5767 ensureUserRunning(userId);
5768
5769 boolean found = false;
5770 for (String pkg : getSmsApps(userId)) {
5771 if (TextUtils.equals(packageName, pkg)) {
5772 found = true;
5773 break;
5774 }
5775 }
5776 if (!found) {
5777 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5778 }
5779
5780 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5781 }
sqianc5eccab2018-10-19 18:46:41 -07005782
5783 @Override
5784 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5785 String callingPackage) {
5786 // TODO connect with internal content
5787 return null;
5788 }
5789
5790 @Override
5791 public boolean isCurrentEmergencyNumber(String number) {
5792 // TODO connect with internal content
5793 return false;
5794 }
chen xud6b45bd2018-10-30 22:27:10 -07005795
5796 @Override
5797 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5798 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5799 Phone phone = getPhone(subId);
5800 if (phone == null) {
5801 return null;
5802 }
5803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 UiccProfile profile = UiccController.getInstance()
5806 .getUiccProfileForPhone(phone.getPhoneId());
5807 if (profile != null) {
5808 return profile.getCertsFromCarrierPrivilegeAccessRules();
5809 }
5810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
5813 return null;
5814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005815}