blob: d3e1f7338ea042d7b1cef6b4bdafecbe1dbda0ca [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;
996 request.result = (ar.exception == null) ? ar.result : new ArrayList<CellInfo>();
997 synchronized (request) {
998 request.notifyAll();
999 }
1000 break;
1001
1002 case CMD_GET_CELL_LOCATION: {
1003 request = (MainThreadRequest) msg.obj;
1004 WorkSource ws = (WorkSource) request.argument;
1005 Phone phone = getPhoneFromRequest(request);
1006 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1007 break;
1008 }
1009
1010 case EVENT_GET_CELL_LOCATION_DONE: {
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 if (ar.exception == null) {
1014 request.result = ar.result;
1015 } else {
1016 Phone phone = getPhoneFromRequest(request);
1017 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1018 ? new CdmaCellLocation() : new GsmCellLocation();
1019 }
1020
1021 synchronized (request) {
1022 request.notifyAll();
1023 }
1024 break;
1025 }
1026
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001027 default:
1028 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1029 break;
1030 }
1031 }
Jake Hambye994d462014-02-03 13:10:13 -08001032
Pengquan Menga1bb6272018-09-06 09:59:22 -07001033 private void notifyRequester(MainThreadRequest request) {
1034 synchronized (request) {
1035 request.notifyAll();
1036 }
1037 }
1038
Jake Hambye994d462014-02-03 13:10:13 -08001039 private void handleNullReturnEvent(Message msg, String command) {
1040 AsyncResult ar = (AsyncResult) msg.obj;
1041 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1042 if (ar.exception == null) {
1043 request.result = true;
1044 } else {
1045 request.result = false;
1046 if (ar.exception instanceof CommandException) {
1047 loge(command + ": CommandException: " + ar.exception);
1048 } else {
1049 loge(command + ": Unknown exception");
1050 }
1051 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001052 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001054 }
1055
1056 /**
1057 * Posts the specified command to be executed on the main thread,
1058 * waits for the request to complete, and returns the result.
1059 * @see #sendRequestAsync
1060 */
1061 private Object sendRequest(int command, Object argument) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001062 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1063 }
1064
1065 /**
1066 * Posts the specified command to be executed on the main thread,
1067 * waits for the request to complete, and returns the result.
1068 * @see #sendRequestAsync
1069 */
1070 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1071 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1072 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001073 }
1074
1075 /**
1076 * Posts the specified command to be executed on the main thread,
1077 * waits for the request to complete, and returns the result.
1078 * @see #sendRequestAsync
1079 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001080 private Object sendRequest(int command, Object argument, Integer subId) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001081 return sendRequest(command, argument, subId, null);
1082 }
1083
1084 /**
1085 * Posts the specified command to be executed on the main thread,
1086 * waits for the request to complete, and returns the result.
1087 * @see #sendRequestAsync
1088 */
1089 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1091 throw new RuntimeException("This method will deadlock if called from the main thread.");
1092 }
1093
vagdeviaf9a5b92018-08-15 16:01:53 -07001094 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001095 Message msg = mMainThreadHandler.obtainMessage(command, request);
1096 msg.sendToTarget();
1097
1098 // Wait for the request to complete
1099 synchronized (request) {
1100 while (request.result == null) {
1101 try {
1102 request.wait();
1103 } catch (InterruptedException e) {
1104 // Do nothing, go back and wait until the request is complete
1105 }
1106 }
1107 }
1108 return request.result;
1109 }
1110
1111 /**
1112 * Asynchronous ("fire and forget") version of sendRequest():
1113 * Posts the specified command to be executed on the main thread, and
1114 * returns immediately.
1115 * @see #sendRequest
1116 */
1117 private void sendRequestAsync(int command) {
1118 mMainThreadHandler.sendEmptyMessage(command);
1119 }
1120
1121 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001122 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1123 * @see {@link #sendRequest(int,Object)}
1124 */
1125 private void sendRequestAsync(int command, Object argument) {
1126 MainThreadRequest request = new MainThreadRequest(argument);
1127 Message msg = mMainThreadHandler.obtainMessage(command, request);
1128 msg.sendToTarget();
1129 }
1130
1131 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001132 * Initialize the singleton PhoneInterfaceManager instance.
1133 * This is only done once, at startup, from PhoneApp.onCreate().
1134 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001135 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 synchronized (PhoneInterfaceManager.class) {
1137 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001138 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 } else {
1140 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1141 }
1142 return sInstance;
1143 }
1144 }
1145
1146 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001147 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 mApp = app;
1149 mPhone = phone;
1150 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001151 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001152 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1153 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001154 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001155 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001156 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001157 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001158 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001159
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 publish();
1161 }
1162
1163 private void publish() {
1164 if (DBG) log("publish: " + this);
1165
1166 ServiceManager.addService("phone", this);
1167 }
1168
Stuart Scott584921c2015-01-15 17:10:34 -08001169 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001170 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1171 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001172 }
1173
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001174 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1175 Phone phone = getPhoneFromRequest(request);
1176 return phone == null ? null :
1177 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1178 }
1179
Wink Saville36469e72014-06-11 15:17:00 -07001180 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001181 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001182 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184
1185 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001186 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001187 }
1188
Wink Savilleb564aae2014-10-23 10:18:09 -07001189 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 if (DBG) log("dial: " + number);
1191 // No permission check needed here: This is just a wrapper around the
1192 // ACTION_DIAL intent, which is available to any app since it puts up
1193 // the UI before it does anything.
1194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001195 final long identity = Binder.clearCallingIdentity();
1196 try {
1197 String url = createTelUrl(number);
1198 if (url == null) {
1199 return;
1200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001202 // PENDING: should we just silently fail if phone is offhook or ringing?
1203 PhoneConstants.State state = mCM.getState(subId);
1204 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1205 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1206 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1207 mApp.startActivity(intent);
1208 }
1209 } finally {
1210 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001211 }
1212 }
1213
1214 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001215 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001216 }
1217
Wink Savilleb564aae2014-10-23 10:18:09 -07001218 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 if (DBG) log("call: " + number);
1220
1221 // This is just a wrapper around the ACTION_CALL intent, but we still
1222 // need to do a permission check since we're calling startActivity()
1223 // from the context of the phone app.
1224 enforceCallPermission();
1225
1226 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1227 != AppOpsManager.MODE_ALLOWED) {
1228 return;
1229 }
1230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001231 final long identity = Binder.clearCallingIdentity();
1232 try {
1233 String url = createTelUrl(number);
1234 if (url == null) {
1235 return;
1236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001238 boolean isValid = false;
1239 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1240 if (slist != null) {
1241 for (SubscriptionInfo subInfoRecord : slist) {
1242 if (subInfoRecord.getSubscriptionId() == subId) {
1243 isValid = true;
1244 break;
1245 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001246 }
Wink Saville08874612014-08-31 19:19:58 -07001247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001248 if (!isValid) {
1249 return;
1250 }
Wink Saville08874612014-08-31 19:19:58 -07001251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001252 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1253 intent.putExtra(SUBSCRIPTION_KEY, subId);
1254 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1255 mApp.startActivity(intent);
1256 } finally {
1257 Binder.restoreCallingIdentity(identity);
1258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 }
1260
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001262 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001263 }
1264
Wink Savilleb564aae2014-10-23 10:18:09 -07001265 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001266 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001267 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1268 }
1269
1270 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001271 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001272 }
1273
Wink Savilleb564aae2014-10-23 10:18:09 -07001274 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001275 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001276 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1277 }
1278
1279 /** {@hide} */
1280 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001281 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
Wink Savilleb564aae2014-10-23 10:18:09 -07001284 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001286
1287 final long identity = Binder.clearCallingIdentity();
1288 try {
1289 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1290 checkSimPin.start();
1291 return checkSimPin.unlockSim(null, pin);
1292 } finally {
1293 Binder.restoreCallingIdentity(identity);
1294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001295 }
1296
Wink Saville9de0f752013-10-22 19:04:03 -07001297 /** {@hide} */
1298 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001299 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001300 }
1301
Wink Savilleb564aae2014-10-23 10:18:09 -07001302 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001304
1305 final long identity = Binder.clearCallingIdentity();
1306 try {
1307 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1308 checkSimPuk.start();
1309 return checkSimPuk.unlockSim(puk, pin);
1310 } finally {
1311 Binder.restoreCallingIdentity(identity);
1312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 }
1314
1315 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001316 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 * a synchronous one.
1318 */
1319 private static class UnlockSim extends Thread {
1320
1321 private final IccCard mSimCard;
1322
1323 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001324 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1325 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326
1327 // For replies from SimCard interface
1328 private Handler mHandler;
1329
1330 // For async handler to identify request type
1331 private static final int SUPPLY_PIN_COMPLETE = 100;
1332
1333 public UnlockSim(IccCard simCard) {
1334 mSimCard = simCard;
1335 }
1336
1337 @Override
1338 public void run() {
1339 Looper.prepare();
1340 synchronized (UnlockSim.this) {
1341 mHandler = new Handler() {
1342 @Override
1343 public void handleMessage(Message msg) {
1344 AsyncResult ar = (AsyncResult) msg.obj;
1345 switch (msg.what) {
1346 case SUPPLY_PIN_COMPLETE:
1347 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1348 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001349 mRetryCount = msg.arg1;
1350 if (ar.exception != null) {
1351 if (ar.exception instanceof CommandException &&
1352 ((CommandException)(ar.exception)).getCommandError()
1353 == CommandException.Error.PASSWORD_INCORRECT) {
1354 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1355 } else {
1356 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1357 }
1358 } else {
1359 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 mDone = true;
1362 UnlockSim.this.notifyAll();
1363 }
1364 break;
1365 }
1366 }
1367 };
1368 UnlockSim.this.notifyAll();
1369 }
1370 Looper.loop();
1371 }
1372
1373 /*
1374 * Use PIN or PUK to unlock SIM card
1375 *
1376 * If PUK is null, unlock SIM card with PIN
1377 *
1378 * If PUK is not null, unlock SIM card with PUK and set PIN code
1379 */
Wink Saville9de0f752013-10-22 19:04:03 -07001380 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381
1382 while (mHandler == null) {
1383 try {
1384 wait();
1385 } catch (InterruptedException e) {
1386 Thread.currentThread().interrupt();
1387 }
1388 }
1389 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1390
1391 if (puk == null) {
1392 mSimCard.supplyPin(pin, callback);
1393 } else {
1394 mSimCard.supplyPuk(puk, pin, callback);
1395 }
1396
1397 while (!mDone) {
1398 try {
1399 Log.d(LOG_TAG, "wait for done");
1400 wait();
1401 } catch (InterruptedException e) {
1402 // Restore the interrupted status
1403 Thread.currentThread().interrupt();
1404 }
1405 }
1406 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001407 int[] resultArray = new int[2];
1408 resultArray[0] = mResult;
1409 resultArray[1] = mRetryCount;
1410 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 }
1412 }
1413
1414 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001415 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001416
1417 }
1418
Wink Savilleb564aae2014-10-23 10:18:09 -07001419 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 // No permission check needed here: this call is harmless, and it's
1421 // needed for the ServiceState.requestStateUpdate() call (which is
1422 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001423 final long identity = Binder.clearCallingIdentity();
1424 try {
1425 final Phone phone = getPhone(subId);
1426 if (phone != null) {
1427 phone.updateServiceLocation();
1428 }
1429 } finally {
1430 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432 }
1433
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001434 @Override
1435 public boolean isRadioOn(String callingPackage) {
1436 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001437 }
1438
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001439 @Override
1440 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001442 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001443 return false;
1444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001445
1446 final long identity = Binder.clearCallingIdentity();
1447 try {
1448 return isRadioOnForSubscriber(subId);
1449 } finally {
1450 Binder.restoreCallingIdentity(identity);
1451 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001452 }
1453
1454 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001455 final long identity = Binder.clearCallingIdentity();
1456 try {
1457 final Phone phone = getPhone(subId);
1458 if (phone != null) {
1459 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1460 } else {
1461 return false;
1462 }
1463 } finally {
1464 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 }
1467
1468 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001469 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470 }
Wink Saville36469e72014-06-11 15:17:00 -07001471
Wink Savilleb564aae2014-10-23 10:18:09 -07001472 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001474
1475 final long identity = Binder.clearCallingIdentity();
1476 try {
1477 final Phone phone = getPhone(subId);
1478 if (phone != null) {
1479 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1480 }
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001483 }
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
1486 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001492
1493 final long identity = Binder.clearCallingIdentity();
1494 try {
1495 final Phone phone = getPhone(subId);
1496 if (phone == null) {
1497 return false;
1498 }
1499 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1500 toggleRadioOnOffForSubscriber(subId);
1501 }
1502 return true;
1503 } finally {
1504 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 }
Wink Saville36469e72014-06-11 15:17:00 -07001507
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001508 public boolean needMobileRadioShutdown() {
1509 /*
1510 * If any of the Radios are available, it will need to be
1511 * shutdown. So return true if any Radio is available.
1512 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001513 final long identity = Binder.clearCallingIdentity();
1514 try {
1515 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1516 Phone phone = PhoneFactory.getPhone(i);
1517 if (phone != null && phone.isRadioAvailable()) return true;
1518 }
1519 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1520 return false;
1521 } finally {
1522 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001523 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001524 }
1525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001526 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001527 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001528 enforceModifyPermission();
1529
1530 final long identity = Binder.clearCallingIdentity();
1531 try {
1532 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1533 logv("Shutting down Phone " + i);
1534 shutdownRadioUsingPhoneId(i);
1535 }
1536 } finally {
1537 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001538 }
1539 }
1540
1541 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001542 Phone phone = PhoneFactory.getPhone(phoneId);
1543 if (phone != null && phone.isRadioAvailable()) {
1544 phone.shutdownRadio();
1545 }
1546 }
1547
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001550
1551 final long identity = Binder.clearCallingIdentity();
1552 try {
1553 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1554 if (defaultPhone != null) {
1555 defaultPhone.setRadioPower(turnOn);
1556 return true;
1557 } else {
1558 loge("There's no default phone.");
1559 return false;
1560 }
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001563 }
Wink Saville36469e72014-06-11 15:17:00 -07001564 }
1565
Wink Savilleb564aae2014-10-23 10:18:09 -07001566 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001568
1569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 final Phone phone = getPhone(subId);
1572 if (phone != null) {
1573 phone.setRadioPower(turnOn);
1574 return true;
1575 } else {
1576 return false;
1577 }
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 }
1582
Wink Saville36469e72014-06-11 15:17:00 -07001583 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001584 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 public boolean enableDataConnectivity() {
1586 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001587
1588 final long identity = Binder.clearCallingIdentity();
1589 try {
1590 int subId = mSubscriptionController.getDefaultDataSubId();
1591 final Phone phone = getPhone(subId);
1592 if (phone != null) {
1593 phone.setUserDataEnabled(true);
1594 return true;
1595 } else {
1596 return false;
1597 }
1598 } finally {
1599 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
Wink Saville36469e72014-06-11 15:17:00 -07001603 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 public boolean disableDataConnectivity() {
1606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001607
1608 final long identity = Binder.clearCallingIdentity();
1609 try {
1610 int subId = mSubscriptionController.getDefaultDataSubId();
1611 final Phone phone = getPhone(subId);
1612 if (phone != null) {
1613 phone.setUserDataEnabled(false);
1614 return true;
1615 } else {
1616 return false;
1617 }
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001624 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001625 final long identity = Binder.clearCallingIdentity();
1626 try {
1627 final Phone phone = getPhone(subId);
1628 if (phone != null) {
1629 return phone.isDataAllowed();
1630 } else {
1631 return false;
1632 }
1633 } finally {
1634 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 }
1637
1638 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001639 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001640 }
1641
pkanwarae03a6b2016-11-06 20:37:09 -08001642 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001643 enforceCallPermission();
1644
1645 final long identity = Binder.clearCallingIdentity();
1646 try {
1647 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1648 return;
1649 }
1650 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1651 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1652 } finally {
1653 Binder.restoreCallingIdentity(identity);
1654 }
pkanwar32d516d2016-10-14 19:37:38 -07001655 };
1656
Wink Savilleb564aae2014-10-23 10:18:09 -07001657 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001659
1660 final long identity = Binder.clearCallingIdentity();
1661 try {
1662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1663 return false;
1664 }
1665 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 }
1670
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001672 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
1674
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001675 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 Phone phone = PhoneFactory.getPhone(slotIndex);
1679 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1680 PhoneConstantConversions.convertCallState(phone.getState());
1681 } finally {
1682 Binder.restoreCallingIdentity(identity);
1683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 }
1685
Sanket Padawe356d7632015-06-22 14:03:32 -07001686 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001688 final long identity = Binder.clearCallingIdentity();
1689 try {
1690 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1691 if (phone != null) {
1692 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1693 } else {
1694 return PhoneConstantConversions.convertDataState(
1695 PhoneConstants.DataState.DISCONNECTED);
1696 }
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 }
1701
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001704 final long identity = Binder.clearCallingIdentity();
1705 try {
1706 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1707 if (phone != null) {
1708 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1709 } else {
1710 return TelephonyManager.DATA_ACTIVITY_NONE;
1711 }
1712 } finally {
1713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 }
1716
1717 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001718 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001719 mPhone.getContext().getSystemService(AppOpsManager.class)
1720 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001721 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001722 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001723 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001726 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727 final long identity = Binder.clearCallingIdentity();
1728 try {
1729 if (DBG_LOC) log("getCellLocation: is active user");
1730 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001731 int subId = mSubscriptionController.getDefaultDataSubId();
1732 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1733 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001734 return data;
1735 } finally {
1736 Binder.restoreCallingIdentity(identity);
1737 }
Svetoslav64fad262015-04-14 14:35:21 -07001738 }
1739
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001741 public String getNetworkCountryIsoForPhone(int phoneId) {
1742 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1743 // registered cell info, so return a NULL country instead.
1744 final long identity = Binder.clearCallingIdentity();
1745 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001746 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1747 // Get default phone in this case.
1748 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1749 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001750 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001751 // Todo: fix this when we can get the actual cellular network info when the device
1752 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001753 if (TelephonyManager.NETWORK_TYPE_IWLAN
1754 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1755 return "";
1756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757 Phone phone = PhoneFactory.getPhone(phoneId);
1758 if (phone != null) {
1759 ServiceStateTracker sst = phone.getServiceStateTracker();
1760 if (sst != null) {
1761 LocaleTracker lt = sst.getLocaleTracker();
1762 if (lt != null) {
1763 return lt.getCurrentCountry();
1764 }
1765 }
1766 }
1767 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001768 } finally {
1769 Binder.restoreCallingIdentity(identity);
1770 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001771 }
1772
1773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001775 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001776 }
1777
Sanket Padawe356d7632015-06-22 14:03:32 -07001778 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001779 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 mApp.enforceCallingOrSelfPermission(
1781 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782
1783 final long identity = Binder.clearCallingIdentity();
1784 try {
1785 final Phone phone = getPhone(subId);
1786 if (phone != null) {
1787 phone.enableLocationUpdates();
1788 }
1789 } finally {
1790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
1793
1794 @Override
1795 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001796 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001797 }
1798
Sanket Padawe356d7632015-06-22 14:03:32 -07001799 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001800 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 mApp.enforceCallingOrSelfPermission(
1802 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001803
1804 final long identity = Binder.clearCallingIdentity();
1805 try {
1806 final Phone phone = getPhone(subId);
1807 if (phone != null) {
1808 phone.disableLocationUpdates();
1809 }
1810 } finally {
1811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
1815 @Override
1816 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001817 public List<NeighboringCellInfo>
1818 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001819 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1820 throw new SecurityException(
1821 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1822 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001823
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1825 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1826 return null;
1827 }
Svetoslav64fad262015-04-14 14:35:21 -07001828
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001829 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830
Nathan Haroldf180aac2018-06-01 18:43:55 -07001831 List<CellInfo> info = getAllCellInfo(callingPackage);
1832 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833
Nathan Haroldf180aac2018-06-01 18:43:55 -07001834 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1835 for (CellInfo ci : info) {
1836 if (ci instanceof CellInfoGsm) {
1837 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1838 } else if (ci instanceof CellInfoWcdma) {
1839 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001842 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 }
1844
1845
1846 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001847 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001848 mPhone.getContext().getSystemService(AppOpsManager.class)
1849 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001850 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001851 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001852 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 }
1854
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001855 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001856 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001857 final long identity = Binder.clearCallingIdentity();
1858 try {
1859 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1860 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001861 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1862 CMD_GET_ALL_CELL_INFO,
1863 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001864 if (info != null) cellInfos.addAll(info);
1865 }
1866 return cellInfos;
1867 } finally {
1868 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 }
1870 }
1871
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001872 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001874 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001875 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001876
1877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 mPhone.setCellInfoListRate(rateInMillis, workSource);
1880 } finally {
1881 Binder.restoreCallingIdentity(identity);
1882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 }
1884
Shishir Agrawala9f32182016-04-12 12:00:16 -07001885 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001886 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001887 Phone phone = PhoneFactory.getPhone(slotIndex);
1888 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001889 return null;
1890 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001891 int subId = phone.getSubId();
1892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1893 mApp, subId, callingPackage, "getImeiForSlot")) {
1894 return null;
1895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896
1897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 return phone.getImei();
1900 } finally {
1901 Binder.restoreCallingIdentity(identity);
1902 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001903 }
1904
1905 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001906 public String getTypeAllocationCodeForSlot(int slotIndex) {
1907 Phone phone = PhoneFactory.getPhone(slotIndex);
1908 String tac = null;
1909 if (phone != null) {
1910 String imei = phone.getImei();
1911 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1912 }
1913 return tac;
1914 }
1915
1916 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001917 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001918 Phone phone = PhoneFactory.getPhone(slotIndex);
1919 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001920 return null;
1921 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001922 int subId = phone.getSubId();
1923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1924 mApp, subId, callingPackage, "getMeidForSlot")) {
1925 return null;
1926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927
1928 final long identity = Binder.clearCallingIdentity();
1929 try {
1930 return phone.getMeid();
1931 } finally {
1932 Binder.restoreCallingIdentity(identity);
1933 }
Jack Yu2af8d712017-03-15 17:14:14 -07001934 }
1935
1936 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001937 public String getManufacturerCodeForSlot(int slotIndex) {
1938 Phone phone = PhoneFactory.getPhone(slotIndex);
1939 String manufacturerCode = null;
1940 if (phone != null) {
1941 String meid = phone.getMeid();
1942 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1943 }
1944 return manufacturerCode;
1945 }
1946
1947 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001948 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001949 Phone phone = PhoneFactory.getPhone(slotIndex);
1950 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001951 return null;
1952 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001953 int subId = phone.getSubId();
1954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1955 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1956 return null;
1957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958
1959 final long identity = Binder.clearCallingIdentity();
1960 try {
1961 return phone.getDeviceSvn();
1962 } finally {
1963 Binder.restoreCallingIdentity(identity);
1964 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001965 }
1966
fionaxu43304da2017-11-27 22:51:16 -08001967 @Override
1968 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969 final long identity = Binder.clearCallingIdentity();
1970 try {
1971 final Phone phone = getPhone(subId);
1972 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1973 } finally {
1974 Binder.restoreCallingIdentity(identity);
1975 }
fionaxu43304da2017-11-27 22:51:16 -08001976 }
1977
1978 @Override
1979 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 final long identity = Binder.clearCallingIdentity();
1981 try {
1982 final Phone phone = getPhone(subId);
1983 return phone == null ? null : phone.getCarrierName();
1984 } finally {
1985 Binder.restoreCallingIdentity(identity);
1986 }
fionaxu43304da2017-11-27 22:51:16 -08001987 }
1988
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 //
1990 // Internal helper methods.
1991 //
1992
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001993 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1995 *
1996 * @throws SecurityException if the caller does not have the required permission
1997 */
1998 private void enforceModifyPermission() {
1999 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2000 }
2001
2002 /**
2003 * Make sure the caller has the CALL_PHONE permission.
2004 *
2005 * @throws SecurityException if the caller does not have the required permission
2006 */
2007 private void enforceCallPermission() {
2008 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2009 }
2010
Stuart Scott8eef64f2015-04-08 15:13:54 -07002011 private void enforceConnectivityInternalPermission() {
2012 mApp.enforceCallingOrSelfPermission(
2013 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2014 "ConnectivityService");
2015 }
2016
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 private String createTelUrl(String number) {
2018 if (TextUtils.isEmpty(number)) {
2019 return null;
2020 }
2021
Jake Hambye994d462014-02-03 13:10:13 -08002022 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002023 }
2024
Ihab Awadf9e92732013-12-05 18:02:52 -08002025 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2027 }
2028
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002029 private static void logv(String msg) {
2030 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2031 }
2032
Ihab Awadf9e92732013-12-05 18:02:52 -08002033 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2035 }
2036
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002037 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002039 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002040 }
2041
Sanket Padawe356d7632015-06-22 14:03:32 -07002042 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002043 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002044 final long identity = Binder.clearCallingIdentity();
2045 try {
2046 final Phone phone = PhoneFactory.getPhone(slotIndex);
2047 if (phone == null) {
2048 return PhoneConstants.PHONE_TYPE_NONE;
2049 } else {
2050 return phone.getPhoneType();
2051 }
2052 } finally {
2053 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 }
2056
2057 /**
2058 * Returns the CDMA ERI icon index to display
2059 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002060 @Override
2061 public int getCdmaEriIconIndex(String callingPackage) {
2062 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002063 }
2064
Sanket Padawe356d7632015-06-22 14:03:32 -07002065 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002066 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002068 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002069 return -1;
2070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071
2072 final long identity = Binder.clearCallingIdentity();
2073 try {
2074 final Phone phone = getPhone(subId);
2075 if (phone != null) {
2076 return phone.getCdmaEriIconIndex();
2077 } else {
2078 return -1;
2079 }
2080 } finally {
2081 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 }
2084
2085 /**
2086 * Returns the CDMA ERI icon mode,
2087 * 0 - ON
2088 * 1 - FLASHING
2089 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002090 @Override
2091 public int getCdmaEriIconMode(String callingPackage) {
2092 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002093 }
2094
Sanket Padawe356d7632015-06-22 14:03:32 -07002095 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002096 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002098 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002099 return -1;
2100 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002101
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 return phone.getCdmaEriIconMode();
2107 } else {
2108 return -1;
2109 }
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114
2115 /**
2116 * Returns the CDMA ERI text,
2117 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002118 @Override
2119 public String getCdmaEriText(String callingPackage) {
2120 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002121 }
2122
Sanket Padawe356d7632015-06-22 14:03:32 -07002123 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002124 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002126 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002127 return null;
2128 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002129
2130 final long identity = Binder.clearCallingIdentity();
2131 try {
2132 final Phone phone = getPhone(subId);
2133 if (phone != null) {
2134 return phone.getCdmaEriText();
2135 } else {
2136 return null;
2137 }
2138 } finally {
2139 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 }
2142
2143 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002144 * Returns the CDMA MDN.
2145 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002146 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002147 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2149 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002150
2151 final long identity = Binder.clearCallingIdentity();
2152 try {
2153 final Phone phone = getPhone(subId);
2154 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2155 return phone.getLine1Number();
2156 } else {
2157 return null;
2158 }
2159 } finally {
2160 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002161 }
2162 }
2163
2164 /**
2165 * Returns the CDMA MIN.
2166 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002167 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002168 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2170 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 final Phone phone = getPhone(subId);
2175 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2176 return phone.getCdmaMin();
2177 } else {
2178 return null;
2179 }
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002182 }
2183 }
2184
2185 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 * Returns true if CDMA provisioning needs to run.
2187 */
2188 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 final long identity = Binder.clearCallingIdentity();
2190 try {
2191 return mPhone.needsOtaServiceProvisioning();
2192 } finally {
2193 Binder.restoreCallingIdentity(identity);
2194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 }
2196
2197 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002198 * Sets the voice mail number of a given subId.
2199 */
2200 @Override
2201 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002202 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002203
2204 final long identity = Binder.clearCallingIdentity();
2205 try {
2206 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2207 new Pair<String, String>(alphaTag, number), new Integer(subId));
2208 return success;
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
2211 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002212 }
2213
Ta-wei Yen87c49842016-05-13 21:19:52 -07002214 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002215 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2216 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2217 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2218 if (!TextUtils.equals(callingPackage, systemDialer)) {
2219 throw new SecurityException("caller must be system dialer");
2220 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002221
2222 final long identity = Binder.clearCallingIdentity();
2223 try {
2224 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2225 if (phoneAccountHandle == null) {
2226 return null;
2227 }
2228 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2229 } finally {
2230 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002231 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002232 }
2233
2234 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002235 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002236 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002238 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002239 return null;
2240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 return RemoteVvmTaskManager
2245 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2246 } finally {
2247 Binder.restoreCallingIdentity(identity);
2248 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002249 }
2250
2251 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002252 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2253 VisualVoicemailSmsFilterSettings settings) {
2254 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255
2256 final long identity = Binder.clearCallingIdentity();
2257 try {
2258 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2259 mPhone.getContext(), callingPackage, subId, settings);
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
2262 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002263 }
2264
2265 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002266 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2267 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268
2269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2272 mPhone.getContext(), callingPackage, subId);
2273 } finally {
2274 Binder.restoreCallingIdentity(identity);
2275 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002276 }
2277
2278 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002279 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2280 String callingPackage, int subId) {
2281 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282
2283 final long identity = Binder.clearCallingIdentity();
2284 try {
2285 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2286 mPhone.getContext(), callingPackage, subId);
2287 } finally {
2288 Binder.restoreCallingIdentity(identity);
2289 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002290 }
2291
2292 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002293 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002294 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2299 mPhone.getContext(), subId);
2300 } finally {
2301 Binder.restoreCallingIdentity(identity);
2302 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002303 }
2304
2305 @Override
2306 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2307 String number, int port, String text, PendingIntent sentIntent) {
2308 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002309 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002310 enforceSendSmsPermission();
2311 // Make the calls as the phone process.
2312 final long identity = Binder.clearCallingIdentity();
2313 try {
2314 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2315 if (port == 0) {
2316 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2317 sentIntent, null, false);
2318 } else {
2319 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2320 smsManager.sendDataMessageWithSelfPermissions(number, null,
2321 (short) port, data, sentIntent, null);
2322 }
2323 } finally {
2324 Binder.restoreCallingIdentity(identity);
2325 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002326 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002327 /**
fionaxu0152e512016-11-14 13:36:14 -08002328 * Sets the voice activation state of a given subId.
2329 */
2330 @Override
2331 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2333 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002334
2335 final long identity = Binder.clearCallingIdentity();
2336 try {
2337 final Phone phone = getPhone(subId);
2338 if (phone != null) {
2339 phone.setVoiceActivationState(activationState);
2340 } else {
2341 loge("setVoiceActivationState fails with invalid subId: " + subId);
2342 }
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002345 }
2346 }
2347
2348 /**
2349 * Sets the data activation state of a given subId.
2350 */
2351 @Override
2352 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2354 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355
2356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 final Phone phone = getPhone(subId);
2359 if (phone != null) {
2360 phone.setDataActivationState(activationState);
2361 } else {
2362 loge("setVoiceActivationState fails with invalid subId: " + subId);
2363 }
2364 } finally {
2365 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002366 }
2367 }
2368
2369 /**
2370 * Returns the voice activation state of a given subId.
2371 */
2372 @Override
2373 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002374 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375
fionaxu0152e512016-11-14 13:36:14 -08002376 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 if (phone != null) {
2380 return phone.getVoiceActivationState();
2381 } else {
2382 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2383 }
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002386 }
2387 }
2388
2389 /**
2390 * Returns the data activation state of a given subId.
2391 */
2392 @Override
2393 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002394 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002395
fionaxu0152e512016-11-14 13:36:14 -08002396 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 if (phone != null) {
2400 return phone.getDataActivationState();
2401 } else {
2402 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2403 }
2404 } finally {
2405 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002406 }
2407 }
2408
2409 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 * Returns the unread count of voicemails
2411 */
2412 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002413 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002414 }
2415
2416 /**
2417 * Returns the unread count of voicemails for a subId
2418 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002419 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002420 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421 final long identity = Binder.clearCallingIdentity();
2422 try {
2423 final Phone phone = getPhone(subId);
2424 if (phone != null) {
2425 return phone.getVoiceMessageCount();
2426 } else {
2427 return 0;
2428 }
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 }
2433
2434 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002435 * returns true, if the device is in a state where both voice and data
2436 * are supported simultaneously. This can change based on location or network condition.
2437 */
2438 @Override
2439 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 final Phone phone = getPhone(subId);
2443 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
2446 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002447 }
2448
2449 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002450 * Send the dialer code if called from the current default dialer or the caller has
2451 * carrier privilege.
2452 * @param inputCode The dialer code to send
2453 */
2454 @Override
2455 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2457 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2458 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002459 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2460 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462
2463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 mPhone.sendDialerSpecialCode(inputCode);
2466 } finally {
2467 Binder.restoreCallingIdentity(identity);
2468 }
fionaxu235cc5e2017-03-06 22:25:57 -08002469 }
2470
2471 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002472 * Returns the data network type.
2473 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 *
2475 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2476 */
2477 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002478 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002479 final long identity = Binder.clearCallingIdentity();
2480 try {
2481 final Phone phone = getPhone(getDefaultSubscription());
2482 if (phone != null) {
2483 return phone.getServiceState().getDataNetworkType();
2484 } else {
2485 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2486 }
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002489 }
Wink Saville36469e72014-06-11 15:17:00 -07002490 }
2491
Pengquan Menga1bb6272018-09-06 09:59:22 -07002492 @Override
2493 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002494 if (!isActiveSubscription(subId)) {
2495 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2496 }
2497
Pengquan Menga1bb6272018-09-06 09:59:22 -07002498 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2499 }
2500
Wink Saville36469e72014-06-11 15:17:00 -07002501 /**
2502 * Returns the network type for a subId
2503 */
2504 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002505 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002507 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002508 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2509 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 final Phone phone = getPhone(subId);
2514 if (phone != null) {
2515 return phone.getServiceState().getDataNetworkType();
2516 } else {
2517 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2518 }
2519 } finally {
2520 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 }
2523
2524 /**
2525 * Returns the data network type
2526 */
2527 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002528 public int getDataNetworkType(String callingPackage) {
2529 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002530 }
2531
2532 /**
2533 * Returns the data network type for a subId
2534 */
2535 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002536 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002538 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002539 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2540 }
2541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 final Phone phone = getPhone(subId);
2545 if (phone != null) {
2546 return phone.getServiceState().getDataNetworkType();
2547 } else {
2548 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2549 }
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554
2555 /**
Wink Saville36469e72014-06-11 15:17:00 -07002556 * Returns the Voice network type for a subId
2557 */
2558 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002559 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002561 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002562 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2563 }
2564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 final Phone phone = getPhone(subId);
2568 if (phone != null) {
2569 return phone.getServiceState().getVoiceNetworkType();
2570 } else {
2571 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2572 }
2573 } finally {
2574 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 }
2577
2578 /**
2579 * @return true if a ICC card is present
2580 */
2581 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002582 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002583 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2584 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002585 }
2586
2587 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002588 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002589 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002590 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002591 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = PhoneFactory.getPhone(slotIndex);
2595 if (phone != null) {
2596 return phone.getIccCard().hasIccCard();
2597 } else {
2598 return false;
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 }
2604
2605 /**
2606 * Return if the current radio is LTE on CDMA. This
2607 * is a tri-state return value as for a period of time
2608 * the mode may be unknown.
2609 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002610 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002612 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002614 @Override
2615 public int getLteOnCdmaMode(String callingPackage) {
2616 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002617 }
2618
Sanket Padawe356d7632015-06-22 14:03:32 -07002619 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002620 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002622 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002623 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2624 }
2625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 final Phone phone = getPhone(subId);
2629 if (phone == null) {
2630 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2631 } else {
2632 return phone.getLteOnCdmaMode();
2633 }
2634 } finally {
2635 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002636 }
Wink Saville36469e72014-06-11 15:17:00 -07002637 }
2638
2639 public void setPhone(Phone phone) {
2640 mPhone = phone;
2641 }
2642
2643 /**
2644 * {@hide}
2645 * Returns Default subId, 0 in the case of single standby.
2646 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002647 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002648 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002649 }
2650
Shishir Agrawala9f32182016-04-12 12:00:16 -07002651 private int getSlotForDefaultSubscription() {
2652 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2653 }
2654
Wink Savilleb564aae2014-10-23 10:18:09 -07002655 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002656 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002658
Pengquan Menge92a50d2018-09-21 15:54:48 -07002659 private boolean isActiveSubscription(int subId) {
2660 return mSubscriptionController.isActiveSubId(subId);
2661 }
2662
Ihab Awadf2177b72013-11-25 13:33:23 -08002663 /**
2664 * @see android.telephony.TelephonyManager.WifiCallingChoices
2665 */
2666 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2670 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2671 getWhenToMakeWifiCallsDefaultPreference());
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
2674 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002675 }
2676
2677 /**
2678 * @see android.telephony.TelephonyManager.WifiCallingChoices
2679 */
2680 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2684 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2685 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
2688 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002689 }
2690
Sailesh Nepald1e68152013-12-12 19:08:02 -08002691 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002692 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002693 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002694 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002695
Shishir Agrawal566b7612013-10-28 14:41:00 -07002696 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002697 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2698 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2700 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 if (TextUtils.equals(ISDR_AID, aid)) {
2706 // Only allows LPA to open logical channel to ISD-R.
2707 ComponentInfo bestComponent =
2708 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2709 if (bestComponent == null
2710 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2711 loge("The calling package is not allowed to access ISD-R.");
2712 throw new SecurityException(
2713 "The calling package is not allowed to access ISD-R.");
2714 }
Derek Tan740e1672017-06-27 14:56:27 -07002715 }
Derek Tan740e1672017-06-27 14:56:27 -07002716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 if (DBG) {
2718 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2719 }
2720 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2721 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2722 if (DBG) log("iccOpenLogicalChannel: " + response);
2723 return response;
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
2726 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002727 }
2728
2729 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002730 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2732 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2737 if (channel < 0) {
2738 return false;
2739 }
2740 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2741 if (DBG) log("iccCloseLogicalChannel: " + success);
2742 return success;
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002745 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002746 }
2747
2748 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002749 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002750 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2752 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 if (DBG) {
2757 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2758 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2759 + p3 + " data=" + data);
2760 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762 if (channel < 0) {
2763 return "";
2764 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2767 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2768 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002770 // Append the returned status code to the end of the response payload.
2771 String s = Integer.toHexString(
2772 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2773 if (response.payload != null) {
2774 s = IccUtils.bytesToHexString(response.payload) + s;
2775 }
2776 return s;
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002779 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002780 }
Jake Hambye994d462014-02-03 13:10:13 -08002781
Evan Charltonc66da362014-05-16 14:06:40 -07002782 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002783 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2784 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2786 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2792 && TextUtils.equals(ISDR_AID, data)) {
2793 // Only allows LPA to select ISD-R.
2794 ComponentInfo bestComponent =
2795 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2796 if (bestComponent == null
2797 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2798 loge("The calling package is not allowed to select ISD-R.");
2799 throw new SecurityException(
2800 "The calling package is not allowed to select ISD-R.");
2801 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002802 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 if (DBG) {
2805 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2806 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2807 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2810 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2811 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 // Append the returned status code to the end of the response payload.
2814 String s = Integer.toHexString(
2815 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2816 if (response.payload != null) {
2817 s = IccUtils.bytesToHexString(response.payload) + s;
2818 }
2819 return s;
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002822 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002823 }
2824
2825 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002826 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002827 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2829 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 if (DBG) {
2834 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2835 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2836 }
2837
2838 IccIoResult response =
2839 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2840 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2841 subId);
2842
2843 if (DBG) {
2844 log("Exchange SIM_IO [R]" + response);
2845 }
2846
2847 byte[] result = null;
2848 int length = 2;
2849 if (response.payload != null) {
2850 length = 2 + response.payload.length;
2851 result = new byte[length];
2852 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2853 } else {
2854 result = new byte[length];
2855 }
2856
2857 result[length - 1] = (byte) response.sw2;
2858 result[length - 2] = (byte) response.sw1;
2859 return result;
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002862 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002863 }
2864
Nathan Haroldb3014052017-01-25 15:57:32 -08002865 /**
2866 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2867 * on a particular subscription
2868 */
sqianb6e41952018-03-12 14:54:01 -07002869 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2871 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2872 return null;
2873 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 if (appType != TelephonyManager.APPTYPE_USIM
2878 && appType != TelephonyManager.APPTYPE_SIM) {
2879 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2880 return null;
2881 }
2882 Object response = sendRequest(
2883 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2884 if (response instanceof String[]) {
2885 return (String[]) response;
2886 }
2887 // Response is an Exception of some kind,
2888 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08002889 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002892 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002893 }
2894
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002895 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002896 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2898 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2903 if (response.payload == null) {
2904 return "";
2905 }
Evan Charltonc66da362014-05-16 14:06:40 -07002906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 // Append the returned status code to the end of the response payload.
2908 String s = Integer.toHexString(
2909 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2910 s = IccUtils.bytesToHexString(response.payload) + s;
2911 return s;
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
2914 }
Evan Charltonc66da362014-05-16 14:06:40 -07002915 }
2916
Jake Hambye994d462014-02-03 13:10:13 -08002917 /**
2918 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2919 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2920 *
2921 * @param itemID the ID of the item to read
2922 * @return the NV item as a String, or null on error.
2923 */
2924 @Override
2925 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07002926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2928 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07002933 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2935 return value;
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
Jake Hambye994d462014-02-03 13:10:13 -08002939 }
2940
2941 /**
2942 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2943 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2944 *
2945 * @param itemID the ID of the item to read
2946 * @param itemValue the value to write, as a String
2947 * @return true on success; false on any failure
2948 */
2949 @Override
2950 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07002951 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2953 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2958 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07002959 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2961 return success;
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
Jake Hambye994d462014-02-03 13:10:13 -08002965 }
2966
2967 /**
2968 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2969 * Used for device configuration by some CDMA operators.
2970 *
2971 * @param preferredRoamingList byte array containing the new PRL
2972 * @return true on success; false on any failure
2973 */
2974 @Override
2975 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2977 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2982 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2983 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2984 return success;
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
Jake Hambye994d462014-02-03 13:10:13 -08002988 }
2989
2990 /**
2991 * Perform the specified type of NV config reset.
2992 * Used for device configuration by some CDMA operators.
2993 *
2994 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2995 * @return true on success; false on any failure
2996 */
2997 @Override
2998 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3000 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001
3002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 if (DBG) log("nvResetConfig: type " + resetType);
3005 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3006 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3007 return success;
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Jake Hambye994d462014-02-03 13:10:13 -08003011 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003012
Svet Ganovb320e182015-04-16 12:30:10 -07003013 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003015 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003016 return new String[0];
3017 }
3018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 return mPhone.getPcscfAddress(apnType);
3022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
Wink Saville36469e72014-06-11 15:17:00 -07003025 }
3026
Brad Ebinger51f743a2017-01-23 13:50:20 -08003027 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003028 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3029 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003030 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003031 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003032 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 PhoneFactory.getImsResolver().enableIms(slotId);
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003040 }
3041
3042 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003043 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3044 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003045 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003046 public void disableIms(int slotId) {
3047 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 PhoneFactory.getImsResolver().disableIms(slotId);
3052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003055 }
3056
3057 /**
3058 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3059 * feature or {@link null} if the service is not available. If the feature is available, the
3060 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3061 */
3062 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003063 IImsServiceFeatureCallback callback) {
3064 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065
3066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003072 }
3073
3074 /**
3075 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3076 * feature during emergency calling or {@link null} if the service is not available. If the
3077 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3078 * listener for feature updates.
3079 */
3080 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3081 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003089 }
3090
Brad Ebinger5f64b052017-12-14 14:26:15 -08003091 /**
3092 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3093 * specified.
3094 */
3095 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3096 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097
3098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003104 }
3105
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003106 /**
3107 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3108 * specified.
3109 */
3110 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3111 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112
3113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003119 }
3120
Brad Ebinger884c07b2018-02-15 16:17:40 -08003121 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003122 * Sets the ImsService Package Name that Telephony will bind to.
3123 *
3124 * @param slotId the slot ID that the ImsService should bind for.
3125 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3126 * ImsService is the device default ImsService.
3127 * @param packageName The package name of the application that contains the ImsService to bind
3128 * to.
3129 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3130 * @hide
3131 */
3132 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003133 int[] subIds = SubscriptionManager.getSubId(slotId);
3134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3135 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3136 "setImsService");
3137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3141 isCarrierImsService, packageName);
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
3144 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003145 }
3146
3147 /**
3148 * Return the ImsService configuration.
3149 *
3150 * @param slotId The slot that the ImsService is associated with.
3151 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3152 * the device default.
3153 * @return the package name of the ImsService configuration.
3154 */
3155 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003156 int[] subIds = SubscriptionManager.getSubId(slotId);
3157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3158 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3159 "getImsService");
3160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3164 isCarrierImsService);
3165 } finally {
3166 Binder.restoreCallingIdentity(identity);
3167 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003168 }
3169
Wink Saville36469e72014-06-11 15:17:00 -07003170 public void setImsRegistrationState(boolean registered) {
3171 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172
3173 final long identity = Binder.clearCallingIdentity();
3174 try {
3175 mPhone.setImsRegistrationState(registered);
3176 } finally {
3177 Binder.restoreCallingIdentity(identity);
3178 }
Wink Saville36469e72014-06-11 15:17:00 -07003179 }
3180
3181 /**
Stuart Scott54788802015-03-30 13:18:01 -07003182 * Set the network selection mode to automatic.
3183 *
3184 */
3185 @Override
3186 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3188 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
Pengquan Menge92a50d2018-09-21 15:54:48 -07003190 if (!isActiveSubscription(subId)) {
3191 return;
3192 }
3193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3197 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
Stuart Scott54788802015-03-30 13:18:01 -07003201 }
3202
Pengquan Mengea84e042018-09-20 14:57:26 -07003203 /**
3204 * Ask the radio to connect to the input network and change selection mode to manual.
3205 *
3206 * @param subId the id of the subscription.
3207 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3208 * the operator to attach to.
3209 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3210 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3211 * normal network selection next time.
3212 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003213 */
3214 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003215 public boolean setNetworkSelectionModeManual(
3216 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3218 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003219
3220 if (!isActiveSubscription(subId)) {
3221 return false;
3222 }
3223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 final long identity = Binder.clearCallingIdentity();
3225 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003226 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003228 if (DBG) {
3229 log("setNetworkSelectionModeManual: subId: " + subId
3230 + " operator: " + operatorInfo);
3231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003232 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003236 }
3237
3238 /**
3239 * Scans for available networks.
3240 */
3241 @Override
3242 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3244 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245
Pengquan Menga1bb6272018-09-06 09:59:22 -07003246 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247 try {
3248 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003249 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003254 }
3255
3256 /**
yinxub1bed742017-04-17 11:45:04 -07003257 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003258 *
yinxub1bed742017-04-17 11:45:04 -07003259 * @param subId id of the subscription
3260 * @param request contains the radio access networks with bands/channels to scan
3261 * @param messenger callback messenger for scan results or errors
3262 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003263 * @return the id of the requested scan which can be used to stop the scan.
3264 */
3265 @Override
3266 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3267 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3269 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270
3271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 return mNetworkScanRequestTracker.startNetworkScan(
3274 request, messenger, binder, getPhone(subId));
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
yinxu504e1392017-04-12 16:03:22 -07003278 }
3279
3280 /**
3281 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003282 *
3283 * @param subId id of the subscription
3284 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003285 */
3286 @Override
3287 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3289 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290
3291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3294 } finally {
3295 Binder.restoreCallingIdentity(identity);
3296 }
yinxu504e1392017-04-12 16:03:22 -07003297 }
3298
3299 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003300 * Get the calculated preferred network type.
3301 * Used for debugging incorrect network type.
3302 *
3303 * @return the preferred network type, defined in RILConstants.java.
3304 */
3305 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003306 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003308 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003309 return RILConstants.PREFERRED_NETWORK_MODE;
3310 }
3311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 // FIXME: need to get SubId from somewhere.
3315 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
Junda Liu84d15a22014-07-02 11:21:04 -07003319 }
3320
3321 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003322 * Get the preferred network type.
3323 * Used for device configuration by some CDMA operators.
3324 *
3325 * @return the preferred network type, defined in RILConstants.java.
3326 */
3327 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003328 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3330 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 if (DBG) log("getPreferredNetworkType");
3335 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3336 int networkType = (result != null ? result[0] : -1);
3337 if (DBG) log("getPreferredNetworkType: " + networkType);
3338 return networkType;
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003342 }
3343
3344 /**
3345 * Set the preferred network type.
3346 * Used for device configuration by some CDMA operators.
3347 *
3348 * @param networkType the preferred network type, defined in RILConstants.java.
3349 * @return true on success; false on any failure.
3350 */
3351 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003352 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3354 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355
3356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3359 Boolean success = (Boolean) sendRequest(
3360 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3361 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3362 if (success) {
3363 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3364 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3365 }
3366 return success;
3367 } finally {
3368 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003369 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003370 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003371
3372 /**
Junda Liu475951f2014-11-07 16:45:03 -08003373 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3374 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3375 * tethering.
3376 *
3377 * @return 0: Not required. 1: required. 2: Not set.
3378 * @hide
3379 */
3380 @Override
3381 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003382 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003383
3384 final long identity = Binder.clearCallingIdentity();
3385 try {
3386 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3387 Settings.Global.TETHER_DUN_REQUIRED, 2);
3388 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3389 // config_tether_apndata.
3390 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3391 dunRequired = 1;
3392 }
3393 return dunRequired;
3394 } finally {
3395 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003396 }
Junda Liu475951f2014-11-07 16:45:03 -08003397 }
3398
3399 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003400 * Set mobile data enabled
3401 * Used by the user through settings etc to turn on/off mobile data
3402 *
3403 * @param enable {@code true} turn turn data on, else {@code false}
3404 */
3405 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003406 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3408 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003409
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 int phoneId = mSubscriptionController.getPhoneId(subId);
3413 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3414 Phone phone = PhoneFactory.getPhone(phoneId);
3415 if (phone != null) {
3416 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3417 phone.setUserDataEnabled(enable);
3418 } else {
3419 loge("setUserDataEnabled: no phone for subId=" + subId);
3420 }
3421 } finally {
3422 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003423 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003424 }
3425
3426 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003427 * Get the user enabled state of Mobile Data.
3428 *
3429 * TODO: remove and use isUserDataEnabled.
3430 * This can't be removed now because some vendor codes
3431 * calls through ITelephony directly while they should
3432 * use TelephonyManager.
3433 *
3434 * @return true on enabled
3435 */
3436 @Override
3437 public boolean getDataEnabled(int subId) {
3438 return isUserDataEnabled(subId);
3439 }
3440
3441 /**
3442 * Get whether mobile data is enabled per user setting.
3443 *
3444 * There are other factors deciding whether mobile data is actually enabled, but they are
3445 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003446 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003447 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003448 *
3449 * @return {@code true} if data is enabled else {@code false}
3450 */
3451 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003452 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003453 try {
3454 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3455 null);
3456 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3458 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003460
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 int phoneId = mSubscriptionController.getPhoneId(subId);
3464 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3465 Phone phone = PhoneFactory.getPhone(phoneId);
3466 if (phone != null) {
3467 boolean retVal = phone.isUserDataEnabled();
3468 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3469 return retVal;
3470 } else {
3471 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3472 return false;
3473 }
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003476 }
3477 }
3478
3479 /**
3480 * Get whether mobile data is enabled.
3481 *
3482 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3483 * whether mobile data is actually enabled.
3484 *
3485 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3486 *
3487 * @return {@code true} if data is enabled else {@code false}
3488 */
3489 @Override
3490 public boolean isDataEnabled(int subId) {
3491 try {
3492 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3493 null);
3494 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3496 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 int phoneId = mSubscriptionController.getPhoneId(subId);
3502 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3503 Phone phone = PhoneFactory.getPhone(phoneId);
3504 if (phone != null) {
3505 boolean retVal = phone.isDataEnabled();
3506 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3507 return retVal;
3508 } else {
3509 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3510 return false;
3511 }
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003514 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003515 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003516
3517 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003518 public int getCarrierPrivilegeStatus(int subId) {
3519 final Phone phone = getPhone(subId);
3520 if (phone == null) {
3521 loge("getCarrierPrivilegeStatus: Invalid subId");
3522 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3523 }
3524 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003525 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003526 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003527 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3528 }
3529 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003530 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003531 }
Junda Liu29340342014-07-10 15:23:27 -07003532
3533 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3535 final Phone phone = getPhone(subId);
3536 if (phone == null) {
3537 loge("getCarrierPrivilegeStatus: Invalid subId");
3538 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3539 }
3540 UiccProfile profile =
3541 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3542 if (profile == null) {
3543 loge("getCarrierPrivilegeStatus: No UICC");
3544 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3545 }
3546 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3547 }
3548
3549 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003550 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003551 if (TextUtils.isEmpty(pkgName))
3552 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003553 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003554 if (card == null) {
3555 loge("checkCarrierPrivilegesForPackage: No UICC");
3556 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3557 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003558 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3559 }
3560
3561 @Override
3562 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003563 if (TextUtils.isEmpty(pkgName))
3564 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003565 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3566 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3567 UiccCard card = UiccController.getInstance().getUiccCard(i);
3568 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003569 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003570 continue;
3571 }
3572
3573 result = card.getCarrierPrivilegeStatus(
3574 mPhone.getContext().getPackageManager(), pkgName);
3575 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3576 break;
3577 }
3578 }
3579
3580 return result;
Junda Liu29340342014-07-10 15:23:27 -07003581 }
Derek Tan89e89d42014-07-08 17:00:10 -07003582
3583 @Override
Junda Liue64de782015-04-16 17:19:16 -07003584 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3585 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3586 loge("phoneId " + phoneId + " is not valid.");
3587 return null;
3588 }
3589 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003590 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003591 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003592 return null ;
3593 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003594 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003595 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003596 }
3597
Amith Yamasani6e118872016-02-19 12:53:51 -08003598 @Override
3599 public List<String> getPackagesWithCarrierPrivileges() {
3600 PackageManager pm = mPhone.getContext().getPackageManager();
3601 List<String> privilegedPackages = new ArrayList<>();
3602 List<PackageInfo> packages = null;
3603 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3604 UiccCard card = UiccController.getInstance().getUiccCard(i);
3605 if (card == null) {
3606 // No UICC in that slot.
3607 continue;
3608 }
3609 if (card.hasCarrierPrivilegeRules()) {
3610 if (packages == null) {
3611 // Only check packages in user 0 for now
3612 packages = pm.getInstalledPackagesAsUser(
3613 PackageManager.MATCH_DISABLED_COMPONENTS
3614 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3615 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3616 }
3617 for (int p = packages.size() - 1; p >= 0; p--) {
3618 PackageInfo pkgInfo = packages.get(p);
3619 if (pkgInfo != null && pkgInfo.packageName != null
3620 && card.getCarrierPrivilegeStatus(pkgInfo)
3621 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3622 privilegedPackages.add(pkgInfo.packageName);
3623 }
3624 }
3625 }
3626 }
3627 return privilegedPackages;
3628 }
3629
Wink Savilleb564aae2014-10-23 10:18:09 -07003630 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003631 final Phone phone = getPhone(subId);
3632 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003633 if (card == null) {
3634 loge("getIccId: No UICC");
3635 return null;
3636 }
3637 String iccId = card.getIccId();
3638 if (TextUtils.isEmpty(iccId)) {
3639 loge("getIccId: ICC ID is null or empty.");
3640 return null;
3641 }
3642 return iccId;
3643 }
3644
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003645 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003646 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3647 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3649 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 final String iccId = getIccId(subId);
3654 final Phone phone = getPhone(subId);
3655 if (phone == null) {
3656 return false;
3657 }
3658 final String subscriberId = phone.getSubscriberId();
3659
3660 if (DBG_MERGE) {
3661 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3662 + subscriberId + " to " + number);
3663 }
3664
3665 if (TextUtils.isEmpty(iccId)) {
3666 return false;
3667 }
3668
3669 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3670
3671 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3672 if (alphaTag == null) {
3673 editor.remove(alphaTagPrefKey);
3674 } else {
3675 editor.putString(alphaTagPrefKey, alphaTag);
3676 }
3677
3678 // Record both the line number and IMSI for this ICCID, since we need to
3679 // track all merged IMSIs based on line number
3680 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3681 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3682 if (number == null) {
3683 editor.remove(numberPrefKey);
3684 editor.remove(subscriberPrefKey);
3685 } else {
3686 editor.putString(numberPrefKey, number);
3687 editor.putString(subscriberPrefKey, subscriberId);
3688 }
3689
3690 editor.commit();
3691 return true;
3692 } finally {
3693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003694 }
Derek Tan7226c842014-07-02 17:42:23 -07003695 }
3696
3697 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003698 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003699 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003701 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003702 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003703 return null;
3704 }
Derek Tan97ebb422014-09-05 16:55:38 -07003705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 String iccId = getIccId(subId);
3709 if (iccId != null) {
3710 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3711 if (DBG_MERGE) {
3712 log("getLine1NumberForDisplay returning "
3713 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3714 }
3715 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003717 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3718 return null;
3719 } finally {
3720 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003721 }
Derek Tan7226c842014-07-02 17:42:23 -07003722 }
3723
3724 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003725 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003727 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003728 return null;
3729 }
Derek Tan97ebb422014-09-05 16:55:38 -07003730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731 final long identity = Binder.clearCallingIdentity();
3732 try {
3733 String iccId = getIccId(subId);
3734 if (iccId != null) {
3735 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3736 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3737 }
3738 return null;
3739 } finally {
3740 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003741 }
Derek Tan7226c842014-07-02 17:42:23 -07003742 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003743
3744 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003745 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003746 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3747 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003749 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3750 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003751 return null;
3752 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003753
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003754 final long identity = Binder.clearCallingIdentity();
3755 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756 final Context context = mPhone.getContext();
3757 final TelephonyManager tele = TelephonyManager.from(context);
3758 final SubscriptionManager sub = SubscriptionManager.from(context);
3759
3760 // Figure out what subscribers are currently active
3761 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3762 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3763 // the process, where TelephonyManager was instantiated.
3764 // Otherwise AppOps check will fail.
3765
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003766 final int[] subIds = sub.getActiveSubscriptionIdList();
3767 for (int subId : subIds) {
3768 activeSubscriberIds.add(tele.getSubscriberId(subId));
3769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770
3771 // First pass, find a number override for an active subscriber
3772 String mergeNumber = null;
3773 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3774 for (String key : prefs.keySet()) {
3775 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3776 final String subscriberId = (String) prefs.get(key);
3777 if (activeSubscriberIds.contains(subscriberId)) {
3778 final String iccId = key.substring(
3779 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3780 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3781 mergeNumber = (String) prefs.get(numberKey);
3782 if (DBG_MERGE) {
3783 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3784 + " for active subscriber " + subscriberId);
3785 }
3786 if (!TextUtils.isEmpty(mergeNumber)) {
3787 break;
3788 }
3789 }
3790 }
3791 }
3792
3793 // Shortcut when no active merged subscribers
3794 if (TextUtils.isEmpty(mergeNumber)) {
3795 return null;
3796 }
3797
3798 // Second pass, find all subscribers under that line override
3799 final ArraySet<String> result = new ArraySet<>();
3800 for (String key : prefs.keySet()) {
3801 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3802 final String number = (String) prefs.get(key);
3803 if (mergeNumber.equals(number)) {
3804 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3805 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3806 final String subscriberId = (String) prefs.get(subscriberKey);
3807 if (!TextUtils.isEmpty(subscriberId)) {
3808 result.add(subscriberId);
3809 }
3810 }
3811 }
3812 }
3813
3814 final String[] resultArray = result.toArray(new String[result.size()]);
3815 Arrays.sort(resultArray);
3816 if (DBG_MERGE) {
3817 Slog.d(LOG_TAG,
3818 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3819 }
3820 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003821 } finally {
3822 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003823 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003824 }
3825
3826 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003827 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003828 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3829 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830
3831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 final Phone phone = getPhone(subId);
3834 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
3837 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003838 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003839
3840 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003841 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003842 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3843 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003844 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003845
3846 final long identity = Binder.clearCallingIdentity();
3847 try {
3848 final Phone phone = getPhone(subId);
3849 if (phone == null) {
3850 return false;
3851 }
3852 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3853 cdmaNonRoamingList);
3854 } finally {
3855 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003856 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003857 }
3858
3859 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003860 @Deprecated
3861 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3862 enforceModifyPermission();
3863
3864 int returnValue = 0;
3865 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07003866 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003867 if(result.exception == null) {
3868 if (result.result != null) {
3869 byte[] responseData = (byte[])(result.result);
3870 if(responseData.length > oemResp.length) {
3871 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3872 responseData.length + "bytes. Buffer Size is " +
3873 oemResp.length + "bytes.");
3874 }
3875 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3876 returnValue = responseData.length;
3877 }
3878 } else {
3879 CommandException ex = (CommandException) result.exception;
3880 returnValue = ex.getCommandError().ordinal();
3881 if(returnValue > 0) returnValue *= -1;
3882 }
3883 } catch (RuntimeException e) {
3884 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3885 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3886 if(returnValue > 0) returnValue *= -1;
3887 }
3888
3889 return returnValue;
3890 }
3891
3892 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003893 public void setRadioCapability(RadioAccessFamily[] rafs) {
3894 try {
3895 ProxyController.getInstance().setRadioCapability(rafs);
3896 } catch (RuntimeException e) {
3897 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3898 }
3899 }
3900
3901 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003902 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003903 Phone phone = PhoneFactory.getPhone(phoneId);
3904 if (phone == null) {
3905 return RadioAccessFamily.RAF_UNKNOWN;
3906 }
3907 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003909 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003910 return RadioAccessFamily.RAF_UNKNOWN;
3911 }
3912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
3918 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003919 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003920
3921 @Override
3922 public void enableVideoCalling(boolean enable) {
3923 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003924
3925 final long identity = Binder.clearCallingIdentity();
3926 try {
3927 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
3928 } finally {
3929 Binder.restoreCallingIdentity(identity);
3930 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003931 }
3932
3933 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003934 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3936 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3937 return false;
3938 }
Svet Ganovb320e182015-04-16 12:30:10 -07003939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 // Check the user preference and the system-level IMS setting. Even if the user has
3943 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3944 // In the long run, we may instead need to check if there exists a connection service
3945 // which can support video calling.
3946 ImsManager imsManager =
3947 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3948 return imsManager.isVtEnabledByPlatform()
3949 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3950 && imsManager.isVtEnabledByUser();
3951 } finally {
3952 Binder.restoreCallingIdentity(identity);
3953 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003954 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003955
Andrew Leea1239f22015-03-02 17:44:07 -08003956 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
3958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3959 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
3960 return false;
3961 }
3962
3963 final long identity = Binder.clearCallingIdentity();
3964 try {
3965 CarrierConfigManager configManager =
3966 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
3967 return configManager.getConfigForSubId(mPhone.getSubId())
3968 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
3971 }
Andrew Leea1239f22015-03-02 17:44:07 -08003972 }
3973
3974 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003975 public boolean isWorldPhone(int subId, String callingPackage) {
3976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3977 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
3978 return false;
3979 }
3980
3981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 CarrierConfigManager configManager =
3984 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
3985 return configManager.getConfigForSubId(mPhone.getSubId())
3986 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
3987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
Andrew Leea1239f22015-03-02 17:44:07 -08003990 }
3991
Andrew Lee9431b832015-03-09 18:46:45 -07003992 @Override
3993 public boolean isTtyModeSupported() {
3994 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003995 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003996 }
3997
3998 @Override
3999 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
4005 }
Andrew Lee9431b832015-03-09 18:46:45 -07004006 }
4007
Hall Liu98187582018-01-22 19:15:32 -08004008 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4012 mPhone.getSubId()).getBoolean(
4013 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4014 boolean isDeviceSupported =
4015 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4016 return isCarrierSupported && isDeviceSupported;
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Hall Liu98187582018-01-22 19:15:32 -08004020 }
4021
Hall Liu3ad5f012018-04-06 16:23:39 -07004022 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 return isRttSupported() && Settings.Secure.getInt(
4026 mPhone.getContext().getContentResolver(),
4027 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004031 }
4032
Sanket Padawe7310cc72015-01-14 09:53:20 -08004033 /**
4034 * Returns the unique device ID of phone, for example, the IMEI for
4035 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4036 *
4037 * <p>Requires Permission:
4038 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4039 */
4040 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004041 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004042 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004043 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004044 return null;
4045 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004046 int subId = phone.getSubId();
4047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4048 mApp, subId, callingPackage, "getDeviceId")) {
4049 return null;
4050 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 return phone.getDeviceId();
4055 } finally {
4056 Binder.restoreCallingIdentity(identity);
4057 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004058 }
4059
Ping Sunc67b7c22016-03-02 19:16:45 +08004060 /**
4061 * {@hide}
4062 * Returns the IMS Registration Status on a particular subid
4063 *
4064 * @param subId
4065 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004066 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004067 Phone phone = getPhone(subId);
4068 if (phone != null) {
4069 return phone.isImsRegistered();
4070 } else {
4071 return false;
4072 }
4073 }
4074
Santos Cordon7a1885b2015-02-03 11:15:19 -08004075 @Override
4076 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004083 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004084
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004085 /**
4086 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004087 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004088 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089 final long identity = Binder.clearCallingIdentity();
4090 try {
4091 Phone phone = getPhone(subId);
4092 if (phone != null) {
4093 return phone.isWifiCallingEnabled();
4094 } else {
4095 return false;
4096 }
4097 } finally {
4098 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004099 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004100 }
4101
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004102 /**
4103 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004104 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004105 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 Phone phone = getPhone(subId);
4109 if (phone != null) {
4110 return phone.isVolteEnabled();
4111 } else {
4112 return false;
4113 }
4114 } finally {
4115 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004116 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004117 }
Svet Ganovb320e182015-04-16 12:30:10 -07004118
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004119 /**
4120 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004121 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004122 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 Phone phone = getPhone(subId);
4126 if (phone != null) {
4127 return phone.isVideoEnabled();
4128 } else {
4129 return false;
4130 }
4131 } finally {
4132 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004133 }
4134 }
4135
4136 /**
4137 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4138 * defined in {@link ImsRegistrationImplBase}.
4139 */
4140 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 Phone phone = getPhone(subId);
4144 if (phone != null) {
4145 return phone.getImsRegistrationTech();
4146 } else {
4147 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4148 }
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004151 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004152 }
4153
Stuart Scott8eef64f2015-04-08 15:13:54 -07004154 @Override
4155 public void factoryReset(int subId) {
4156 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004157 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4158 return;
4159 }
4160
Svet Ganovcc087f82015-05-12 20:35:54 -07004161 final long identity = Binder.clearCallingIdentity();
4162 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004163 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4164 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004165 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004166 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004167 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4168 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004169 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004170 }
4171 } finally {
4172 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004173 }
4174 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004175
4176 @Override
4177 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 // We query all subscriptions instead of just the active ones, because
4181 // this might be called early on in the provisioning flow when the
4182 // subscriptions potentially aren't active yet.
4183 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4184 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004185 return null;
4186 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004188 // This function may be called very early, say, from the setup wizard, at
4189 // which point we won't have a default subscription set. If that's the case
4190 // we just choose the first, which will be valid in "most cases".
4191 final int defaultSubId = getDefaultSubscription();
4192 SubscriptionInfo info = null;
4193 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4194 info = slist.get(0);
4195 } else {
4196 for (SubscriptionInfo item : slist) {
4197 if (item.getSubscriptionId() == defaultSubId) {
4198 info = item;
4199 break;
4200 }
4201 }
4202
4203 if (info == null) {
4204 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004205 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004206 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 // Try and fetch the locale from the carrier properties or from the SIM language
4209 // preferences (EF-PL and EF-LI)...
4210 final int mcc = info.getMcc();
4211 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4212 String simLanguage = null;
4213 if (defaultPhone != null) {
4214 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4215 if (localeFromDefaultSim != null) {
4216 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4217 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4218 return localeFromDefaultSim.toLanguageTag();
4219 } else {
4220 simLanguage = localeFromDefaultSim.getLanguage();
4221 }
4222 }
4223 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004225 // The SIM language preferences only store a language (e.g. fr = French), not an
4226 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4227 // the SIM and carrier preferences does not include a country we add the country
4228 // determined from the SIM MCC to provide an exact locale.
4229 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4230 simLanguage);
4231 if (mccLocale != null) {
4232 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4233 return mccLocale.toLanguageTag();
4234 }
4235
4236 if (DBG) log("No locale found - returning null");
4237 return null;
4238 } finally {
4239 Binder.restoreCallingIdentity(identity);
4240 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004241 }
4242
4243 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004244 return mSubscriptionController.getAllSubInfoList(
4245 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004246 }
4247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248 /**
4249 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4250 */
4251 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4252 return mSubscriptionController.getActiveSubscriptionInfoList(
4253 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004254 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004255
Chenjie Yu1ba97252018-01-11 18:16:20 -08004256 private final ModemActivityInfo mLastModemActivityInfo =
4257 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4258
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004259 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004260 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4261 * representing the state of the modem.
4262 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004263 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4264 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004265 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004266 */
4267 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004268 public void requestModemActivityInfo(ResultReceiver result) {
4269 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004271
4272 final long identity = Binder.clearCallingIdentity();
4273 try {
4274 ModemActivityInfo ret = null;
4275 synchronized (mLastModemActivityInfo) {
4276 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4277 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004278 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004279 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4281 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4282 mergedTxTimeMs[i] =
4283 info.getTxTimeMillis()[i]
4284 + mLastModemActivityInfo.getTxTimeMillis()[i];
4285 }
4286 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4287 mLastModemActivityInfo.setSleepTimeMillis(
4288 info.getSleepTimeMillis()
4289 + mLastModemActivityInfo.getSleepTimeMillis());
4290 mLastModemActivityInfo.setIdleTimeMillis(
4291 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4292 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4293 mLastModemActivityInfo.setRxTimeMillis(
4294 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4295 mLastModemActivityInfo.setEnergyUsed(
4296 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004298 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4299 mLastModemActivityInfo.getSleepTimeMillis(),
4300 mLastModemActivityInfo.getIdleTimeMillis(),
4301 mLastModemActivityInfo.getTxTimeMillis(),
4302 mLastModemActivityInfo.getRxTimeMillis(),
4303 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 Bundle bundle = new Bundle();
4306 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4307 result.send(0, bundle);
4308 } finally {
4309 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004310 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004311 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004312
Siddharth Rayb8114062018-06-17 15:02:38 -07004313 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4314 // less than total activity duration.
4315 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4316 if (info == null) {
4317 return false;
4318 }
4319 int activityDurationMs =
4320 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4321 int totalTxTimeMs = 0;
4322 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4323 totalTxTimeMs += info.getTxTimeMillis()[i];
4324 }
4325 return (info.isValid()
4326 && (info.getSleepTimeMillis() <= activityDurationMs)
4327 && (info.getIdleTimeMillis() <= activityDurationMs)
4328 && (info.getRxTimeMillis() <= activityDurationMs)
4329 && (totalTxTimeMs <= activityDurationMs));
4330 }
4331
Jack Yu85bd38a2015-11-09 11:34:32 -08004332 /**
4333 * {@hide}
4334 * Returns the service state information on specified subscription.
4335 */
4336 @Override
4337 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004339 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004340 return null;
4341 }
4342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 final long identity = Binder.clearCallingIdentity();
4344 try {
4345 final Phone phone = getPhone(subId);
4346 if (phone == null) {
4347 return null;
4348 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 return phone.getServiceState();
4351 } finally {
4352 Binder.restoreCallingIdentity(identity);
4353 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004354 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004355
4356 /**
4357 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4358 *
4359 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4360 * voicemail ringtone.
4361 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4362 * PhoneAccount.
4363 */
4364 @Override
4365 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 final long identity = Binder.clearCallingIdentity();
4367 try {
4368 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4369 if (phone == null) {
4370 phone = mPhone;
4371 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4374 } finally {
4375 Binder.restoreCallingIdentity(identity);
4376 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004377 }
4378
4379 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004380 * Sets the per-account voicemail ringtone.
4381 *
4382 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4383 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4384 *
4385 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4386 * voicemail ringtone.
4387 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4388 * PhoneAccount.
4389 */
4390 @Override
4391 public void setVoicemailRingtoneUri(String callingPackage,
4392 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4394 if (!TextUtils.equals(callingPackage,
4395 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4397 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4398 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004399 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400
4401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4404 if (phone == null) {
4405 phone = mPhone;
4406 }
4407 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4408 } finally {
4409 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004410 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004411 }
4412
4413 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004414 * Returns whether vibration is set for voicemail notification in Phone settings.
4415 *
4416 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4417 * voicemail vibration setting.
4418 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4419 */
4420 @Override
4421 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4425 if (phone == null) {
4426 phone = mPhone;
4427 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004433 }
4434
Youhan Wange64578a2016-05-02 15:32:42 -07004435 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004436 * Sets the per-account voicemail vibration.
4437 *
4438 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4439 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4440 *
4441 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4442 * voicemail vibration setting.
4443 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4444 * specific PhoneAccount.
4445 */
4446 @Override
4447 public void setVoicemailVibrationEnabled(String callingPackage,
4448 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4449 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4450 if (!TextUtils.equals(callingPackage,
4451 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4453 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4454 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004455 }
4456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 final long identity = Binder.clearCallingIdentity();
4458 try {
4459 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4460 if (phone == null) {
4461 phone = mPhone;
4462 }
4463 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004466 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004467 }
4468
4469 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004470 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4471 *
4472 * @throws SecurityException if the caller does not have the required permission
4473 */
4474 private void enforceReadPrivilegedPermission() {
4475 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4476 null);
4477 }
4478
4479 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004480 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4481 * permission.
4482 *
4483 * @throws SecurityException if the caller does not have the required permission
4484 */
4485 private void enforceSendSmsPermission() {
4486 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4487 }
4488
4489 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004490 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004491 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004492 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004493 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004494 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
4497 ComponentName componentName =
4498 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4499 if (componentName == null) {
4500 throw new SecurityException(
4501 "Caller not current active visual voicemail package[null]");
4502 }
4503 String vvmPackage = componentName.getPackageName();
4504 if (!callingPackage.equals(vvmPackage)) {
4505 throw new SecurityException("Caller not current active visual voicemail package["
4506 + vvmPackage + "]");
4507 }
4508 } finally {
4509 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004510 }
4511 }
4512
4513 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004514 * Return the application ID for the app type.
4515 *
4516 * @param subId the subscription ID that this request applies to.
4517 * @param appType the uicc app type.
4518 * @return Application ID for specificied app type, or null if no uicc.
4519 */
4520 @Override
4521 public String getAidForAppType(int subId, int appType) {
4522 enforceReadPrivilegedPermission();
4523 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004524
4525 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004526 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004527 if (phone == null) {
4528 return null;
4529 }
4530 String aid = null;
4531 try {
4532 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4533 .getApplicationByType(appType).getAid();
4534 } catch (Exception e) {
4535 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4536 }
4537 return aid;
4538 } finally {
4539 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004540 }
Youhan Wange64578a2016-05-02 15:32:42 -07004541 }
4542
Youhan Wang4001d252016-05-11 10:29:41 -07004543 /**
4544 * Return the Electronic Serial Number.
4545 *
4546 * @param subId the subscription ID that this request applies to.
4547 * @return ESN or null if error.
4548 */
4549 @Override
4550 public String getEsn(int subId) {
4551 enforceReadPrivilegedPermission();
4552 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553
4554 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004555 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 if (phone == null) {
4557 return null;
4558 }
4559 String esn = null;
4560 try {
4561 esn = phone.getEsn();
4562 } catch (Exception e) {
4563 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4564 }
4565 return esn;
4566 } finally {
4567 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004568 }
Youhan Wang4001d252016-05-11 10:29:41 -07004569 }
4570
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004571 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004572 * Return the Preferred Roaming List Version.
4573 *
4574 * @param subId the subscription ID that this request applies to.
4575 * @return PRLVersion or null if error.
4576 */
4577 @Override
4578 public String getCdmaPrlVersion(int subId) {
4579 enforceReadPrivilegedPermission();
4580 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581
4582 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004583 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004584 if (phone == null) {
4585 return null;
4586 }
4587 String cdmaPrlVersion = null;
4588 try {
4589 cdmaPrlVersion = phone.getCdmaPrlVersion();
4590 } catch (Exception e) {
4591 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4592 }
4593 return cdmaPrlVersion;
4594 } finally {
4595 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004596 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004597 }
4598
4599 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004600 * Get snapshot of Telephony histograms
4601 * @return List of Telephony histograms
4602 * @hide
4603 */
4604 @Override
4605 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4607 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608
4609 final long identity = Binder.clearCallingIdentity();
4610 try {
4611 return RIL.getTelephonyRILTimingHistograms();
4612 } finally {
4613 Binder.restoreCallingIdentity(identity);
4614 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004615 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004616
4617 /**
4618 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004619 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004620 * Require system privileges. In the future we may add this to carrier APIs.
4621 *
4622 * @return The number of carriers set successfully, should match length of carriers
4623 */
4624 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004625 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004626 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004627 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004628
Meng Wang9b7c4e92017-02-17 11:41:27 -08004629 if (carriers == null) {
4630 throw new NullPointerException("carriers cannot be null");
4631 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 final long identity = Binder.clearCallingIdentity();
4634 try {
4635 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004636 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4637 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638 return retVal[0];
4639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004642 }
4643
4644 /**
4645 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004646 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004647 * Require system privileges. In the future we may add this to carrier APIs.
4648 *
4649 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4650 * means all carriers are allowed.
4651 */
4652 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004653 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004654 enforceReadPrivilegedPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004655 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656
4657 final long identity = Binder.clearCallingIdentity();
4658 try {
4659 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004660 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4661 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004665 }
4666
fionaxu59545b42016-05-25 15:53:37 -07004667 /**
4668 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4669 * @param subId the subscription ID that this action applies to.
4670 * @param enabled control enable or disable metered apns.
4671 * {@hide}
4672 */
4673 @Override
4674 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4675 enforceModifyPermission();
4676 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677
4678 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004679 if (phone == null) {
4680 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4681 return;
4682 }
4683 try {
4684 phone.carrierActionSetMeteredApnsEnabled(enabled);
4685 } catch (Exception e) {
4686 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687 } finally {
4688 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004689 }
4690 }
4691
4692 /**
4693 * Action set from carrier signalling broadcast receivers to enable/disable radio
4694 * @param subId the subscription ID that this action applies to.
4695 * @param enabled control enable or disable radio.
4696 * {@hide}
4697 */
4698 @Override
4699 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4700 enforceModifyPermission();
4701 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702
4703 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004704 if (phone == null) {
4705 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4706 return;
4707 }
4708 try {
4709 phone.carrierActionSetRadioEnabled(enabled);
4710 } catch (Exception e) {
4711 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004714 }
4715 }
4716
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004717 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004718 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4719 * network status based on which carrier apps could apply actions accordingly,
4720 * enable/disable default url handler for example.
4721 *
4722 * @param subId the subscription ID that this action applies to.
4723 * @param report control start/stop reporting the default network status.
4724 * {@hide}
4725 */
4726 @Override
4727 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4728 enforceModifyPermission();
4729 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730
4731 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004732 if (phone == null) {
4733 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4734 return;
4735 }
4736 try {
4737 phone.carrierActionReportDefaultNetworkStatus(report);
4738 } catch (Exception e) {
4739 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740 } finally {
4741 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004742 }
4743 }
4744
4745 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004746 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4747 * bug report is being generated.
4748 */
4749 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004750 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004751 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4752 != PackageManager.PERMISSION_GRANTED) {
4753 writer.println("Permission Denial: can't dump Phone from pid="
4754 + Binder.getCallingPid()
4755 + ", uid=" + Binder.getCallingUid()
4756 + "without permission "
4757 + android.Manifest.permission.DUMP);
4758 return;
4759 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004760 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004761 }
Jack Yueb89b242016-06-22 13:27:47 -07004762
Brad Ebingerdac2f002018-04-03 15:17:52 -07004763 @Override
4764 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4765 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4766 throws RemoteException {
4767 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4768 }
4769
Jack Yueb89b242016-06-22 13:27:47 -07004770 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004771 * Get aggregated video call data usage since boot.
4772 *
4773 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4774 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004775 * {@hide}
4776 */
4777 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004778 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004779 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4780 null);
4781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782 final long identity = Binder.clearCallingIdentity();
4783 try {
4784 // NetworkStatsService keeps tracking the active network interface and identity. It
4785 // records the delta with the corresponding network identity.
4786 // We just return the total video call data usage snapshot since boot.
4787 Phone phone = getPhone(subId);
4788 if (phone != null) {
4789 return phone.getVtDataUsage(perUidStats);
4790 }
4791 return null;
4792 } finally {
4793 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004794 }
Jack Yueb89b242016-06-22 13:27:47 -07004795 }
Jack Yu75ab2952016-07-08 14:29:33 -07004796
4797 /**
4798 * Policy control of data connection. Usually used when data limit is passed.
4799 * @param enabled True if enabling the data, otherwise disabling.
4800 * @param subId Subscription index
4801 * {@hide}
4802 */
4803 @Override
4804 public void setPolicyDataEnabled(boolean enabled, int subId) {
4805 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004806
4807 final long identity = Binder.clearCallingIdentity();
4808 try {
4809 Phone phone = getPhone(subId);
4810 if (phone != null) {
4811 phone.setPolicyDataEnabled(enabled);
4812 }
4813 } finally {
4814 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004815 }
4816 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004817
4818 /**
4819 * Get Client request stats
4820 * @return List of Client Request Stats
4821 * @hide
4822 */
4823 @Override
4824 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004826 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004827 return null;
4828 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004829 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 if (phone != null) {
4834 return phone.getClientRequestStats();
4835 }
4836
4837 return null;
4838 } finally {
4839 Binder.restoreCallingIdentity(identity);
4840 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004841 }
4842
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004843 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004844 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004845 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004846 }
Jack Yueb4124c2017-02-16 15:32:43 -08004847
4848 /**
Grace Chen70990072017-03-24 17:21:30 -07004849 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004850 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004851 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004852 * @param state State of SIM (power down, power up, pass through)
4853 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4854 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4855 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004856 *
4857 **/
4858 @Override
Grace Chen70990072017-03-24 17:21:30 -07004859 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004860 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004861 Phone phone = PhoneFactory.getPhone(slotIndex);
4862
vagdeviaf9a5b92018-08-15 16:01:53 -07004863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 final long identity = Binder.clearCallingIdentity();
4866 try {
4867 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004868 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 }
4870 } finally {
4871 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004872 }
4873 }
Shuo Qiandd210312017-04-12 22:11:33 +00004874
Tyler Gunn65d45c22017-06-05 11:22:26 -07004875 private boolean isUssdApiAllowed(int subId) {
4876 CarrierConfigManager configManager =
4877 (CarrierConfigManager) mPhone.getContext().getSystemService(
4878 Context.CARRIER_CONFIG_SERVICE);
4879 if (configManager == null) {
4880 return false;
4881 }
4882 PersistableBundle pb = configManager.getConfigForSubId(subId);
4883 if (pb == null) {
4884 return false;
4885 }
4886 return pb.getBoolean(
4887 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4888 }
4889
Shuo Qiandd210312017-04-12 22:11:33 +00004890 /**
4891 * Check if phone is in emergency callback mode
4892 * @return true if phone is in emergency callback mode
4893 * @param subId sub id
4894 */
goneil9c5f4872017-12-05 14:07:56 -08004895 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004896 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004897 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004898 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899
4900 final long identity = Binder.clearCallingIdentity();
4901 try {
4902 if (phone != null) {
4903 return phone.isInEcm();
4904 } else {
4905 return false;
4906 }
4907 } finally {
4908 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004909 }
4910 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004911
4912 /**
4913 * Get the current signal strength information for the given subscription.
4914 * Because this information is not updated when the device is in a low power state
4915 * it should not be relied-upon to be current.
4916 * @param subId Subscription index
4917 * @return the most recent cached signal strength info from the modem
4918 */
4919 @Override
4920 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 final long identity = Binder.clearCallingIdentity();
4922 try {
4923 Phone p = getPhone(subId);
4924 if (p == null) {
4925 return null;
4926 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 return p.getSignalStrength();
4929 } finally {
4930 Binder.restoreCallingIdentity(identity);
4931 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004932 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004933
Pengquan Meng77b7f132018-08-22 14:49:57 -07004934 /**
4935 * Checks if data roaming is enabled on the subscription with id {@code subId}.
4936 *
4937 * <p>Requires one of the following permissions:
4938 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
4939 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
4940 * privileges.
4941 *
4942 * @param subId subscription id
4943 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
4944 * {@code false}.
4945 */
4946 @Override
4947 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07004948 boolean isEnabled = false;
4949 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07004950 try {
4951 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07004952 null /* message */);
4953 Phone phone = getPhone(subId);
4954 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07004955 } catch (Exception e) {
4956 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
4957 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07004960 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004961 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07004962 }
4963
4964
4965 /**
4966 * Enables/Disables the data roaming on the subscription with id {@code subId}.
4967 *
4968 * <p> Requires permission:
4969 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
4970 * privileges.
4971 *
4972 * @param subId subscription id
4973 * @param isEnabled {@code true} means enable, {@code false} means disable.
4974 */
4975 @Override
4976 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07004977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4980 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07004981
Pengquan Menga1bb6272018-09-06 09:59:22 -07004982 Phone phone = getPhone(subId);
4983 if (phone != null) {
4984 phone.setDataRoamingEnabled(isEnabled);
4985 }
4986 } finally {
4987 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07004988 }
4989 }
4990
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004991 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07004992 public boolean isManualNetworkSelectionAllowed(int subId) {
4993 boolean isAllowed = true;
4994 final long identity = Binder.clearCallingIdentity();
4995 try {
4996 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
4997 mApp, subId, "isManualNetworkSelectionAllowed");
4998 Phone phone = getPhone(subId);
4999 if (phone != null) {
5000 isAllowed = phone.isCspPlmnEnabled();
5001 }
5002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
5005 return isAllowed;
5006 }
5007
5008 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005009 public UiccSlotInfo[] getUiccSlotsInfo() {
5010 enforceReadPrivilegedPermission();
5011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 final long identity = Binder.clearCallingIdentity();
5013 try {
5014 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5015 if (slots == null) {
5016 Rlog.i(LOG_TAG, "slots is null.");
5017 return null;
5018 }
5019
5020 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5021 for (int i = 0; i < slots.length; i++) {
5022 UiccSlot slot = slots[i];
5023 if (slot == null) {
5024 continue;
5025 }
5026
5027 String cardId;
5028 UiccCard card = slot.getUiccCard();
5029 if (card != null) {
5030 cardId = card.getCardId();
5031 } else {
5032 cardId = slot.getIccId();
5033 }
5034
5035 int cardState = 0;
5036 switch (slot.getCardState()) {
5037 case CARDSTATE_ABSENT:
5038 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5039 break;
5040 case CARDSTATE_PRESENT:
5041 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5042 break;
5043 case CARDSTATE_ERROR:
5044 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5045 break;
5046 case CARDSTATE_RESTRICTED:
5047 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5048 break;
5049 default:
5050 break;
5051
5052 }
5053
5054 infos[i] = new UiccSlotInfo(
5055 slot.isActive(),
5056 slot.isEuicc(),
5057 cardId,
5058 cardState,
5059 slot.getPhoneId(),
5060 slot.isExtendedApduSupported());
5061 }
5062 return infos;
5063 } finally {
5064 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005065 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005066 }
5067
5068 @Override
5069 public boolean switchSlots(int[] physicalSlots) {
5070 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071
5072 final long identity = Binder.clearCallingIdentity();
5073 try {
5074 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5075 } finally {
5076 Binder.restoreCallingIdentity(identity);
5077 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005078 }
Jack Yu4c988042018-02-27 15:30:01 -08005079
5080 @Override
5081 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5082 enforceModifyPermission();
5083 final Phone phone = getPhone(subId);
5084 if (phone == null) {
5085 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5086 return;
5087 }
5088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 phone.setRadioIndicationUpdateMode(filters, mode);
5092 } finally {
5093 Binder.restoreCallingIdentity(identity);
5094 }
Jack Yu4c988042018-02-27 15:30:01 -08005095 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005096
5097 /**
goneil47ffb6e2018-04-06 15:40:58 -07005098 * A test API to reload the UICC profile.
5099 *
5100 * <p>Requires that the calling app has permission
5101 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5102 * @hide
5103 */
5104 @Override
5105 public void refreshUiccProfile(int subId) {
5106 enforceModifyPermission();
5107
5108 final long identity = Binder.clearCallingIdentity();
5109 try {
5110 Phone phone = getPhone(subId);
5111 if (phone == null) {
5112 return;
5113 }
5114 UiccCard uiccCard = phone.getUiccCard();
5115 if (uiccCard == null) {
5116 return;
5117 }
5118 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5119 if (uiccProfile == null) {
5120 return;
5121 }
5122 uiccProfile.refresh();
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
5125 }
5126 }
5127
5128 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005129 * Returns false if the mobile data is disabled by default, otherwise return true.
5130 */
5131 private boolean getDefaultDataEnabled() {
5132 return "true".equalsIgnoreCase(
5133 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5134 }
5135
5136 /**
5137 * Returns true if the data roaming is enabled by default, i.e the system property
5138 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5139 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5140 */
5141 private boolean getDefaultDataRoamingEnabled(int subId) {
5142 final CarrierConfigManager configMgr = (CarrierConfigManager)
5143 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5144 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5145 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5146 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5147 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5148 return isDataRoamingEnabled;
5149 }
5150
5151 /**
5152 * Returns the default network type for the given {@code subId}, if the default network type is
5153 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5154 */
5155 private int getDefaultNetworkType(int subId) {
5156 return Integer.parseInt(
5157 TelephonyManager.getTelephonyProperty(
5158 mSubscriptionController.getPhoneId(subId),
5159 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5160 String.valueOf(Phone.PREFERRED_NT_MODE)));
5161 }
fionaxua13278b2018-03-21 00:08:13 -07005162
5163 @Override
5164 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5165 gid1, String gid2, String plmn, String spn) {
5166 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167
5168 final long identity = Binder.clearCallingIdentity();
5169 try {
5170 final Phone phone = getPhone(subId);
5171 if (phone == null) {
5172 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5173 return;
5174 }
5175 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5176 } finally {
5177 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005178 }
fionaxua13278b2018-03-21 00:08:13 -07005179 }
5180
5181 @Override
5182 public int getCarrierIdListVersion(int subId) {
5183 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184
5185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 final Phone phone = getPhone(subId);
5188 if (phone == null) {
5189 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5190 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5191 }
5192 return phone.getCarrierIdListVersion();
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005195 }
fionaxua13278b2018-03-21 00:08:13 -07005196 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005197
5198 @Override
5199 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5201 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5202 return -1;
5203 }
5204
5205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
5211 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005212
5213 @Override
5214 public int getCdmaRoamingMode(int subId) {
5215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5216 mApp, subId, "getCdmaRoamingMode");
5217
5218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5221 } finally {
5222 Binder.restoreCallingIdentity(identity);
5223 }
5224 }
5225
5226 @Override
5227 public boolean setCdmaRoamingMode(int subId, int mode) {
5228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5229 mApp, subId, "setCdmaRoamingMode");
5230
5231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
5237 }
5238
5239 @Override
5240 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5242 mApp, subId, "setCdmaSubscriptionMode");
5243
5244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
5250 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005251
5252 private void ensureUserRunning(int userId) {
5253 if (!mUserManager.isUserRunning(userId)) {
5254 throw new IllegalStateException("User " + userId + " does not exist or not running");
5255 }
5256 }
5257
5258 /**
5259 * Returns a list of SMS apps on a given user.
5260 *
5261 * Only the shell user (UID 2000 or 0) can call it.
5262 * Target user must be running.
5263 */
5264 @Override
5265 public String[] getSmsApps(int userId) {
5266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5267 ensureUserRunning(userId);
5268
5269 final Collection<SmsApplicationData> apps =
5270 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5271
5272 String[] ret = new String[apps.size()];
5273 int i = 0;
5274 for (SmsApplicationData app : apps) {
5275 ret[i++] = app.mPackageName;
5276 }
5277 return ret;
5278 }
5279
5280 /**
5281 * Returns the default SMS app package name on a given user.
5282 *
5283 * Only the shell user (UID 2000 or 0) can call it.
5284 * Target user must be running.
5285 */
5286 @Override
5287 public String getDefaultSmsApp(int userId) {
5288 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5289 ensureUserRunning(userId);
5290
5291 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5292 /* updateIfNeeded= */ true, userId);
5293 return cn == null ? null : cn.getPackageName();
5294 }
5295
5296 /**
5297 * Set a package as the default SMS app on a given user.
5298 *
5299 * Only the shell user (UID 2000 or 0) can call it.
5300 * Target user must be running.
5301 */
5302 @Override
5303 public void setDefaultSmsApp(int userId, String packageName) {
5304 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5305 ensureUserRunning(userId);
5306
5307 boolean found = false;
5308 for (String pkg : getSmsApps(userId)) {
5309 if (TextUtils.equals(packageName, pkg)) {
5310 found = true;
5311 break;
5312 }
5313 }
5314 if (!found) {
5315 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5316 }
5317
5318 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5319 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005320}