blob: 7735f3a63bcb8e9401bfa01bd966f0c756f5dd68 [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;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070045import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070046import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070048import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070049import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070050import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080051import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070052import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080053import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080054import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070055import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070056import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070058import android.telephony.CellInfoGsm;
59import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070060import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070061import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070062import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080063import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070064import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080065import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070066import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070067import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070068import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080070import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070071import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080072import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070074import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070075import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000076import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070077import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070078import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070079import android.telephony.cdma.CdmaCellLocation;
80import android.telephony.gsm.GsmCellLocation;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080081import android.telephony.ims.aidl.IImsConfig;
82import android.telephony.ims.aidl.IImsMmTelFeature;
83import android.telephony.ims.aidl.IImsRcsFeature;
84import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080085import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080087import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080091
Andrew Lee312e8172014-10-23 17:01:36 -070092import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080093import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070094import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070095import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070096import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070097import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070098import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800101import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700102import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100103import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700104import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700105import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700107import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800108import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700109import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700110import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700111import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700112import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700113import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700114import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700115import com.android.internal.telephony.SmsApplication;
116import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800117import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800118import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700119import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700120import com.android.internal.telephony.uicc.IccIoResult;
121import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800122import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700123import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800124import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800126import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000127import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700128import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800129import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700130import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800131import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700132import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700133import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800134
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700135import java.io.FileDescriptor;
136import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800137import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700140import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800141import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100142import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800143import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144
145/**
146 * Implementation of the ITelephony interface.
147 */
Santos Cordon117fee72014-05-16 17:56:12 -0700148public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149 private static final String LOG_TAG = "PhoneInterfaceManager";
150 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
151 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800152 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153
154 // Message codes used with mMainThreadHandler
155 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700156 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
157 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158 private static final int CMD_OPEN_CHANNEL = 9;
159 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
160 private static final int CMD_CLOSE_CHANNEL = 11;
161 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800162 private static final int CMD_NV_READ_ITEM = 13;
163 private static final int EVENT_NV_READ_ITEM_DONE = 14;
164 private static final int CMD_NV_WRITE_ITEM = 15;
165 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
166 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
167 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
168 private static final int CMD_NV_RESET_CONFIG = 19;
169 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800170 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
171 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
172 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
173 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800174 private static final int CMD_SEND_ENVELOPE = 25;
175 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000176 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
177 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700178 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
179 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
180 private static final int CMD_EXCHANGE_SIM_IO = 31;
181 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800182 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
183 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700184 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
185 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700186 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
187 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700188 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
189 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
190 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
191 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700192 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
193 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
194 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
195 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700196 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
198 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000199 private static final int CMD_SWITCH_SLOTS = 50;
200 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700201 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
202 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
203 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
204 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
205 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
206 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
207 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
208 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700209 private static final int CMD_GET_ALL_CELL_INFO = 60;
210 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
211 private static final int CMD_GET_CELL_LOCATION = 62;
212 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800214 // Parameters of select command.
215 private static final int SELECT_COMMAND = 0xA4;
216 private static final int SELECT_P1 = 0x04;
217 private static final int SELECT_P2 = 0;
218 private static final int SELECT_P3 = 0x10;
219
Pengquan Meng85728fb2018-03-12 16:31:21 -0700220 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
221 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
222 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
223
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 /** The singleton instance. */
225 private static PhoneInterfaceManager sInstance;
226
Wink Saville3ab207e2014-11-20 13:07:20 -0800227 private PhoneGlobals mApp;
228 private Phone mPhone;
229 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700230 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800231 private AppOpsManager mAppOps;
232 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800233 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800234 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700235 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236
Derek Tan97ebb422014-09-05 16:55:38 -0700237 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
238 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800239 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700240
Derek Tan740e1672017-06-27 14:56:27 -0700241 // The AID of ISD-R.
242 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
243
yinxub1bed742017-04-17 11:45:04 -0700244 private NetworkScanRequestTracker mNetworkScanRequestTracker;
245
David Kelly5e06a7f2018-03-12 14:10:59 +0000246 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
247 private static final int MANUFACTURER_CODE_LENGTH = 8;
248
Derek Tan89e89d42014-07-08 17:00:10 -0700249 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700250 * A request object to use for transmitting data to an ICC.
251 */
252 private static final class IccAPDUArgument {
253 public int channel, cla, command, p1, p2, p3;
254 public String data;
255
256 public IccAPDUArgument(int channel, int cla, int command,
257 int p1, int p2, int p3, String data) {
258 this.channel = channel;
259 this.cla = cla;
260 this.command = command;
261 this.p1 = p1;
262 this.p2 = p2;
263 this.p3 = p3;
264 this.data = data;
265 }
266 }
267
268 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700269 * A request object to use for transmitting data to an ICC.
270 */
271 private static final class ManualNetworkSelectionArgument {
272 public OperatorInfo operatorInfo;
273 public boolean persistSelection;
274
275 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
276 this.operatorInfo = operatorInfo;
277 this.persistSelection = persistSelection;
278 }
279 }
280
281 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
283 * request after sending. The main thread will notify the request when it is complete.
284 */
285 private static final class MainThreadRequest {
286 /** The argument to use for the request */
287 public Object argument;
288 /** The result of the request that is run on the main thread */
289 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800290 // The subscriber id that this request applies to. Defaults to
291 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
292 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293
vagdeviaf9a5b92018-08-15 16:01:53 -0700294 public WorkSource workSource;
295
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 public MainThreadRequest(Object argument) {
297 this.argument = argument;
298 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800299
vagdeviaf9a5b92018-08-15 16:01:53 -0700300 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800301 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800302 if (subId != null) {
303 this.subId = subId;
304 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700305 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700307 }
308
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800309 private static final class IncomingThirdPartyCallArgs {
310 public final ComponentName component;
311 public final String callId;
312 public final String callerDisplayName;
313
314 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
315 String callerDisplayName) {
316 this.component = component;
317 this.callId = callId;
318 this.callerDisplayName = callerDisplayName;
319 }
320 }
321
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 /**
323 * A handler that processes messages on the main thread in the phone process. Since many
324 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
325 * inbound binder threads to the main thread in the phone process. The Binder thread
326 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
327 * on, which will be notified when the operation completes and will contain the result of the
328 * request.
329 *
330 * <p>If a MainThreadRequest object is provided in the msg.obj field,
331 * note that request.result must be set to something non-null for the calling thread to
332 * unblock.
333 */
334 private final class MainThreadHandler extends Handler {
335 @Override
336 public void handleMessage(Message msg) {
337 MainThreadRequest request;
338 Message onCompleted;
339 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800340 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700341 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
343 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700344 case CMD_HANDLE_USSD_REQUEST: {
345 request = (MainThreadRequest) msg.obj;
346 final Phone phone = getPhoneFromRequest(request);
347 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
348 String ussdRequest = ussdObject.first;
349 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700350
Pengquan Menga1bb6272018-09-06 09:59:22 -0700351 if (!isUssdApiAllowed(request.subId)) {
352 // Carrier does not support use of this API, return failure.
353 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
354 UssdResponse response = new UssdResponse(ussdRequest, null);
355 Bundle returnData = new Bundle();
356 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
357 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700358
Pengquan Menga1bb6272018-09-06 09:59:22 -0700359 request.result = true;
360 notifyRequester(request);
361 return;
362 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700363
Pengquan Menga1bb6272018-09-06 09:59:22 -0700364 try {
365 request.result = phone != null
366 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
367 } catch (CallStateException cse) {
368 request.result = false;
369 }
370 // Wake up the requesting thread
371 notifyRequester(request);
372 break;
pkanwar32d516d2016-10-14 19:37:38 -0700373 }
374
Yorke Lee716f67e2015-06-17 15:39:16 -0700375 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700377 final Phone phone = getPhoneFromRequest(request);
378 request.result = phone != null ?
379 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
380 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700382 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700386 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700387 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700388 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800389 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700390 if (uiccCard == null) {
391 loge("iccTransmitApduLogicalChannel: No UICC");
392 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700393 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700394 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700395 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
396 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700397 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700398 iccArgument.channel, iccArgument.cla, iccArgument.command,
399 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700400 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700401 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700402 break;
403
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 ar = (AsyncResult) msg.obj;
406 request = (MainThreadRequest) ar.userObj;
407 if (ar.exception == null && ar.result != null) {
408 request.result = ar.result;
409 } else {
410 request.result = new IccIoResult(0x6F, 0, (byte[])null);
411 if (ar.result == null) {
412 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800413 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800415 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 } else {
417 loge("iccTransmitApduLogicalChannel: Unknown exception");
418 }
419 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 break;
422
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
424 request = (MainThreadRequest) msg.obj;
425 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800426 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 if (uiccCard == null) {
428 loge("iccTransmitApduBasicChannel: No UICC");
429 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700430 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 } else {
432 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
433 request);
434 uiccCard.iccTransmitApduBasicChannel(
435 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
436 iccArgument.p3, iccArgument.data, onCompleted);
437 }
438 break;
439
440 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
441 ar = (AsyncResult) msg.obj;
442 request = (MainThreadRequest) ar.userObj;
443 if (ar.exception == null && ar.result != null) {
444 request.result = ar.result;
445 } else {
446 request.result = new IccIoResult(0x6F, 0, (byte[])null);
447 if (ar.result == null) {
448 loge("iccTransmitApduBasicChannel: Empty response");
449 } else if (ar.exception instanceof CommandException) {
450 loge("iccTransmitApduBasicChannel: CommandException: " +
451 ar.exception);
452 } else {
453 loge("iccTransmitApduBasicChannel: Unknown exception");
454 }
455 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 break;
458
459 case CMD_EXCHANGE_SIM_IO:
460 request = (MainThreadRequest) msg.obj;
461 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800462 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 if (uiccCard == null) {
464 loge("iccExchangeSimIO: No UICC");
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 } else {
468 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
469 request);
470 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
471 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
472 iccArgument.data, onCompleted);
473 }
474 break;
475
476 case EVENT_EXCHANGE_SIM_IO_DONE:
477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6f, 0, (byte[])null);
483 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 break;
486
Derek Tan4d5e5c12014-02-04 11:54:58 -0800487 case CMD_SEND_ENVELOPE:
488 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 if (uiccCard == null) {
491 loge("sendEnvelopeWithStatus: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700494 } else {
495 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
496 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
497 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800498 break;
499
500 case EVENT_SEND_ENVELOPE_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800505 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
507 if (ar.result == null) {
508 loge("sendEnvelopeWithStatus: Empty response");
509 } else if (ar.exception instanceof CommandException) {
510 loge("sendEnvelopeWithStatus: CommandException: " +
511 ar.exception);
512 } else {
513 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
514 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800517 break;
518
Shishir Agrawal566b7612013-10-28 14:41:00 -0700519 case CMD_OPEN_CHANNEL:
520 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800522 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700523 if (uiccCard == null) {
524 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800525 request.result = new IccOpenLogicalChannelResponse(-1,
526 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700528 } else {
529 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800530 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
531 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700533 break;
534
535 case EVENT_OPEN_CHANNEL_DONE:
536 ar = (AsyncResult) msg.obj;
537 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 int[] result = (int[]) ar.result;
541 int channelId = result[0];
542 byte[] selectResponse = null;
543 if (result.length > 1) {
544 selectResponse = new byte[result.length - 1];
545 for (int i = 1; i < result.length; ++i) {
546 selectResponse[i - 1] = (byte) result[i];
547 }
548 }
549 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700550 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 if (ar.result == null) {
553 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 if (ar.exception != null) {
556 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
557 }
558
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700559 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700560 if (ar.exception instanceof CommandException) {
561 CommandException.Error error =
562 ((CommandException) (ar.exception)).getCommandError();
563 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700564 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700565 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700566 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 }
568 }
569 openChannelResp = new IccOpenLogicalChannelResponse(
570 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700572 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 break;
575
576 case CMD_CLOSE_CHANNEL:
577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800578 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900581 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 } else {
584 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
585 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
586 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 break;
588
589 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800590 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
591 break;
592
593 case CMD_NV_READ_ITEM:
594 request = (MainThreadRequest) msg.obj;
595 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700596 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800597 break;
598
599 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 ar = (AsyncResult) msg.obj;
601 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800602 if (ar.exception == null && ar.result != null) {
603 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800605 request.result = "";
606 if (ar.result == null) {
607 loge("nvReadItem: Empty response");
608 } else if (ar.exception instanceof CommandException) {
609 loge("nvReadItem: CommandException: " +
610 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800612 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
614 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 break;
617
Jake Hambye994d462014-02-03 13:10:13 -0800618 case CMD_NV_WRITE_ITEM:
619 request = (MainThreadRequest) msg.obj;
620 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
621 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700622 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
623 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800624 break;
625
626 case EVENT_NV_WRITE_ITEM_DONE:
627 handleNullReturnEvent(msg, "nvWriteItem");
628 break;
629
630 case CMD_NV_WRITE_CDMA_PRL:
631 request = (MainThreadRequest) msg.obj;
632 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
633 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
634 break;
635
636 case EVENT_NV_WRITE_CDMA_PRL_DONE:
637 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
638 break;
639
640 case CMD_NV_RESET_CONFIG:
641 request = (MainThreadRequest) msg.obj;
642 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
643 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
644 break;
645
646 case EVENT_NV_RESET_CONFIG_DONE:
647 handleNullReturnEvent(msg, "nvResetConfig");
648 break;
649
Jake Hamby7c27be32014-03-03 13:25:59 -0800650 case CMD_GET_PREFERRED_NETWORK_TYPE:
651 request = (MainThreadRequest) msg.obj;
652 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700653 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800654 break;
655
656 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
657 ar = (AsyncResult) msg.obj;
658 request = (MainThreadRequest) ar.userObj;
659 if (ar.exception == null && ar.result != null) {
660 request.result = ar.result; // Integer
661 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800662 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800663 if (ar.result == null) {
664 loge("getPreferredNetworkType: Empty response");
665 } else if (ar.exception instanceof CommandException) {
666 loge("getPreferredNetworkType: CommandException: " +
667 ar.exception);
668 } else {
669 loge("getPreferredNetworkType: Unknown exception");
670 }
671 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800673 break;
674
675 case CMD_SET_PREFERRED_NETWORK_TYPE:
676 request = (MainThreadRequest) msg.obj;
677 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
678 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700679 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800680 break;
681
682 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
683 handleNullReturnEvent(msg, "setPreferredNetworkType");
684 break;
685
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000686 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
687 request = (MainThreadRequest)msg.obj;
688 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700689 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000690 break;
691
692 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
693 ar = (AsyncResult)msg.obj;
694 request = (MainThreadRequest)ar.userObj;
695 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000697 break;
698
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800699 case CMD_SET_VOICEMAIL_NUMBER:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
702 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800703 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
704 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800705 break;
706
707 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
708 handleNullReturnEvent(msg, "setVoicemailNumber");
709 break;
710
Stuart Scott54788802015-03-30 13:18:01 -0700711 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
714 request);
715 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
716 break;
717
718 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
719 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
720 break;
721
Shishir Agrawal302c8692015-06-19 13:49:39 -0700722 case CMD_PERFORM_NETWORK_SCAN:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
725 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
726 break;
727
728 case EVENT_PERFORM_NETWORK_SCAN_DONE:
729 ar = (AsyncResult) msg.obj;
730 request = (MainThreadRequest) ar.userObj;
731 CellNetworkScanResult cellScanResult;
732 if (ar.exception == null && ar.result != null) {
733 cellScanResult = new CellNetworkScanResult(
734 CellNetworkScanResult.STATUS_SUCCESS,
735 (List<OperatorInfo>) ar.result);
736 } else {
737 if (ar.result == null) {
738 loge("getCellNetworkScanResults: Empty response");
739 }
740 if (ar.exception != null) {
741 loge("getCellNetworkScanResults: Exception: " + ar.exception);
742 }
743 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
744 if (ar.exception instanceof CommandException) {
745 CommandException.Error error =
746 ((CommandException) (ar.exception)).getCommandError();
747 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
748 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
749 } else if (error == CommandException.Error.GENERIC_FAILURE) {
750 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
751 }
752 }
753 cellScanResult = new CellNetworkScanResult(errorCode, null);
754 }
755 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700756 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700757 break;
758
759 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
760 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700761 ManualNetworkSelectionArgument selArg =
762 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700763 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
764 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700765 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
766 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700767 break;
768
769 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
772 if (ar.exception == null) {
773 request.result = true;
774 } else {
775 request.result = false;
776 loge("setNetworkSelectionModeManual " + ar.exception);
777 }
778 notifyRequester(request);
779 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700780 break;
781
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700782 case CMD_GET_MODEM_ACTIVITY_INFO:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700785 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700786 break;
787
788 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
789 ar = (AsyncResult) msg.obj;
790 request = (MainThreadRequest) ar.userObj;
791 if (ar.exception == null && ar.result != null) {
792 request.result = ar.result;
793 } else {
794 if (ar.result == null) {
795 loge("queryModemActivityInfo: Empty response");
796 } else if (ar.exception instanceof CommandException) {
797 loge("queryModemActivityInfo: CommandException: " +
798 ar.exception);
799 } else {
800 loge("queryModemActivityInfo: Unknown exception");
801 }
802 }
Amit Mahajand4766222016-01-28 15:28:28 -0800803 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
804 if (request.result == null) {
805 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
806 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700807 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700808 break;
809
Meng Wang1a7c35a2016-05-05 20:56:15 -0700810 case CMD_SET_ALLOWED_CARRIERS:
811 request = (MainThreadRequest) msg.obj;
812 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
813 mPhone.setAllowedCarriers(
814 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700815 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700816 break;
817
818 case EVENT_SET_ALLOWED_CARRIERS_DONE:
819 ar = (AsyncResult) msg.obj;
820 request = (MainThreadRequest) ar.userObj;
821 if (ar.exception == null && ar.result != null) {
822 request.result = ar.result;
823 } else {
824 if (ar.result == null) {
825 loge("setAllowedCarriers: Empty response");
826 } else if (ar.exception instanceof CommandException) {
827 loge("setAllowedCarriers: CommandException: " +
828 ar.exception);
829 } else {
830 loge("setAllowedCarriers: Unknown exception");
831 }
832 }
833 // Result cannot be null. Return -1 on error.
834 if (request.result == null) {
835 request.result = new int[]{-1};
836 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700837 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700838 break;
839
840 case CMD_GET_ALLOWED_CARRIERS:
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700843 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700844 break;
845
846 case EVENT_GET_ALLOWED_CARRIERS_DONE:
847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null && ar.result != null) {
850 request.result = ar.result;
851 } else {
852 if (ar.result == null) {
853 loge("getAllowedCarriers: Empty response");
854 } else if (ar.exception instanceof CommandException) {
855 loge("getAllowedCarriers: CommandException: " +
856 ar.exception);
857 } else {
858 loge("getAllowedCarriers: Unknown exception");
859 }
860 }
861 // Result cannot be null. Return empty list of CarrierIdentifier.
862 if (request.result == null) {
863 request.result = new ArrayList<CarrierIdentifier>(0);
864 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700865 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 break;
867
Nathan Haroldb3014052017-01-25 15:57:32 -0800868 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
874 request.result = new IllegalArgumentException(
875 "Failed to retrieve Forbidden Plmns");
876 if (ar.result == null) {
877 loge("getForbiddenPlmns: Empty response");
878 } else {
879 loge("getForbiddenPlmns: Unknown exception");
880 }
881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800883 break;
884
885 case CMD_GET_FORBIDDEN_PLMNS:
886 request = (MainThreadRequest) msg.obj;
887 uiccCard = getUiccCardFromRequest(request);
888 if (uiccCard == null) {
889 loge("getForbiddenPlmns() UiccCard is null");
890 request.result = new IllegalArgumentException(
891 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700892 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800893 break;
894 }
895 Integer appType = (Integer) request.argument;
896 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
897 if (uiccApp == null) {
898 loge("getForbiddenPlmns() no app with specified type -- "
899 + appType);
900 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700901 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800902 break;
903 } else {
904 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
905 + " specified type -- " + appType);
906 }
907 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
908 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
909 onCompleted);
910 break;
911
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000912 case CMD_SWITCH_SLOTS:
913 request = (MainThreadRequest) msg.obj;
914 int[] physicalSlots = (int[]) request.argument;
915 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
916 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
917 break;
918
919 case EVENT_SWITCH_SLOTS_DONE:
920 ar = (AsyncResult) msg.obj;
921 request = (MainThreadRequest) ar.userObj;
922 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700923 notifyRequester(request);
924 break;
925 case CMD_GET_NETWORK_SELECTION_MODE:
926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
928 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
929 break;
930
931 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
932 ar = (AsyncResult) msg.obj;
933 request = (MainThreadRequest) ar.userObj;
934 if (ar.exception != null) {
935 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
936 } else {
937 int mode = ((int[]) ar.result)[0];
938 if (mode == 0) {
939 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
940 } else {
941 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
942 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000943 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700944 notifyRequester(request);
945 break;
946 case CMD_GET_CDMA_ROAMING_MODE:
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
949 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
950 break;
951 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
952 ar = (AsyncResult) msg.obj;
953 request = (MainThreadRequest) ar.userObj;
954 if (ar.exception != null) {
955 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
956 } else {
957 request.result = ((int[]) ar.result)[0];
958 }
959 notifyRequester(request);
960 break;
961 case CMD_SET_CDMA_ROAMING_MODE:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
964 int mode = (int) request.argument;
965 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
966 break;
967 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
970 request.result = ar.exception == null;
971 notifyRequester(request);
972 break;
973 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
976 int subscriptionMode = (int) request.argument;
977 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
978 break;
979 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 request.result = ar.exception == null;
983 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000984 break;
985
Nathan Harold3ff88932018-08-14 10:19:49 -0700986 case CMD_GET_ALL_CELL_INFO:
987 request = (MainThreadRequest) msg.obj;
988 Pair<Phone, WorkSource> args = (Pair<Phone, WorkSource>) request.argument;
989 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
990 ((Phone) args.first).getAllCellInfo(args.second, onCompleted);
991 break;
992
993 case EVENT_GET_ALL_CELL_INFO_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -0700996 // If a timeout occurs, the response will be null
997 request.result = (ar.exception == null && ar.result != null)
998 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -0700999 synchronized (request) {
1000 request.notifyAll();
1001 }
1002 break;
1003
1004 case CMD_GET_CELL_LOCATION: {
1005 request = (MainThreadRequest) msg.obj;
1006 WorkSource ws = (WorkSource) request.argument;
1007 Phone phone = getPhoneFromRequest(request);
1008 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1009 break;
1010 }
1011
1012 case EVENT_GET_CELL_LOCATION_DONE: {
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception == null) {
1016 request.result = ar.result;
1017 } else {
1018 Phone phone = getPhoneFromRequest(request);
1019 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1020 ? new CdmaCellLocation() : new GsmCellLocation();
1021 }
1022
1023 synchronized (request) {
1024 request.notifyAll();
1025 }
1026 break;
1027 }
1028
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001029 default:
1030 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1031 break;
1032 }
1033 }
Jake Hambye994d462014-02-03 13:10:13 -08001034
Pengquan Menga1bb6272018-09-06 09:59:22 -07001035 private void notifyRequester(MainThreadRequest request) {
1036 synchronized (request) {
1037 request.notifyAll();
1038 }
1039 }
1040
Jake Hambye994d462014-02-03 13:10:13 -08001041 private void handleNullReturnEvent(Message msg, String command) {
1042 AsyncResult ar = (AsyncResult) msg.obj;
1043 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1044 if (ar.exception == null) {
1045 request.result = true;
1046 } else {
1047 request.result = false;
1048 if (ar.exception instanceof CommandException) {
1049 loge(command + ": CommandException: " + ar.exception);
1050 } else {
1051 loge(command + ": Unknown exception");
1052 }
1053 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001054 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001055 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001056 }
1057
1058 /**
1059 * Posts the specified command to be executed on the main thread,
1060 * waits for the request to complete, and returns the result.
1061 * @see #sendRequestAsync
1062 */
1063 private Object sendRequest(int command, Object argument) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001064 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1065 }
1066
1067 /**
1068 * Posts the specified command to be executed on the main thread,
1069 * waits for the request to complete, and returns the result.
1070 * @see #sendRequestAsync
1071 */
1072 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1073 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1074 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001075 }
1076
1077 /**
1078 * Posts the specified command to be executed on the main thread,
1079 * waits for the request to complete, and returns the result.
1080 * @see #sendRequestAsync
1081 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001082 private Object sendRequest(int command, Object argument, Integer subId) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001083 return sendRequest(command, argument, subId, null);
1084 }
1085
1086 /**
1087 * Posts the specified command to be executed on the main thread,
1088 * waits for the request to complete, and returns the result.
1089 * @see #sendRequestAsync
1090 */
1091 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001092 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1093 throw new RuntimeException("This method will deadlock if called from the main thread.");
1094 }
1095
vagdeviaf9a5b92018-08-15 16:01:53 -07001096 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001097 Message msg = mMainThreadHandler.obtainMessage(command, request);
1098 msg.sendToTarget();
1099
1100 // Wait for the request to complete
1101 synchronized (request) {
1102 while (request.result == null) {
1103 try {
1104 request.wait();
1105 } catch (InterruptedException e) {
1106 // Do nothing, go back and wait until the request is complete
1107 }
1108 }
1109 }
1110 return request.result;
1111 }
1112
1113 /**
1114 * Asynchronous ("fire and forget") version of sendRequest():
1115 * Posts the specified command to be executed on the main thread, and
1116 * returns immediately.
1117 * @see #sendRequest
1118 */
1119 private void sendRequestAsync(int command) {
1120 mMainThreadHandler.sendEmptyMessage(command);
1121 }
1122
1123 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001124 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1125 * @see {@link #sendRequest(int,Object)}
1126 */
1127 private void sendRequestAsync(int command, Object argument) {
1128 MainThreadRequest request = new MainThreadRequest(argument);
1129 Message msg = mMainThreadHandler.obtainMessage(command, request);
1130 msg.sendToTarget();
1131 }
1132
1133 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001134 * Initialize the singleton PhoneInterfaceManager instance.
1135 * This is only done once, at startup, from PhoneApp.onCreate().
1136 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001137 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 synchronized (PhoneInterfaceManager.class) {
1139 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001140 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 } else {
1142 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1143 }
1144 return sInstance;
1145 }
1146 }
1147
1148 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001149 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 mApp = app;
1151 mPhone = phone;
1152 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001153 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001154 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1155 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001156 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001157 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001158 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001159 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001160 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001161
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 publish();
1163 }
1164
1165 private void publish() {
1166 if (DBG) log("publish: " + this);
1167
1168 ServiceManager.addService("phone", this);
1169 }
1170
Stuart Scott584921c2015-01-15 17:10:34 -08001171 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001172 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1173 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001174 }
1175
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001176 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1177 Phone phone = getPhoneFromRequest(request);
1178 return phone == null ? null :
1179 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1180 }
1181
Wink Saville36469e72014-06-11 15:17:00 -07001182 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001183 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001184 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001186
1187 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001188 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001189 }
1190
Wink Savilleb564aae2014-10-23 10:18:09 -07001191 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 if (DBG) log("dial: " + number);
1193 // No permission check needed here: This is just a wrapper around the
1194 // ACTION_DIAL intent, which is available to any app since it puts up
1195 // the UI before it does anything.
1196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001197 final long identity = Binder.clearCallingIdentity();
1198 try {
1199 String url = createTelUrl(number);
1200 if (url == null) {
1201 return;
1202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001204 // PENDING: should we just silently fail if phone is offhook or ringing?
1205 PhoneConstants.State state = mCM.getState(subId);
1206 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1207 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1208 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1209 mApp.startActivity(intent);
1210 }
1211 } finally {
1212 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001213 }
1214 }
1215
1216 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001217 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001218 }
1219
Wink Savilleb564aae2014-10-23 10:18:09 -07001220 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 if (DBG) log("call: " + number);
1222
1223 // This is just a wrapper around the ACTION_CALL intent, but we still
1224 // need to do a permission check since we're calling startActivity()
1225 // from the context of the phone app.
1226 enforceCallPermission();
1227
1228 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1229 != AppOpsManager.MODE_ALLOWED) {
1230 return;
1231 }
1232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001233 final long identity = Binder.clearCallingIdentity();
1234 try {
1235 String url = createTelUrl(number);
1236 if (url == null) {
1237 return;
1238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001240 boolean isValid = false;
1241 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1242 if (slist != null) {
1243 for (SubscriptionInfo subInfoRecord : slist) {
1244 if (subInfoRecord.getSubscriptionId() == subId) {
1245 isValid = true;
1246 break;
1247 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001248 }
Wink Saville08874612014-08-31 19:19:58 -07001249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001250 if (!isValid) {
1251 return;
1252 }
Wink Saville08874612014-08-31 19:19:58 -07001253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001254 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1255 intent.putExtra(SUBSCRIPTION_KEY, subId);
1256 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1257 mApp.startActivity(intent);
1258 } finally {
1259 Binder.restoreCallingIdentity(identity);
1260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 }
1262
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001264 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001265 }
1266
Wink Savilleb564aae2014-10-23 10:18:09 -07001267 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001268 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001269 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1270 }
1271
1272 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001273 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001274 }
1275
Wink Savilleb564aae2014-10-23 10:18:09 -07001276 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001277 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001278 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1279 }
1280
1281 /** {@hide} */
1282 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001283 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001284 }
1285
Wink Savilleb564aae2014-10-23 10:18:09 -07001286 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001287 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001288
1289 final long identity = Binder.clearCallingIdentity();
1290 try {
1291 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1292 checkSimPin.start();
1293 return checkSimPin.unlockSim(null, pin);
1294 } finally {
1295 Binder.restoreCallingIdentity(identity);
1296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001297 }
1298
Wink Saville9de0f752013-10-22 19:04:03 -07001299 /** {@hide} */
1300 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001301 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001302 }
1303
Wink Savilleb564aae2014-10-23 10:18:09 -07001304 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001306
1307 final long identity = Binder.clearCallingIdentity();
1308 try {
1309 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1310 checkSimPuk.start();
1311 return checkSimPuk.unlockSim(puk, pin);
1312 } finally {
1313 Binder.restoreCallingIdentity(identity);
1314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 }
1316
1317 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001318 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 * a synchronous one.
1320 */
1321 private static class UnlockSim extends Thread {
1322
1323 private final IccCard mSimCard;
1324
1325 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001326 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1327 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328
1329 // For replies from SimCard interface
1330 private Handler mHandler;
1331
1332 // For async handler to identify request type
1333 private static final int SUPPLY_PIN_COMPLETE = 100;
1334
1335 public UnlockSim(IccCard simCard) {
1336 mSimCard = simCard;
1337 }
1338
1339 @Override
1340 public void run() {
1341 Looper.prepare();
1342 synchronized (UnlockSim.this) {
1343 mHandler = new Handler() {
1344 @Override
1345 public void handleMessage(Message msg) {
1346 AsyncResult ar = (AsyncResult) msg.obj;
1347 switch (msg.what) {
1348 case SUPPLY_PIN_COMPLETE:
1349 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1350 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001351 mRetryCount = msg.arg1;
1352 if (ar.exception != null) {
1353 if (ar.exception instanceof CommandException &&
1354 ((CommandException)(ar.exception)).getCommandError()
1355 == CommandException.Error.PASSWORD_INCORRECT) {
1356 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1357 } else {
1358 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1359 }
1360 } else {
1361 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 mDone = true;
1364 UnlockSim.this.notifyAll();
1365 }
1366 break;
1367 }
1368 }
1369 };
1370 UnlockSim.this.notifyAll();
1371 }
1372 Looper.loop();
1373 }
1374
1375 /*
1376 * Use PIN or PUK to unlock SIM card
1377 *
1378 * If PUK is null, unlock SIM card with PIN
1379 *
1380 * If PUK is not null, unlock SIM card with PUK and set PIN code
1381 */
Wink Saville9de0f752013-10-22 19:04:03 -07001382 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383
1384 while (mHandler == null) {
1385 try {
1386 wait();
1387 } catch (InterruptedException e) {
1388 Thread.currentThread().interrupt();
1389 }
1390 }
1391 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1392
1393 if (puk == null) {
1394 mSimCard.supplyPin(pin, callback);
1395 } else {
1396 mSimCard.supplyPuk(puk, pin, callback);
1397 }
1398
1399 while (!mDone) {
1400 try {
1401 Log.d(LOG_TAG, "wait for done");
1402 wait();
1403 } catch (InterruptedException e) {
1404 // Restore the interrupted status
1405 Thread.currentThread().interrupt();
1406 }
1407 }
1408 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001409 int[] resultArray = new int[2];
1410 resultArray[0] = mResult;
1411 resultArray[1] = mRetryCount;
1412 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 }
1414 }
1415
1416 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001417 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001418
1419 }
1420
Wink Savilleb564aae2014-10-23 10:18:09 -07001421 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001422 // No permission check needed here: this call is harmless, and it's
1423 // needed for the ServiceState.requestStateUpdate() call (which is
1424 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001425 final long identity = Binder.clearCallingIdentity();
1426 try {
1427 final Phone phone = getPhone(subId);
1428 if (phone != null) {
1429 phone.updateServiceLocation();
1430 }
1431 } finally {
1432 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001434 }
1435
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001436 @Override
1437 public boolean isRadioOn(String callingPackage) {
1438 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001439 }
1440
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001441 @Override
1442 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001444 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001445 return false;
1446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001447
1448 final long identity = Binder.clearCallingIdentity();
1449 try {
1450 return isRadioOnForSubscriber(subId);
1451 } finally {
1452 Binder.restoreCallingIdentity(identity);
1453 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001454 }
1455
1456 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001457 final long identity = Binder.clearCallingIdentity();
1458 try {
1459 final Phone phone = getPhone(subId);
1460 if (phone != null) {
1461 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1462 } else {
1463 return false;
1464 }
1465 } finally {
1466 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 }
1469
1470 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001471 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 }
Wink Saville36469e72014-06-11 15:17:00 -07001473
Wink Savilleb564aae2014-10-23 10:18:09 -07001474 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001476
1477 final long identity = Binder.clearCallingIdentity();
1478 try {
1479 final Phone phone = getPhone(subId);
1480 if (phone != null) {
1481 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1482 }
1483 } finally {
1484 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001485 }
Wink Saville36469e72014-06-11 15:17:00 -07001486 }
1487
1488 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001489 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001490 }
1491
Wink Savilleb564aae2014-10-23 10:18:09 -07001492 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001494
1495 final long identity = Binder.clearCallingIdentity();
1496 try {
1497 final Phone phone = getPhone(subId);
1498 if (phone == null) {
1499 return false;
1500 }
1501 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1502 toggleRadioOnOffForSubscriber(subId);
1503 }
1504 return true;
1505 } finally {
1506 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 }
Wink Saville36469e72014-06-11 15:17:00 -07001509
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001510 public boolean needMobileRadioShutdown() {
1511 /*
1512 * If any of the Radios are available, it will need to be
1513 * shutdown. So return true if any Radio is available.
1514 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001515 final long identity = Binder.clearCallingIdentity();
1516 try {
1517 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1518 Phone phone = PhoneFactory.getPhone(i);
1519 if (phone != null && phone.isRadioAvailable()) return true;
1520 }
1521 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1522 return false;
1523 } finally {
1524 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001525 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001526 }
1527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001528 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001529 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001530 enforceModifyPermission();
1531
1532 final long identity = Binder.clearCallingIdentity();
1533 try {
1534 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1535 logv("Shutting down Phone " + i);
1536 shutdownRadioUsingPhoneId(i);
1537 }
1538 } finally {
1539 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001540 }
1541 }
1542
1543 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001544 Phone phone = PhoneFactory.getPhone(phoneId);
1545 if (phone != null && phone.isRadioAvailable()) {
1546 phone.shutdownRadio();
1547 }
1548 }
1549
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001552
1553 final long identity = Binder.clearCallingIdentity();
1554 try {
1555 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1556 if (defaultPhone != null) {
1557 defaultPhone.setRadioPower(turnOn);
1558 return true;
1559 } else {
1560 loge("There's no default phone.");
1561 return false;
1562 }
1563 } finally {
1564 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001565 }
Wink Saville36469e72014-06-11 15:17:00 -07001566 }
1567
Wink Savilleb564aae2014-10-23 10:18:09 -07001568 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001570
1571 final long identity = Binder.clearCallingIdentity();
1572 try {
1573 final Phone phone = getPhone(subId);
1574 if (phone != null) {
1575 phone.setRadioPower(turnOn);
1576 return true;
1577 } else {
1578 return false;
1579 }
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
Wink Saville36469e72014-06-11 15:17:00 -07001585 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 public boolean enableDataConnectivity() {
1588 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001589
1590 final long identity = Binder.clearCallingIdentity();
1591 try {
1592 int subId = mSubscriptionController.getDefaultDataSubId();
1593 final Phone phone = getPhone(subId);
1594 if (phone != null) {
1595 phone.setUserDataEnabled(true);
1596 return true;
1597 } else {
1598 return false;
1599 }
1600 } finally {
1601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 }
1604
Wink Saville36469e72014-06-11 15:17:00 -07001605 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 public boolean disableDataConnectivity() {
1608 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001609
1610 final long identity = Binder.clearCallingIdentity();
1611 try {
1612 int subId = mSubscriptionController.getDefaultDataSubId();
1613 final Phone phone = getPhone(subId);
1614 if (phone != null) {
1615 phone.setUserDataEnabled(false);
1616 return true;
1617 } else {
1618 return false;
1619 }
1620 } finally {
1621 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 }
1624
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001626 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001627 final long identity = Binder.clearCallingIdentity();
1628 try {
1629 final Phone phone = getPhone(subId);
1630 if (phone != null) {
1631 return phone.isDataAllowed();
1632 } else {
1633 return false;
1634 }
1635 } finally {
1636 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 }
1639
1640 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001641 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001642 }
1643
pkanwarae03a6b2016-11-06 20:37:09 -08001644 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001645 enforceCallPermission();
1646
1647 final long identity = Binder.clearCallingIdentity();
1648 try {
1649 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1650 return;
1651 }
1652 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1653 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1654 } finally {
1655 Binder.restoreCallingIdentity(identity);
1656 }
pkanwar32d516d2016-10-14 19:37:38 -07001657 };
1658
Wink Savilleb564aae2014-10-23 10:18:09 -07001659 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001661
1662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1665 return false;
1666 }
1667 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 }
1672
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001674 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001675 }
1676
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001677 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 Phone phone = PhoneFactory.getPhone(slotIndex);
1681 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1682 PhoneConstantConversions.convertCallState(phone.getState());
1683 } finally {
1684 Binder.restoreCallingIdentity(identity);
1685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687
Sanket Padawe356d7632015-06-22 14:03:32 -07001688 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001690 final long identity = Binder.clearCallingIdentity();
1691 try {
1692 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1693 if (phone != null) {
1694 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1695 } else {
1696 return PhoneConstantConversions.convertDataState(
1697 PhoneConstants.DataState.DISCONNECTED);
1698 }
1699 } finally {
1700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 }
1703
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001706 final long identity = Binder.clearCallingIdentity();
1707 try {
1708 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1709 if (phone != null) {
1710 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1711 } else {
1712 return TelephonyManager.DATA_ACTIVITY_NONE;
1713 }
1714 } finally {
1715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 }
1718
1719 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001720 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001721 mPhone.getContext().getSystemService(AppOpsManager.class)
1722 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001723 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001724 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001725 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001728 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729 final long identity = Binder.clearCallingIdentity();
1730 try {
1731 if (DBG_LOC) log("getCellLocation: is active user");
1732 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001733 int subId = mSubscriptionController.getDefaultDataSubId();
1734 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1735 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001736 return data;
1737 } finally {
1738 Binder.restoreCallingIdentity(identity);
1739 }
Svetoslav64fad262015-04-14 14:35:21 -07001740 }
1741
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001743 public String getNetworkCountryIsoForPhone(int phoneId) {
1744 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1745 // registered cell info, so return a NULL country instead.
1746 final long identity = Binder.clearCallingIdentity();
1747 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001748 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1749 // Get default phone in this case.
1750 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1751 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001752 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001753 // Todo: fix this when we can get the actual cellular network info when the device
1754 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001755 if (TelephonyManager.NETWORK_TYPE_IWLAN
1756 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1757 return "";
1758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001759 Phone phone = PhoneFactory.getPhone(phoneId);
1760 if (phone != null) {
1761 ServiceStateTracker sst = phone.getServiceStateTracker();
1762 if (sst != null) {
1763 LocaleTracker lt = sst.getLocaleTracker();
1764 if (lt != null) {
1765 return lt.getCurrentCountry();
1766 }
1767 }
1768 }
1769 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001770 } finally {
1771 Binder.restoreCallingIdentity(identity);
1772 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001773 }
1774
1775 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001777 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001778 }
1779
Sanket Padawe356d7632015-06-22 14:03:32 -07001780 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001781 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 mApp.enforceCallingOrSelfPermission(
1783 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784
1785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 final Phone phone = getPhone(subId);
1788 if (phone != null) {
1789 phone.enableLocationUpdates();
1790 }
1791 } finally {
1792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 }
1795
1796 @Override
1797 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001798 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001799 }
1800
Sanket Padawe356d7632015-06-22 14:03:32 -07001801 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001802 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 mApp.enforceCallingOrSelfPermission(
1804 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805
1806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 final Phone phone = getPhone(subId);
1809 if (phone != null) {
1810 phone.disableLocationUpdates();
1811 }
1812 } finally {
1813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
1816
1817 @Override
1818 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001819 public List<NeighboringCellInfo>
1820 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001821 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1822 throw new SecurityException(
1823 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1824 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001825
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1827 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1828 return null;
1829 }
Svetoslav64fad262015-04-14 14:35:21 -07001830
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001831 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832
Nathan Haroldf180aac2018-06-01 18:43:55 -07001833 List<CellInfo> info = getAllCellInfo(callingPackage);
1834 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835
Nathan Haroldf180aac2018-06-01 18:43:55 -07001836 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1837 for (CellInfo ci : info) {
1838 if (ci instanceof CellInfoGsm) {
1839 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1840 } else if (ci instanceof CellInfoWcdma) {
1841 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001844 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 }
1846
1847
1848 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001849 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001850 mPhone.getContext().getSystemService(AppOpsManager.class)
1851 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001852 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001853 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001854 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855 }
1856
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001857 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001858 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001859 final long identity = Binder.clearCallingIdentity();
1860 try {
1861 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1862 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001863 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1864 CMD_GET_ALL_CELL_INFO,
1865 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 if (info != null) cellInfos.addAll(info);
1867 }
1868 return cellInfos;
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 }
1872 }
1873
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001874 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001876 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001877 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878
1879 final long identity = Binder.clearCallingIdentity();
1880 try {
1881 mPhone.setCellInfoListRate(rateInMillis, workSource);
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
1884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
Shishir Agrawala9f32182016-04-12 12:00:16 -07001887 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001888 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001889 Phone phone = PhoneFactory.getPhone(slotIndex);
1890 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001891 return null;
1892 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001893 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001894 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1895 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001896 return null;
1897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898
1899 final long identity = Binder.clearCallingIdentity();
1900 try {
1901 return phone.getImei();
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
1904 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001905 }
1906
1907 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001908 public String getTypeAllocationCodeForSlot(int slotIndex) {
1909 Phone phone = PhoneFactory.getPhone(slotIndex);
1910 String tac = null;
1911 if (phone != null) {
1912 String imei = phone.getImei();
1913 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1914 }
1915 return tac;
1916 }
1917
1918 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001919 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001920 Phone phone = PhoneFactory.getPhone(slotIndex);
1921 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001922 return null;
1923 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001924 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001925 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1926 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001927 return null;
1928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001929
1930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 return phone.getMeid();
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
1935 }
Jack Yu2af8d712017-03-15 17:14:14 -07001936 }
1937
1938 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001939 public String getManufacturerCodeForSlot(int slotIndex) {
1940 Phone phone = PhoneFactory.getPhone(slotIndex);
1941 String manufacturerCode = null;
1942 if (phone != null) {
1943 String meid = phone.getMeid();
1944 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1945 }
1946 return manufacturerCode;
1947 }
1948
1949 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001950 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001951 Phone phone = PhoneFactory.getPhone(slotIndex);
1952 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001953 return null;
1954 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001955 int subId = phone.getSubId();
1956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1957 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1958 return null;
1959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001960
1961 final long identity = Binder.clearCallingIdentity();
1962 try {
1963 return phone.getDeviceSvn();
1964 } finally {
1965 Binder.restoreCallingIdentity(identity);
1966 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001967 }
1968
fionaxu43304da2017-11-27 22:51:16 -08001969 @Override
1970 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001971 final long identity = Binder.clearCallingIdentity();
1972 try {
1973 final Phone phone = getPhone(subId);
1974 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1975 } finally {
1976 Binder.restoreCallingIdentity(identity);
1977 }
fionaxu43304da2017-11-27 22:51:16 -08001978 }
1979
1980 @Override
1981 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001982 final long identity = Binder.clearCallingIdentity();
1983 try {
1984 final Phone phone = getPhone(subId);
1985 return phone == null ? null : phone.getCarrierName();
1986 } finally {
1987 Binder.restoreCallingIdentity(identity);
1988 }
fionaxu43304da2017-11-27 22:51:16 -08001989 }
1990
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 //
1992 // Internal helper methods.
1993 //
1994
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001995 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1997 *
1998 * @throws SecurityException if the caller does not have the required permission
1999 */
2000 private void enforceModifyPermission() {
2001 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2002 }
2003
2004 /**
2005 * Make sure the caller has the CALL_PHONE permission.
2006 *
2007 * @throws SecurityException if the caller does not have the required permission
2008 */
2009 private void enforceCallPermission() {
2010 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2011 }
2012
Stuart Scott8eef64f2015-04-08 15:13:54 -07002013 private void enforceConnectivityInternalPermission() {
2014 mApp.enforceCallingOrSelfPermission(
2015 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2016 "ConnectivityService");
2017 }
2018
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 private String createTelUrl(String number) {
2020 if (TextUtils.isEmpty(number)) {
2021 return null;
2022 }
2023
Jake Hambye994d462014-02-03 13:10:13 -08002024 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002025 }
2026
Ihab Awadf9e92732013-12-05 18:02:52 -08002027 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2029 }
2030
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002031 private static void logv(String msg) {
2032 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2033 }
2034
Ihab Awadf9e92732013-12-05 18:02:52 -08002035 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2037 }
2038
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002039 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002041 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002042 }
2043
Sanket Padawe356d7632015-06-22 14:03:32 -07002044 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002045 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002046 final long identity = Binder.clearCallingIdentity();
2047 try {
2048 final Phone phone = PhoneFactory.getPhone(slotIndex);
2049 if (phone == null) {
2050 return PhoneConstants.PHONE_TYPE_NONE;
2051 } else {
2052 return phone.getPhoneType();
2053 }
2054 } finally {
2055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 }
2058
2059 /**
2060 * Returns the CDMA ERI icon index to display
2061 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002062 @Override
2063 public int getCdmaEriIconIndex(String callingPackage) {
2064 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002065 }
2066
Sanket Padawe356d7632015-06-22 14:03:32 -07002067 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002068 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002070 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002071 return -1;
2072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002073
2074 final long identity = Binder.clearCallingIdentity();
2075 try {
2076 final Phone phone = getPhone(subId);
2077 if (phone != null) {
2078 return phone.getCdmaEriIconIndex();
2079 } else {
2080 return -1;
2081 }
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 }
2086
2087 /**
2088 * Returns the CDMA ERI icon mode,
2089 * 0 - ON
2090 * 1 - FLASHING
2091 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002092 @Override
2093 public int getCdmaEriIconMode(String callingPackage) {
2094 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002095 }
2096
Sanket Padawe356d7632015-06-22 14:03:32 -07002097 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002098 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002100 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002101 return -1;
2102 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103
2104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 final Phone phone = getPhone(subId);
2107 if (phone != null) {
2108 return phone.getCdmaEriIconMode();
2109 } else {
2110 return -1;
2111 }
2112 } finally {
2113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 }
2116
2117 /**
2118 * Returns the CDMA ERI text,
2119 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002120 @Override
2121 public String getCdmaEriText(String callingPackage) {
2122 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002123 }
2124
Sanket Padawe356d7632015-06-22 14:03:32 -07002125 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002126 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002128 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002129 return null;
2130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002131
2132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 final Phone phone = getPhone(subId);
2135 if (phone != null) {
2136 return phone.getCdmaEriText();
2137 } else {
2138 return null;
2139 }
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 }
2144
2145 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002146 * Returns the CDMA MDN.
2147 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002149 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2151 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 final Phone phone = getPhone(subId);
2156 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2157 return phone.getLine1Number();
2158 } else {
2159 return null;
2160 }
2161 } finally {
2162 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002163 }
2164 }
2165
2166 /**
2167 * Returns the CDMA MIN.
2168 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002169 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002170 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2172 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002173
2174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 final Phone phone = getPhone(subId);
2177 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2178 return phone.getCdmaMin();
2179 } else {
2180 return null;
2181 }
2182 } finally {
2183 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002184 }
2185 }
2186
2187 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 * Returns true if CDMA provisioning needs to run.
2189 */
2190 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002191 final long identity = Binder.clearCallingIdentity();
2192 try {
2193 return mPhone.needsOtaServiceProvisioning();
2194 } finally {
2195 Binder.restoreCallingIdentity(identity);
2196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
2198
2199 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002200 * Sets the voice mail number of a given subId.
2201 */
2202 @Override
2203 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002204 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2209 new Pair<String, String>(alphaTag, number), new Integer(subId));
2210 return success;
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
2213 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002214 }
2215
Ta-wei Yen87c49842016-05-13 21:19:52 -07002216 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002217 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2218 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2219 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2220 if (!TextUtils.equals(callingPackage, systemDialer)) {
2221 throw new SecurityException("caller must be system dialer");
2222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223
2224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2227 if (phoneAccountHandle == null) {
2228 return null;
2229 }
2230 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2231 } finally {
2232 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002233 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002234 }
2235
2236 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002237 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002238 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002240 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002241 return null;
2242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 return RemoteVvmTaskManager
2247 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
2250 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002251 }
2252
2253 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002254 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2255 VisualVoicemailSmsFilterSettings settings) {
2256 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257
2258 final long identity = Binder.clearCallingIdentity();
2259 try {
2260 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2261 mPhone.getContext(), callingPackage, subId, settings);
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002265 }
2266
2267 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002268 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002270
2271 final long identity = Binder.clearCallingIdentity();
2272 try {
2273 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2274 mPhone.getContext(), callingPackage, subId);
2275 } finally {
2276 Binder.restoreCallingIdentity(identity);
2277 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002278 }
2279
2280 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002281 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2282 String callingPackage, int subId) {
2283 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284
2285 final long identity = Binder.clearCallingIdentity();
2286 try {
2287 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2288 mPhone.getContext(), callingPackage, subId);
2289 } finally {
2290 Binder.restoreCallingIdentity(identity);
2291 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002292 }
2293
2294 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002295 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002296 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297
2298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2301 mPhone.getContext(), subId);
2302 } finally {
2303 Binder.restoreCallingIdentity(identity);
2304 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002305 }
2306
2307 @Override
2308 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2309 String number, int port, String text, PendingIntent sentIntent) {
2310 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002311 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002312 enforceSendSmsPermission();
2313 // Make the calls as the phone process.
2314 final long identity = Binder.clearCallingIdentity();
2315 try {
2316 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2317 if (port == 0) {
2318 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2319 sentIntent, null, false);
2320 } else {
2321 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2322 smsManager.sendDataMessageWithSelfPermissions(number, null,
2323 (short) port, data, sentIntent, null);
2324 }
2325 } finally {
2326 Binder.restoreCallingIdentity(identity);
2327 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002328 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002329 /**
fionaxu0152e512016-11-14 13:36:14 -08002330 * Sets the voice activation state of a given subId.
2331 */
2332 @Override
2333 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2335 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002336
2337 final long identity = Binder.clearCallingIdentity();
2338 try {
2339 final Phone phone = getPhone(subId);
2340 if (phone != null) {
2341 phone.setVoiceActivationState(activationState);
2342 } else {
2343 loge("setVoiceActivationState fails with invalid subId: " + subId);
2344 }
2345 } finally {
2346 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002347 }
2348 }
2349
2350 /**
2351 * Sets the data activation state of a given subId.
2352 */
2353 @Override
2354 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2356 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357
2358 final long identity = Binder.clearCallingIdentity();
2359 try {
2360 final Phone phone = getPhone(subId);
2361 if (phone != null) {
2362 phone.setDataActivationState(activationState);
2363 } else {
2364 loge("setVoiceActivationState fails with invalid subId: " + subId);
2365 }
2366 } finally {
2367 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002368 }
2369 }
2370
2371 /**
2372 * Returns the voice activation state of a given subId.
2373 */
2374 @Override
2375 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002376 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377
fionaxu0152e512016-11-14 13:36:14 -08002378 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 if (phone != null) {
2382 return phone.getVoiceActivationState();
2383 } else {
2384 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2385 }
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002388 }
2389 }
2390
2391 /**
2392 * Returns the data activation state of a given subId.
2393 */
2394 @Override
2395 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002396 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397
fionaxu0152e512016-11-14 13:36:14 -08002398 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 if (phone != null) {
2402 return phone.getDataActivationState();
2403 } else {
2404 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2405 }
2406 } finally {
2407 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002408 }
2409 }
2410
2411 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 * Returns the unread count of voicemails
2413 */
2414 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002415 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002416 }
2417
2418 /**
2419 * Returns the unread count of voicemails for a subId
2420 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002421 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002422 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 final Phone phone = getPhone(subId);
2426 if (phone != null) {
2427 return phone.getVoiceMessageCount();
2428 } else {
2429 return 0;
2430 }
2431 } finally {
2432 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 }
2435
2436 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002437 * returns true, if the device is in a state where both voice and data
2438 * are supported simultaneously. This can change based on location or network condition.
2439 */
2440 @Override
2441 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442 final long identity = Binder.clearCallingIdentity();
2443 try {
2444 final Phone phone = getPhone(subId);
2445 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2446 } finally {
2447 Binder.restoreCallingIdentity(identity);
2448 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002449 }
2450
2451 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002452 * Send the dialer code if called from the current default dialer or the caller has
2453 * carrier privilege.
2454 * @param inputCode The dialer code to send
2455 */
2456 @Override
2457 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2459 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2460 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002461 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2462 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 mPhone.sendDialerSpecialCode(inputCode);
2468 } finally {
2469 Binder.restoreCallingIdentity(identity);
2470 }
fionaxu235cc5e2017-03-06 22:25:57 -08002471 }
2472
2473 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002474 * Returns the data network type.
2475 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 *
2477 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2478 */
2479 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002480 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 final Phone phone = getPhone(getDefaultSubscription());
2484 if (phone != null) {
2485 return phone.getServiceState().getDataNetworkType();
2486 } else {
2487 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2488 }
2489 } finally {
2490 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002491 }
Wink Saville36469e72014-06-11 15:17:00 -07002492 }
2493
Pengquan Menga1bb6272018-09-06 09:59:22 -07002494 @Override
2495 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002496 if (!isActiveSubscription(subId)) {
2497 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2498 }
2499
Pengquan Menga1bb6272018-09-06 09:59:22 -07002500 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2501 }
2502
Wink Saville36469e72014-06-11 15:17:00 -07002503 /**
2504 * Returns the network type for a subId
2505 */
2506 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002507 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002509 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002510 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2511 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 final long identity = Binder.clearCallingIdentity();
2514 try {
2515 final Phone phone = getPhone(subId);
2516 if (phone != null) {
2517 return phone.getServiceState().getDataNetworkType();
2518 } else {
2519 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2520 }
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
2525
2526 /**
2527 * Returns the data network type
2528 */
2529 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002530 public int getDataNetworkType(String callingPackage) {
2531 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002532 }
2533
2534 /**
2535 * Returns the data network type for a subId
2536 */
2537 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002538 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002540 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002541 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2542 }
2543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 final Phone phone = getPhone(subId);
2547 if (phone != null) {
2548 return phone.getServiceState().getDataNetworkType();
2549 } else {
2550 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2551 }
2552 } finally {
2553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 }
2556
2557 /**
Wink Saville36469e72014-06-11 15:17:00 -07002558 * Returns the Voice network type for a subId
2559 */
2560 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002561 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002563 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002564 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2565 }
2566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 final Phone phone = getPhone(subId);
2570 if (phone != null) {
2571 return phone.getServiceState().getVoiceNetworkType();
2572 } else {
2573 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2574 }
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 }
2579
2580 /**
2581 * @return true if a ICC card is present
2582 */
2583 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002584 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002585 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2586 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
2589 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002590 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002591 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002592 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002593 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594 final long identity = Binder.clearCallingIdentity();
2595 try {
2596 final Phone phone = PhoneFactory.getPhone(slotIndex);
2597 if (phone != null) {
2598 return phone.getIccCard().hasIccCard();
2599 } else {
2600 return false;
2601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 }
2606
2607 /**
2608 * Return if the current radio is LTE on CDMA. This
2609 * is a tri-state return value as for a period of time
2610 * the mode may be unknown.
2611 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002612 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002614 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002615 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002616 @Override
2617 public int getLteOnCdmaMode(String callingPackage) {
2618 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002619 }
2620
Sanket Padawe356d7632015-06-22 14:03:32 -07002621 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002622 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002624 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002625 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2626 }
2627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 final Phone phone = getPhone(subId);
2631 if (phone == null) {
2632 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2633 } else {
2634 return phone.getLteOnCdmaMode();
2635 }
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002638 }
Wink Saville36469e72014-06-11 15:17:00 -07002639 }
2640
2641 public void setPhone(Phone phone) {
2642 mPhone = phone;
2643 }
2644
2645 /**
2646 * {@hide}
2647 * Returns Default subId, 0 in the case of single standby.
2648 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002649 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002650 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002651 }
2652
Shishir Agrawala9f32182016-04-12 12:00:16 -07002653 private int getSlotForDefaultSubscription() {
2654 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2655 }
2656
Wink Savilleb564aae2014-10-23 10:18:09 -07002657 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002658 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002660
Pengquan Menge92a50d2018-09-21 15:54:48 -07002661 private boolean isActiveSubscription(int subId) {
2662 return mSubscriptionController.isActiveSubId(subId);
2663 }
2664
Ihab Awadf2177b72013-11-25 13:33:23 -08002665 /**
2666 * @see android.telephony.TelephonyManager.WifiCallingChoices
2667 */
2668 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2672 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2673 getWhenToMakeWifiCallsDefaultPreference());
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
2676 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002677 }
2678
2679 /**
2680 * @see android.telephony.TelephonyManager.WifiCallingChoices
2681 */
2682 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2686 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2687 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002691 }
2692
Sailesh Nepald1e68152013-12-12 19:08:02 -08002693 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002694 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002695 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002696 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002697
Shishir Agrawal566b7612013-10-28 14:41:00 -07002698 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002699 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2700 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2702 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 if (TextUtils.equals(ISDR_AID, aid)) {
2708 // Only allows LPA to open logical channel to ISD-R.
2709 ComponentInfo bestComponent =
2710 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2711 if (bestComponent == null
2712 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2713 loge("The calling package is not allowed to access ISD-R.");
2714 throw new SecurityException(
2715 "The calling package is not allowed to access ISD-R.");
2716 }
Derek Tan740e1672017-06-27 14:56:27 -07002717 }
Derek Tan740e1672017-06-27 14:56:27 -07002718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 if (DBG) {
2720 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2721 }
2722 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2723 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2724 if (DBG) log("iccOpenLogicalChannel: " + response);
2725 return response;
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
2728 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002729 }
2730
2731 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002732 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2734 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 final long identity = Binder.clearCallingIdentity();
2737 try {
2738 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2739 if (channel < 0) {
2740 return false;
2741 }
2742 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2743 if (DBG) log("iccCloseLogicalChannel: " + success);
2744 return success;
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002747 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002748 }
2749
2750 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002751 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002752 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2754 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 if (DBG) {
2759 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2760 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2761 + p3 + " data=" + data);
2762 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764 if (channel < 0) {
2765 return "";
2766 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2769 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2770 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 // Append the returned status code to the end of the response payload.
2773 String s = Integer.toHexString(
2774 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2775 if (response.payload != null) {
2776 s = IccUtils.bytesToHexString(response.payload) + s;
2777 }
2778 return s;
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002781 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002782 }
Jake Hambye994d462014-02-03 13:10:13 -08002783
Evan Charltonc66da362014-05-16 14:06:40 -07002784 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002785 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2786 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2788 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2794 && TextUtils.equals(ISDR_AID, data)) {
2795 // Only allows LPA to select ISD-R.
2796 ComponentInfo bestComponent =
2797 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2798 if (bestComponent == null
2799 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2800 loge("The calling package is not allowed to select ISD-R.");
2801 throw new SecurityException(
2802 "The calling package is not allowed to select ISD-R.");
2803 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002804 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 if (DBG) {
2807 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2808 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2809 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2812 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2813 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815 // Append the returned status code to the end of the response payload.
2816 String s = Integer.toHexString(
2817 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2818 if (response.payload != null) {
2819 s = IccUtils.bytesToHexString(response.payload) + s;
2820 }
2821 return s;
2822 } finally {
2823 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002824 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002825 }
2826
2827 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002828 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002829 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2831 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 if (DBG) {
2836 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2837 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2838 }
2839
2840 IccIoResult response =
2841 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2842 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2843 subId);
2844
2845 if (DBG) {
2846 log("Exchange SIM_IO [R]" + response);
2847 }
2848
2849 byte[] result = null;
2850 int length = 2;
2851 if (response.payload != null) {
2852 length = 2 + response.payload.length;
2853 result = new byte[length];
2854 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2855 } else {
2856 result = new byte[length];
2857 }
2858
2859 result[length - 1] = (byte) response.sw2;
2860 result[length - 2] = (byte) response.sw1;
2861 return result;
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002864 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002865 }
2866
Nathan Haroldb3014052017-01-25 15:57:32 -08002867 /**
2868 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2869 * on a particular subscription
2870 */
sqianb6e41952018-03-12 14:54:01 -07002871 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2873 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2874 return null;
2875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
2879 if (appType != TelephonyManager.APPTYPE_USIM
2880 && appType != TelephonyManager.APPTYPE_SIM) {
2881 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2882 return null;
2883 }
2884 Object response = sendRequest(
2885 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2886 if (response instanceof String[]) {
2887 return (String[]) response;
2888 }
2889 // Response is an Exception of some kind,
2890 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08002891 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 } finally {
2893 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002894 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002895 }
2896
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002897 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002898 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2900 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2905 if (response.payload == null) {
2906 return "";
2907 }
Evan Charltonc66da362014-05-16 14:06:40 -07002908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 // Append the returned status code to the end of the response payload.
2910 String s = Integer.toHexString(
2911 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2912 s = IccUtils.bytesToHexString(response.payload) + s;
2913 return s;
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
Evan Charltonc66da362014-05-16 14:06:40 -07002917 }
2918
Jake Hambye994d462014-02-03 13:10:13 -08002919 /**
2920 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2921 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2922 *
2923 * @param itemID the ID of the item to read
2924 * @return the NV item as a String, or null on error.
2925 */
2926 @Override
2927 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07002928 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2930 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07002935 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2937 return value;
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
Jake Hambye994d462014-02-03 13:10:13 -08002941 }
2942
2943 /**
2944 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2945 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2946 *
2947 * @param itemID the ID of the item to read
2948 * @param itemValue the value to write, as a String
2949 * @return true on success; false on any failure
2950 */
2951 @Override
2952 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07002953 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2955 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956
2957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2960 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07002961 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2963 return success;
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
Jake Hambye994d462014-02-03 13:10:13 -08002967 }
2968
2969 /**
2970 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2971 * Used for device configuration by some CDMA operators.
2972 *
2973 * @param preferredRoamingList byte array containing the new PRL
2974 * @return true on success; false on any failure
2975 */
2976 @Override
2977 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2979 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980
2981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2984 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2985 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2986 return success;
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
Jake Hambye994d462014-02-03 13:10:13 -08002990 }
2991
2992 /**
2993 * Perform the specified type of NV config reset.
2994 * Used for device configuration by some CDMA operators.
2995 *
2996 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2997 * @return true on success; false on any failure
2998 */
2999 @Override
3000 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3002 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003
3004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 if (DBG) log("nvResetConfig: type " + resetType);
3007 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3008 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3009 return success;
3010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
Jake Hambye994d462014-02-03 13:10:13 -08003013 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003014
Svet Ganovb320e182015-04-16 12:30:10 -07003015 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003017 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003018 return new String[0];
3019 }
3020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 return mPhone.getPcscfAddress(apnType);
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
Wink Saville36469e72014-06-11 15:17:00 -07003027 }
3028
Brad Ebinger51f743a2017-01-23 13:50:20 -08003029 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003030 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3031 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003032 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003033 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003034 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035
3036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 PhoneFactory.getImsResolver().enableIms(slotId);
3039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003042 }
3043
3044 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003045 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3046 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003047 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003048 public void disableIms(int slotId) {
3049 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 PhoneFactory.getImsResolver().disableIms(slotId);
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003057 }
3058
3059 /**
3060 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3061 * feature or {@link null} if the service is not available. If the feature is available, the
3062 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3063 */
3064 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003065 IImsServiceFeatureCallback callback) {
3066 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003067
3068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3071 } finally {
3072 Binder.restoreCallingIdentity(identity);
3073 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003074 }
3075
3076 /**
3077 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3078 * feature during emergency calling or {@link null} if the service is not available. If the
3079 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3080 * listener for feature updates.
3081 */
3082 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3083 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003091 }
3092
Brad Ebinger5f64b052017-12-14 14:26:15 -08003093 /**
3094 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3095 * specified.
3096 */
3097 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099
3100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003106 }
3107
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003108 /**
3109 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3110 * specified.
3111 */
3112 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114
3115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3118 } finally {
3119 Binder.restoreCallingIdentity(identity);
3120 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003121 }
3122
Brad Ebinger884c07b2018-02-15 16:17:40 -08003123 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003124 * Sets the ImsService Package Name that Telephony will bind to.
3125 *
3126 * @param slotId the slot ID that the ImsService should bind for.
3127 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3128 * ImsService is the device default ImsService.
3129 * @param packageName The package name of the application that contains the ImsService to bind
3130 * to.
3131 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3132 * @hide
3133 */
3134 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003135 int[] subIds = SubscriptionManager.getSubId(slotId);
3136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3137 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3138 "setImsService");
3139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003140 final long identity = Binder.clearCallingIdentity();
3141 try {
3142 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3143 isCarrierImsService, packageName);
3144 } finally {
3145 Binder.restoreCallingIdentity(identity);
3146 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003147 }
3148
3149 /**
3150 * Return the ImsService configuration.
3151 *
3152 * @param slotId The slot that the ImsService is associated with.
3153 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3154 * the device default.
3155 * @return the package name of the ImsService configuration.
3156 */
3157 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003158 int[] subIds = SubscriptionManager.getSubId(slotId);
3159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3160 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3161 "getImsService");
3162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3166 isCarrierImsService);
3167 } finally {
3168 Binder.restoreCallingIdentity(identity);
3169 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003170 }
3171
Wink Saville36469e72014-06-11 15:17:00 -07003172 public void setImsRegistrationState(boolean registered) {
3173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174
3175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 mPhone.setImsRegistrationState(registered);
3178 } finally {
3179 Binder.restoreCallingIdentity(identity);
3180 }
Wink Saville36469e72014-06-11 15:17:00 -07003181 }
3182
3183 /**
Stuart Scott54788802015-03-30 13:18:01 -07003184 * Set the network selection mode to automatic.
3185 *
3186 */
3187 @Override
3188 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3190 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003191
Pengquan Menge92a50d2018-09-21 15:54:48 -07003192 if (!isActiveSubscription(subId)) {
3193 return;
3194 }
3195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3199 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
3202 }
Stuart Scott54788802015-03-30 13:18:01 -07003203 }
3204
Pengquan Mengea84e042018-09-20 14:57:26 -07003205 /**
3206 * Ask the radio to connect to the input network and change selection mode to manual.
3207 *
3208 * @param subId the id of the subscription.
3209 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3210 * the operator to attach to.
3211 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3212 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3213 * normal network selection next time.
3214 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003215 */
3216 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003217 public boolean setNetworkSelectionModeManual(
3218 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3220 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003221
3222 if (!isActiveSubscription(subId)) {
3223 return false;
3224 }
3225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 final long identity = Binder.clearCallingIdentity();
3227 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003228 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003230 if (DBG) {
3231 log("setNetworkSelectionModeManual: subId: " + subId
3232 + " operator: " + operatorInfo);
3233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003238 }
3239
3240 /**
3241 * Scans for available networks.
3242 */
3243 @Override
3244 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3246 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247
Pengquan Menga1bb6272018-09-06 09:59:22 -07003248 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249 try {
3250 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003251 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003256 }
3257
3258 /**
yinxub1bed742017-04-17 11:45:04 -07003259 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003260 *
yinxub1bed742017-04-17 11:45:04 -07003261 * @param subId id of the subscription
3262 * @param request contains the radio access networks with bands/channels to scan
3263 * @param messenger callback messenger for scan results or errors
3264 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003265 * @return the id of the requested scan which can be used to stop the scan.
3266 */
3267 @Override
3268 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3269 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3271 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272
3273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 return mNetworkScanRequestTracker.startNetworkScan(
3276 request, messenger, binder, getPhone(subId));
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
yinxu504e1392017-04-12 16:03:22 -07003280 }
3281
3282 /**
3283 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003284 *
3285 * @param subId id of the subscription
3286 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003287 */
3288 @Override
3289 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
yinxu504e1392017-04-12 16:03:22 -07003299 }
3300
3301 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003302 * Get the calculated preferred network type.
3303 * Used for debugging incorrect network type.
3304 *
3305 * @return the preferred network type, defined in RILConstants.java.
3306 */
3307 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003308 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003310 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003311 return RILConstants.PREFERRED_NETWORK_MODE;
3312 }
3313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 // FIXME: need to get SubId from somewhere.
3317 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
Junda Liu84d15a22014-07-02 11:21:04 -07003321 }
3322
3323 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003324 * Get the preferred network type.
3325 * Used for device configuration by some CDMA operators.
3326 *
3327 * @return the preferred network type, defined in RILConstants.java.
3328 */
3329 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003330 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3332 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333
3334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 if (DBG) log("getPreferredNetworkType");
3337 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3338 int networkType = (result != null ? result[0] : -1);
3339 if (DBG) log("getPreferredNetworkType: " + networkType);
3340 return networkType;
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003344 }
3345
3346 /**
3347 * Set the preferred network type.
3348 * Used for device configuration by some CDMA operators.
3349 *
3350 * @param networkType the preferred network type, defined in RILConstants.java.
3351 * @return true on success; false on any failure.
3352 */
3353 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003354 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3356 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357
3358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3361 Boolean success = (Boolean) sendRequest(
3362 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3363 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3364 if (success) {
3365 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3366 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3367 }
3368 return success;
3369 } finally {
3370 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003371 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003372 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003373
3374 /**
Junda Liu475951f2014-11-07 16:45:03 -08003375 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3376 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3377 * tethering.
3378 *
3379 * @return 0: Not required. 1: required. 2: Not set.
3380 * @hide
3381 */
3382 @Override
3383 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003384 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003385
3386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3389 Settings.Global.TETHER_DUN_REQUIRED, 2);
3390 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3391 // config_tether_apndata.
3392 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3393 dunRequired = 1;
3394 }
3395 return dunRequired;
3396 } finally {
3397 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003398 }
Junda Liu475951f2014-11-07 16:45:03 -08003399 }
3400
3401 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003402 * Set mobile data enabled
3403 * Used by the user through settings etc to turn on/off mobile data
3404 *
3405 * @param enable {@code true} turn turn data on, else {@code false}
3406 */
3407 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003408 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3410 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411
3412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 int phoneId = mSubscriptionController.getPhoneId(subId);
3415 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3416 Phone phone = PhoneFactory.getPhone(phoneId);
3417 if (phone != null) {
3418 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3419 phone.setUserDataEnabled(enable);
3420 } else {
3421 loge("setUserDataEnabled: no phone for subId=" + subId);
3422 }
3423 } finally {
3424 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003425 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003426 }
3427
3428 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003429 * Get the user enabled state of Mobile Data.
3430 *
3431 * TODO: remove and use isUserDataEnabled.
3432 * This can't be removed now because some vendor codes
3433 * calls through ITelephony directly while they should
3434 * use TelephonyManager.
3435 *
3436 * @return true on enabled
3437 */
3438 @Override
3439 public boolean getDataEnabled(int subId) {
3440 return isUserDataEnabled(subId);
3441 }
3442
3443 /**
3444 * Get whether mobile data is enabled per user setting.
3445 *
3446 * There are other factors deciding whether mobile data is actually enabled, but they are
3447 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003448 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003449 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003450 *
3451 * @return {@code true} if data is enabled else {@code false}
3452 */
3453 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003454 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003455 try {
3456 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3457 null);
3458 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3460 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462
3463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 int phoneId = mSubscriptionController.getPhoneId(subId);
3466 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3467 Phone phone = PhoneFactory.getPhone(phoneId);
3468 if (phone != null) {
3469 boolean retVal = phone.isUserDataEnabled();
3470 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3471 return retVal;
3472 } else {
3473 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3474 return false;
3475 }
3476 } finally {
3477 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003478 }
3479 }
3480
3481 /**
3482 * Get whether mobile data is enabled.
3483 *
3484 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3485 * whether mobile data is actually enabled.
3486 *
3487 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3488 *
3489 * @return {@code true} if data is enabled else {@code false}
3490 */
3491 @Override
3492 public boolean isDataEnabled(int subId) {
3493 try {
3494 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3495 null);
3496 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3498 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003500
3501 final long identity = Binder.clearCallingIdentity();
3502 try {
3503 int phoneId = mSubscriptionController.getPhoneId(subId);
3504 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3505 Phone phone = PhoneFactory.getPhone(phoneId);
3506 if (phone != null) {
3507 boolean retVal = phone.isDataEnabled();
3508 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3509 return retVal;
3510 } else {
3511 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3512 return false;
3513 }
3514 } finally {
3515 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003516 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003517 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003518
3519 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003520 public int getCarrierPrivilegeStatus(int subId) {
3521 final Phone phone = getPhone(subId);
3522 if (phone == null) {
3523 loge("getCarrierPrivilegeStatus: Invalid subId");
3524 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3525 }
3526 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003527 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003528 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003529 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3530 }
3531 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003532 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003533 }
Junda Liu29340342014-07-10 15:23:27 -07003534
3535 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003536 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3537 final Phone phone = getPhone(subId);
3538 if (phone == null) {
3539 loge("getCarrierPrivilegeStatus: Invalid subId");
3540 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3541 }
3542 UiccProfile profile =
3543 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3544 if (profile == null) {
3545 loge("getCarrierPrivilegeStatus: No UICC");
3546 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3547 }
3548 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3549 }
3550
3551 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003552 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003553 if (TextUtils.isEmpty(pkgName))
3554 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003555 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003556 if (card == null) {
3557 loge("checkCarrierPrivilegesForPackage: No UICC");
3558 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3559 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003560 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3561 }
3562
3563 @Override
3564 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003565 if (TextUtils.isEmpty(pkgName))
3566 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003567 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3568 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3569 UiccCard card = UiccController.getInstance().getUiccCard(i);
3570 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003571 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003572 continue;
3573 }
3574
3575 result = card.getCarrierPrivilegeStatus(
3576 mPhone.getContext().getPackageManager(), pkgName);
3577 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3578 break;
3579 }
3580 }
3581
3582 return result;
Junda Liu29340342014-07-10 15:23:27 -07003583 }
Derek Tan89e89d42014-07-08 17:00:10 -07003584
3585 @Override
Junda Liue64de782015-04-16 17:19:16 -07003586 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3587 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3588 loge("phoneId " + phoneId + " is not valid.");
3589 return null;
3590 }
3591 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003592 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003593 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003594 return null ;
3595 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003596 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003597 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003598 }
3599
Amith Yamasani6e118872016-02-19 12:53:51 -08003600 @Override
3601 public List<String> getPackagesWithCarrierPrivileges() {
3602 PackageManager pm = mPhone.getContext().getPackageManager();
3603 List<String> privilegedPackages = new ArrayList<>();
3604 List<PackageInfo> packages = null;
3605 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3606 UiccCard card = UiccController.getInstance().getUiccCard(i);
3607 if (card == null) {
3608 // No UICC in that slot.
3609 continue;
3610 }
3611 if (card.hasCarrierPrivilegeRules()) {
3612 if (packages == null) {
3613 // Only check packages in user 0 for now
3614 packages = pm.getInstalledPackagesAsUser(
3615 PackageManager.MATCH_DISABLED_COMPONENTS
3616 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3617 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3618 }
3619 for (int p = packages.size() - 1; p >= 0; p--) {
3620 PackageInfo pkgInfo = packages.get(p);
3621 if (pkgInfo != null && pkgInfo.packageName != null
3622 && card.getCarrierPrivilegeStatus(pkgInfo)
3623 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3624 privilegedPackages.add(pkgInfo.packageName);
3625 }
3626 }
3627 }
3628 }
3629 return privilegedPackages;
3630 }
3631
Wink Savilleb564aae2014-10-23 10:18:09 -07003632 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003633 final Phone phone = getPhone(subId);
3634 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003635 if (card == null) {
3636 loge("getIccId: No UICC");
3637 return null;
3638 }
3639 String iccId = card.getIccId();
3640 if (TextUtils.isEmpty(iccId)) {
3641 loge("getIccId: ICC ID is null or empty.");
3642 return null;
3643 }
3644 return iccId;
3645 }
3646
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003647 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003648 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3649 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003650 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3651 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 final String iccId = getIccId(subId);
3656 final Phone phone = getPhone(subId);
3657 if (phone == null) {
3658 return false;
3659 }
3660 final String subscriberId = phone.getSubscriberId();
3661
3662 if (DBG_MERGE) {
3663 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3664 + subscriberId + " to " + number);
3665 }
3666
3667 if (TextUtils.isEmpty(iccId)) {
3668 return false;
3669 }
3670
3671 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3672
3673 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3674 if (alphaTag == null) {
3675 editor.remove(alphaTagPrefKey);
3676 } else {
3677 editor.putString(alphaTagPrefKey, alphaTag);
3678 }
3679
3680 // Record both the line number and IMSI for this ICCID, since we need to
3681 // track all merged IMSIs based on line number
3682 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3683 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3684 if (number == null) {
3685 editor.remove(numberPrefKey);
3686 editor.remove(subscriberPrefKey);
3687 } else {
3688 editor.putString(numberPrefKey, number);
3689 editor.putString(subscriberPrefKey, subscriberId);
3690 }
3691
3692 editor.commit();
3693 return true;
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003696 }
Derek Tan7226c842014-07-02 17:42:23 -07003697 }
3698
3699 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003700 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003701 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003703 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003704 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003705 return null;
3706 }
Derek Tan97ebb422014-09-05 16:55:38 -07003707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708 final long identity = Binder.clearCallingIdentity();
3709 try {
3710 String iccId = getIccId(subId);
3711 if (iccId != null) {
3712 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3713 if (DBG_MERGE) {
3714 log("getLine1NumberForDisplay returning "
3715 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3716 }
3717 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3720 return null;
3721 } finally {
3722 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003723 }
Derek Tan7226c842014-07-02 17:42:23 -07003724 }
3725
3726 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003727 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003728 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003729 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003730 return null;
3731 }
Derek Tan97ebb422014-09-05 16:55:38 -07003732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 String iccId = getIccId(subId);
3736 if (iccId != null) {
3737 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3738 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3739 }
3740 return null;
3741 } finally {
3742 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003743 }
Derek Tan7226c842014-07-02 17:42:23 -07003744 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003745
3746 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003747 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003748 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3749 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003750 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003751 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3752 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003753 return null;
3754 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003755
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003756 final long identity = Binder.clearCallingIdentity();
3757 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758 final Context context = mPhone.getContext();
3759 final TelephonyManager tele = TelephonyManager.from(context);
3760 final SubscriptionManager sub = SubscriptionManager.from(context);
3761
3762 // Figure out what subscribers are currently active
3763 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3764 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3765 // the process, where TelephonyManager was instantiated.
3766 // Otherwise AppOps check will fail.
3767
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003768 final int[] subIds = sub.getActiveSubscriptionIdList();
3769 for (int subId : subIds) {
3770 activeSubscriberIds.add(tele.getSubscriberId(subId));
3771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772
3773 // First pass, find a number override for an active subscriber
3774 String mergeNumber = null;
3775 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3776 for (String key : prefs.keySet()) {
3777 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3778 final String subscriberId = (String) prefs.get(key);
3779 if (activeSubscriberIds.contains(subscriberId)) {
3780 final String iccId = key.substring(
3781 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3782 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3783 mergeNumber = (String) prefs.get(numberKey);
3784 if (DBG_MERGE) {
3785 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3786 + " for active subscriber " + subscriberId);
3787 }
3788 if (!TextUtils.isEmpty(mergeNumber)) {
3789 break;
3790 }
3791 }
3792 }
3793 }
3794
3795 // Shortcut when no active merged subscribers
3796 if (TextUtils.isEmpty(mergeNumber)) {
3797 return null;
3798 }
3799
3800 // Second pass, find all subscribers under that line override
3801 final ArraySet<String> result = new ArraySet<>();
3802 for (String key : prefs.keySet()) {
3803 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3804 final String number = (String) prefs.get(key);
3805 if (mergeNumber.equals(number)) {
3806 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3807 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3808 final String subscriberId = (String) prefs.get(subscriberKey);
3809 if (!TextUtils.isEmpty(subscriberId)) {
3810 result.add(subscriberId);
3811 }
3812 }
3813 }
3814 }
3815
3816 final String[] resultArray = result.toArray(new String[result.size()]);
3817 Arrays.sort(resultArray);
3818 if (DBG_MERGE) {
3819 Slog.d(LOG_TAG,
3820 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3821 }
3822 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003823 } finally {
3824 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003825 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003826 }
3827
3828 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003829 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003830 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3831 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832
3833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 final Phone phone = getPhone(subId);
3836 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
3839 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003840 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003841
3842 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003843 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003844 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3845 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003846 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847
3848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 final Phone phone = getPhone(subId);
3851 if (phone == null) {
3852 return false;
3853 }
3854 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3855 cdmaNonRoamingList);
3856 } finally {
3857 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003858 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003859 }
3860
3861 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003862 @Deprecated
3863 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3864 enforceModifyPermission();
3865
3866 int returnValue = 0;
3867 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07003868 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003869 if(result.exception == null) {
3870 if (result.result != null) {
3871 byte[] responseData = (byte[])(result.result);
3872 if(responseData.length > oemResp.length) {
3873 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3874 responseData.length + "bytes. Buffer Size is " +
3875 oemResp.length + "bytes.");
3876 }
3877 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3878 returnValue = responseData.length;
3879 }
3880 } else {
3881 CommandException ex = (CommandException) result.exception;
3882 returnValue = ex.getCommandError().ordinal();
3883 if(returnValue > 0) returnValue *= -1;
3884 }
3885 } catch (RuntimeException e) {
3886 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3887 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3888 if(returnValue > 0) returnValue *= -1;
3889 }
3890
3891 return returnValue;
3892 }
3893
3894 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003895 public void setRadioCapability(RadioAccessFamily[] rafs) {
3896 try {
3897 ProxyController.getInstance().setRadioCapability(rafs);
3898 } catch (RuntimeException e) {
3899 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3900 }
3901 }
3902
3903 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003904 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003905 Phone phone = PhoneFactory.getPhone(phoneId);
3906 if (phone == null) {
3907 return RadioAccessFamily.RAF_UNKNOWN;
3908 }
3909 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003910 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003911 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003912 return RadioAccessFamily.RAF_UNKNOWN;
3913 }
3914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915 final long identity = Binder.clearCallingIdentity();
3916 try {
3917 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003921 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003922
3923 @Override
3924 public void enableVideoCalling(boolean enable) {
3925 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926
3927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
3930 } finally {
3931 Binder.restoreCallingIdentity(identity);
3932 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003933 }
3934
3935 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003936 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3938 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3939 return false;
3940 }
Svet Ganovb320e182015-04-16 12:30:10 -07003941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 // Check the user preference and the system-level IMS setting. Even if the user has
3945 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3946 // In the long run, we may instead need to check if there exists a connection service
3947 // which can support video calling.
3948 ImsManager imsManager =
3949 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3950 return imsManager.isVtEnabledByPlatform()
3951 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3952 && imsManager.isVtEnabledByUser();
3953 } finally {
3954 Binder.restoreCallingIdentity(identity);
3955 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003956 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003957
Andrew Leea1239f22015-03-02 17:44:07 -08003958 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
3960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3961 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
3962 return false;
3963 }
3964
3965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 CarrierConfigManager configManager =
3968 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
3969 return configManager.getConfigForSubId(mPhone.getSubId())
3970 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
3971 } finally {
3972 Binder.restoreCallingIdentity(identity);
3973 }
Andrew Leea1239f22015-03-02 17:44:07 -08003974 }
3975
3976 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003977 public boolean isWorldPhone(int subId, String callingPackage) {
3978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3979 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
3980 return false;
3981 }
3982
3983 final long identity = Binder.clearCallingIdentity();
3984 try {
3985 CarrierConfigManager configManager =
3986 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
3987 return configManager.getConfigForSubId(mPhone.getSubId())
3988 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
Andrew Leea1239f22015-03-02 17:44:07 -08003992 }
3993
Andrew Lee9431b832015-03-09 18:46:45 -07003994 @Override
3995 public boolean isTtyModeSupported() {
3996 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003997 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003998 }
3999
4000 @Override
4001 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
Andrew Lee9431b832015-03-09 18:46:45 -07004008 }
4009
Hall Liu98187582018-01-22 19:15:32 -08004010 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4014 mPhone.getSubId()).getBoolean(
4015 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4016 boolean isDeviceSupported =
4017 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4018 return isCarrierSupported && isDeviceSupported;
4019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
Hall Liu98187582018-01-22 19:15:32 -08004022 }
4023
Hall Liu3ad5f012018-04-06 16:23:39 -07004024 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025 final long identity = Binder.clearCallingIdentity();
4026 try {
4027 return isRttSupported() && Settings.Secure.getInt(
4028 mPhone.getContext().getContentResolver(),
4029 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4030 } finally {
4031 Binder.restoreCallingIdentity(identity);
4032 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004033 }
4034
Sanket Padawe7310cc72015-01-14 09:53:20 -08004035 /**
4036 * Returns the unique device ID of phone, for example, the IMEI for
4037 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4038 *
4039 * <p>Requires Permission:
4040 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4041 */
4042 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004043 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004044 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004045 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004046 return null;
4047 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004048 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004049 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4050 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004051 return null;
4052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053
4054 final long identity = Binder.clearCallingIdentity();
4055 try {
4056 return phone.getDeviceId();
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004060 }
4061
Ping Sunc67b7c22016-03-02 19:16:45 +08004062 /**
4063 * {@hide}
4064 * Returns the IMS Registration Status on a particular subid
4065 *
4066 * @param subId
4067 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004068 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004069 Phone phone = getPhone(subId);
4070 if (phone != null) {
4071 return phone.isImsRegistered();
4072 } else {
4073 return false;
4074 }
4075 }
4076
Santos Cordon7a1885b2015-02-03 11:15:19 -08004077 @Override
4078 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004085 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004086
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004087 /**
4088 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004089 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004090 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 Phone phone = getPhone(subId);
4094 if (phone != null) {
4095 return phone.isWifiCallingEnabled();
4096 } else {
4097 return false;
4098 }
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004101 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004102 }
4103
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004104 /**
4105 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004106 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004107 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 Phone phone = getPhone(subId);
4111 if (phone != null) {
4112 return phone.isVolteEnabled();
4113 } else {
4114 return false;
4115 }
4116 } finally {
4117 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004118 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004119 }
Svet Ganovb320e182015-04-16 12:30:10 -07004120
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004121 /**
4122 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004123 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004124 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 Phone phone = getPhone(subId);
4128 if (phone != null) {
4129 return phone.isVideoEnabled();
4130 } else {
4131 return false;
4132 }
4133 } finally {
4134 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004135 }
4136 }
4137
4138 /**
4139 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4140 * defined in {@link ImsRegistrationImplBase}.
4141 */
4142 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 Phone phone = getPhone(subId);
4146 if (phone != null) {
4147 return phone.getImsRegistrationTech();
4148 } else {
4149 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4150 }
4151 } finally {
4152 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004153 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004154 }
4155
Stuart Scott8eef64f2015-04-08 15:13:54 -07004156 @Override
4157 public void factoryReset(int subId) {
4158 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004159 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4160 return;
4161 }
4162
Svet Ganovcc087f82015-05-12 20:35:54 -07004163 final long identity = Binder.clearCallingIdentity();
4164 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004165 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4166 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004167 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004168 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004169 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4170 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004171 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004172 }
4173 } finally {
4174 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004175 }
4176 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004177
4178 @Override
4179 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 // We query all subscriptions instead of just the active ones, because
4183 // this might be called early on in the provisioning flow when the
4184 // subscriptions potentially aren't active yet.
4185 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4186 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004187 return null;
4188 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190 // This function may be called very early, say, from the setup wizard, at
4191 // which point we won't have a default subscription set. If that's the case
4192 // we just choose the first, which will be valid in "most cases".
4193 final int defaultSubId = getDefaultSubscription();
4194 SubscriptionInfo info = null;
4195 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4196 info = slist.get(0);
4197 } else {
4198 for (SubscriptionInfo item : slist) {
4199 if (item.getSubscriptionId() == defaultSubId) {
4200 info = item;
4201 break;
4202 }
4203 }
4204
4205 if (info == null) {
4206 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004207 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004208 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210 // Try and fetch the locale from the carrier properties or from the SIM language
4211 // preferences (EF-PL and EF-LI)...
4212 final int mcc = info.getMcc();
4213 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4214 String simLanguage = null;
4215 if (defaultPhone != null) {
4216 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4217 if (localeFromDefaultSim != null) {
4218 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4219 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4220 return localeFromDefaultSim.toLanguageTag();
4221 } else {
4222 simLanguage = localeFromDefaultSim.getLanguage();
4223 }
4224 }
4225 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227 // The SIM language preferences only store a language (e.g. fr = French), not an
4228 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4229 // the SIM and carrier preferences does not include a country we add the country
4230 // determined from the SIM MCC to provide an exact locale.
4231 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4232 simLanguage);
4233 if (mccLocale != null) {
4234 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4235 return mccLocale.toLanguageTag();
4236 }
4237
4238 if (DBG) log("No locale found - returning null");
4239 return null;
4240 } finally {
4241 Binder.restoreCallingIdentity(identity);
4242 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004243 }
4244
4245 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246 return mSubscriptionController.getAllSubInfoList(
4247 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004248 }
4249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 /**
4251 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4252 */
4253 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4254 return mSubscriptionController.getActiveSubscriptionInfoList(
4255 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004256 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004257
Chenjie Yu1ba97252018-01-11 18:16:20 -08004258 private final ModemActivityInfo mLastModemActivityInfo =
4259 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4260
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004261 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004262 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4263 * representing the state of the modem.
4264 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004265 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4266 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004267 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004268 */
4269 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004270 public void requestModemActivityInfo(ResultReceiver result) {
4271 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004272 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273
4274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 ModemActivityInfo ret = null;
4277 synchronized (mLastModemActivityInfo) {
4278 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4279 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004280 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004281 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4283 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4284 mergedTxTimeMs[i] =
4285 info.getTxTimeMillis()[i]
4286 + mLastModemActivityInfo.getTxTimeMillis()[i];
4287 }
4288 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4289 mLastModemActivityInfo.setSleepTimeMillis(
4290 info.getSleepTimeMillis()
4291 + mLastModemActivityInfo.getSleepTimeMillis());
4292 mLastModemActivityInfo.setIdleTimeMillis(
4293 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4294 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4295 mLastModemActivityInfo.setRxTimeMillis(
4296 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4297 mLastModemActivityInfo.setEnergyUsed(
4298 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004299 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4301 mLastModemActivityInfo.getSleepTimeMillis(),
4302 mLastModemActivityInfo.getIdleTimeMillis(),
4303 mLastModemActivityInfo.getTxTimeMillis(),
4304 mLastModemActivityInfo.getRxTimeMillis(),
4305 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 Bundle bundle = new Bundle();
4308 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4309 result.send(0, bundle);
4310 } finally {
4311 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004312 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004313 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004314
Siddharth Rayb8114062018-06-17 15:02:38 -07004315 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4316 // less than total activity duration.
4317 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4318 if (info == null) {
4319 return false;
4320 }
4321 int activityDurationMs =
4322 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4323 int totalTxTimeMs = 0;
4324 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4325 totalTxTimeMs += info.getTxTimeMillis()[i];
4326 }
4327 return (info.isValid()
4328 && (info.getSleepTimeMillis() <= activityDurationMs)
4329 && (info.getIdleTimeMillis() <= activityDurationMs)
4330 && (info.getRxTimeMillis() <= activityDurationMs)
4331 && (totalTxTimeMs <= activityDurationMs));
4332 }
4333
Jack Yu85bd38a2015-11-09 11:34:32 -08004334 /**
4335 * {@hide}
4336 * Returns the service state information on specified subscription.
4337 */
4338 @Override
4339 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004341 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004342 return null;
4343 }
4344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 final Phone phone = getPhone(subId);
4348 if (phone == null) {
4349 return null;
4350 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352 return phone.getServiceState();
4353 } finally {
4354 Binder.restoreCallingIdentity(identity);
4355 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004356 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004357
4358 /**
4359 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4360 *
4361 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4362 * voicemail ringtone.
4363 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4364 * PhoneAccount.
4365 */
4366 @Override
4367 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 final long identity = Binder.clearCallingIdentity();
4369 try {
4370 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4371 if (phone == null) {
4372 phone = mPhone;
4373 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004379 }
4380
4381 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004382 * Sets the per-account voicemail ringtone.
4383 *
4384 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4385 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4386 *
4387 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4388 * voicemail ringtone.
4389 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4390 * PhoneAccount.
4391 */
4392 @Override
4393 public void setVoicemailRingtoneUri(String callingPackage,
4394 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4395 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4396 if (!TextUtils.equals(callingPackage,
4397 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4399 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4400 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402
4403 final long identity = Binder.clearCallingIdentity();
4404 try {
4405 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4406 if (phone == null) {
4407 phone = mPhone;
4408 }
4409 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004412 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004413 }
4414
4415 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004416 * Returns whether vibration is set for voicemail notification in Phone settings.
4417 *
4418 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4419 * voicemail vibration setting.
4420 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4421 */
4422 @Override
4423 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4427 if (phone == null) {
4428 phone = mPhone;
4429 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004430
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004435 }
4436
Youhan Wange64578a2016-05-02 15:32:42 -07004437 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004438 * Sets the per-account voicemail vibration.
4439 *
4440 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4441 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4442 *
4443 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4444 * voicemail vibration setting.
4445 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4446 * specific PhoneAccount.
4447 */
4448 @Override
4449 public void setVoicemailVibrationEnabled(String callingPackage,
4450 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4452 if (!TextUtils.equals(callingPackage,
4453 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4455 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4456 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004457 }
4458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004459 final long identity = Binder.clearCallingIdentity();
4460 try {
4461 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4462 if (phone == null) {
4463 phone = mPhone;
4464 }
4465 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4466 } finally {
4467 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004468 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004469 }
4470
4471 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004472 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4473 *
4474 * @throws SecurityException if the caller does not have the required permission
4475 */
4476 private void enforceReadPrivilegedPermission() {
4477 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4478 null);
4479 }
4480
4481 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004482 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4483 * permission.
4484 *
4485 * @throws SecurityException if the caller does not have the required permission
4486 */
4487 private void enforceSendSmsPermission() {
4488 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4489 }
4490
4491 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004492 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004493 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004494 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004495 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004496 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497 final long identity = Binder.clearCallingIdentity();
4498 try {
4499 ComponentName componentName =
4500 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4501 if (componentName == null) {
4502 throw new SecurityException(
4503 "Caller not current active visual voicemail package[null]");
4504 }
4505 String vvmPackage = componentName.getPackageName();
4506 if (!callingPackage.equals(vvmPackage)) {
4507 throw new SecurityException("Caller not current active visual voicemail package["
4508 + vvmPackage + "]");
4509 }
4510 } finally {
4511 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004512 }
4513 }
4514
4515 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004516 * Return the application ID for the app type.
4517 *
4518 * @param subId the subscription ID that this request applies to.
4519 * @param appType the uicc app type.
4520 * @return Application ID for specificied app type, or null if no uicc.
4521 */
4522 @Override
4523 public String getAidForAppType(int subId, int appType) {
4524 enforceReadPrivilegedPermission();
4525 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526
4527 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004528 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 if (phone == null) {
4530 return null;
4531 }
4532 String aid = null;
4533 try {
4534 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4535 .getApplicationByType(appType).getAid();
4536 } catch (Exception e) {
4537 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4538 }
4539 return aid;
4540 } finally {
4541 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004542 }
Youhan Wange64578a2016-05-02 15:32:42 -07004543 }
4544
Youhan Wang4001d252016-05-11 10:29:41 -07004545 /**
4546 * Return the Electronic Serial Number.
4547 *
4548 * @param subId the subscription ID that this request applies to.
4549 * @return ESN or null if error.
4550 */
4551 @Override
4552 public String getEsn(int subId) {
4553 enforceReadPrivilegedPermission();
4554 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555
4556 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004557 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004558 if (phone == null) {
4559 return null;
4560 }
4561 String esn = null;
4562 try {
4563 esn = phone.getEsn();
4564 } catch (Exception e) {
4565 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4566 }
4567 return esn;
4568 } finally {
4569 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004570 }
Youhan Wang4001d252016-05-11 10:29:41 -07004571 }
4572
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004573 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004574 * Return the Preferred Roaming List Version.
4575 *
4576 * @param subId the subscription ID that this request applies to.
4577 * @return PRLVersion or null if error.
4578 */
4579 @Override
4580 public String getCdmaPrlVersion(int subId) {
4581 enforceReadPrivilegedPermission();
4582 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004583
4584 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004585 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586 if (phone == null) {
4587 return null;
4588 }
4589 String cdmaPrlVersion = null;
4590 try {
4591 cdmaPrlVersion = phone.getCdmaPrlVersion();
4592 } catch (Exception e) {
4593 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4594 }
4595 return cdmaPrlVersion;
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004598 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004599 }
4600
4601 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004602 * Get snapshot of Telephony histograms
4603 * @return List of Telephony histograms
4604 * @hide
4605 */
4606 @Override
4607 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4609 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610
4611 final long identity = Binder.clearCallingIdentity();
4612 try {
4613 return RIL.getTelephonyRILTimingHistograms();
4614 } finally {
4615 Binder.restoreCallingIdentity(identity);
4616 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004617 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004618
4619 /**
4620 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004621 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004622 * Require system privileges. In the future we may add this to carrier APIs.
4623 *
4624 * @return The number of carriers set successfully, should match length of carriers
4625 */
4626 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004627 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004628 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004629 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004630
Meng Wang9b7c4e92017-02-17 11:41:27 -08004631 if (carriers == null) {
4632 throw new NullPointerException("carriers cannot be null");
4633 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 final long identity = Binder.clearCallingIdentity();
4636 try {
4637 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004638 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4639 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 return retVal[0];
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
4643 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004644 }
4645
4646 /**
4647 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004648 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004649 * Require system privileges. In the future we may add this to carrier APIs.
4650 *
4651 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4652 * means all carriers are allowed.
4653 */
4654 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004655 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004656 enforceReadPrivilegedPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004657 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004658
4659 final long identity = Binder.clearCallingIdentity();
4660 try {
4661 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004662 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4663 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 } finally {
4665 Binder.restoreCallingIdentity(identity);
4666 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004667 }
4668
fionaxu59545b42016-05-25 15:53:37 -07004669 /**
4670 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4671 * @param subId the subscription ID that this action applies to.
4672 * @param enabled control enable or disable metered apns.
4673 * {@hide}
4674 */
4675 @Override
4676 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4677 enforceModifyPermission();
4678 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679
4680 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004681 if (phone == null) {
4682 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4683 return;
4684 }
4685 try {
4686 phone.carrierActionSetMeteredApnsEnabled(enabled);
4687 } catch (Exception e) {
4688 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 } finally {
4690 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004691 }
4692 }
4693
4694 /**
4695 * Action set from carrier signalling broadcast receivers to enable/disable radio
4696 * @param subId the subscription ID that this action applies to.
4697 * @param enabled control enable or disable radio.
4698 * {@hide}
4699 */
4700 @Override
4701 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4702 enforceModifyPermission();
4703 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704
4705 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004706 if (phone == null) {
4707 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4708 return;
4709 }
4710 try {
4711 phone.carrierActionSetRadioEnabled(enabled);
4712 } catch (Exception e) {
4713 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004714 } finally {
4715 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004716 }
4717 }
4718
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004719 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004720 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4721 * network status based on which carrier apps could apply actions accordingly,
4722 * enable/disable default url handler for example.
4723 *
4724 * @param subId the subscription ID that this action applies to.
4725 * @param report control start/stop reporting the default network status.
4726 * {@hide}
4727 */
4728 @Override
4729 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4730 enforceModifyPermission();
4731 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732
4733 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004734 if (phone == null) {
4735 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4736 return;
4737 }
4738 try {
4739 phone.carrierActionReportDefaultNetworkStatus(report);
4740 } catch (Exception e) {
4741 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 } finally {
4743 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004744 }
4745 }
4746
4747 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004748 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4749 * bug report is being generated.
4750 */
4751 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004752 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004753 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4754 != PackageManager.PERMISSION_GRANTED) {
4755 writer.println("Permission Denial: can't dump Phone from pid="
4756 + Binder.getCallingPid()
4757 + ", uid=" + Binder.getCallingUid()
4758 + "without permission "
4759 + android.Manifest.permission.DUMP);
4760 return;
4761 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004762 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004763 }
Jack Yueb89b242016-06-22 13:27:47 -07004764
Brad Ebingerdac2f002018-04-03 15:17:52 -07004765 @Override
4766 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4767 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4768 throws RemoteException {
4769 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4770 }
4771
Jack Yueb89b242016-06-22 13:27:47 -07004772 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004773 * Get aggregated video call data usage since boot.
4774 *
4775 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4776 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004777 * {@hide}
4778 */
4779 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004780 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004781 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4782 null);
4783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 final long identity = Binder.clearCallingIdentity();
4785 try {
4786 // NetworkStatsService keeps tracking the active network interface and identity. It
4787 // records the delta with the corresponding network identity.
4788 // We just return the total video call data usage snapshot since boot.
4789 Phone phone = getPhone(subId);
4790 if (phone != null) {
4791 return phone.getVtDataUsage(perUidStats);
4792 }
4793 return null;
4794 } finally {
4795 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004796 }
Jack Yueb89b242016-06-22 13:27:47 -07004797 }
Jack Yu75ab2952016-07-08 14:29:33 -07004798
4799 /**
4800 * Policy control of data connection. Usually used when data limit is passed.
4801 * @param enabled True if enabling the data, otherwise disabling.
4802 * @param subId Subscription index
4803 * {@hide}
4804 */
4805 @Override
4806 public void setPolicyDataEnabled(boolean enabled, int subId) {
4807 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004808
4809 final long identity = Binder.clearCallingIdentity();
4810 try {
4811 Phone phone = getPhone(subId);
4812 if (phone != null) {
4813 phone.setPolicyDataEnabled(enabled);
4814 }
4815 } finally {
4816 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004817 }
4818 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004819
4820 /**
4821 * Get Client request stats
4822 * @return List of Client Request Stats
4823 * @hide
4824 */
4825 @Override
4826 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004828 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004829 return null;
4830 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004831 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 final long identity = Binder.clearCallingIdentity();
4834 try {
4835 if (phone != null) {
4836 return phone.getClientRequestStats();
4837 }
4838
4839 return null;
4840 } finally {
4841 Binder.restoreCallingIdentity(identity);
4842 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004843 }
4844
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004845 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004846 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004847 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004848 }
Jack Yueb4124c2017-02-16 15:32:43 -08004849
4850 /**
Grace Chen70990072017-03-24 17:21:30 -07004851 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004852 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004853 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004854 * @param state State of SIM (power down, power up, pass through)
4855 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4856 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4857 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004858 *
4859 **/
4860 @Override
Grace Chen70990072017-03-24 17:21:30 -07004861 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004862 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004863 Phone phone = PhoneFactory.getPhone(slotIndex);
4864
vagdeviaf9a5b92018-08-15 16:01:53 -07004865 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867 final long identity = Binder.clearCallingIdentity();
4868 try {
4869 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004870 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 }
4872 } finally {
4873 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004874 }
4875 }
Shuo Qiandd210312017-04-12 22:11:33 +00004876
Tyler Gunn65d45c22017-06-05 11:22:26 -07004877 private boolean isUssdApiAllowed(int subId) {
4878 CarrierConfigManager configManager =
4879 (CarrierConfigManager) mPhone.getContext().getSystemService(
4880 Context.CARRIER_CONFIG_SERVICE);
4881 if (configManager == null) {
4882 return false;
4883 }
4884 PersistableBundle pb = configManager.getConfigForSubId(subId);
4885 if (pb == null) {
4886 return false;
4887 }
4888 return pb.getBoolean(
4889 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4890 }
4891
Shuo Qiandd210312017-04-12 22:11:33 +00004892 /**
4893 * Check if phone is in emergency callback mode
4894 * @return true if phone is in emergency callback mode
4895 * @param subId sub id
4896 */
goneil9c5f4872017-12-05 14:07:56 -08004897 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004898 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004899 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004900 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004901
4902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 if (phone != null) {
4905 return phone.isInEcm();
4906 } else {
4907 return false;
4908 }
4909 } finally {
4910 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004911 }
4912 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004913
4914 /**
4915 * Get the current signal strength information for the given subscription.
4916 * Because this information is not updated when the device is in a low power state
4917 * it should not be relied-upon to be current.
4918 * @param subId Subscription index
4919 * @return the most recent cached signal strength info from the modem
4920 */
4921 @Override
4922 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 final long identity = Binder.clearCallingIdentity();
4924 try {
4925 Phone p = getPhone(subId);
4926 if (p == null) {
4927 return null;
4928 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930 return p.getSignalStrength();
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004934 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004935
Pengquan Meng77b7f132018-08-22 14:49:57 -07004936 /**
4937 * Checks if data roaming is enabled on the subscription with id {@code subId}.
4938 *
4939 * <p>Requires one of the following permissions:
4940 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
4941 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
4942 * privileges.
4943 *
4944 * @param subId subscription id
4945 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
4946 * {@code false}.
4947 */
4948 @Override
4949 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07004950 boolean isEnabled = false;
4951 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07004952 try {
4953 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07004954 null /* message */);
4955 Phone phone = getPhone(subId);
4956 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07004957 } catch (Exception e) {
4958 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
4959 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07004960 } finally {
4961 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07004962 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004963 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07004964 }
4965
4966
4967 /**
4968 * Enables/Disables the data roaming on the subscription with id {@code subId}.
4969 *
4970 * <p> Requires permission:
4971 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
4972 * privileges.
4973 *
4974 * @param subId subscription id
4975 * @param isEnabled {@code true} means enable, {@code false} means disable.
4976 */
4977 @Override
4978 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07004979 final long identity = Binder.clearCallingIdentity();
4980 try {
4981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4982 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07004983
Pengquan Menga1bb6272018-09-06 09:59:22 -07004984 Phone phone = getPhone(subId);
4985 if (phone != null) {
4986 phone.setDataRoamingEnabled(isEnabled);
4987 }
4988 } finally {
4989 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07004990 }
4991 }
4992
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004993 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07004994 public boolean isManualNetworkSelectionAllowed(int subId) {
4995 boolean isAllowed = true;
4996 final long identity = Binder.clearCallingIdentity();
4997 try {
4998 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
4999 mApp, subId, "isManualNetworkSelectionAllowed");
5000 Phone phone = getPhone(subId);
5001 if (phone != null) {
5002 isAllowed = phone.isCspPlmnEnabled();
5003 }
5004 } finally {
5005 Binder.restoreCallingIdentity(identity);
5006 }
5007 return isAllowed;
5008 }
5009
5010 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005011 public UiccSlotInfo[] getUiccSlotsInfo() {
5012 enforceReadPrivilegedPermission();
5013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5017 if (slots == null) {
5018 Rlog.i(LOG_TAG, "slots is null.");
5019 return null;
5020 }
5021
5022 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5023 for (int i = 0; i < slots.length; i++) {
5024 UiccSlot slot = slots[i];
5025 if (slot == null) {
5026 continue;
5027 }
5028
5029 String cardId;
5030 UiccCard card = slot.getUiccCard();
5031 if (card != null) {
5032 cardId = card.getCardId();
5033 } else {
5034 cardId = slot.getIccId();
5035 }
5036
5037 int cardState = 0;
5038 switch (slot.getCardState()) {
5039 case CARDSTATE_ABSENT:
5040 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5041 break;
5042 case CARDSTATE_PRESENT:
5043 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5044 break;
5045 case CARDSTATE_ERROR:
5046 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5047 break;
5048 case CARDSTATE_RESTRICTED:
5049 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5050 break;
5051 default:
5052 break;
5053
5054 }
5055
5056 infos[i] = new UiccSlotInfo(
5057 slot.isActive(),
5058 slot.isEuicc(),
5059 cardId,
5060 cardState,
5061 slot.getPhoneId(),
5062 slot.isExtendedApduSupported());
5063 }
5064 return infos;
5065 } finally {
5066 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005067 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005068 }
5069
5070 @Override
5071 public boolean switchSlots(int[] physicalSlots) {
5072 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073
5074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
5079 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005080 }
Jack Yu4c988042018-02-27 15:30:01 -08005081
5082 @Override
5083 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5084 enforceModifyPermission();
5085 final Phone phone = getPhone(subId);
5086 if (phone == null) {
5087 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5088 return;
5089 }
5090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 phone.setRadioIndicationUpdateMode(filters, mode);
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
Jack Yu4c988042018-02-27 15:30:01 -08005097 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005098
5099 /**
goneil47ffb6e2018-04-06 15:40:58 -07005100 * A test API to reload the UICC profile.
5101 *
5102 * <p>Requires that the calling app has permission
5103 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5104 * @hide
5105 */
5106 @Override
5107 public void refreshUiccProfile(int subId) {
5108 enforceModifyPermission();
5109
5110 final long identity = Binder.clearCallingIdentity();
5111 try {
5112 Phone phone = getPhone(subId);
5113 if (phone == null) {
5114 return;
5115 }
5116 UiccCard uiccCard = phone.getUiccCard();
5117 if (uiccCard == null) {
5118 return;
5119 }
5120 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5121 if (uiccProfile == null) {
5122 return;
5123 }
5124 uiccProfile.refresh();
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
5128 }
5129
5130 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005131 * Returns false if the mobile data is disabled by default, otherwise return true.
5132 */
5133 private boolean getDefaultDataEnabled() {
5134 return "true".equalsIgnoreCase(
5135 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5136 }
5137
5138 /**
5139 * Returns true if the data roaming is enabled by default, i.e the system property
5140 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5141 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5142 */
5143 private boolean getDefaultDataRoamingEnabled(int subId) {
5144 final CarrierConfigManager configMgr = (CarrierConfigManager)
5145 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5146 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5147 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5148 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5149 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5150 return isDataRoamingEnabled;
5151 }
5152
5153 /**
5154 * Returns the default network type for the given {@code subId}, if the default network type is
5155 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5156 */
5157 private int getDefaultNetworkType(int subId) {
5158 return Integer.parseInt(
5159 TelephonyManager.getTelephonyProperty(
5160 mSubscriptionController.getPhoneId(subId),
5161 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5162 String.valueOf(Phone.PREFERRED_NT_MODE)));
5163 }
fionaxua13278b2018-03-21 00:08:13 -07005164
5165 @Override
5166 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5167 gid1, String gid2, String plmn, String spn) {
5168 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169
5170 final long identity = Binder.clearCallingIdentity();
5171 try {
5172 final Phone phone = getPhone(subId);
5173 if (phone == null) {
5174 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5175 return;
5176 }
5177 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5178 } finally {
5179 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005180 }
fionaxua13278b2018-03-21 00:08:13 -07005181 }
5182
5183 @Override
5184 public int getCarrierIdListVersion(int subId) {
5185 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186
5187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 final Phone phone = getPhone(subId);
5190 if (phone == null) {
5191 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5192 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5193 }
5194 return phone.getCarrierIdListVersion();
5195 } finally {
5196 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005197 }
fionaxua13278b2018-03-21 00:08:13 -07005198 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005199
5200 @Override
5201 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5203 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5204 return -1;
5205 }
5206
5207 final long identity = Binder.clearCallingIdentity();
5208 try {
5209 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
5213 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005214
5215 @Override
5216 public int getCdmaRoamingMode(int subId) {
5217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5218 mApp, subId, "getCdmaRoamingMode");
5219
5220 final long identity = Binder.clearCallingIdentity();
5221 try {
5222 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
5226 }
5227
5228 @Override
5229 public boolean setCdmaRoamingMode(int subId, int mode) {
5230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5231 mApp, subId, "setCdmaRoamingMode");
5232
5233 final long identity = Binder.clearCallingIdentity();
5234 try {
5235 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
5239 }
5240
5241 @Override
5242 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5244 mApp, subId, "setCdmaSubscriptionMode");
5245
5246 final long identity = Binder.clearCallingIdentity();
5247 try {
5248 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
5252 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005253
5254 private void ensureUserRunning(int userId) {
5255 if (!mUserManager.isUserRunning(userId)) {
5256 throw new IllegalStateException("User " + userId + " does not exist or not running");
5257 }
5258 }
5259
5260 /**
5261 * Returns a list of SMS apps on a given user.
5262 *
5263 * Only the shell user (UID 2000 or 0) can call it.
5264 * Target user must be running.
5265 */
5266 @Override
5267 public String[] getSmsApps(int userId) {
5268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5269 ensureUserRunning(userId);
5270
5271 final Collection<SmsApplicationData> apps =
5272 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5273
5274 String[] ret = new String[apps.size()];
5275 int i = 0;
5276 for (SmsApplicationData app : apps) {
5277 ret[i++] = app.mPackageName;
5278 }
5279 return ret;
5280 }
5281
5282 /**
5283 * Returns the default SMS app package name on a given user.
5284 *
5285 * Only the shell user (UID 2000 or 0) can call it.
5286 * Target user must be running.
5287 */
5288 @Override
5289 public String getDefaultSmsApp(int userId) {
5290 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5291 ensureUserRunning(userId);
5292
5293 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5294 /* updateIfNeeded= */ true, userId);
5295 return cn == null ? null : cn.getPackageName();
5296 }
5297
5298 /**
5299 * Set a package as the default SMS app on a given user.
5300 *
5301 * Only the shell user (UID 2000 or 0) can call it.
5302 * Target user must be running.
5303 */
5304 @Override
5305 public void setDefaultSmsApp(int userId, String packageName) {
5306 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5307 ensureUserRunning(userId);
5308
5309 boolean found = false;
5310 for (String pkg : getSmsApps(userId)) {
5311 if (TextUtils.equals(packageName, pkg)) {
5312 found = true;
5313 break;
5314 }
5315 }
5316 if (!found) {
5317 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5318 }
5319
5320 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005322}