blob: 065373509ce30460151d3d3e660dd26c9dab3d2f [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 Chenf144d942018-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;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800115import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800116import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700117import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.uicc.IccIoResult;
119import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800120import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700121import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800122import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800124import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700126import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800127import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700128import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800129import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700130import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700131import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800132
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700133import java.io.FileDescriptor;
134import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800135import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800137import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800138import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100139import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141
142/**
143 * Implementation of the ITelephony interface.
144 */
Santos Cordon117fee72014-05-16 17:56:12 -0700145public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 private static final String LOG_TAG = "PhoneInterfaceManager";
147 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
148 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800149 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150
151 // Message codes used with mMainThreadHandler
152 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700153 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
154 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155 private static final int CMD_OPEN_CHANNEL = 9;
156 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
157 private static final int CMD_CLOSE_CHANNEL = 11;
158 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800159 private static final int CMD_NV_READ_ITEM = 13;
160 private static final int EVENT_NV_READ_ITEM_DONE = 14;
161 private static final int CMD_NV_WRITE_ITEM = 15;
162 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
163 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
164 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
165 private static final int CMD_NV_RESET_CONFIG = 19;
166 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800167 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
168 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
169 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
170 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800171 private static final int CMD_SEND_ENVELOPE = 25;
172 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000173 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
174 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700175 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
176 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
177 private static final int CMD_EXCHANGE_SIM_IO = 31;
178 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800179 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
180 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700181 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
182 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700183 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
184 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700185 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
186 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
187 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
188 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700189 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
190 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
191 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
192 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700193 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800194 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
195 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000196 private static final int CMD_SWITCH_SLOTS = 50;
197 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700198 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
199 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
200 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
201 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
202 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
203 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
204 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
205 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700206 private static final int CMD_GET_ALL_CELL_INFO = 60;
207 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
208 private static final int CMD_GET_CELL_LOCATION = 62;
209 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700210
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800211 // Parameters of select command.
212 private static final int SELECT_COMMAND = 0xA4;
213 private static final int SELECT_P1 = 0x04;
214 private static final int SELECT_P2 = 0;
215 private static final int SELECT_P3 = 0x10;
216
Pengquan Meng85728fb2018-03-12 16:31:21 -0700217 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
218 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
219 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
220
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221 /** The singleton instance. */
222 private static PhoneInterfaceManager sInstance;
223
Wink Saville3ab207e2014-11-20 13:07:20 -0800224 private PhoneGlobals mApp;
225 private Phone mPhone;
226 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700227 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800228 private AppOpsManager mAppOps;
229 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800230 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800231 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700232 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233
Derek Tan97ebb422014-09-05 16:55:38 -0700234 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
235 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700237
Derek Tan740e1672017-06-27 14:56:27 -0700238 // The AID of ISD-R.
239 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
240
yinxub1bed742017-04-17 11:45:04 -0700241 private NetworkScanRequestTracker mNetworkScanRequestTracker;
242
David Kelly5e06a7f2018-03-12 14:10:59 +0000243 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
244 private static final int MANUFACTURER_CODE_LENGTH = 8;
245
Derek Tan89e89d42014-07-08 17:00:10 -0700246 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700247 * A request object to use for transmitting data to an ICC.
248 */
249 private static final class IccAPDUArgument {
250 public int channel, cla, command, p1, p2, p3;
251 public String data;
252
253 public IccAPDUArgument(int channel, int cla, int command,
254 int p1, int p2, int p3, String data) {
255 this.channel = channel;
256 this.cla = cla;
257 this.command = command;
258 this.p1 = p1;
259 this.p2 = p2;
260 this.p3 = p3;
261 this.data = data;
262 }
263 }
264
265 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700266 * A request object to use for transmitting data to an ICC.
267 */
268 private static final class ManualNetworkSelectionArgument {
269 public OperatorInfo operatorInfo;
270 public boolean persistSelection;
271
272 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
273 this.operatorInfo = operatorInfo;
274 this.persistSelection = persistSelection;
275 }
276 }
277
278 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
280 * request after sending. The main thread will notify the request when it is complete.
281 */
282 private static final class MainThreadRequest {
283 /** The argument to use for the request */
284 public Object argument;
285 /** The result of the request that is run on the main thread */
286 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800287 // The subscriber id that this request applies to. Defaults to
288 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
289 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
vagdevie435a3e2018-08-15 16:01:53 -0700291 public WorkSource workSource;
292
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293 public MainThreadRequest(Object argument) {
294 this.argument = argument;
295 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800296
vagdevie435a3e2018-08-15 16:01:53 -0700297 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800298 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800299 if (subId != null) {
300 this.subId = subId;
301 }
vagdevie435a3e2018-08-15 16:01:53 -0700302 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304 }
305
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800306 private static final class IncomingThirdPartyCallArgs {
307 public final ComponentName component;
308 public final String callId;
309 public final String callerDisplayName;
310
311 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
312 String callerDisplayName) {
313 this.component = component;
314 this.callId = callId;
315 this.callerDisplayName = callerDisplayName;
316 }
317 }
318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 /**
320 * A handler that processes messages on the main thread in the phone process. Since many
321 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
322 * inbound binder threads to the main thread in the phone process. The Binder thread
323 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
324 * on, which will be notified when the operation completes and will contain the result of the
325 * request.
326 *
327 * <p>If a MainThreadRequest object is provided in the msg.obj field,
328 * note that request.result must be set to something non-null for the calling thread to
329 * unblock.
330 */
331 private final class MainThreadHandler extends Handler {
332 @Override
333 public void handleMessage(Message msg) {
334 MainThreadRequest request;
335 Message onCompleted;
336 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800337 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700338 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339
340 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700341 case CMD_HANDLE_USSD_REQUEST: {
342 request = (MainThreadRequest) msg.obj;
343 final Phone phone = getPhoneFromRequest(request);
344 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
345 String ussdRequest = ussdObject.first;
346 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700347
Pengquan Meng0c05b502018-09-06 09:59:22 -0700348 if (!isUssdApiAllowed(request.subId)) {
349 // Carrier does not support use of this API, return failure.
350 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
351 UssdResponse response = new UssdResponse(ussdRequest, null);
352 Bundle returnData = new Bundle();
353 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
354 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700355
Pengquan Meng0c05b502018-09-06 09:59:22 -0700356 request.result = true;
357 notifyRequester(request);
358 return;
359 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700360
Pengquan Meng0c05b502018-09-06 09:59:22 -0700361 try {
362 request.result = phone != null
363 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
364 } catch (CallStateException cse) {
365 request.result = false;
366 }
367 // Wake up the requesting thread
368 notifyRequester(request);
369 break;
pkanwar32d516d2016-10-14 19:37:38 -0700370 }
371
Yorke Lee716f67e2015-06-17 15:39:16 -0700372 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700374 final Phone phone = getPhoneFromRequest(request);
375 request.result = phone != null ?
376 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
377 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700379 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700383 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700384 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700385 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800386 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700387 if (uiccCard == null) {
388 loge("iccTransmitApduLogicalChannel: No UICC");
389 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700390 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700391 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700392 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
393 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700394 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700395 iccArgument.channel, iccArgument.cla, iccArgument.command,
396 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700397 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700398 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700399 break;
400
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700402 ar = (AsyncResult) msg.obj;
403 request = (MainThreadRequest) ar.userObj;
404 if (ar.exception == null && ar.result != null) {
405 request.result = ar.result;
406 } else {
407 request.result = new IccIoResult(0x6F, 0, (byte[])null);
408 if (ar.result == null) {
409 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800410 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700411 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800412 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700413 } else {
414 loge("iccTransmitApduLogicalChannel: Unknown exception");
415 }
416 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700417 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 break;
419
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
421 request = (MainThreadRequest) msg.obj;
422 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800423 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 if (uiccCard == null) {
425 loge("iccTransmitApduBasicChannel: No UICC");
426 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700427 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 } else {
429 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
430 request);
431 uiccCard.iccTransmitApduBasicChannel(
432 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
433 iccArgument.p3, iccArgument.data, onCompleted);
434 }
435 break;
436
437 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
438 ar = (AsyncResult) msg.obj;
439 request = (MainThreadRequest) ar.userObj;
440 if (ar.exception == null && ar.result != null) {
441 request.result = ar.result;
442 } else {
443 request.result = new IccIoResult(0x6F, 0, (byte[])null);
444 if (ar.result == null) {
445 loge("iccTransmitApduBasicChannel: Empty response");
446 } else if (ar.exception instanceof CommandException) {
447 loge("iccTransmitApduBasicChannel: CommandException: " +
448 ar.exception);
449 } else {
450 loge("iccTransmitApduBasicChannel: Unknown exception");
451 }
452 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 break;
455
456 case CMD_EXCHANGE_SIM_IO:
457 request = (MainThreadRequest) msg.obj;
458 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800459 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 if (uiccCard == null) {
461 loge("iccExchangeSimIO: No UICC");
462 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700463 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 } else {
465 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
466 request);
467 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
468 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
469 iccArgument.data, onCompleted);
470 }
471 break;
472
473 case EVENT_EXCHANGE_SIM_IO_DONE:
474 ar = (AsyncResult) msg.obj;
475 request = (MainThreadRequest) ar.userObj;
476 if (ar.exception == null && ar.result != null) {
477 request.result = ar.result;
478 } else {
479 request.result = new IccIoResult(0x6f, 0, (byte[])null);
480 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 break;
483
Derek Tan4d5e5c12014-02-04 11:54:58 -0800484 case CMD_SEND_ENVELOPE:
485 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700487 if (uiccCard == null) {
488 loge("sendEnvelopeWithStatus: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 } else {
492 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
493 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
494 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800495 break;
496
497 case EVENT_SEND_ENVELOPE_DONE:
498 ar = (AsyncResult) msg.obj;
499 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700500 if (ar.exception == null && ar.result != null) {
501 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800502 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700503 request.result = new IccIoResult(0x6F, 0, (byte[])null);
504 if (ar.result == null) {
505 loge("sendEnvelopeWithStatus: Empty response");
506 } else if (ar.exception instanceof CommandException) {
507 loge("sendEnvelopeWithStatus: CommandException: " +
508 ar.exception);
509 } else {
510 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
511 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800512 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700513 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800514 break;
515
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 case CMD_OPEN_CHANNEL:
517 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800519 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700520 if (uiccCard == null) {
521 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800522 request.result = new IccOpenLogicalChannelResponse(-1,
523 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700524 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700525 } else {
526 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800527 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
528 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 break;
531
532 case EVENT_OPEN_CHANNEL_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700536 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 int[] result = (int[]) ar.result;
538 int channelId = result[0];
539 byte[] selectResponse = null;
540 if (result.length > 1) {
541 selectResponse = new byte[result.length - 1];
542 for (int i = 1; i < result.length; ++i) {
543 selectResponse[i - 1] = (byte) result[i];
544 }
545 }
546 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700547 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 if (ar.result == null) {
550 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 if (ar.exception != null) {
553 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
554 }
555
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700556 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700557 if (ar.exception instanceof CommandException) {
558 CommandException.Error error =
559 ((CommandException) (ar.exception)).getCommandError();
560 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700561 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700562 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700563 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 }
565 }
566 openChannelResp = new IccOpenLogicalChannelResponse(
567 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700569 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700570 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 break;
572
573 case CMD_CLOSE_CHANNEL:
574 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800575 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 if (uiccCard == null) {
577 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900578 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 } else {
581 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
582 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
583 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 break;
585
586 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800587 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
588 break;
589
590 case CMD_NV_READ_ITEM:
591 request = (MainThreadRequest) msg.obj;
592 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700593 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800594 break;
595
596 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 ar = (AsyncResult) msg.obj;
598 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800599 if (ar.exception == null && ar.result != null) {
600 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800602 request.result = "";
603 if (ar.result == null) {
604 loge("nvReadItem: Empty response");
605 } else if (ar.exception instanceof CommandException) {
606 loge("nvReadItem: CommandException: " +
607 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800609 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 }
611 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 break;
614
Jake Hambye994d462014-02-03 13:10:13 -0800615 case CMD_NV_WRITE_ITEM:
616 request = (MainThreadRequest) msg.obj;
617 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
618 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700619 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
620 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800621 break;
622
623 case EVENT_NV_WRITE_ITEM_DONE:
624 handleNullReturnEvent(msg, "nvWriteItem");
625 break;
626
627 case CMD_NV_WRITE_CDMA_PRL:
628 request = (MainThreadRequest) msg.obj;
629 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
630 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
631 break;
632
633 case EVENT_NV_WRITE_CDMA_PRL_DONE:
634 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
635 break;
636
637 case CMD_NV_RESET_CONFIG:
638 request = (MainThreadRequest) msg.obj;
639 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
640 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
641 break;
642
643 case EVENT_NV_RESET_CONFIG_DONE:
644 handleNullReturnEvent(msg, "nvResetConfig");
645 break;
646
Jake Hamby7c27be32014-03-03 13:25:59 -0800647 case CMD_GET_PREFERRED_NETWORK_TYPE:
648 request = (MainThreadRequest) msg.obj;
649 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700650 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800651 break;
652
653 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result; // Integer
658 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800659 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800660 if (ar.result == null) {
661 loge("getPreferredNetworkType: Empty response");
662 } else if (ar.exception instanceof CommandException) {
663 loge("getPreferredNetworkType: CommandException: " +
664 ar.exception);
665 } else {
666 loge("getPreferredNetworkType: Unknown exception");
667 }
668 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700669 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800670 break;
671
672 case CMD_SET_PREFERRED_NETWORK_TYPE:
673 request = (MainThreadRequest) msg.obj;
674 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
675 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700676 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800677 break;
678
679 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
680 handleNullReturnEvent(msg, "setPreferredNetworkType");
681 break;
682
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000683 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
684 request = (MainThreadRequest)msg.obj;
685 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700686 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000687 break;
688
689 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
690 ar = (AsyncResult)msg.obj;
691 request = (MainThreadRequest)ar.userObj;
692 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700693 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000694 break;
695
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800696 case CMD_SET_VOICEMAIL_NUMBER:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
699 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800700 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
701 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800702 break;
703
704 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
705 handleNullReturnEvent(msg, "setVoicemailNumber");
706 break;
707
Stuart Scott54788802015-03-30 13:18:01 -0700708 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
711 request);
712 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
713 break;
714
715 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
716 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
717 break;
718
Shishir Agrawal302c8692015-06-19 13:49:39 -0700719 case CMD_PERFORM_NETWORK_SCAN:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
722 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
723 break;
724
725 case EVENT_PERFORM_NETWORK_SCAN_DONE:
726 ar = (AsyncResult) msg.obj;
727 request = (MainThreadRequest) ar.userObj;
728 CellNetworkScanResult cellScanResult;
729 if (ar.exception == null && ar.result != null) {
730 cellScanResult = new CellNetworkScanResult(
731 CellNetworkScanResult.STATUS_SUCCESS,
732 (List<OperatorInfo>) ar.result);
733 } else {
734 if (ar.result == null) {
735 loge("getCellNetworkScanResults: Empty response");
736 }
737 if (ar.exception != null) {
738 loge("getCellNetworkScanResults: Exception: " + ar.exception);
739 }
740 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
741 if (ar.exception instanceof CommandException) {
742 CommandException.Error error =
743 ((CommandException) (ar.exception)).getCommandError();
744 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
745 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
746 } else if (error == CommandException.Error.GENERIC_FAILURE) {
747 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
748 }
749 }
750 cellScanResult = new CellNetworkScanResult(errorCode, null);
751 }
752 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700753 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700754 break;
755
756 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
757 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700758 ManualNetworkSelectionArgument selArg =
759 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700760 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
761 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700762 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
763 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700764 break;
765
766 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
767 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
768 break;
769
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700770 case CMD_GET_MODEM_ACTIVITY_INFO:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700773 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700774 break;
775
776 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
779 if (ar.exception == null && ar.result != null) {
780 request.result = ar.result;
781 } else {
782 if (ar.result == null) {
783 loge("queryModemActivityInfo: Empty response");
784 } else if (ar.exception instanceof CommandException) {
785 loge("queryModemActivityInfo: CommandException: " +
786 ar.exception);
787 } else {
788 loge("queryModemActivityInfo: Unknown exception");
789 }
790 }
Amit Mahajand4766222016-01-28 15:28:28 -0800791 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
792 if (request.result == null) {
793 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
794 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700795 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700796 break;
797
Meng Wang1a7c35a2016-05-05 20:56:15 -0700798 case CMD_SET_ALLOWED_CARRIERS:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
801 mPhone.setAllowedCarriers(
802 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700803 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700804 break;
805
806 case EVENT_SET_ALLOWED_CARRIERS_DONE:
807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null && ar.result != null) {
810 request.result = ar.result;
811 } else {
812 if (ar.result == null) {
813 loge("setAllowedCarriers: Empty response");
814 } else if (ar.exception instanceof CommandException) {
815 loge("setAllowedCarriers: CommandException: " +
816 ar.exception);
817 } else {
818 loge("setAllowedCarriers: Unknown exception");
819 }
820 }
821 // Result cannot be null. Return -1 on error.
822 if (request.result == null) {
823 request.result = new int[]{-1};
824 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700825 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700826 break;
827
828 case CMD_GET_ALLOWED_CARRIERS:
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700831 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700832 break;
833
834 case EVENT_GET_ALLOWED_CARRIERS_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result;
839 } else {
840 if (ar.result == null) {
841 loge("getAllowedCarriers: Empty response");
842 } else if (ar.exception instanceof CommandException) {
843 loge("getAllowedCarriers: CommandException: " +
844 ar.exception);
845 } else {
846 loge("getAllowedCarriers: Unknown exception");
847 }
848 }
849 // Result cannot be null. Return empty list of CarrierIdentifier.
850 if (request.result == null) {
851 request.result = new ArrayList<CarrierIdentifier>(0);
852 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700853 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700854 break;
855
Nathan Haroldb3014052017-01-25 15:57:32 -0800856 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
857 ar = (AsyncResult) msg.obj;
858 request = (MainThreadRequest) ar.userObj;
859 if (ar.exception == null && ar.result != null) {
860 request.result = ar.result;
861 } else {
862 request.result = new IllegalArgumentException(
863 "Failed to retrieve Forbidden Plmns");
864 if (ar.result == null) {
865 loge("getForbiddenPlmns: Empty response");
866 } else {
867 loge("getForbiddenPlmns: Unknown exception");
868 }
869 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700870 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800871 break;
872
873 case CMD_GET_FORBIDDEN_PLMNS:
874 request = (MainThreadRequest) msg.obj;
875 uiccCard = getUiccCardFromRequest(request);
876 if (uiccCard == null) {
877 loge("getForbiddenPlmns() UiccCard is null");
878 request.result = new IllegalArgumentException(
879 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700880 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800881 break;
882 }
883 Integer appType = (Integer) request.argument;
884 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
885 if (uiccApp == null) {
886 loge("getForbiddenPlmns() no app with specified type -- "
887 + appType);
888 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700889 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800890 break;
891 } else {
892 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
893 + " specified type -- " + appType);
894 }
895 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
896 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
897 onCompleted);
898 break;
899
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000900 case CMD_SWITCH_SLOTS:
901 request = (MainThreadRequest) msg.obj;
902 int[] physicalSlots = (int[]) request.argument;
903 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
904 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
905 break;
906
907 case EVENT_SWITCH_SLOTS_DONE:
908 ar = (AsyncResult) msg.obj;
909 request = (MainThreadRequest) ar.userObj;
910 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700911 notifyRequester(request);
912 break;
913 case CMD_GET_NETWORK_SELECTION_MODE:
914 request = (MainThreadRequest) msg.obj;
915 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
916 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
917 break;
918
919 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
920 ar = (AsyncResult) msg.obj;
921 request = (MainThreadRequest) ar.userObj;
922 if (ar.exception != null) {
923 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
924 } else {
925 int mode = ((int[]) ar.result)[0];
926 if (mode == 0) {
927 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
928 } else {
929 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
930 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000931 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700932 notifyRequester(request);
933 break;
934 case CMD_GET_CDMA_ROAMING_MODE:
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
937 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
938 break;
939 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
940 ar = (AsyncResult) msg.obj;
941 request = (MainThreadRequest) ar.userObj;
942 if (ar.exception != null) {
943 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
944 } else {
945 request.result = ((int[]) ar.result)[0];
946 }
947 notifyRequester(request);
948 break;
949 case CMD_SET_CDMA_ROAMING_MODE:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
952 int mode = (int) request.argument;
953 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
954 break;
955 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
956 ar = (AsyncResult) msg.obj;
957 request = (MainThreadRequest) ar.userObj;
958 request.result = ar.exception == null;
959 notifyRequester(request);
960 break;
961 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
964 int subscriptionMode = (int) request.argument;
965 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
966 break;
967 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
970 request.result = ar.exception == null;
971 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000972 break;
973
Nathan Harold3ff88932018-08-14 10:19:49 -0700974 case CMD_GET_ALL_CELL_INFO:
975 request = (MainThreadRequest) msg.obj;
976 Pair<Phone, WorkSource> args = (Pair<Phone, WorkSource>) request.argument;
977 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
978 ((Phone) args.first).getAllCellInfo(args.second, onCompleted);
979 break;
980
981 case EVENT_GET_ALL_CELL_INFO_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 request.result = (ar.exception == null) ? ar.result : new ArrayList<CellInfo>();
985 synchronized (request) {
986 request.notifyAll();
987 }
988 break;
989
990 case CMD_GET_CELL_LOCATION: {
991 request = (MainThreadRequest) msg.obj;
992 WorkSource ws = (WorkSource) request.argument;
993 Phone phone = getPhoneFromRequest(request);
994 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
995 break;
996 }
997
998 case EVENT_GET_CELL_LOCATION_DONE: {
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null) {
1002 request.result = ar.result;
1003 } else {
1004 Phone phone = getPhoneFromRequest(request);
1005 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1006 ? new CdmaCellLocation() : new GsmCellLocation();
1007 }
1008
1009 synchronized (request) {
1010 request.notifyAll();
1011 }
1012 break;
1013 }
1014
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001015 default:
1016 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1017 break;
1018 }
1019 }
Jake Hambye994d462014-02-03 13:10:13 -08001020
Pengquan Meng0c05b502018-09-06 09:59:22 -07001021 private void notifyRequester(MainThreadRequest request) {
1022 synchronized (request) {
1023 request.notifyAll();
1024 }
1025 }
1026
Jake Hambye994d462014-02-03 13:10:13 -08001027 private void handleNullReturnEvent(Message msg, String command) {
1028 AsyncResult ar = (AsyncResult) msg.obj;
1029 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception == null) {
1031 request.result = true;
1032 } else {
1033 request.result = false;
1034 if (ar.exception instanceof CommandException) {
1035 loge(command + ": CommandException: " + ar.exception);
1036 } else {
1037 loge(command + ": Unknown exception");
1038 }
1039 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001040 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001042 }
1043
1044 /**
1045 * Posts the specified command to be executed on the main thread,
1046 * waits for the request to complete, and returns the result.
1047 * @see #sendRequestAsync
1048 */
1049 private Object sendRequest(int command, Object argument) {
vagdevie435a3e2018-08-15 16:01:53 -07001050 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1051 }
1052
1053 /**
1054 * Posts the specified command to be executed on the main thread,
1055 * waits for the request to complete, and returns the result.
1056 * @see #sendRequestAsync
1057 */
1058 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1059 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1060 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001061 }
1062
1063 /**
1064 * Posts the specified command to be executed on the main thread,
1065 * waits for the request to complete, and returns the result.
1066 * @see #sendRequestAsync
1067 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001068 private Object sendRequest(int command, Object argument, Integer subId) {
vagdevie435a3e2018-08-15 16:01:53 -07001069 return sendRequest(command, argument, subId, null);
1070 }
1071
1072 /**
1073 * Posts the specified command to be executed on the main thread,
1074 * waits for the request to complete, and returns the result.
1075 * @see #sendRequestAsync
1076 */
1077 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1079 throw new RuntimeException("This method will deadlock if called from the main thread.");
1080 }
1081
vagdevie435a3e2018-08-15 16:01:53 -07001082 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 Message msg = mMainThreadHandler.obtainMessage(command, request);
1084 msg.sendToTarget();
1085
1086 // Wait for the request to complete
1087 synchronized (request) {
1088 while (request.result == null) {
1089 try {
1090 request.wait();
1091 } catch (InterruptedException e) {
1092 // Do nothing, go back and wait until the request is complete
1093 }
1094 }
1095 }
1096 return request.result;
1097 }
1098
1099 /**
1100 * Asynchronous ("fire and forget") version of sendRequest():
1101 * Posts the specified command to be executed on the main thread, and
1102 * returns immediately.
1103 * @see #sendRequest
1104 */
1105 private void sendRequestAsync(int command) {
1106 mMainThreadHandler.sendEmptyMessage(command);
1107 }
1108
1109 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001110 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1111 * @see {@link #sendRequest(int,Object)}
1112 */
1113 private void sendRequestAsync(int command, Object argument) {
1114 MainThreadRequest request = new MainThreadRequest(argument);
1115 Message msg = mMainThreadHandler.obtainMessage(command, request);
1116 msg.sendToTarget();
1117 }
1118
1119 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001120 * Initialize the singleton PhoneInterfaceManager instance.
1121 * This is only done once, at startup, from PhoneApp.onCreate().
1122 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001123 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001124 synchronized (PhoneInterfaceManager.class) {
1125 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001126 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001127 } else {
1128 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1129 }
1130 return sInstance;
1131 }
1132 }
1133
1134 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001135 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 mApp = app;
1137 mPhone = phone;
1138 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001139 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1141 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001142 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001143 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001144 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001145 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001146 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001147
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 publish();
1149 }
1150
1151 private void publish() {
1152 if (DBG) log("publish: " + this);
1153
1154 ServiceManager.addService("phone", this);
1155 }
1156
Stuart Scott584921c2015-01-15 17:10:34 -08001157 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001158 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1159 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001160 }
1161
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001162 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1163 Phone phone = getPhoneFromRequest(request);
1164 return phone == null ? null :
1165 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1166 }
1167
Wink Saville36469e72014-06-11 15:17:00 -07001168 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001169 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001170 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172
1173 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001174 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001175 }
1176
Wink Savilleb564aae2014-10-23 10:18:09 -07001177 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001178 if (DBG) log("dial: " + number);
1179 // No permission check needed here: This is just a wrapper around the
1180 // ACTION_DIAL intent, which is available to any app since it puts up
1181 // the UI before it does anything.
1182
Malcolm Chenaabec062018-02-28 15:00:40 -08001183 final long identity = Binder.clearCallingIdentity();
1184 try {
1185 String url = createTelUrl(number);
1186 if (url == null) {
1187 return;
1188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189
Malcolm Chenaabec062018-02-28 15:00:40 -08001190 // PENDING: should we just silently fail if phone is offhook or ringing?
1191 PhoneConstants.State state = mCM.getState(subId);
1192 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1193 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1194 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1195 mApp.startActivity(intent);
1196 }
1197 } finally {
1198 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 }
1200 }
1201
1202 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001203 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001204 }
1205
Wink Savilleb564aae2014-10-23 10:18:09 -07001206 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 if (DBG) log("call: " + number);
1208
1209 // This is just a wrapper around the ACTION_CALL intent, but we still
1210 // need to do a permission check since we're calling startActivity()
1211 // from the context of the phone app.
1212 enforceCallPermission();
1213
1214 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1215 != AppOpsManager.MODE_ALLOWED) {
1216 return;
1217 }
1218
Malcolm Chenaabec062018-02-28 15:00:40 -08001219 final long identity = Binder.clearCallingIdentity();
1220 try {
1221 String url = createTelUrl(number);
1222 if (url == null) {
1223 return;
1224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225
Malcolm Chenaabec062018-02-28 15:00:40 -08001226 boolean isValid = false;
1227 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1228 if (slist != null) {
1229 for (SubscriptionInfo subInfoRecord : slist) {
1230 if (subInfoRecord.getSubscriptionId() == subId) {
1231 isValid = true;
1232 break;
1233 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001234 }
Wink Saville08874612014-08-31 19:19:58 -07001235 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001236 if (!isValid) {
1237 return;
1238 }
Wink Saville08874612014-08-31 19:19:58 -07001239
Malcolm Chenaabec062018-02-28 15:00:40 -08001240 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1241 intent.putExtra(SUBSCRIPTION_KEY, subId);
1242 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1243 mApp.startActivity(intent);
1244 } finally {
1245 Binder.restoreCallingIdentity(identity);
1246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 }
1248
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 /**
1250 * End a call based on call state
1251 * @return true is a call was ended
1252 */
1253 public boolean endCall() {
Hall Liu91943182018-09-14 17:42:41 -07001254 return false;
Wink Saville36469e72014-06-11 15:17:00 -07001255 }
1256
1257 /**
1258 * End a call based on the call state of the subId
1259 * @return true is a call was ended
1260 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001261 public boolean endCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001262 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 }
1264
1265 public void answerRingingCall() {
Hall Liu91943182018-09-14 17:42:41 -07001266 // Deprecated.
Wink Saville36469e72014-06-11 15:17:00 -07001267 }
1268
Wink Savilleb564aae2014-10-23 10:18:09 -07001269 public void answerRingingCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001270 // Deprecated
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271 }
1272
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001274 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001275 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001276 public void silenceRinger() {
1277 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 }
1279
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001280 @Override
1281 public boolean isOffhook(String callingPackage) {
1282 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001283 }
1284
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001285 @Override
1286 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001288 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001289 return false;
1290 }
1291
Malcolm Chenaabec062018-02-28 15:00:40 -08001292 final long identity = Binder.clearCallingIdentity();
1293 try {
1294 final Phone phone = getPhone(subId);
1295 if (phone != null) {
1296 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1297 } else {
1298 return false;
1299 }
1300 } finally {
1301 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 }
1304
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001305 @Override
1306 public boolean isRinging(String callingPackage) {
1307 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001308 }
1309
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001310 @Override
1311 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001313 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001314 return false;
1315 }
1316
Malcolm Chenaabec062018-02-28 15:00:40 -08001317 final long identity = Binder.clearCallingIdentity();
1318 try {
1319 final Phone phone = getPhone(subId);
1320 if (phone != null) {
1321 return (phone.getState() == PhoneConstants.State.RINGING);
1322 } else {
1323 return false;
1324 }
1325 } finally {
1326 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 }
1329
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001330 @Override
1331 public boolean isIdle(String callingPackage) {
1332 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001333 }
1334
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001335 @Override
1336 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001338 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001339 return false;
1340 }
1341
Malcolm Chenaabec062018-02-28 15:00:40 -08001342 final long identity = Binder.clearCallingIdentity();
1343 try {
1344 final Phone phone = getPhone(subId);
1345 if (phone != null) {
1346 return (phone.getState() == PhoneConstants.State.IDLE);
1347 } else {
1348 return false;
1349 }
1350 } finally {
1351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001353 }
1354
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001355 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001357 }
1358
Wink Savilleb564aae2014-10-23 10:18:09 -07001359 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001360 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001361 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1362 }
1363
1364 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001365 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001366 }
1367
Wink Savilleb564aae2014-10-23 10:18:09 -07001368 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001369 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001370 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1371 }
1372
1373 /** {@hide} */
1374 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001380
1381 final long identity = Binder.clearCallingIdentity();
1382 try {
1383 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1384 checkSimPin.start();
1385 return checkSimPin.unlockSim(null, pin);
1386 } finally {
1387 Binder.restoreCallingIdentity(identity);
1388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389 }
1390
Wink Saville9de0f752013-10-22 19:04:03 -07001391 /** {@hide} */
1392 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001393 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001394 }
1395
Wink Savilleb564aae2014-10-23 10:18:09 -07001396 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001398
1399 final long identity = Binder.clearCallingIdentity();
1400 try {
1401 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1402 checkSimPuk.start();
1403 return checkSimPuk.unlockSim(puk, pin);
1404 } finally {
1405 Binder.restoreCallingIdentity(identity);
1406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 }
1408
1409 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001410 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 * a synchronous one.
1412 */
1413 private static class UnlockSim extends Thread {
1414
1415 private final IccCard mSimCard;
1416
1417 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001418 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1419 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420
1421 // For replies from SimCard interface
1422 private Handler mHandler;
1423
1424 // For async handler to identify request type
1425 private static final int SUPPLY_PIN_COMPLETE = 100;
1426
1427 public UnlockSim(IccCard simCard) {
1428 mSimCard = simCard;
1429 }
1430
1431 @Override
1432 public void run() {
1433 Looper.prepare();
1434 synchronized (UnlockSim.this) {
1435 mHandler = new Handler() {
1436 @Override
1437 public void handleMessage(Message msg) {
1438 AsyncResult ar = (AsyncResult) msg.obj;
1439 switch (msg.what) {
1440 case SUPPLY_PIN_COMPLETE:
1441 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1442 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001443 mRetryCount = msg.arg1;
1444 if (ar.exception != null) {
1445 if (ar.exception instanceof CommandException &&
1446 ((CommandException)(ar.exception)).getCommandError()
1447 == CommandException.Error.PASSWORD_INCORRECT) {
1448 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1449 } else {
1450 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1451 }
1452 } else {
1453 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 mDone = true;
1456 UnlockSim.this.notifyAll();
1457 }
1458 break;
1459 }
1460 }
1461 };
1462 UnlockSim.this.notifyAll();
1463 }
1464 Looper.loop();
1465 }
1466
1467 /*
1468 * Use PIN or PUK to unlock SIM card
1469 *
1470 * If PUK is null, unlock SIM card with PIN
1471 *
1472 * If PUK is not null, unlock SIM card with PUK and set PIN code
1473 */
Wink Saville9de0f752013-10-22 19:04:03 -07001474 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475
1476 while (mHandler == null) {
1477 try {
1478 wait();
1479 } catch (InterruptedException e) {
1480 Thread.currentThread().interrupt();
1481 }
1482 }
1483 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1484
1485 if (puk == null) {
1486 mSimCard.supplyPin(pin, callback);
1487 } else {
1488 mSimCard.supplyPuk(puk, pin, callback);
1489 }
1490
1491 while (!mDone) {
1492 try {
1493 Log.d(LOG_TAG, "wait for done");
1494 wait();
1495 } catch (InterruptedException e) {
1496 // Restore the interrupted status
1497 Thread.currentThread().interrupt();
1498 }
1499 }
1500 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001501 int[] resultArray = new int[2];
1502 resultArray[0] = mResult;
1503 resultArray[1] = mRetryCount;
1504 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 }
1506 }
1507
1508 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001509 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001510
1511 }
1512
Wink Savilleb564aae2014-10-23 10:18:09 -07001513 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514 // No permission check needed here: this call is harmless, and it's
1515 // needed for the ServiceState.requestStateUpdate() call (which is
1516 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001517 final long identity = Binder.clearCallingIdentity();
1518 try {
1519 final Phone phone = getPhone(subId);
1520 if (phone != null) {
1521 phone.updateServiceLocation();
1522 }
1523 } finally {
1524 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 }
1527
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001528 @Override
1529 public boolean isRadioOn(String callingPackage) {
1530 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001531 }
1532
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001533 @Override
1534 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001536 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001537 return false;
1538 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001539
1540 final long identity = Binder.clearCallingIdentity();
1541 try {
1542 return isRadioOnForSubscriber(subId);
1543 } finally {
1544 Binder.restoreCallingIdentity(identity);
1545 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001546 }
1547
1548 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001549 final long identity = Binder.clearCallingIdentity();
1550 try {
1551 final Phone phone = getPhone(subId);
1552 if (phone != null) {
1553 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1554 } else {
1555 return false;
1556 }
1557 } finally {
1558 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 }
1561
1562 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001563 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
Wink Saville36469e72014-06-11 15:17:00 -07001565
Wink Savilleb564aae2014-10-23 10:18:09 -07001566 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001568
1569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 final Phone phone = getPhone(subId);
1572 if (phone != null) {
1573 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1574 }
1575 } finally {
1576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001577 }
Wink Saville36469e72014-06-11 15:17:00 -07001578 }
1579
1580 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001581 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001582 }
1583
Wink Savilleb564aae2014-10-23 10:18:09 -07001584 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001585 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001586
1587 final long identity = Binder.clearCallingIdentity();
1588 try {
1589 final Phone phone = getPhone(subId);
1590 if (phone == null) {
1591 return false;
1592 }
1593 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1594 toggleRadioOnOffForSubscriber(subId);
1595 }
1596 return true;
1597 } finally {
1598 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
Wink Saville36469e72014-06-11 15:17:00 -07001601
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001602 public boolean needMobileRadioShutdown() {
1603 /*
1604 * If any of the Radios are available, it will need to be
1605 * shutdown. So return true if any Radio is available.
1606 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001607 final long identity = Binder.clearCallingIdentity();
1608 try {
1609 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1610 Phone phone = PhoneFactory.getPhone(i);
1611 if (phone != null && phone.isRadioAvailable()) return true;
1612 }
1613 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1614 return false;
1615 } finally {
1616 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001617 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001618 }
1619
Malcolm Chenaabec062018-02-28 15:00:40 -08001620 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001621 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001622 enforceModifyPermission();
1623
1624 final long identity = Binder.clearCallingIdentity();
1625 try {
1626 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1627 logv("Shutting down Phone " + i);
1628 shutdownRadioUsingPhoneId(i);
1629 }
1630 } finally {
1631 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001632 }
1633 }
1634
1635 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001636 Phone phone = PhoneFactory.getPhone(phoneId);
1637 if (phone != null && phone.isRadioAvailable()) {
1638 phone.shutdownRadio();
1639 }
1640 }
1641
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001643 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001644
1645 final long identity = Binder.clearCallingIdentity();
1646 try {
1647 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1648 if (defaultPhone != null) {
1649 defaultPhone.setRadioPower(turnOn);
1650 return true;
1651 } else {
1652 loge("There's no default phone.");
1653 return false;
1654 }
1655 } finally {
1656 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001657 }
Wink Saville36469e72014-06-11 15:17:00 -07001658 }
1659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001662
1663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 final Phone phone = getPhone(subId);
1666 if (phone != null) {
1667 phone.setRadioPower(turnOn);
1668 return true;
1669 } else {
1670 return false;
1671 }
1672 } finally {
1673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 }
1676
Wink Saville36469e72014-06-11 15:17:00 -07001677 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001678 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 public boolean enableDataConnectivity() {
1680 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001681
1682 final long identity = Binder.clearCallingIdentity();
1683 try {
1684 int subId = mSubscriptionController.getDefaultDataSubId();
1685 final Phone phone = getPhone(subId);
1686 if (phone != null) {
1687 phone.setUserDataEnabled(true);
1688 return true;
1689 } else {
1690 return false;
1691 }
1692 } finally {
1693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 }
1696
Wink Saville36469e72014-06-11 15:17:00 -07001697 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 public boolean disableDataConnectivity() {
1700 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001701
1702 final long identity = Binder.clearCallingIdentity();
1703 try {
1704 int subId = mSubscriptionController.getDefaultDataSubId();
1705 final Phone phone = getPhone(subId);
1706 if (phone != null) {
1707 phone.setUserDataEnabled(false);
1708 return true;
1709 } else {
1710 return false;
1711 }
1712 } finally {
1713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 }
1716
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001718 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001719 final long identity = Binder.clearCallingIdentity();
1720 try {
1721 final Phone phone = getPhone(subId);
1722 if (phone != null) {
1723 return phone.isDataAllowed();
1724 } else {
1725 return false;
1726 }
1727 } finally {
1728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 }
1731
1732 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001733 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001734 }
1735
pkanwarae03a6b2016-11-06 20:37:09 -08001736 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001737 enforceCallPermission();
1738
1739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1742 return;
1743 }
1744 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1745 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
1748 }
pkanwar32d516d2016-10-14 19:37:38 -07001749 };
1750
Wink Savilleb564aae2014-10-23 10:18:09 -07001751 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001753
1754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1757 return false;
1758 }
1759 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
1764
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001766 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
1768
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001769 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001770 final long identity = Binder.clearCallingIdentity();
1771 try {
1772 Phone phone = PhoneFactory.getPhone(slotIndex);
1773 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1774 PhoneConstantConversions.convertCallState(phone.getState());
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
1777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Sanket Padawe356d7632015-06-22 14:03:32 -07001780 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001782 final long identity = Binder.clearCallingIdentity();
1783 try {
1784 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1785 if (phone != null) {
1786 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1787 } else {
1788 return PhoneConstantConversions.convertDataState(
1789 PhoneConstants.DataState.DISCONNECTED);
1790 }
1791 } finally {
1792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 }
1795
Sanket Padawe356d7632015-06-22 14:03:32 -07001796 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001798 final long identity = Binder.clearCallingIdentity();
1799 try {
1800 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1801 if (phone != null) {
1802 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1803 } else {
1804 return TelephonyManager.DATA_ACTIVITY_NONE;
1805 }
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
1811 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001812 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001813 mPhone.getContext().getSystemService(AppOpsManager.class)
1814 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001815 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001816 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001817 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 }
1819
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001820 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 if (DBG_LOC) log("getCellLocation: is active user");
1824 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001825 int subId = mSubscriptionController.getDefaultDataSubId();
1826 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1827 cl.fillInNotifierBundle(data);
Malcolm Chenaabec062018-02-28 15:00:40 -08001828 return data;
1829 } finally {
1830 Binder.restoreCallingIdentity(identity);
1831 }
Svetoslav64fad262015-04-14 14:35:21 -07001832 }
1833
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001835 public String getNetworkCountryIsoForPhone(int phoneId) {
1836 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1837 // registered cell info, so return a NULL country instead.
1838 final long identity = Binder.clearCallingIdentity();
1839 try {
1840 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001841 // Todo: fix this when we can get the actual cellular network info when the device
1842 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001843 if (TelephonyManager.NETWORK_TYPE_IWLAN
1844 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1845 return "";
1846 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001847 Phone phone = PhoneFactory.getPhone(phoneId);
1848 if (phone != null) {
1849 ServiceStateTracker sst = phone.getServiceStateTracker();
1850 if (sst != null) {
1851 LocaleTracker lt = sst.getLocaleTracker();
1852 if (lt != null) {
1853 return lt.getCurrentCountry();
1854 }
1855 }
1856 }
1857 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001858 } finally {
1859 Binder.restoreCallingIdentity(identity);
1860 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001861 }
1862
1863 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001865 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001866 }
1867
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001869 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 mApp.enforceCallingOrSelfPermission(
1871 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001872
1873 final long identity = Binder.clearCallingIdentity();
1874 try {
1875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
1877 phone.enableLocationUpdates();
1878 }
1879 } finally {
1880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 }
1883
1884 @Override
1885 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001886 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001887 }
1888
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001890 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 mApp.enforceCallingOrSelfPermission(
1892 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001893
1894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
1898 phone.disableLocationUpdates();
1899 }
1900 } finally {
1901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905 @Override
1906 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001907 public List<NeighboringCellInfo>
1908 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001909 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1910 throw new SecurityException(
1911 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1912 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001913
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1915 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1916 return null;
1917 }
Svetoslav64fad262015-04-14 14:35:21 -07001918
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001919 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920
Nathan Haroldf180aac2018-06-01 18:43:55 -07001921 List<CellInfo> info = getAllCellInfo(callingPackage);
1922 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923
Nathan Haroldf180aac2018-06-01 18:43:55 -07001924 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1925 for (CellInfo ci : info) {
1926 if (ci instanceof CellInfoGsm) {
1927 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1928 } else if (ci instanceof CellInfoWcdma) {
1929 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001932 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 }
1934
1935
1936 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001937 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001938 mPhone.getContext().getSystemService(AppOpsManager.class)
1939 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001940 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001941 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001942 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001945 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001946 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001947 final long identity = Binder.clearCallingIdentity();
1948 try {
1949 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1950 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001951 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1952 CMD_GET_ALL_CELL_INFO,
1953 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaabec062018-02-28 15:00:40 -08001954 if (info != null) cellInfos.addAll(info);
1955 }
1956 return cellInfos;
1957 } finally {
1958 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 }
1960 }
1961
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001962 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001964 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001965 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001966
1967 final long identity = Binder.clearCallingIdentity();
1968 try {
1969 mPhone.setCellInfoListRate(rateInMillis, workSource);
1970 } finally {
1971 Binder.restoreCallingIdentity(identity);
1972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 }
1974
Shishir Agrawala9f32182016-04-12 12:00:16 -07001975 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001976 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001977 Phone phone = PhoneFactory.getPhone(slotIndex);
1978 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001979 return null;
1980 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001981 int subId = phone.getSubId();
1982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1983 mApp, subId, callingPackage, "getImeiForSlot")) {
1984 return null;
1985 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001986
1987 final long identity = Binder.clearCallingIdentity();
1988 try {
1989 return phone.getImei();
1990 } finally {
1991 Binder.restoreCallingIdentity(identity);
1992 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001993 }
1994
1995 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001996 public String getTypeAllocationCodeForSlot(int slotIndex) {
1997 Phone phone = PhoneFactory.getPhone(slotIndex);
1998 String tac = null;
1999 if (phone != null) {
2000 String imei = phone.getImei();
2001 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2002 }
2003 return tac;
2004 }
2005
2006 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002007 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002008 Phone phone = PhoneFactory.getPhone(slotIndex);
2009 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002010 return null;
2011 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002012 int subId = phone.getSubId();
2013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2014 mApp, subId, callingPackage, "getMeidForSlot")) {
2015 return null;
2016 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002017
2018 final long identity = Binder.clearCallingIdentity();
2019 try {
2020 return phone.getMeid();
2021 } finally {
2022 Binder.restoreCallingIdentity(identity);
2023 }
Jack Yu2af8d712017-03-15 17:14:14 -07002024 }
2025
2026 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002027 public String getManufacturerCodeForSlot(int slotIndex) {
2028 Phone phone = PhoneFactory.getPhone(slotIndex);
2029 String manufacturerCode = null;
2030 if (phone != null) {
2031 String meid = phone.getMeid();
2032 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2033 }
2034 return manufacturerCode;
2035 }
2036
2037 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002038 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002039 Phone phone = PhoneFactory.getPhone(slotIndex);
2040 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002041 return null;
2042 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002043 int subId = phone.getSubId();
2044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2045 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2046 return null;
2047 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002048
2049 final long identity = Binder.clearCallingIdentity();
2050 try {
2051 return phone.getDeviceSvn();
2052 } finally {
2053 Binder.restoreCallingIdentity(identity);
2054 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002055 }
2056
fionaxu43304da2017-11-27 22:51:16 -08002057 @Override
2058 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002059 final long identity = Binder.clearCallingIdentity();
2060 try {
2061 final Phone phone = getPhone(subId);
2062 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
2065 }
fionaxu43304da2017-11-27 22:51:16 -08002066 }
2067
2068 @Override
2069 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002070 final long identity = Binder.clearCallingIdentity();
2071 try {
2072 final Phone phone = getPhone(subId);
2073 return phone == null ? null : phone.getCarrierName();
2074 } finally {
2075 Binder.restoreCallingIdentity(identity);
2076 }
fionaxu43304da2017-11-27 22:51:16 -08002077 }
2078
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 //
2080 // Internal helper methods.
2081 //
2082
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002083 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2085 *
2086 * @throws SecurityException if the caller does not have the required permission
2087 */
2088 private void enforceModifyPermission() {
2089 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2090 }
2091
2092 /**
2093 * Make sure the caller has the CALL_PHONE permission.
2094 *
2095 * @throws SecurityException if the caller does not have the required permission
2096 */
2097 private void enforceCallPermission() {
2098 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2099 }
2100
Stuart Scott8eef64f2015-04-08 15:13:54 -07002101 private void enforceConnectivityInternalPermission() {
2102 mApp.enforceCallingOrSelfPermission(
2103 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2104 "ConnectivityService");
2105 }
2106
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 private String createTelUrl(String number) {
2108 if (TextUtils.isEmpty(number)) {
2109 return null;
2110 }
2111
Jake Hambye994d462014-02-03 13:10:13 -08002112 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114
Ihab Awadf9e92732013-12-05 18:02:52 -08002115 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2117 }
2118
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002119 private static void logv(String msg) {
2120 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2121 }
2122
Ihab Awadf9e92732013-12-05 18:02:52 -08002123 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2125 }
2126
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002127 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002129 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002130 }
2131
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002133 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 final Phone phone = PhoneFactory.getPhone(slotIndex);
2137 if (phone == null) {
2138 return PhoneConstants.PHONE_TYPE_NONE;
2139 } else {
2140 return phone.getPhoneType();
2141 }
2142 } finally {
2143 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 }
2146
2147 /**
2148 * Returns the CDMA ERI icon index to display
2149 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002150 @Override
2151 public int getCdmaEriIconIndex(String callingPackage) {
2152 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002153 }
2154
Sanket Padawe356d7632015-06-22 14:03:32 -07002155 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002156 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002158 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002159 return -1;
2160 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002161
2162 final long identity = Binder.clearCallingIdentity();
2163 try {
2164 final Phone phone = getPhone(subId);
2165 if (phone != null) {
2166 return phone.getCdmaEriIconIndex();
2167 } else {
2168 return -1;
2169 }
2170 } finally {
2171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 }
2174
2175 /**
2176 * Returns the CDMA ERI icon mode,
2177 * 0 - ON
2178 * 1 - FLASHING
2179 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002180 @Override
2181 public int getCdmaEriIconMode(String callingPackage) {
2182 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002183 }
2184
Sanket Padawe356d7632015-06-22 14:03:32 -07002185 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002186 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002188 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002189 return -1;
2190 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002191
2192 final long identity = Binder.clearCallingIdentity();
2193 try {
2194 final Phone phone = getPhone(subId);
2195 if (phone != null) {
2196 return phone.getCdmaEriIconMode();
2197 } else {
2198 return -1;
2199 }
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 }
2204
2205 /**
2206 * Returns the CDMA ERI text,
2207 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002208 @Override
2209 public String getCdmaEriText(String callingPackage) {
2210 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002211 }
2212
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002214 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002216 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002217 return null;
2218 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002219
2220 final long identity = Binder.clearCallingIdentity();
2221 try {
2222 final Phone phone = getPhone(subId);
2223 if (phone != null) {
2224 return phone.getCdmaEriText();
2225 } else {
2226 return null;
2227 }
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232
2233 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002234 * Returns the CDMA MDN.
2235 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002237 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2239 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002240
2241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 final Phone phone = getPhone(subId);
2244 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2245 return phone.getLine1Number();
2246 } else {
2247 return null;
2248 }
2249 } finally {
2250 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002251 }
2252 }
2253
2254 /**
2255 * Returns the CDMA MIN.
2256 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002257 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002258 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2260 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002261
2262 final long identity = Binder.clearCallingIdentity();
2263 try {
2264 final Phone phone = getPhone(subId);
2265 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2266 return phone.getCdmaMin();
2267 } else {
2268 return null;
2269 }
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002272 }
2273 }
2274
2275 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 * Returns true if CDMA provisioning needs to run.
2277 */
2278 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002279 final long identity = Binder.clearCallingIdentity();
2280 try {
2281 return mPhone.needsOtaServiceProvisioning();
2282 } finally {
2283 Binder.restoreCallingIdentity(identity);
2284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286
2287 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002288 * Sets the voice mail number of a given subId.
2289 */
2290 @Override
2291 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002292 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002293
2294 final long identity = Binder.clearCallingIdentity();
2295 try {
2296 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2297 new Pair<String, String>(alphaTag, number), new Integer(subId));
2298 return success;
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
2301 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002302 }
2303
Ta-wei Yen87c49842016-05-13 21:19:52 -07002304 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002305 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2306 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2307 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2308 if (!TextUtils.equals(callingPackage, systemDialer)) {
2309 throw new SecurityException("caller must be system dialer");
2310 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002311
2312 final long identity = Binder.clearCallingIdentity();
2313 try {
2314 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2315 if (phoneAccountHandle == null) {
2316 return null;
2317 }
2318 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2319 } finally {
2320 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002321 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002322 }
2323
2324 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002325 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002326 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002328 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002329 return null;
2330 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002331
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 return RemoteVvmTaskManager
2335 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
2338 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002339 }
2340
2341 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002342 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2343 VisualVoicemailSmsFilterSettings settings) {
2344 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002345
2346 final long identity = Binder.clearCallingIdentity();
2347 try {
2348 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2349 mPhone.getContext(), callingPackage, subId, settings);
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
2352 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002353 }
2354
2355 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002356 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002358
2359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2362 mPhone.getContext(), callingPackage, subId);
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
2365 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002366 }
2367
2368 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002369 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2370 String callingPackage, int subId) {
2371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002372
2373 final long identity = Binder.clearCallingIdentity();
2374 try {
2375 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2376 mPhone.getContext(), callingPackage, subId);
2377 } finally {
2378 Binder.restoreCallingIdentity(identity);
2379 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002380 }
2381
2382 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002383 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002384 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002385
2386 final long identity = Binder.clearCallingIdentity();
2387 try {
2388 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2389 mPhone.getContext(), subId);
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
2392 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002393 }
2394
2395 @Override
2396 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2397 String number, int port, String text, PendingIntent sentIntent) {
2398 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002399 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002400 enforceSendSmsPermission();
2401 // Make the calls as the phone process.
2402 final long identity = Binder.clearCallingIdentity();
2403 try {
2404 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2405 if (port == 0) {
2406 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2407 sentIntent, null, false);
2408 } else {
2409 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2410 smsManager.sendDataMessageWithSelfPermissions(number, null,
2411 (short) port, data, sentIntent, null);
2412 }
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002416 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002417 /**
fionaxu0152e512016-11-14 13:36:14 -08002418 * Sets the voice activation state of a given subId.
2419 */
2420 @Override
2421 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2423 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002424
2425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 final Phone phone = getPhone(subId);
2428 if (phone != null) {
2429 phone.setVoiceActivationState(activationState);
2430 } else {
2431 loge("setVoiceActivationState fails with invalid subId: " + subId);
2432 }
2433 } finally {
2434 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002435 }
2436 }
2437
2438 /**
2439 * Sets the data activation state of a given subId.
2440 */
2441 @Override
2442 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2444 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002445
2446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 final Phone phone = getPhone(subId);
2449 if (phone != null) {
2450 phone.setDataActivationState(activationState);
2451 } else {
2452 loge("setVoiceActivationState fails with invalid subId: " + subId);
2453 }
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002456 }
2457 }
2458
2459 /**
2460 * Returns the voice activation state of a given subId.
2461 */
2462 @Override
2463 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002464 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002465
fionaxu0152e512016-11-14 13:36:14 -08002466 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 if (phone != null) {
2470 return phone.getVoiceActivationState();
2471 } else {
2472 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2473 }
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002476 }
2477 }
2478
2479 /**
2480 * Returns the data activation state of a given subId.
2481 */
2482 @Override
2483 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002484 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002485
fionaxu0152e512016-11-14 13:36:14 -08002486 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002487 final long identity = Binder.clearCallingIdentity();
2488 try {
2489 if (phone != null) {
2490 return phone.getDataActivationState();
2491 } else {
2492 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2493 }
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002496 }
2497 }
2498
2499 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 * Returns the unread count of voicemails
2501 */
2502 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002503 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002504 }
2505
2506 /**
2507 * Returns the unread count of voicemails for a subId
2508 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002510 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-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.getVoiceMessageCount();
2516 } else {
2517 return 0;
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 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002525 * returns true, if the device is in a state where both voice and data
2526 * are supported simultaneously. This can change based on location or network condition.
2527 */
2528 @Override
2529 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 final Phone phone = getPhone(subId);
2533 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002537 }
2538
2539 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002540 * Send the dialer code if called from the current default dialer or the caller has
2541 * carrier privilege.
2542 * @param inputCode The dialer code to send
2543 */
2544 @Override
2545 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2546 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2547 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2548 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002549 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2550 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002551 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 mPhone.sendDialerSpecialCode(inputCode);
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
2558 }
fionaxu235cc5e2017-03-06 22:25:57 -08002559 }
2560
2561 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002562 * Returns the data network type.
2563 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 *
2565 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2566 */
2567 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002568 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 final Phone phone = getPhone(getDefaultSubscription());
2572 if (phone != null) {
2573 return phone.getServiceState().getDataNetworkType();
2574 } else {
2575 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2576 }
2577 } finally {
2578 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002579 }
Wink Saville36469e72014-06-11 15:17:00 -07002580 }
2581
Pengquan Meng0c05b502018-09-06 09:59:22 -07002582 @Override
2583 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002584 if (!isActiveSubscription(subId)) {
2585 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2586 }
2587
Pengquan Meng0c05b502018-09-06 09:59:22 -07002588 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2589 }
2590
Wink Saville36469e72014-06-11 15:17:00 -07002591 /**
2592 * Returns the network type for a subId
2593 */
2594 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002595 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002597 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002598 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2599 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002600
Malcolm Chenaabec062018-02-28 15:00:40 -08002601 final long identity = Binder.clearCallingIdentity();
2602 try {
2603 final Phone phone = getPhone(subId);
2604 if (phone != null) {
2605 return phone.getServiceState().getDataNetworkType();
2606 } else {
2607 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2608 }
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613
2614 /**
2615 * Returns the data network type
2616 */
2617 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002618 public int getDataNetworkType(String callingPackage) {
2619 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002620 }
2621
2622 /**
2623 * Returns the data network type for a subId
2624 */
2625 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002626 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002628 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002629 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2630 }
2631
Malcolm Chenaabec062018-02-28 15:00:40 -08002632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 final Phone phone = getPhone(subId);
2635 if (phone != null) {
2636 return phone.getServiceState().getDataNetworkType();
2637 } else {
2638 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2639 }
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 }
2644
2645 /**
Wink Saville36469e72014-06-11 15:17:00 -07002646 * Returns the Voice network type for a subId
2647 */
2648 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002649 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002651 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002652 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2653 }
2654
Malcolm Chenaabec062018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 final Phone phone = getPhone(subId);
2658 if (phone != null) {
2659 return phone.getServiceState().getVoiceNetworkType();
2660 } else {
2661 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667
2668 /**
2669 * @return true if a ICC card is present
2670 */
2671 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002672 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002673 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2674 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002675 }
2676
2677 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002678 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002679 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002680 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002681 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 final Phone phone = PhoneFactory.getPhone(slotIndex);
2685 if (phone != null) {
2686 return phone.getIccCard().hasIccCard();
2687 } else {
2688 return false;
2689 }
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
2694
2695 /**
2696 * Return if the current radio is LTE on CDMA. This
2697 * is a tri-state return value as for a period of time
2698 * the mode may be unknown.
2699 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002700 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002702 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002704 @Override
2705 public int getLteOnCdmaMode(String callingPackage) {
2706 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002707 }
2708
Sanket Padawe356d7632015-06-22 14:03:32 -07002709 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002710 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002712 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002713 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2714 }
2715
Malcolm Chenaabec062018-02-28 15:00:40 -08002716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 final Phone phone = getPhone(subId);
2719 if (phone == null) {
2720 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2721 } else {
2722 return phone.getLteOnCdmaMode();
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 }
Wink Saville36469e72014-06-11 15:17:00 -07002727 }
2728
2729 public void setPhone(Phone phone) {
2730 mPhone = phone;
2731 }
2732
2733 /**
2734 * {@hide}
2735 * Returns Default subId, 0 in the case of single standby.
2736 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002737 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002738 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002739 }
2740
Shishir Agrawala9f32182016-04-12 12:00:16 -07002741 private int getSlotForDefaultSubscription() {
2742 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2743 }
2744
Wink Savilleb564aae2014-10-23 10:18:09 -07002745 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002746 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002748
Pengquan Meng466e2482018-09-21 15:54:48 -07002749 private boolean isActiveSubscription(int subId) {
2750 return mSubscriptionController.isActiveSubId(subId);
2751 }
2752
Ihab Awadf2177b72013-11-25 13:33:23 -08002753 /**
2754 * @see android.telephony.TelephonyManager.WifiCallingChoices
2755 */
2756 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2760 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2761 getWhenToMakeWifiCallsDefaultPreference());
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
2764 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002765 }
2766
2767 /**
2768 * @see android.telephony.TelephonyManager.WifiCallingChoices
2769 */
2770 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2774 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2775 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
2778 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002779 }
2780
Sailesh Nepald1e68152013-12-12 19:08:02 -08002781 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002782 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002783 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002784 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002785
Shishir Agrawal566b7612013-10-28 14:41:00 -07002786 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002787 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2788 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2790 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002791 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002792
Malcolm Chenaabec062018-02-28 15:00:40 -08002793 final long identity = Binder.clearCallingIdentity();
2794 try {
2795 if (TextUtils.equals(ISDR_AID, aid)) {
2796 // Only allows LPA to open logical channel to ISD-R.
2797 ComponentInfo bestComponent =
2798 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2799 if (bestComponent == null
2800 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2801 loge("The calling package is not allowed to access ISD-R.");
2802 throw new SecurityException(
2803 "The calling package is not allowed to access ISD-R.");
2804 }
Derek Tan740e1672017-06-27 14:56:27 -07002805 }
Derek Tan740e1672017-06-27 14:56:27 -07002806
Malcolm Chenaabec062018-02-28 15:00:40 -08002807 if (DBG) {
2808 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2809 }
2810 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2811 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2812 if (DBG) log("iccOpenLogicalChannel: " + response);
2813 return response;
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002817 }
2818
2819 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002820 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2822 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002823
Malcolm Chenaabec062018-02-28 15:00:40 -08002824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2827 if (channel < 0) {
2828 return false;
2829 }
2830 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2831 if (DBG) log("iccCloseLogicalChannel: " + success);
2832 return success;
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002835 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002836 }
2837
2838 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002839 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002840 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2842 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002843
Malcolm Chenaabec062018-02-28 15:00:40 -08002844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 if (DBG) {
2847 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2848 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2849 + p3 + " data=" + data);
2850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002851
Malcolm Chenaabec062018-02-28 15:00:40 -08002852 if (channel < 0) {
2853 return "";
2854 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002855
Malcolm Chenaabec062018-02-28 15:00:40 -08002856 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2857 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2858 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002859
Malcolm Chenaabec062018-02-28 15:00:40 -08002860 // Append the returned status code to the end of the response payload.
2861 String s = Integer.toHexString(
2862 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2863 if (response.payload != null) {
2864 s = IccUtils.bytesToHexString(response.payload) + s;
2865 }
2866 return s;
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002870 }
Jake Hambye994d462014-02-03 13:10:13 -08002871
Evan Charltonc66da362014-05-16 14:06:40 -07002872 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002873 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2874 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2876 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002877 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002878
Malcolm Chenaabec062018-02-28 15:00:40 -08002879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2882 && TextUtils.equals(ISDR_AID, data)) {
2883 // Only allows LPA to select ISD-R.
2884 ComponentInfo bestComponent =
2885 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2886 if (bestComponent == null
2887 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2888 loge("The calling package is not allowed to select ISD-R.");
2889 throw new SecurityException(
2890 "The calling package is not allowed to select ISD-R.");
2891 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002892 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002893
Malcolm Chenaabec062018-02-28 15:00:40 -08002894 if (DBG) {
2895 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2896 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2897 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002898
Malcolm Chenaabec062018-02-28 15:00:40 -08002899 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2900 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2901 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002902
Malcolm Chenaabec062018-02-28 15:00:40 -08002903 // Append the returned status code to the end of the response payload.
2904 String s = Integer.toHexString(
2905 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2906 if (response.payload != null) {
2907 s = IccUtils.bytesToHexString(response.payload) + s;
2908 }
2909 return s;
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002912 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002913 }
2914
2915 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002916 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002917 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2919 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002920
Malcolm Chenaabec062018-02-28 15:00:40 -08002921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 if (DBG) {
2924 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2925 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2926 }
2927
2928 IccIoResult response =
2929 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2930 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2931 subId);
2932
2933 if (DBG) {
2934 log("Exchange SIM_IO [R]" + response);
2935 }
2936
2937 byte[] result = null;
2938 int length = 2;
2939 if (response.payload != null) {
2940 length = 2 + response.payload.length;
2941 result = new byte[length];
2942 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2943 } else {
2944 result = new byte[length];
2945 }
2946
2947 result[length - 1] = (byte) response.sw2;
2948 result[length - 2] = (byte) response.sw1;
2949 return result;
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002952 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002953 }
2954
Nathan Haroldb3014052017-01-25 15:57:32 -08002955 /**
2956 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2957 * on a particular subscription
2958 */
sqianb6e41952018-03-12 14:54:01 -07002959 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2961 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2962 return null;
2963 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002964 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2965 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2966 return null;
2967 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002968
2969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2972 if (response instanceof String[]) {
2973 return (String[]) response;
2974 }
2975 // Response is an Exception of some kind,
2976 // which is signalled to the user as a NULL retval
2977 return null;
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002980 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002981 }
2982
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002983 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002984 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2986 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002987
Malcolm Chenaabec062018-02-28 15:00:40 -08002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2991 if (response.payload == null) {
2992 return "";
2993 }
Evan Charltonc66da362014-05-16 14:06:40 -07002994
Malcolm Chenaabec062018-02-28 15:00:40 -08002995 // Append the returned status code to the end of the response payload.
2996 String s = Integer.toHexString(
2997 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2998 s = IccUtils.bytesToHexString(response.payload) + s;
2999 return s;
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
Evan Charltonc66da362014-05-16 14:06:40 -07003003 }
3004
Jake Hambye994d462014-02-03 13:10:13 -08003005 /**
3006 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3007 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3008 *
3009 * @param itemID the ID of the item to read
3010 * @return the NV item as a String, or null on error.
3011 */
3012 @Override
3013 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003014 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3016 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003021 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003022 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3023 return value;
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
Jake Hambye994d462014-02-03 13:10:13 -08003027 }
3028
3029 /**
3030 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3031 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3032 *
3033 * @param itemID the ID of the item to read
3034 * @param itemValue the value to write, as a String
3035 * @return true on success; false on any failure
3036 */
3037 @Override
3038 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003039 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3041 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003042
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3046 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003047 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003048 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3049 return success;
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
Jake Hambye994d462014-02-03 13:10:13 -08003053 }
3054
3055 /**
3056 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3057 * Used for device configuration by some CDMA operators.
3058 *
3059 * @param preferredRoamingList byte array containing the new PRL
3060 * @return true on success; false on any failure
3061 */
3062 @Override
3063 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3065 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003066
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3070 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3071 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3072 return success;
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
Jake Hambye994d462014-02-03 13:10:13 -08003076 }
3077
3078 /**
3079 * Perform the specified type of NV config reset.
3080 * Used for device configuration by some CDMA operators.
3081 *
3082 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3083 * @return true on success; false on any failure
3084 */
3085 @Override
3086 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3088 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003089
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 if (DBG) log("nvResetConfig: type " + resetType);
3093 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3094 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3095 return success;
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
Jake Hambye994d462014-02-03 13:10:13 -08003099 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003100
Svet Ganovb320e182015-04-16 12:30:10 -07003101 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003103 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003104 return new String[0];
3105 }
3106
Malcolm Chenaabec062018-02-28 15:00:40 -08003107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 return mPhone.getPcscfAddress(apnType);
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
Wink Saville36469e72014-06-11 15:17:00 -07003113 }
3114
Brad Ebinger51f743a2017-01-23 13:50:20 -08003115 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003116 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3117 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003118 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003119 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003120 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003121
3122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 PhoneFactory.getImsResolver().enableIms(slotId);
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003128 }
3129
3130 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003131 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3132 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003133 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003134 public void disableIms(int slotId) {
3135 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003136
3137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 PhoneFactory.getImsResolver().disableIms(slotId);
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003143 }
3144
3145 /**
3146 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3147 * feature or {@link null} if the service is not available. If the feature is available, the
3148 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3149 */
3150 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003151 IImsServiceFeatureCallback callback) {
3152 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003153
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003160 }
3161
3162 /**
3163 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3164 * feature during emergency calling or {@link null} if the service is not available. If the
3165 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3166 * listener for feature updates.
3167 */
3168 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3169 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003170
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003177 }
3178
Brad Ebinger5f64b052017-12-14 14:26:15 -08003179 /**
3180 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3181 * specified.
3182 */
3183 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3184 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003185
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003192 }
3193
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003194 /**
3195 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3196 * specified.
3197 */
3198 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3199 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003200
3201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003207 }
3208
Brad Ebinger884c07b2018-02-15 16:17:40 -08003209 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003210 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3211 * available, false if the IMS resolver is idle.
3212 */
3213 public boolean isResolvingImsBinding() {
3214 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003215
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 return PhoneFactory.getImsResolver().isResolvingBinding();
3219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
Brad Ebinger67801702018-03-02 13:43:36 -08003222 }
3223
Brad Ebingerdac2f002018-04-03 15:17:52 -07003224 /**
3225 * Sets the ImsService Package Name that Telephony will bind to.
3226 *
3227 * @param slotId the slot ID that the ImsService should bind for.
3228 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3229 * ImsService is the device default ImsService.
3230 * @param packageName The package name of the application that contains the ImsService to bind
3231 * to.
3232 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3233 * @hide
3234 */
3235 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003236 int[] subIds = SubscriptionManager.getSubId(slotId);
3237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3238 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3239 "setImsService");
3240
Malcolm Chenaabec062018-02-28 15:00:40 -08003241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3244 isCarrierImsService, packageName);
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003248 }
3249
3250 /**
3251 * Return the ImsService configuration.
3252 *
3253 * @param slotId The slot that the ImsService is associated with.
3254 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3255 * the device default.
3256 * @return the package name of the ImsService configuration.
3257 */
3258 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003259 int[] subIds = SubscriptionManager.getSubId(slotId);
3260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3261 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3262 "getImsService");
3263
Malcolm Chenaabec062018-02-28 15:00:40 -08003264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3267 isCarrierImsService);
3268 } finally {
3269 Binder.restoreCallingIdentity(identity);
3270 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003271 }
3272
Wink Saville36469e72014-06-11 15:17:00 -07003273 public void setImsRegistrationState(boolean registered) {
3274 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003275
3276 final long identity = Binder.clearCallingIdentity();
3277 try {
3278 mPhone.setImsRegistrationState(registered);
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
Wink Saville36469e72014-06-11 15:17:00 -07003282 }
3283
3284 /**
Stuart Scott54788802015-03-30 13:18:01 -07003285 * Set the network selection mode to automatic.
3286 *
3287 */
3288 @Override
3289 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003292
Pengquan Meng466e2482018-09-21 15:54:48 -07003293 if (!isActiveSubscription(subId)) {
3294 return;
3295 }
3296
Malcolm Chenaabec062018-02-28 15:00:40 -08003297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3300 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
Stuart Scott54788802015-03-30 13:18:01 -07003304 }
3305
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003306 /**
3307 * Ask the radio to connect to the input network and change selection mode to manual.
3308 *
3309 * @param subId the id of the subscription.
3310 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3311 * the operator to attach to.
3312 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3313 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3314 * normal network selection next time.
3315 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003316 */
3317 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003318 public boolean setNetworkSelectionModeManual(
3319 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3321 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003322
3323 if (!isActiveSubscription(subId)) {
3324 return false;
3325 }
3326
Malcolm Chenaabec062018-02-28 15:00:40 -08003327 final long identity = Binder.clearCallingIdentity();
3328 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003329 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaabec062018-02-28 15:00:40 -08003330 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003331 if (DBG) {
3332 log("setNetworkSelectionModeManual: subId: " + subId
3333 + " operator: " + operatorInfo);
3334 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003335 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003339 }
3340
3341 /**
3342 * Scans for available networks.
3343 */
3344 @Override
3345 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3347 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003348
Pengquan Meng0c05b502018-09-06 09:59:22 -07003349 long identity = Binder.clearCallingIdentity();
Malcolm Chenaabec062018-02-28 15:00:40 -08003350 try {
3351 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003352 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaabec062018-02-28 15:00:40 -08003353 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08003354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003357 }
3358
3359 /**
yinxub1bed742017-04-17 11:45:04 -07003360 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003361 *
yinxub1bed742017-04-17 11:45:04 -07003362 * @param subId id of the subscription
3363 * @param request contains the radio access networks with bands/channels to scan
3364 * @param messenger callback messenger for scan results or errors
3365 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003366 * @return the id of the requested scan which can be used to stop the scan.
3367 */
3368 @Override
3369 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3370 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3372 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003373
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 return mNetworkScanRequestTracker.startNetworkScan(
3377 request, messenger, binder, getPhone(subId));
3378 } finally {
3379 Binder.restoreCallingIdentity(identity);
3380 }
yinxu504e1392017-04-12 16:03:22 -07003381 }
3382
3383 /**
3384 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003385 *
3386 * @param subId id of the subscription
3387 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003388 */
3389 @Override
3390 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3392 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003393
3394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
yinxu504e1392017-04-12 16:03:22 -07003400 }
3401
3402 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003403 * Get the calculated preferred network type.
3404 * Used for debugging incorrect network type.
3405 *
3406 * @return the preferred network type, defined in RILConstants.java.
3407 */
3408 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003409 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003411 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003412 return RILConstants.PREFERRED_NETWORK_MODE;
3413 }
3414
Malcolm Chenaabec062018-02-28 15:00:40 -08003415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 // FIXME: need to get SubId from somewhere.
3418 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
Junda Liu84d15a22014-07-02 11:21:04 -07003422 }
3423
3424 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003425 * Get the preferred network type.
3426 * Used for device configuration by some CDMA operators.
3427 *
3428 * @return the preferred network type, defined in RILConstants.java.
3429 */
3430 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003431 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3433 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003434
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 if (DBG) log("getPreferredNetworkType");
3438 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3439 int networkType = (result != null ? result[0] : -1);
3440 if (DBG) log("getPreferredNetworkType: " + networkType);
3441 return networkType;
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003445 }
3446
3447 /**
3448 * Set the preferred network type.
3449 * Used for device configuration by some CDMA operators.
3450 *
3451 * @param networkType the preferred network type, defined in RILConstants.java.
3452 * @return true on success; false on any failure.
3453 */
3454 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003455 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3457 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003458
3459 final long identity = Binder.clearCallingIdentity();
3460 try {
3461 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3462 Boolean success = (Boolean) sendRequest(
3463 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3464 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3465 if (success) {
3466 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3467 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3468 }
3469 return success;
3470 } finally {
3471 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003472 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003473 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003474
3475 /**
Junda Liu475951f2014-11-07 16:45:03 -08003476 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3477 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3478 * tethering.
3479 *
3480 * @return 0: Not required. 1: required. 2: Not set.
3481 * @hide
3482 */
3483 @Override
3484 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003485 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003486
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3490 Settings.Global.TETHER_DUN_REQUIRED, 2);
3491 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3492 // config_tether_apndata.
3493 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3494 dunRequired = 1;
3495 }
3496 return dunRequired;
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003499 }
Junda Liu475951f2014-11-07 16:45:03 -08003500 }
3501
3502 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003503 * Set mobile data enabled
3504 * Used by the user through settings etc to turn on/off mobile data
3505 *
3506 * @param enable {@code true} turn turn data on, else {@code false}
3507 */
3508 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003509 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3511 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003512
3513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 int phoneId = mSubscriptionController.getPhoneId(subId);
3516 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3517 Phone phone = PhoneFactory.getPhone(phoneId);
3518 if (phone != null) {
3519 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3520 phone.setUserDataEnabled(enable);
3521 } else {
3522 loge("setUserDataEnabled: no phone for subId=" + subId);
3523 }
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003526 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003527 }
3528
3529 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003530 * Get the user enabled state of Mobile Data.
3531 *
3532 * TODO: remove and use isUserDataEnabled.
3533 * This can't be removed now because some vendor codes
3534 * calls through ITelephony directly while they should
3535 * use TelephonyManager.
3536 *
3537 * @return true on enabled
3538 */
3539 @Override
3540 public boolean getDataEnabled(int subId) {
3541 return isUserDataEnabled(subId);
3542 }
3543
3544 /**
3545 * Get whether mobile data is enabled per user setting.
3546 *
3547 * There are other factors deciding whether mobile data is actually enabled, but they are
3548 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003549 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003550 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003551 *
3552 * @return {@code true} if data is enabled else {@code false}
3553 */
3554 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003555 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003556 try {
3557 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3558 null);
3559 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3561 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003562 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003563
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 int phoneId = mSubscriptionController.getPhoneId(subId);
3567 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3568 Phone phone = PhoneFactory.getPhone(phoneId);
3569 if (phone != null) {
3570 boolean retVal = phone.isUserDataEnabled();
3571 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3572 return retVal;
3573 } else {
3574 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3575 return false;
3576 }
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003579 }
3580 }
3581
3582 /**
3583 * Get whether mobile data is enabled.
3584 *
3585 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3586 * whether mobile data is actually enabled.
3587 *
3588 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3589 *
3590 * @return {@code true} if data is enabled else {@code false}
3591 */
3592 @Override
3593 public boolean isDataEnabled(int subId) {
3594 try {
3595 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3596 null);
3597 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3599 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003600 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003601
3602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 int phoneId = mSubscriptionController.getPhoneId(subId);
3605 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3606 Phone phone = PhoneFactory.getPhone(phoneId);
3607 if (phone != null) {
3608 boolean retVal = phone.isDataEnabled();
3609 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3610 return retVal;
3611 } else {
3612 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3613 return false;
3614 }
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003617 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003618 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003619
3620 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003621 public int getCarrierPrivilegeStatus(int subId) {
3622 final Phone phone = getPhone(subId);
3623 if (phone == null) {
3624 loge("getCarrierPrivilegeStatus: Invalid subId");
3625 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3626 }
3627 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003628 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003629 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003630 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3631 }
3632 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003633 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003634 }
Junda Liu29340342014-07-10 15:23:27 -07003635
3636 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003637 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3638 final Phone phone = getPhone(subId);
3639 if (phone == null) {
3640 loge("getCarrierPrivilegeStatus: Invalid subId");
3641 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3642 }
3643 UiccProfile profile =
3644 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3645 if (profile == null) {
3646 loge("getCarrierPrivilegeStatus: No UICC");
3647 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3648 }
3649 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3650 }
3651
3652 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003653 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003654 if (TextUtils.isEmpty(pkgName))
3655 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003656 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003657 if (card == null) {
3658 loge("checkCarrierPrivilegesForPackage: No UICC");
3659 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3660 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003661 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3662 }
3663
3664 @Override
3665 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003666 if (TextUtils.isEmpty(pkgName))
3667 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003668 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3669 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3670 UiccCard card = UiccController.getInstance().getUiccCard(i);
3671 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003672 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003673 continue;
3674 }
3675
3676 result = card.getCarrierPrivilegeStatus(
3677 mPhone.getContext().getPackageManager(), pkgName);
3678 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3679 break;
3680 }
3681 }
3682
3683 return result;
Junda Liu29340342014-07-10 15:23:27 -07003684 }
Derek Tan89e89d42014-07-08 17:00:10 -07003685
3686 @Override
Junda Liue64de782015-04-16 17:19:16 -07003687 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3688 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3689 loge("phoneId " + phoneId + " is not valid.");
3690 return null;
3691 }
3692 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003693 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003694 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003695 return null ;
3696 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003697 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003698 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003699 }
3700
Amith Yamasani6e118872016-02-19 12:53:51 -08003701 @Override
3702 public List<String> getPackagesWithCarrierPrivileges() {
3703 PackageManager pm = mPhone.getContext().getPackageManager();
3704 List<String> privilegedPackages = new ArrayList<>();
3705 List<PackageInfo> packages = null;
3706 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3707 UiccCard card = UiccController.getInstance().getUiccCard(i);
3708 if (card == null) {
3709 // No UICC in that slot.
3710 continue;
3711 }
3712 if (card.hasCarrierPrivilegeRules()) {
3713 if (packages == null) {
3714 // Only check packages in user 0 for now
3715 packages = pm.getInstalledPackagesAsUser(
3716 PackageManager.MATCH_DISABLED_COMPONENTS
3717 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3718 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3719 }
3720 for (int p = packages.size() - 1; p >= 0; p--) {
3721 PackageInfo pkgInfo = packages.get(p);
3722 if (pkgInfo != null && pkgInfo.packageName != null
3723 && card.getCarrierPrivilegeStatus(pkgInfo)
3724 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3725 privilegedPackages.add(pkgInfo.packageName);
3726 }
3727 }
3728 }
3729 }
3730 return privilegedPackages;
3731 }
3732
Wink Savilleb564aae2014-10-23 10:18:09 -07003733 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003734 final Phone phone = getPhone(subId);
3735 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003736 if (card == null) {
3737 loge("getIccId: No UICC");
3738 return null;
3739 }
3740 String iccId = card.getIccId();
3741 if (TextUtils.isEmpty(iccId)) {
3742 loge("getIccId: ICC ID is null or empty.");
3743 return null;
3744 }
3745 return iccId;
3746 }
3747
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003748 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003749 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3750 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003751 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3752 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003753
Malcolm Chenaabec062018-02-28 15:00:40 -08003754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 final String iccId = getIccId(subId);
3757 final Phone phone = getPhone(subId);
3758 if (phone == null) {
3759 return false;
3760 }
3761 final String subscriberId = phone.getSubscriberId();
3762
3763 if (DBG_MERGE) {
3764 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3765 + subscriberId + " to " + number);
3766 }
3767
3768 if (TextUtils.isEmpty(iccId)) {
3769 return false;
3770 }
3771
3772 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3773
3774 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3775 if (alphaTag == null) {
3776 editor.remove(alphaTagPrefKey);
3777 } else {
3778 editor.putString(alphaTagPrefKey, alphaTag);
3779 }
3780
3781 // Record both the line number and IMSI for this ICCID, since we need to
3782 // track all merged IMSIs based on line number
3783 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3784 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3785 if (number == null) {
3786 editor.remove(numberPrefKey);
3787 editor.remove(subscriberPrefKey);
3788 } else {
3789 editor.putString(numberPrefKey, number);
3790 editor.putString(subscriberPrefKey, subscriberId);
3791 }
3792
3793 editor.commit();
3794 return true;
3795 } finally {
3796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003797 }
Derek Tan7226c842014-07-02 17:42:23 -07003798 }
3799
3800 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003801 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003802 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003804 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003805 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003806 return null;
3807 }
Derek Tan97ebb422014-09-05 16:55:38 -07003808
Malcolm Chenaabec062018-02-28 15:00:40 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 String iccId = getIccId(subId);
3812 if (iccId != null) {
3813 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3814 if (DBG_MERGE) {
3815 log("getLine1NumberForDisplay returning "
3816 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3817 }
3818 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003819 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003820 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3821 return null;
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003824 }
Derek Tan7226c842014-07-02 17:42:23 -07003825 }
3826
3827 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003828 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003830 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003831 return null;
3832 }
Derek Tan97ebb422014-09-05 16:55:38 -07003833
Malcolm Chenaabec062018-02-28 15:00:40 -08003834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 String iccId = getIccId(subId);
3837 if (iccId != null) {
3838 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3839 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3840 }
3841 return null;
3842 } finally {
3843 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003844 }
Derek Tan7226c842014-07-02 17:42:23 -07003845 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003846
3847 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003848 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003849 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3850 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003852 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3853 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003854 return null;
3855 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003856
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003857 final long identity = Binder.clearCallingIdentity();
3858 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003859 final Context context = mPhone.getContext();
3860 final TelephonyManager tele = TelephonyManager.from(context);
3861 final SubscriptionManager sub = SubscriptionManager.from(context);
3862
3863 // Figure out what subscribers are currently active
3864 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3865 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3866 // the process, where TelephonyManager was instantiated.
3867 // Otherwise AppOps check will fail.
3868
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003869 final int[] subIds = sub.getActiveSubscriptionIdList();
3870 for (int subId : subIds) {
3871 activeSubscriberIds.add(tele.getSubscriberId(subId));
3872 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003873
3874 // First pass, find a number override for an active subscriber
3875 String mergeNumber = null;
3876 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3877 for (String key : prefs.keySet()) {
3878 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3879 final String subscriberId = (String) prefs.get(key);
3880 if (activeSubscriberIds.contains(subscriberId)) {
3881 final String iccId = key.substring(
3882 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3883 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3884 mergeNumber = (String) prefs.get(numberKey);
3885 if (DBG_MERGE) {
3886 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3887 + " for active subscriber " + subscriberId);
3888 }
3889 if (!TextUtils.isEmpty(mergeNumber)) {
3890 break;
3891 }
3892 }
3893 }
3894 }
3895
3896 // Shortcut when no active merged subscribers
3897 if (TextUtils.isEmpty(mergeNumber)) {
3898 return null;
3899 }
3900
3901 // Second pass, find all subscribers under that line override
3902 final ArraySet<String> result = new ArraySet<>();
3903 for (String key : prefs.keySet()) {
3904 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3905 final String number = (String) prefs.get(key);
3906 if (mergeNumber.equals(number)) {
3907 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3908 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3909 final String subscriberId = (String) prefs.get(subscriberKey);
3910 if (!TextUtils.isEmpty(subscriberId)) {
3911 result.add(subscriberId);
3912 }
3913 }
3914 }
3915 }
3916
3917 final String[] resultArray = result.toArray(new String[result.size()]);
3918 Arrays.sort(resultArray);
3919 if (DBG_MERGE) {
3920 Slog.d(LOG_TAG,
3921 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3922 }
3923 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003924 } finally {
3925 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003926 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003927 }
3928
3929 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003930 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003931 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3932 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003933
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 final Phone phone = getPhone(subId);
3937 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3938 } finally {
3939 Binder.restoreCallingIdentity(identity);
3940 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003941 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003942
3943 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003944 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003945 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3946 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003947 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003948
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 final Phone phone = getPhone(subId);
3952 if (phone == null) {
3953 return false;
3954 }
3955 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3956 cdmaNonRoamingList);
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003959 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003960 }
3961
3962 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003963 @Deprecated
3964 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3965 enforceModifyPermission();
3966
3967 int returnValue = 0;
3968 try {
vagdevie435a3e2018-08-15 16:01:53 -07003969 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003970 if(result.exception == null) {
3971 if (result.result != null) {
3972 byte[] responseData = (byte[])(result.result);
3973 if(responseData.length > oemResp.length) {
3974 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3975 responseData.length + "bytes. Buffer Size is " +
3976 oemResp.length + "bytes.");
3977 }
3978 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3979 returnValue = responseData.length;
3980 }
3981 } else {
3982 CommandException ex = (CommandException) result.exception;
3983 returnValue = ex.getCommandError().ordinal();
3984 if(returnValue > 0) returnValue *= -1;
3985 }
3986 } catch (RuntimeException e) {
3987 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3988 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3989 if(returnValue > 0) returnValue *= -1;
3990 }
3991
3992 return returnValue;
3993 }
3994
3995 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003996 public void setRadioCapability(RadioAccessFamily[] rafs) {
3997 try {
3998 ProxyController.getInstance().setRadioCapability(rafs);
3999 } catch (RuntimeException e) {
4000 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4001 }
4002 }
4003
4004 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004005 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004006 Phone phone = PhoneFactory.getPhone(phoneId);
4007 if (phone == null) {
4008 return RadioAccessFamily.RAF_UNKNOWN;
4009 }
4010 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004012 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004013 return RadioAccessFamily.RAF_UNKNOWN;
4014 }
4015
Malcolm Chenaabec062018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004022 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004023
4024 @Override
4025 public void enableVideoCalling(boolean enable) {
4026 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004034 }
4035
4036 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004037 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4039 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4040 return false;
4041 }
Svet Ganovb320e182015-04-16 12:30:10 -07004042
Malcolm Chenaabec062018-02-28 15:00:40 -08004043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 // Check the user preference and the system-level IMS setting. Even if the user has
4046 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4047 // In the long run, we may instead need to check if there exists a connection service
4048 // which can support video calling.
4049 ImsManager imsManager =
4050 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4051 return imsManager.isVtEnabledByPlatform()
4052 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4053 && imsManager.isVtEnabledByUser();
4054 } finally {
4055 Binder.restoreCallingIdentity(identity);
4056 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004057 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004058
Andrew Leea1239f22015-03-02 17:44:07 -08004059 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004060 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4062 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4063 return false;
4064 }
4065
4066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 CarrierConfigManager configManager =
4069 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4070 return configManager.getConfigForSubId(mPhone.getSubId())
4071 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
Andrew Leea1239f22015-03-02 17:44:07 -08004075 }
4076
4077 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004078 public boolean isWorldPhone(int subId, String callingPackage) {
4079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4080 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4081 return false;
4082 }
4083
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 CarrierConfigManager configManager =
4087 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4088 return configManager.getConfigForSubId(mPhone.getSubId())
4089 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4090 } finally {
4091 Binder.restoreCallingIdentity(identity);
4092 }
Andrew Leea1239f22015-03-02 17:44:07 -08004093 }
4094
Andrew Lee9431b832015-03-09 18:46:45 -07004095 @Override
4096 public boolean isTtyModeSupported() {
4097 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004098 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004099 }
4100
4101 @Override
4102 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4106 } finally {
4107 Binder.restoreCallingIdentity(identity);
4108 }
Andrew Lee9431b832015-03-09 18:46:45 -07004109 }
4110
Hall Liu98187582018-01-22 19:15:32 -08004111 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4115 mPhone.getSubId()).getBoolean(
4116 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4117 boolean isDeviceSupported =
4118 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4119 return isCarrierSupported && isDeviceSupported;
4120 } finally {
4121 Binder.restoreCallingIdentity(identity);
4122 }
Hall Liu98187582018-01-22 19:15:32 -08004123 }
4124
Hall Liu3ad5f012018-04-06 16:23:39 -07004125 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 return isRttSupported() && Settings.Secure.getInt(
4129 mPhone.getContext().getContentResolver(),
4130 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004134 }
4135
Sanket Padawe7310cc72015-01-14 09:53:20 -08004136 /**
4137 * Returns the unique device ID of phone, for example, the IMEI for
4138 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4139 *
4140 * <p>Requires Permission:
4141 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4142 */
4143 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004144 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004145 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004146 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004147 return null;
4148 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004149 int subId = phone.getSubId();
4150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4151 mApp, subId, callingPackage, "getDeviceId")) {
4152 return null;
4153 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004154
4155 final long identity = Binder.clearCallingIdentity();
4156 try {
4157 return phone.getDeviceId();
4158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004161 }
4162
Ping Sunc67b7c22016-03-02 19:16:45 +08004163 /**
4164 * {@hide}
4165 * Returns the IMS Registration Status on a particular subid
4166 *
4167 * @param subId
4168 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004169 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004170 Phone phone = getPhone(subId);
4171 if (phone != null) {
4172 return phone.isImsRegistered();
4173 } else {
4174 return false;
4175 }
4176 }
4177
Santos Cordon7a1885b2015-02-03 11:15:19 -08004178 @Override
4179 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004186 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004187
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004188 /**
4189 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004190 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004191 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004192 final long identity = Binder.clearCallingIdentity();
4193 try {
4194 Phone phone = getPhone(subId);
4195 if (phone != null) {
4196 return phone.isWifiCallingEnabled();
4197 } else {
4198 return false;
4199 }
4200 } finally {
4201 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004202 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004203 }
4204
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004205 /**
4206 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004207 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004208 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004209 final long identity = Binder.clearCallingIdentity();
4210 try {
4211 Phone phone = getPhone(subId);
4212 if (phone != null) {
4213 return phone.isVolteEnabled();
4214 } else {
4215 return false;
4216 }
4217 } finally {
4218 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004219 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004220 }
Svet Ganovb320e182015-04-16 12:30:10 -07004221
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004222 /**
4223 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004224 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004225 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004226 final long identity = Binder.clearCallingIdentity();
4227 try {
4228 Phone phone = getPhone(subId);
4229 if (phone != null) {
4230 return phone.isVideoEnabled();
4231 } else {
4232 return false;
4233 }
4234 } finally {
4235 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004236 }
4237 }
4238
4239 /**
4240 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4241 * defined in {@link ImsRegistrationImplBase}.
4242 */
4243 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004244 final long identity = Binder.clearCallingIdentity();
4245 try {
4246 Phone phone = getPhone(subId);
4247 if (phone != null) {
4248 return phone.getImsRegistrationTech();
4249 } else {
4250 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4251 }
4252 } finally {
4253 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004254 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004255 }
4256
Stuart Scott8eef64f2015-04-08 15:13:54 -07004257 @Override
4258 public void factoryReset(int subId) {
4259 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004260 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4261 return;
4262 }
4263
Svet Ganovcc087f82015-05-12 20:35:54 -07004264 final long identity = Binder.clearCallingIdentity();
4265 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004266 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4267 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004268 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004269 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004270 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4271 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004272 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004273 }
4274 } finally {
4275 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004276 }
4277 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004278
4279 @Override
4280 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 // We query all subscriptions instead of just the active ones, because
4284 // this might be called early on in the provisioning flow when the
4285 // subscriptions potentially aren't active yet.
4286 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4287 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004288 return null;
4289 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004290
Malcolm Chenaabec062018-02-28 15:00:40 -08004291 // This function may be called very early, say, from the setup wizard, at
4292 // which point we won't have a default subscription set. If that's the case
4293 // we just choose the first, which will be valid in "most cases".
4294 final int defaultSubId = getDefaultSubscription();
4295 SubscriptionInfo info = null;
4296 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4297 info = slist.get(0);
4298 } else {
4299 for (SubscriptionInfo item : slist) {
4300 if (item.getSubscriptionId() == defaultSubId) {
4301 info = item;
4302 break;
4303 }
4304 }
4305
4306 if (info == null) {
4307 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004308 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004309 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004310
Malcolm Chenaabec062018-02-28 15:00:40 -08004311 // Try and fetch the locale from the carrier properties or from the SIM language
4312 // preferences (EF-PL and EF-LI)...
4313 final int mcc = info.getMcc();
4314 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4315 String simLanguage = null;
4316 if (defaultPhone != null) {
4317 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4318 if (localeFromDefaultSim != null) {
4319 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4320 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4321 return localeFromDefaultSim.toLanguageTag();
4322 } else {
4323 simLanguage = localeFromDefaultSim.getLanguage();
4324 }
4325 }
4326 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004327
Malcolm Chenaabec062018-02-28 15:00:40 -08004328 // The SIM language preferences only store a language (e.g. fr = French), not an
4329 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4330 // the SIM and carrier preferences does not include a country we add the country
4331 // determined from the SIM MCC to provide an exact locale.
4332 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4333 simLanguage);
4334 if (mccLocale != null) {
4335 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4336 return mccLocale.toLanguageTag();
4337 }
4338
4339 if (DBG) log("No locale found - returning null");
4340 return null;
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004344 }
4345
4346 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004347 return mSubscriptionController.getAllSubInfoList(
4348 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004349 }
4350
Malcolm Chenaabec062018-02-28 15:00:40 -08004351 /**
4352 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4353 */
4354 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4355 return mSubscriptionController.getActiveSubscriptionInfoList(
4356 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004357 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004358
Chenjie Yu1ba97252018-01-11 18:16:20 -08004359 private final ModemActivityInfo mLastModemActivityInfo =
4360 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4361
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004362 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004363 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4364 * representing the state of the modem.
4365 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004366 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4367 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004368 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004369 */
4370 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004371 public void requestModemActivityInfo(ResultReceiver result) {
4372 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004373 ModemActivityInfo ret = null;
vagdevie435a3e2018-08-15 16:01:53 -07004374 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Adam Lesinski903a54c2016-04-11 14:49:52 -07004375
Malcolm Chenaabec062018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004378 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004379 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4380 CMD_GET_MODEM_ACTIVITY_INFO,
4381 null, workSource);
Siddharth Rayc339f892018-06-17 15:02:38 -07004382 if (isModemActivityInfoValid(info)) {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004383 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4384 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4385 mergedTxTimeMs[i] =
4386 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4387 }
4388 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4389 mLastModemActivityInfo.setSleepTimeMillis(
4390 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4391 mLastModemActivityInfo.setIdleTimeMillis(
4392 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4393 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4394 mLastModemActivityInfo.setRxTimeMillis(
4395 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4396 mLastModemActivityInfo.setEnergyUsed(
4397 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004398 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004399 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4400 mLastModemActivityInfo.getSleepTimeMillis(),
4401 mLastModemActivityInfo.getIdleTimeMillis(),
4402 mLastModemActivityInfo.getTxTimeMillis(),
4403 mLastModemActivityInfo.getRxTimeMillis(),
4404 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004405 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004406 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004407 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004408 result.send(0, bundle);
4409 } finally {
4410 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004411 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004412 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004413
Siddharth Rayc339f892018-06-17 15:02:38 -07004414 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4415 // less than total activity duration.
4416 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4417 if (info == null) {
4418 return false;
4419 }
4420 int activityDurationMs =
4421 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4422 int totalTxTimeMs = 0;
4423 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4424 totalTxTimeMs += info.getTxTimeMillis()[i];
4425 }
4426 return (info.isValid()
4427 && (info.getSleepTimeMillis() <= activityDurationMs)
4428 && (info.getIdleTimeMillis() <= activityDurationMs)
4429 && (info.getRxTimeMillis() <= activityDurationMs)
4430 && (totalTxTimeMs <= activityDurationMs));
4431 }
4432
Jack Yu85bd38a2015-11-09 11:34:32 -08004433 /**
4434 * {@hide}
4435 * Returns the service state information on specified subscription.
4436 */
4437 @Override
4438 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004440 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004441 return null;
4442 }
4443
Malcolm Chenaabec062018-02-28 15:00:40 -08004444 final long identity = Binder.clearCallingIdentity();
4445 try {
4446 final Phone phone = getPhone(subId);
4447 if (phone == null) {
4448 return null;
4449 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004450
Malcolm Chenaabec062018-02-28 15:00:40 -08004451 return phone.getServiceState();
4452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004455 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004456
4457 /**
4458 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4459 *
4460 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4461 * voicemail ringtone.
4462 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4463 * PhoneAccount.
4464 */
4465 @Override
4466 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004467 final long identity = Binder.clearCallingIdentity();
4468 try {
4469 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4470 if (phone == null) {
4471 phone = mPhone;
4472 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004473
Malcolm Chenaabec062018-02-28 15:00:40 -08004474 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004478 }
4479
4480 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004481 * Sets the per-account voicemail ringtone.
4482 *
4483 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4484 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4485 *
4486 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4487 * voicemail ringtone.
4488 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4489 * PhoneAccount.
4490 */
4491 @Override
4492 public void setVoicemailRingtoneUri(String callingPackage,
4493 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4494 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4495 if (!TextUtils.equals(callingPackage,
4496 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4498 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4499 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004500 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004501
4502 final long identity = Binder.clearCallingIdentity();
4503 try {
4504 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4505 if (phone == null) {
4506 phone = mPhone;
4507 }
4508 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4509 } finally {
4510 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004511 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004512 }
4513
4514 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004515 * Returns whether vibration is set for voicemail notification in Phone settings.
4516 *
4517 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4518 * voicemail vibration setting.
4519 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4520 */
4521 @Override
4522 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004523 final long identity = Binder.clearCallingIdentity();
4524 try {
4525 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4526 if (phone == null) {
4527 phone = mPhone;
4528 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004529
Malcolm Chenaabec062018-02-28 15:00:40 -08004530 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004534 }
4535
Youhan Wange64578a2016-05-02 15:32:42 -07004536 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004537 * Sets the per-account voicemail vibration.
4538 *
4539 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4540 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4541 *
4542 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4543 * voicemail vibration setting.
4544 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4545 * specific PhoneAccount.
4546 */
4547 @Override
4548 public void setVoicemailVibrationEnabled(String callingPackage,
4549 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4551 if (!TextUtils.equals(callingPackage,
4552 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4554 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4555 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004556 }
4557
Malcolm Chenaabec062018-02-28 15:00:40 -08004558 final long identity = Binder.clearCallingIdentity();
4559 try {
4560 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4561 if (phone == null) {
4562 phone = mPhone;
4563 }
4564 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4565 } finally {
4566 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004567 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004568 }
4569
4570 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004571 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4572 *
4573 * @throws SecurityException if the caller does not have the required permission
4574 */
4575 private void enforceReadPrivilegedPermission() {
4576 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4577 null);
4578 }
4579
4580 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004581 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4582 * permission.
4583 *
4584 * @throws SecurityException if the caller does not have the required permission
4585 */
4586 private void enforceSendSmsPermission() {
4587 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4588 }
4589
4590 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004591 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004592 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004593 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004594 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004595 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004596 final long identity = Binder.clearCallingIdentity();
4597 try {
4598 ComponentName componentName =
4599 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4600 if (componentName == null) {
4601 throw new SecurityException(
4602 "Caller not current active visual voicemail package[null]");
4603 }
4604 String vvmPackage = componentName.getPackageName();
4605 if (!callingPackage.equals(vvmPackage)) {
4606 throw new SecurityException("Caller not current active visual voicemail package["
4607 + vvmPackage + "]");
4608 }
4609 } finally {
4610 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004611 }
4612 }
4613
4614 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004615 * Return the application ID for the app type.
4616 *
4617 * @param subId the subscription ID that this request applies to.
4618 * @param appType the uicc app type.
4619 * @return Application ID for specificied app type, or null if no uicc.
4620 */
4621 @Override
4622 public String getAidForAppType(int subId, int appType) {
4623 enforceReadPrivilegedPermission();
4624 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004625
4626 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004627 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004628 if (phone == null) {
4629 return null;
4630 }
4631 String aid = null;
4632 try {
4633 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4634 .getApplicationByType(appType).getAid();
4635 } catch (Exception e) {
4636 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4637 }
4638 return aid;
4639 } finally {
4640 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004641 }
Youhan Wange64578a2016-05-02 15:32:42 -07004642 }
4643
Youhan Wang4001d252016-05-11 10:29:41 -07004644 /**
4645 * Return the Electronic Serial Number.
4646 *
4647 * @param subId the subscription ID that this request applies to.
4648 * @return ESN or null if error.
4649 */
4650 @Override
4651 public String getEsn(int subId) {
4652 enforceReadPrivilegedPermission();
4653 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004654
4655 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004656 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004657 if (phone == null) {
4658 return null;
4659 }
4660 String esn = null;
4661 try {
4662 esn = phone.getEsn();
4663 } catch (Exception e) {
4664 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4665 }
4666 return esn;
4667 } finally {
4668 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004669 }
Youhan Wang4001d252016-05-11 10:29:41 -07004670 }
4671
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004672 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004673 * Return the Preferred Roaming List Version.
4674 *
4675 * @param subId the subscription ID that this request applies to.
4676 * @return PRLVersion or null if error.
4677 */
4678 @Override
4679 public String getCdmaPrlVersion(int subId) {
4680 enforceReadPrivilegedPermission();
4681 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004682
4683 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004684 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004685 if (phone == null) {
4686 return null;
4687 }
4688 String cdmaPrlVersion = null;
4689 try {
4690 cdmaPrlVersion = phone.getCdmaPrlVersion();
4691 } catch (Exception e) {
4692 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4693 }
4694 return cdmaPrlVersion;
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004697 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004698 }
4699
4700 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004701 * Get snapshot of Telephony histograms
4702 * @return List of Telephony histograms
4703 * @hide
4704 */
4705 @Override
4706 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4708 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004709
4710 final long identity = Binder.clearCallingIdentity();
4711 try {
4712 return RIL.getTelephonyRILTimingHistograms();
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
4715 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004716 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004717
4718 /**
4719 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004720 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004721 * Require system privileges. In the future we may add this to carrier APIs.
4722 *
4723 * @return The number of carriers set successfully, should match length of carriers
4724 */
4725 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004726 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004727 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004728 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004729
Meng Wang9b7c4e92017-02-17 11:41:27 -08004730 if (carriers == null) {
4731 throw new NullPointerException("carriers cannot be null");
4732 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004733
Malcolm Chenaabec062018-02-28 15:00:40 -08004734 final long identity = Binder.clearCallingIdentity();
4735 try {
4736 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004737 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4738 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004739 return retVal[0];
4740 } finally {
4741 Binder.restoreCallingIdentity(identity);
4742 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004743 }
4744
4745 /**
4746 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004747 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004748 * Require system privileges. In the future we may add this to carrier APIs.
4749 *
4750 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4751 * means all carriers are allowed.
4752 */
4753 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004754 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004755 enforceReadPrivilegedPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08004757
4758 final long identity = Binder.clearCallingIdentity();
4759 try {
4760 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004761 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4762 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004766 }
4767
fionaxu59545b42016-05-25 15:53:37 -07004768 /**
4769 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4770 * @param subId the subscription ID that this action applies to.
4771 * @param enabled control enable or disable metered apns.
4772 * {@hide}
4773 */
4774 @Override
4775 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4776 enforceModifyPermission();
4777 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004778
4779 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004780 if (phone == null) {
4781 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4782 return;
4783 }
4784 try {
4785 phone.carrierActionSetMeteredApnsEnabled(enabled);
4786 } catch (Exception e) {
4787 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004788 } finally {
4789 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004790 }
4791 }
4792
4793 /**
4794 * Action set from carrier signalling broadcast receivers to enable/disable radio
4795 * @param subId the subscription ID that this action applies to.
4796 * @param enabled control enable or disable radio.
4797 * {@hide}
4798 */
4799 @Override
4800 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4801 enforceModifyPermission();
4802 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004803
4804 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004805 if (phone == null) {
4806 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4807 return;
4808 }
4809 try {
4810 phone.carrierActionSetRadioEnabled(enabled);
4811 } catch (Exception e) {
4812 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004813 } finally {
4814 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004815 }
4816 }
4817
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004818 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004819 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4820 * network status based on which carrier apps could apply actions accordingly,
4821 * enable/disable default url handler for example.
4822 *
4823 * @param subId the subscription ID that this action applies to.
4824 * @param report control start/stop reporting the default network status.
4825 * {@hide}
4826 */
4827 @Override
4828 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4829 enforceModifyPermission();
4830 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004831
4832 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004833 if (phone == null) {
4834 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4835 return;
4836 }
4837 try {
4838 phone.carrierActionReportDefaultNetworkStatus(report);
4839 } catch (Exception e) {
4840 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004841 } finally {
4842 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004843 }
4844 }
4845
4846 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004847 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4848 * bug report is being generated.
4849 */
4850 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004851 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004852 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4853 != PackageManager.PERMISSION_GRANTED) {
4854 writer.println("Permission Denial: can't dump Phone from pid="
4855 + Binder.getCallingPid()
4856 + ", uid=" + Binder.getCallingUid()
4857 + "without permission "
4858 + android.Manifest.permission.DUMP);
4859 return;
4860 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004861 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004862 }
Jack Yueb89b242016-06-22 13:27:47 -07004863
Brad Ebingerdac2f002018-04-03 15:17:52 -07004864 @Override
4865 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4866 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4867 throws RemoteException {
4868 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4869 }
4870
Jack Yueb89b242016-06-22 13:27:47 -07004871 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004872 * Get aggregated video call data usage since boot.
4873 *
4874 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4875 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004876 * {@hide}
4877 */
4878 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004879 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004880 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4881 null);
4882
Malcolm Chenaabec062018-02-28 15:00:40 -08004883 final long identity = Binder.clearCallingIdentity();
4884 try {
4885 // NetworkStatsService keeps tracking the active network interface and identity. It
4886 // records the delta with the corresponding network identity.
4887 // We just return the total video call data usage snapshot since boot.
4888 Phone phone = getPhone(subId);
4889 if (phone != null) {
4890 return phone.getVtDataUsage(perUidStats);
4891 }
4892 return null;
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004895 }
Jack Yueb89b242016-06-22 13:27:47 -07004896 }
Jack Yu75ab2952016-07-08 14:29:33 -07004897
4898 /**
4899 * Policy control of data connection. Usually used when data limit is passed.
4900 * @param enabled True if enabling the data, otherwise disabling.
4901 * @param subId Subscription index
4902 * {@hide}
4903 */
4904 @Override
4905 public void setPolicyDataEnabled(boolean enabled, int subId) {
4906 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004907
4908 final long identity = Binder.clearCallingIdentity();
4909 try {
4910 Phone phone = getPhone(subId);
4911 if (phone != null) {
4912 phone.setPolicyDataEnabled(enabled);
4913 }
4914 } finally {
4915 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004916 }
4917 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004918
4919 /**
4920 * Get Client request stats
4921 * @return List of Client Request Stats
4922 * @hide
4923 */
4924 @Override
4925 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004927 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004928 return null;
4929 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004930 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004931
Malcolm Chenaabec062018-02-28 15:00:40 -08004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 if (phone != null) {
4935 return phone.getClientRequestStats();
4936 }
4937
4938 return null;
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004942 }
4943
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004944 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004945 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004946 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004947 }
Jack Yueb4124c2017-02-16 15:32:43 -08004948
4949 /**
Grace Chen70990072017-03-24 17:21:30 -07004950 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004951 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004952 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004953 * @param state State of SIM (power down, power up, pass through)
4954 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4955 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4956 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004957 *
4958 **/
4959 @Override
Grace Chen70990072017-03-24 17:21:30 -07004960 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004961 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004962 Phone phone = PhoneFactory.getPhone(slotIndex);
4963
vagdevie435a3e2018-08-15 16:01:53 -07004964 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4965
Malcolm Chenaabec062018-02-28 15:00:40 -08004966 final long identity = Binder.clearCallingIdentity();
4967 try {
4968 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07004969 phone.setSimPowerState(state, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004970 }
4971 } finally {
4972 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004973 }
4974 }
Shuo Qiandd210312017-04-12 22:11:33 +00004975
Tyler Gunn65d45c22017-06-05 11:22:26 -07004976 private boolean isUssdApiAllowed(int subId) {
4977 CarrierConfigManager configManager =
4978 (CarrierConfigManager) mPhone.getContext().getSystemService(
4979 Context.CARRIER_CONFIG_SERVICE);
4980 if (configManager == null) {
4981 return false;
4982 }
4983 PersistableBundle pb = configManager.getConfigForSubId(subId);
4984 if (pb == null) {
4985 return false;
4986 }
4987 return pb.getBoolean(
4988 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4989 }
4990
Shuo Qiandd210312017-04-12 22:11:33 +00004991 /**
4992 * Check if phone is in emergency callback mode
4993 * @return true if phone is in emergency callback mode
4994 * @param subId sub id
4995 */
goneil9c5f4872017-12-05 14:07:56 -08004996 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004997 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004998 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004999 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08005000
5001 final long identity = Binder.clearCallingIdentity();
5002 try {
5003 if (phone != null) {
5004 return phone.isInEcm();
5005 } else {
5006 return false;
5007 }
5008 } finally {
5009 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005010 }
5011 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005012
5013 /**
5014 * Get the current signal strength information for the given subscription.
5015 * Because this information is not updated when the device is in a low power state
5016 * it should not be relied-upon to be current.
5017 * @param subId Subscription index
5018 * @return the most recent cached signal strength info from the modem
5019 */
5020 @Override
5021 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08005022 final long identity = Binder.clearCallingIdentity();
5023 try {
5024 Phone p = getPhone(subId);
5025 if (p == null) {
5026 return null;
5027 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005028
Malcolm Chenaabec062018-02-28 15:00:40 -08005029 return p.getSignalStrength();
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
5032 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005033 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005034
Pengquan Meng9140aec2018-08-22 14:49:57 -07005035 /**
5036 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5037 *
5038 * <p>Requires one of the following permissions:
5039 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5040 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5041 * privileges.
5042 *
5043 * @param subId subscription id
5044 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5045 * {@code false}.
5046 */
5047 @Override
5048 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005049 boolean isEnabled = false;
5050 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005051 try {
5052 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005053 null /* message */);
5054 Phone phone = getPhone(subId);
5055 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005056 } catch (Exception e) {
5057 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5058 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005061 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005062 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005063 }
5064
5065
5066 /**
5067 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5068 *
5069 * <p> Requires permission:
5070 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5071 * privileges.
5072 *
5073 * @param subId subscription id
5074 * @param isEnabled {@code true} means enable, {@code false} means disable.
5075 */
5076 @Override
5077 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5081 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005082
Pengquan Meng0c05b502018-09-06 09:59:22 -07005083 Phone phone = getPhone(subId);
5084 if (phone != null) {
5085 phone.setDataRoamingEnabled(isEnabled);
5086 }
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005089 }
5090 }
5091
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005092 @Override
5093 public UiccSlotInfo[] getUiccSlotsInfo() {
5094 enforceReadPrivilegedPermission();
5095
Malcolm Chenaabec062018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005099 if (slots == null) {
5100 Rlog.i(LOG_TAG, "slots is null.");
5101 return null;
5102 }
5103
Malcolm Chenaabec062018-02-28 15:00:40 -08005104 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5105 for (int i = 0; i < slots.length; i++) {
5106 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005107 if (slot == null) {
5108 continue;
5109 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005110
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005111 String cardId;
5112 UiccCard card = slot.getUiccCard();
5113 if (card != null) {
5114 cardId = card.getCardId();
5115 } else {
5116 cardId = slot.getIccId();
5117 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005118
Malcolm Chenaabec062018-02-28 15:00:40 -08005119 int cardState = 0;
5120 switch (slot.getCardState()) {
5121 case CARDSTATE_ABSENT:
5122 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5123 break;
5124 case CARDSTATE_PRESENT:
5125 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5126 break;
5127 case CARDSTATE_ERROR:
5128 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5129 break;
5130 case CARDSTATE_RESTRICTED:
5131 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5132 break;
5133 default:
5134 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005135
Malcolm Chenaabec062018-02-28 15:00:40 -08005136 }
5137
5138 infos[i] = new UiccSlotInfo(
5139 slot.isActive(),
5140 slot.isEuicc(),
5141 cardId,
5142 cardState,
5143 slot.getPhoneId(),
5144 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005145 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005146 return infos;
5147 } finally {
5148 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005149 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005150 }
5151
5152 @Override
5153 public boolean switchSlots(int[] physicalSlots) {
5154 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005155
5156 final long identity = Binder.clearCallingIdentity();
5157 try {
5158 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005162 }
Jack Yu4c988042018-02-27 15:30:01 -08005163
5164 @Override
5165 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5166 enforceModifyPermission();
5167 final Phone phone = getPhone(subId);
5168 if (phone == null) {
5169 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5170 return;
5171 }
5172
Malcolm Chenaabec062018-02-28 15:00:40 -08005173 final long identity = Binder.clearCallingIdentity();
5174 try {
5175 phone.setRadioIndicationUpdateMode(filters, mode);
5176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
Jack Yu4c988042018-02-27 15:30:01 -08005179 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005180
5181 /**
goneil47ffb6e2018-04-06 15:40:58 -07005182 * A test API to reload the UICC profile.
5183 *
5184 * <p>Requires that the calling app has permission
5185 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5186 * @hide
5187 */
5188 @Override
5189 public void refreshUiccProfile(int subId) {
5190 enforceModifyPermission();
5191
5192 final long identity = Binder.clearCallingIdentity();
5193 try {
5194 Phone phone = getPhone(subId);
5195 if (phone == null) {
5196 return;
5197 }
5198 UiccCard uiccCard = phone.getUiccCard();
5199 if (uiccCard == null) {
5200 return;
5201 }
5202 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5203 if (uiccProfile == null) {
5204 return;
5205 }
5206 uiccProfile.refresh();
5207 } finally {
5208 Binder.restoreCallingIdentity(identity);
5209 }
5210 }
5211
5212 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005213 * Returns false if the mobile data is disabled by default, otherwise return true.
5214 */
5215 private boolean getDefaultDataEnabled() {
5216 return "true".equalsIgnoreCase(
5217 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5218 }
5219
5220 /**
5221 * Returns true if the data roaming is enabled by default, i.e the system property
5222 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5223 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5224 */
5225 private boolean getDefaultDataRoamingEnabled(int subId) {
5226 final CarrierConfigManager configMgr = (CarrierConfigManager)
5227 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5228 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5229 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5230 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5231 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5232 return isDataRoamingEnabled;
5233 }
5234
5235 /**
5236 * Returns the default network type for the given {@code subId}, if the default network type is
5237 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5238 */
5239 private int getDefaultNetworkType(int subId) {
5240 return Integer.parseInt(
5241 TelephonyManager.getTelephonyProperty(
5242 mSubscriptionController.getPhoneId(subId),
5243 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5244 String.valueOf(Phone.PREFERRED_NT_MODE)));
5245 }
fionaxua13278b2018-03-21 00:08:13 -07005246
5247 @Override
5248 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5249 gid1, String gid2, String plmn, String spn) {
5250 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005251
5252 final long identity = Binder.clearCallingIdentity();
5253 try {
5254 final Phone phone = getPhone(subId);
5255 if (phone == null) {
5256 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5257 return;
5258 }
5259 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005262 }
fionaxua13278b2018-03-21 00:08:13 -07005263 }
5264
5265 @Override
5266 public int getCarrierIdListVersion(int subId) {
5267 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005268
5269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 final Phone phone = getPhone(subId);
5272 if (phone == null) {
5273 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5274 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5275 }
5276 return phone.getCarrierIdListVersion();
5277 } finally {
5278 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005279 }
fionaxua13278b2018-03-21 00:08:13 -07005280 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005281
5282 @Override
5283 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5285 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5286 return -1;
5287 }
5288
5289 final long identity = Binder.clearCallingIdentity();
5290 try {
5291 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5292 } finally {
5293 Binder.restoreCallingIdentity(identity);
5294 }
5295 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005296
5297 @Override
5298 public int getCdmaRoamingMode(int subId) {
5299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5300 mApp, subId, "getCdmaRoamingMode");
5301
5302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
5308 }
5309
5310 @Override
5311 public boolean setCdmaRoamingMode(int subId, int mode) {
5312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5313 mApp, subId, "setCdmaRoamingMode");
5314
5315 final long identity = Binder.clearCallingIdentity();
5316 try {
5317 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5318 } finally {
5319 Binder.restoreCallingIdentity(identity);
5320 }
5321 }
5322
5323 @Override
5324 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5326 mApp, subId, "setCdmaSubscriptionMode");
5327
5328 final long identity = Binder.clearCallingIdentity();
5329 try {
5330 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
5334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005335}