blob: 876ce0afea6cb58284aac1cda0fbb51220655666 [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:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700767 ar = (AsyncResult) msg.obj;
768 request = (MainThreadRequest) ar.userObj;
769 if (ar.exception == null) {
770 request.result = true;
771 } else {
772 request.result = false;
773 loge("setNetworkSelectionModeManual " + ar.exception);
774 }
775 notifyRequester(request);
776 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700777 break;
778
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700779 case CMD_GET_MODEM_ACTIVITY_INFO:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700782 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700783 break;
784
785 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
786 ar = (AsyncResult) msg.obj;
787 request = (MainThreadRequest) ar.userObj;
788 if (ar.exception == null && ar.result != null) {
789 request.result = ar.result;
790 } else {
791 if (ar.result == null) {
792 loge("queryModemActivityInfo: Empty response");
793 } else if (ar.exception instanceof CommandException) {
794 loge("queryModemActivityInfo: CommandException: " +
795 ar.exception);
796 } else {
797 loge("queryModemActivityInfo: Unknown exception");
798 }
799 }
Amit Mahajand4766222016-01-28 15:28:28 -0800800 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
801 if (request.result == null) {
802 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
803 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700804 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700805 break;
806
Meng Wang1a7c35a2016-05-05 20:56:15 -0700807 case CMD_SET_ALLOWED_CARRIERS:
808 request = (MainThreadRequest) msg.obj;
809 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
810 mPhone.setAllowedCarriers(
811 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700812 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700813 break;
814
815 case EVENT_SET_ALLOWED_CARRIERS_DONE:
816 ar = (AsyncResult) msg.obj;
817 request = (MainThreadRequest) ar.userObj;
818 if (ar.exception == null && ar.result != null) {
819 request.result = ar.result;
820 } else {
821 if (ar.result == null) {
822 loge("setAllowedCarriers: Empty response");
823 } else if (ar.exception instanceof CommandException) {
824 loge("setAllowedCarriers: CommandException: " +
825 ar.exception);
826 } else {
827 loge("setAllowedCarriers: Unknown exception");
828 }
829 }
830 // Result cannot be null. Return -1 on error.
831 if (request.result == null) {
832 request.result = new int[]{-1};
833 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700834 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700835 break;
836
837 case CMD_GET_ALLOWED_CARRIERS:
838 request = (MainThreadRequest) msg.obj;
839 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700840 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700841 break;
842
843 case EVENT_GET_ALLOWED_CARRIERS_DONE:
844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null && ar.result != null) {
847 request.result = ar.result;
848 } else {
849 if (ar.result == null) {
850 loge("getAllowedCarriers: Empty response");
851 } else if (ar.exception instanceof CommandException) {
852 loge("getAllowedCarriers: CommandException: " +
853 ar.exception);
854 } else {
855 loge("getAllowedCarriers: Unknown exception");
856 }
857 }
858 // Result cannot be null. Return empty list of CarrierIdentifier.
859 if (request.result == null) {
860 request.result = new ArrayList<CarrierIdentifier>(0);
861 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700862 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700863 break;
864
Nathan Haroldb3014052017-01-25 15:57:32 -0800865 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
868 if (ar.exception == null && ar.result != null) {
869 request.result = ar.result;
870 } else {
871 request.result = new IllegalArgumentException(
872 "Failed to retrieve Forbidden Plmns");
873 if (ar.result == null) {
874 loge("getForbiddenPlmns: Empty response");
875 } else {
876 loge("getForbiddenPlmns: Unknown exception");
877 }
878 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700879 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800880 break;
881
882 case CMD_GET_FORBIDDEN_PLMNS:
883 request = (MainThreadRequest) msg.obj;
884 uiccCard = getUiccCardFromRequest(request);
885 if (uiccCard == null) {
886 loge("getForbiddenPlmns() UiccCard is null");
887 request.result = new IllegalArgumentException(
888 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700889 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800890 break;
891 }
892 Integer appType = (Integer) request.argument;
893 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
894 if (uiccApp == null) {
895 loge("getForbiddenPlmns() no app with specified type -- "
896 + appType);
897 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700898 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800899 break;
900 } else {
901 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
902 + " specified type -- " + appType);
903 }
904 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
905 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
906 onCompleted);
907 break;
908
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000909 case CMD_SWITCH_SLOTS:
910 request = (MainThreadRequest) msg.obj;
911 int[] physicalSlots = (int[]) request.argument;
912 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
913 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
914 break;
915
916 case EVENT_SWITCH_SLOTS_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700920 notifyRequester(request);
921 break;
922 case CMD_GET_NETWORK_SELECTION_MODE:
923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
925 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
926 break;
927
928 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
929 ar = (AsyncResult) msg.obj;
930 request = (MainThreadRequest) ar.userObj;
931 if (ar.exception != null) {
932 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
933 } else {
934 int mode = ((int[]) ar.result)[0];
935 if (mode == 0) {
936 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
937 } else {
938 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
939 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000940 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700941 notifyRequester(request);
942 break;
943 case CMD_GET_CDMA_ROAMING_MODE:
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
946 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
947 break;
948 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 if (ar.exception != null) {
952 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
953 } else {
954 request.result = ((int[]) ar.result)[0];
955 }
956 notifyRequester(request);
957 break;
958 case CMD_SET_CDMA_ROAMING_MODE:
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
961 int mode = (int) request.argument;
962 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
963 break;
964 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 request.result = ar.exception == null;
968 notifyRequester(request);
969 break;
970 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
973 int subscriptionMode = (int) request.argument;
974 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
975 break;
976 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
979 request.result = ar.exception == null;
980 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000981 break;
982
Nathan Harold3ff88932018-08-14 10:19:49 -0700983 case CMD_GET_ALL_CELL_INFO:
984 request = (MainThreadRequest) msg.obj;
985 Pair<Phone, WorkSource> args = (Pair<Phone, WorkSource>) request.argument;
986 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
987 ((Phone) args.first).getAllCellInfo(args.second, onCompleted);
988 break;
989
990 case EVENT_GET_ALL_CELL_INFO_DONE:
991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -0700993 // If a timeout occurs, the response will be null
994 request.result = (ar.exception == null && ar.result != null)
995 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -0700996 synchronized (request) {
997 request.notifyAll();
998 }
999 break;
1000
1001 case CMD_GET_CELL_LOCATION: {
1002 request = (MainThreadRequest) msg.obj;
1003 WorkSource ws = (WorkSource) request.argument;
1004 Phone phone = getPhoneFromRequest(request);
1005 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1006 break;
1007 }
1008
1009 case EVENT_GET_CELL_LOCATION_DONE: {
1010 ar = (AsyncResult) msg.obj;
1011 request = (MainThreadRequest) ar.userObj;
1012 if (ar.exception == null) {
1013 request.result = ar.result;
1014 } else {
1015 Phone phone = getPhoneFromRequest(request);
1016 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1017 ? new CdmaCellLocation() : new GsmCellLocation();
1018 }
1019
1020 synchronized (request) {
1021 request.notifyAll();
1022 }
1023 break;
1024 }
1025
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 default:
1027 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1028 break;
1029 }
1030 }
Jake Hambye994d462014-02-03 13:10:13 -08001031
Pengquan Meng0c05b502018-09-06 09:59:22 -07001032 private void notifyRequester(MainThreadRequest request) {
1033 synchronized (request) {
1034 request.notifyAll();
1035 }
1036 }
1037
Jake Hambye994d462014-02-03 13:10:13 -08001038 private void handleNullReturnEvent(Message msg, String command) {
1039 AsyncResult ar = (AsyncResult) msg.obj;
1040 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1041 if (ar.exception == null) {
1042 request.result = true;
1043 } else {
1044 request.result = false;
1045 if (ar.exception instanceof CommandException) {
1046 loge(command + ": CommandException: " + ar.exception);
1047 } else {
1048 loge(command + ": Unknown exception");
1049 }
1050 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001051 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001053 }
1054
1055 /**
1056 * Posts the specified command to be executed on the main thread,
1057 * waits for the request to complete, and returns the result.
1058 * @see #sendRequestAsync
1059 */
1060 private Object sendRequest(int command, Object argument) {
vagdevie435a3e2018-08-15 16:01:53 -07001061 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1062 }
1063
1064 /**
1065 * Posts the specified command to be executed on the main thread,
1066 * waits for the request to complete, and returns the result.
1067 * @see #sendRequestAsync
1068 */
1069 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1070 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1071 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001072 }
1073
1074 /**
1075 * Posts the specified command to be executed on the main thread,
1076 * waits for the request to complete, and returns the result.
1077 * @see #sendRequestAsync
1078 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001079 private Object sendRequest(int command, Object argument, Integer subId) {
vagdevie435a3e2018-08-15 16:01:53 -07001080 return sendRequest(command, argument, subId, null);
1081 }
1082
1083 /**
1084 * Posts the specified command to be executed on the main thread,
1085 * waits for the request to complete, and returns the result.
1086 * @see #sendRequestAsync
1087 */
1088 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001089 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1090 throw new RuntimeException("This method will deadlock if called from the main thread.");
1091 }
1092
vagdevie435a3e2018-08-15 16:01:53 -07001093 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001094 Message msg = mMainThreadHandler.obtainMessage(command, request);
1095 msg.sendToTarget();
1096
1097 // Wait for the request to complete
1098 synchronized (request) {
1099 while (request.result == null) {
1100 try {
1101 request.wait();
1102 } catch (InterruptedException e) {
1103 // Do nothing, go back and wait until the request is complete
1104 }
1105 }
1106 }
1107 return request.result;
1108 }
1109
1110 /**
1111 * Asynchronous ("fire and forget") version of sendRequest():
1112 * Posts the specified command to be executed on the main thread, and
1113 * returns immediately.
1114 * @see #sendRequest
1115 */
1116 private void sendRequestAsync(int command) {
1117 mMainThreadHandler.sendEmptyMessage(command);
1118 }
1119
1120 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001121 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1122 * @see {@link #sendRequest(int,Object)}
1123 */
1124 private void sendRequestAsync(int command, Object argument) {
1125 MainThreadRequest request = new MainThreadRequest(argument);
1126 Message msg = mMainThreadHandler.obtainMessage(command, request);
1127 msg.sendToTarget();
1128 }
1129
1130 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001131 * Initialize the singleton PhoneInterfaceManager instance.
1132 * This is only done once, at startup, from PhoneApp.onCreate().
1133 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001134 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 synchronized (PhoneInterfaceManager.class) {
1136 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001137 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 } else {
1139 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1140 }
1141 return sInstance;
1142 }
1143 }
1144
1145 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001146 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001147 mApp = app;
1148 mPhone = phone;
1149 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001150 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001151 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1152 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001153 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001154 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001155 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001156 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001157 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001158
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001159 publish();
1160 }
1161
1162 private void publish() {
1163 if (DBG) log("publish: " + this);
1164
1165 ServiceManager.addService("phone", this);
1166 }
1167
Stuart Scott584921c2015-01-15 17:10:34 -08001168 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001169 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1170 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001171 }
1172
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001173 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1174 Phone phone = getPhoneFromRequest(request);
1175 return phone == null ? null :
1176 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1177 }
1178
Wink Saville36469e72014-06-11 15:17:00 -07001179 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001180 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001181 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001183
1184 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001185 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001186 }
1187
Wink Savilleb564aae2014-10-23 10:18:09 -07001188 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189 if (DBG) log("dial: " + number);
1190 // No permission check needed here: This is just a wrapper around the
1191 // ACTION_DIAL intent, which is available to any app since it puts up
1192 // the UI before it does anything.
1193
Malcolm Chenaabec062018-02-28 15:00:40 -08001194 final long identity = Binder.clearCallingIdentity();
1195 try {
1196 String url = createTelUrl(number);
1197 if (url == null) {
1198 return;
1199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001200
Malcolm Chenaabec062018-02-28 15:00:40 -08001201 // PENDING: should we just silently fail if phone is offhook or ringing?
1202 PhoneConstants.State state = mCM.getState(subId);
1203 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1204 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1205 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1206 mApp.startActivity(intent);
1207 }
1208 } finally {
1209 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001210 }
1211 }
1212
1213 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001214 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001215 }
1216
Wink Savilleb564aae2014-10-23 10:18:09 -07001217 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 if (DBG) log("call: " + number);
1219
1220 // This is just a wrapper around the ACTION_CALL intent, but we still
1221 // need to do a permission check since we're calling startActivity()
1222 // from the context of the phone app.
1223 enforceCallPermission();
1224
1225 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1226 != AppOpsManager.MODE_ALLOWED) {
1227 return;
1228 }
1229
Malcolm Chenaabec062018-02-28 15:00:40 -08001230 final long identity = Binder.clearCallingIdentity();
1231 try {
1232 String url = createTelUrl(number);
1233 if (url == null) {
1234 return;
1235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236
Malcolm Chenaabec062018-02-28 15:00:40 -08001237 boolean isValid = false;
1238 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1239 if (slist != null) {
1240 for (SubscriptionInfo subInfoRecord : slist) {
1241 if (subInfoRecord.getSubscriptionId() == subId) {
1242 isValid = true;
1243 break;
1244 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001245 }
Wink Saville08874612014-08-31 19:19:58 -07001246 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001247 if (!isValid) {
1248 return;
1249 }
Wink Saville08874612014-08-31 19:19:58 -07001250
Malcolm Chenaabec062018-02-28 15:00:40 -08001251 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1252 intent.putExtra(SUBSCRIPTION_KEY, subId);
1253 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1254 mApp.startActivity(intent);
1255 } finally {
1256 Binder.restoreCallingIdentity(identity);
1257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 /**
1261 * End a call based on call state
1262 * @return true is a call was ended
1263 */
1264 public boolean endCall() {
Hall Liu91943182018-09-14 17:42:41 -07001265 return false;
Wink Saville36469e72014-06-11 15:17:00 -07001266 }
1267
1268 /**
1269 * End a call based on the call state of the subId
1270 * @return true is a call was ended
1271 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001272 public boolean endCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001273 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 }
1275
1276 public void answerRingingCall() {
Hall Liu91943182018-09-14 17:42:41 -07001277 // Deprecated.
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
Wink Savilleb564aae2014-10-23 10:18:09 -07001280 public void answerRingingCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001281 // Deprecated
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 }
1283
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001285 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001287 public void silenceRinger() {
1288 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001289 }
1290
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001291 @Override
1292 public boolean isOffhook(String callingPackage) {
1293 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001294 }
1295
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001296 @Override
1297 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001299 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001300 return false;
1301 }
1302
Malcolm Chenaabec062018-02-28 15:00:40 -08001303 final long identity = Binder.clearCallingIdentity();
1304 try {
1305 final Phone phone = getPhone(subId);
1306 if (phone != null) {
1307 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1308 } else {
1309 return false;
1310 }
1311 } finally {
1312 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 }
1315
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001316 @Override
1317 public boolean isRinging(String callingPackage) {
1318 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001319 }
1320
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001321 @Override
1322 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001324 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001325 return false;
1326 }
1327
Malcolm Chenaabec062018-02-28 15:00:40 -08001328 final long identity = Binder.clearCallingIdentity();
1329 try {
1330 final Phone phone = getPhone(subId);
1331 if (phone != null) {
1332 return (phone.getState() == PhoneConstants.State.RINGING);
1333 } else {
1334 return false;
1335 }
1336 } finally {
1337 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 }
1340
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001341 @Override
1342 public boolean isIdle(String callingPackage) {
1343 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001344 }
1345
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001346 @Override
1347 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001349 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001350 return false;
1351 }
1352
Malcolm Chenaabec062018-02-28 15:00:40 -08001353 final long identity = Binder.clearCallingIdentity();
1354 try {
1355 final Phone phone = getPhone(subId);
1356 if (phone != null) {
1357 return (phone.getState() == PhoneConstants.State.IDLE);
1358 } else {
1359 return false;
1360 }
1361 } finally {
1362 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 }
1365
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001367 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001368 }
1369
Wink Savilleb564aae2014-10-23 10:18:09 -07001370 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001371 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001372 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1373 }
1374
1375 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001376 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001377 }
1378
Wink Savilleb564aae2014-10-23 10:18:09 -07001379 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001380 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001381 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1382 }
1383
1384 /** {@hide} */
1385 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001386 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001387 }
1388
Wink Savilleb564aae2014-10-23 10:18:09 -07001389 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001391
1392 final long identity = Binder.clearCallingIdentity();
1393 try {
1394 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1395 checkSimPin.start();
1396 return checkSimPin.unlockSim(null, pin);
1397 } finally {
1398 Binder.restoreCallingIdentity(identity);
1399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 }
1401
Wink Saville9de0f752013-10-22 19:04:03 -07001402 /** {@hide} */
1403 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001404 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001405 }
1406
Wink Savilleb564aae2014-10-23 10:18:09 -07001407 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001409
1410 final long identity = Binder.clearCallingIdentity();
1411 try {
1412 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1413 checkSimPuk.start();
1414 return checkSimPuk.unlockSim(puk, pin);
1415 } finally {
1416 Binder.restoreCallingIdentity(identity);
1417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 }
1419
1420 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001421 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001422 * a synchronous one.
1423 */
1424 private static class UnlockSim extends Thread {
1425
1426 private final IccCard mSimCard;
1427
1428 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001429 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1430 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431
1432 // For replies from SimCard interface
1433 private Handler mHandler;
1434
1435 // For async handler to identify request type
1436 private static final int SUPPLY_PIN_COMPLETE = 100;
1437
1438 public UnlockSim(IccCard simCard) {
1439 mSimCard = simCard;
1440 }
1441
1442 @Override
1443 public void run() {
1444 Looper.prepare();
1445 synchronized (UnlockSim.this) {
1446 mHandler = new Handler() {
1447 @Override
1448 public void handleMessage(Message msg) {
1449 AsyncResult ar = (AsyncResult) msg.obj;
1450 switch (msg.what) {
1451 case SUPPLY_PIN_COMPLETE:
1452 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1453 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001454 mRetryCount = msg.arg1;
1455 if (ar.exception != null) {
1456 if (ar.exception instanceof CommandException &&
1457 ((CommandException)(ar.exception)).getCommandError()
1458 == CommandException.Error.PASSWORD_INCORRECT) {
1459 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1460 } else {
1461 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1462 }
1463 } else {
1464 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 mDone = true;
1467 UnlockSim.this.notifyAll();
1468 }
1469 break;
1470 }
1471 }
1472 };
1473 UnlockSim.this.notifyAll();
1474 }
1475 Looper.loop();
1476 }
1477
1478 /*
1479 * Use PIN or PUK to unlock SIM card
1480 *
1481 * If PUK is null, unlock SIM card with PIN
1482 *
1483 * If PUK is not null, unlock SIM card with PUK and set PIN code
1484 */
Wink Saville9de0f752013-10-22 19:04:03 -07001485 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486
1487 while (mHandler == null) {
1488 try {
1489 wait();
1490 } catch (InterruptedException e) {
1491 Thread.currentThread().interrupt();
1492 }
1493 }
1494 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1495
1496 if (puk == null) {
1497 mSimCard.supplyPin(pin, callback);
1498 } else {
1499 mSimCard.supplyPuk(puk, pin, callback);
1500 }
1501
1502 while (!mDone) {
1503 try {
1504 Log.d(LOG_TAG, "wait for done");
1505 wait();
1506 } catch (InterruptedException e) {
1507 // Restore the interrupted status
1508 Thread.currentThread().interrupt();
1509 }
1510 }
1511 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001512 int[] resultArray = new int[2];
1513 resultArray[0] = mResult;
1514 resultArray[1] = mRetryCount;
1515 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001516 }
1517 }
1518
1519 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001520 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001521
1522 }
1523
Wink Savilleb564aae2014-10-23 10:18:09 -07001524 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 // No permission check needed here: this call is harmless, and it's
1526 // needed for the ServiceState.requestStateUpdate() call (which is
1527 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001528 final long identity = Binder.clearCallingIdentity();
1529 try {
1530 final Phone phone = getPhone(subId);
1531 if (phone != null) {
1532 phone.updateServiceLocation();
1533 }
1534 } finally {
1535 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001537 }
1538
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001539 @Override
1540 public boolean isRadioOn(String callingPackage) {
1541 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001544 @Override
1545 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001547 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001548 return false;
1549 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001550
1551 final long identity = Binder.clearCallingIdentity();
1552 try {
1553 return isRadioOnForSubscriber(subId);
1554 } finally {
1555 Binder.restoreCallingIdentity(identity);
1556 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001557 }
1558
1559 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001560 final long identity = Binder.clearCallingIdentity();
1561 try {
1562 final Phone phone = getPhone(subId);
1563 if (phone != null) {
1564 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1565 } else {
1566 return false;
1567 }
1568 } finally {
1569 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 }
1572
1573 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001574 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 }
Wink Saville36469e72014-06-11 15:17:00 -07001576
Wink Savilleb564aae2014-10-23 10:18:09 -07001577 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001579
1580 final long identity = Binder.clearCallingIdentity();
1581 try {
1582 final Phone phone = getPhone(subId);
1583 if (phone != null) {
1584 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1585 }
1586 } finally {
1587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001588 }
Wink Saville36469e72014-06-11 15:17:00 -07001589 }
1590
1591 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001592 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001593 }
1594
Wink Savilleb564aae2014-10-23 10:18:09 -07001595 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001596 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001597
1598 final long identity = Binder.clearCallingIdentity();
1599 try {
1600 final Phone phone = getPhone(subId);
1601 if (phone == null) {
1602 return false;
1603 }
1604 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1605 toggleRadioOnOffForSubscriber(subId);
1606 }
1607 return true;
1608 } finally {
1609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 }
Wink Saville36469e72014-06-11 15:17:00 -07001612
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001613 public boolean needMobileRadioShutdown() {
1614 /*
1615 * If any of the Radios are available, it will need to be
1616 * shutdown. So return true if any Radio is available.
1617 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001618 final long identity = Binder.clearCallingIdentity();
1619 try {
1620 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1621 Phone phone = PhoneFactory.getPhone(i);
1622 if (phone != null && phone.isRadioAvailable()) return true;
1623 }
1624 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1625 return false;
1626 } finally {
1627 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001628 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001629 }
1630
Malcolm Chenaabec062018-02-28 15:00:40 -08001631 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001632 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001633 enforceModifyPermission();
1634
1635 final long identity = Binder.clearCallingIdentity();
1636 try {
1637 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1638 logv("Shutting down Phone " + i);
1639 shutdownRadioUsingPhoneId(i);
1640 }
1641 } finally {
1642 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001643 }
1644 }
1645
1646 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001647 Phone phone = PhoneFactory.getPhone(phoneId);
1648 if (phone != null && phone.isRadioAvailable()) {
1649 phone.shutdownRadio();
1650 }
1651 }
1652
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001654 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001655
1656 final long identity = Binder.clearCallingIdentity();
1657 try {
1658 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1659 if (defaultPhone != null) {
1660 defaultPhone.setRadioPower(turnOn);
1661 return true;
1662 } else {
1663 loge("There's no default phone.");
1664 return false;
1665 }
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001668 }
Wink Saville36469e72014-06-11 15:17:00 -07001669 }
1670
Wink Savilleb564aae2014-10-23 10:18:09 -07001671 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001673
1674 final long identity = Binder.clearCallingIdentity();
1675 try {
1676 final Phone phone = getPhone(subId);
1677 if (phone != null) {
1678 phone.setRadioPower(turnOn);
1679 return true;
1680 } else {
1681 return false;
1682 }
1683 } finally {
1684 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687
Wink Saville36469e72014-06-11 15:17:00 -07001688 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 public boolean enableDataConnectivity() {
1691 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001692
1693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 int subId = mSubscriptionController.getDefaultDataSubId();
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 phone.setUserDataEnabled(true);
1699 return true;
1700 } else {
1701 return false;
1702 }
1703 } finally {
1704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 }
1707
Wink Saville36469e72014-06-11 15:17:00 -07001708 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 public boolean disableDataConnectivity() {
1711 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001712
1713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 int subId = mSubscriptionController.getDefaultDataSubId();
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.setUserDataEnabled(false);
1719 return true;
1720 } else {
1721 return false;
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001729 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001730 final long identity = Binder.clearCallingIdentity();
1731 try {
1732 final Phone phone = getPhone(subId);
1733 if (phone != null) {
1734 return phone.isDataAllowed();
1735 } else {
1736 return false;
1737 }
1738 } finally {
1739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
1742
1743 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001744 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001745 }
1746
pkanwarae03a6b2016-11-06 20:37:09 -08001747 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001748 enforceCallPermission();
1749
1750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1753 return;
1754 }
1755 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1756 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1757 } finally {
1758 Binder.restoreCallingIdentity(identity);
1759 }
pkanwar32d516d2016-10-14 19:37:38 -07001760 };
1761
Wink Savilleb564aae2014-10-23 10:18:09 -07001762 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001764
1765 final long identity = Binder.clearCallingIdentity();
1766 try {
1767 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1768 return false;
1769 }
1770 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
1775
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001777 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001778 }
1779
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001780 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001781 final long identity = Binder.clearCallingIdentity();
1782 try {
1783 Phone phone = PhoneFactory.getPhone(slotIndex);
1784 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1785 PhoneConstantConversions.convertCallState(phone.getState());
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
1788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001793 final long identity = Binder.clearCallingIdentity();
1794 try {
1795 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1796 if (phone != null) {
1797 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1798 } else {
1799 return PhoneConstantConversions.convertDataState(
1800 PhoneConstants.DataState.DISCONNECTED);
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 }
1806
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1812 if (phone != null) {
1813 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1814 } else {
1815 return TelephonyManager.DATA_ACTIVITY_NONE;
1816 }
1817 } finally {
1818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 }
1821
1822 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001823 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001824 mPhone.getContext().getSystemService(AppOpsManager.class)
1825 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001826 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001827 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001828 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 }
1830
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001831 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001832 final long identity = Binder.clearCallingIdentity();
1833 try {
1834 if (DBG_LOC) log("getCellLocation: is active user");
1835 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001836 int subId = mSubscriptionController.getDefaultDataSubId();
1837 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1838 cl.fillInNotifierBundle(data);
Malcolm Chenaabec062018-02-28 15:00:40 -08001839 return data;
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
1842 }
Svetoslav64fad262015-04-14 14:35:21 -07001843 }
1844
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001846 public String getNetworkCountryIsoForPhone(int phoneId) {
1847 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1848 // registered cell info, so return a NULL country instead.
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001852 // Todo: fix this when we can get the actual cellular network info when the device
1853 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001854 if (TelephonyManager.NETWORK_TYPE_IWLAN
1855 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1856 return "";
1857 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001858 Phone phone = PhoneFactory.getPhone(phoneId);
1859 if (phone != null) {
1860 ServiceStateTracker sst = phone.getServiceStateTracker();
1861 if (sst != null) {
1862 LocaleTracker lt = sst.getLocaleTracker();
1863 if (lt != null) {
1864 return lt.getCurrentCountry();
1865 }
1866 }
1867 }
1868 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001869 } finally {
1870 Binder.restoreCallingIdentity(identity);
1871 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001872 }
1873
1874 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001876 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001877 }
1878
Sanket Padawe356d7632015-06-22 14:03:32 -07001879 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001880 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 mApp.enforceCallingOrSelfPermission(
1882 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001883
1884 final long identity = Binder.clearCallingIdentity();
1885 try {
1886 final Phone phone = getPhone(subId);
1887 if (phone != null) {
1888 phone.enableLocationUpdates();
1889 }
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 }
1894
1895 @Override
1896 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001897 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001898 }
1899
Sanket Padawe356d7632015-06-22 14:03:32 -07001900 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001901 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 mApp.enforceCallingOrSelfPermission(
1903 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001904
1905 final long identity = Binder.clearCallingIdentity();
1906 try {
1907 final Phone phone = getPhone(subId);
1908 if (phone != null) {
1909 phone.disableLocationUpdates();
1910 }
1911 } finally {
1912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 }
1915
1916 @Override
1917 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001918 public List<NeighboringCellInfo>
1919 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001920 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1921 throw new SecurityException(
1922 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1923 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001924
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1926 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1927 return null;
1928 }
Svetoslav64fad262015-04-14 14:35:21 -07001929
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001930 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931
Nathan Haroldf180aac2018-06-01 18:43:55 -07001932 List<CellInfo> info = getAllCellInfo(callingPackage);
1933 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934
Nathan Haroldf180aac2018-06-01 18:43:55 -07001935 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1936 for (CellInfo ci : info) {
1937 if (ci instanceof CellInfoGsm) {
1938 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1939 } else if (ci instanceof CellInfoWcdma) {
1940 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001943 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 }
1945
1946
1947 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001948 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001949 mPhone.getContext().getSystemService(AppOpsManager.class)
1950 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001951 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001952 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001953 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
1955
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001956 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001957 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001958 final long identity = Binder.clearCallingIdentity();
1959 try {
1960 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1961 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001962 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1963 CMD_GET_ALL_CELL_INFO,
1964 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaabec062018-02-28 15:00:40 -08001965 if (info != null) cellInfos.addAll(info);
1966 }
1967 return cellInfos;
1968 } finally {
1969 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971 }
1972
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001973 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001975 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001977
1978 final long identity = Binder.clearCallingIdentity();
1979 try {
1980 mPhone.setCellInfoListRate(rateInMillis, workSource);
1981 } finally {
1982 Binder.restoreCallingIdentity(identity);
1983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985
Shishir Agrawala9f32182016-04-12 12:00:16 -07001986 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001987 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001988 Phone phone = PhoneFactory.getPhone(slotIndex);
1989 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001990 return null;
1991 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001992 int subId = phone.getSubId();
1993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1994 mApp, subId, callingPackage, "getImeiForSlot")) {
1995 return null;
1996 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001997
1998 final long identity = Binder.clearCallingIdentity();
1999 try {
2000 return phone.getImei();
2001 } finally {
2002 Binder.restoreCallingIdentity(identity);
2003 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002004 }
2005
2006 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002007 public String getTypeAllocationCodeForSlot(int slotIndex) {
2008 Phone phone = PhoneFactory.getPhone(slotIndex);
2009 String tac = null;
2010 if (phone != null) {
2011 String imei = phone.getImei();
2012 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2013 }
2014 return tac;
2015 }
2016
2017 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002018 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002019 Phone phone = PhoneFactory.getPhone(slotIndex);
2020 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002021 return null;
2022 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002023 int subId = phone.getSubId();
2024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2025 mApp, subId, callingPackage, "getMeidForSlot")) {
2026 return null;
2027 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002028
2029 final long identity = Binder.clearCallingIdentity();
2030 try {
2031 return phone.getMeid();
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
2034 }
Jack Yu2af8d712017-03-15 17:14:14 -07002035 }
2036
2037 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002038 public String getManufacturerCodeForSlot(int slotIndex) {
2039 Phone phone = PhoneFactory.getPhone(slotIndex);
2040 String manufacturerCode = null;
2041 if (phone != null) {
2042 String meid = phone.getMeid();
2043 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2044 }
2045 return manufacturerCode;
2046 }
2047
2048 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002049 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002050 Phone phone = PhoneFactory.getPhone(slotIndex);
2051 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002052 return null;
2053 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002054 int subId = phone.getSubId();
2055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2056 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2057 return null;
2058 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002059
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
2062 return phone.getDeviceSvn();
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
2065 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002066 }
2067
fionaxu43304da2017-11-27 22:51:16 -08002068 @Override
2069 public int getSubscriptionCarrierId(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 ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2074 } finally {
2075 Binder.restoreCallingIdentity(identity);
2076 }
fionaxu43304da2017-11-27 22:51:16 -08002077 }
2078
2079 @Override
2080 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 final Phone phone = getPhone(subId);
2084 return phone == null ? null : phone.getCarrierName();
2085 } finally {
2086 Binder.restoreCallingIdentity(identity);
2087 }
fionaxu43304da2017-11-27 22:51:16 -08002088 }
2089
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 //
2091 // Internal helper methods.
2092 //
2093
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002094 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2096 *
2097 * @throws SecurityException if the caller does not have the required permission
2098 */
2099 private void enforceModifyPermission() {
2100 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2101 }
2102
2103 /**
2104 * Make sure the caller has the CALL_PHONE permission.
2105 *
2106 * @throws SecurityException if the caller does not have the required permission
2107 */
2108 private void enforceCallPermission() {
2109 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2110 }
2111
Stuart Scott8eef64f2015-04-08 15:13:54 -07002112 private void enforceConnectivityInternalPermission() {
2113 mApp.enforceCallingOrSelfPermission(
2114 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2115 "ConnectivityService");
2116 }
2117
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 private String createTelUrl(String number) {
2119 if (TextUtils.isEmpty(number)) {
2120 return null;
2121 }
2122
Jake Hambye994d462014-02-03 13:10:13 -08002123 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 }
2125
Ihab Awadf9e92732013-12-05 18:02:52 -08002126 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2128 }
2129
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002130 private static void logv(String msg) {
2131 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2132 }
2133
Ihab Awadf9e92732013-12-05 18:02:52 -08002134 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2136 }
2137
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002138 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002140 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002141 }
2142
Sanket Padawe356d7632015-06-22 14:03:32 -07002143 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002144 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002145 final long identity = Binder.clearCallingIdentity();
2146 try {
2147 final Phone phone = PhoneFactory.getPhone(slotIndex);
2148 if (phone == null) {
2149 return PhoneConstants.PHONE_TYPE_NONE;
2150 } else {
2151 return phone.getPhoneType();
2152 }
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 }
2157
2158 /**
2159 * Returns the CDMA ERI icon index to display
2160 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002161 @Override
2162 public int getCdmaEriIconIndex(String callingPackage) {
2163 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002164 }
2165
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002167 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002169 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002170 return -1;
2171 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 final Phone phone = getPhone(subId);
2176 if (phone != null) {
2177 return phone.getCdmaEriIconIndex();
2178 } else {
2179 return -1;
2180 }
2181 } finally {
2182 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 }
2185
2186 /**
2187 * Returns the CDMA ERI icon mode,
2188 * 0 - ON
2189 * 1 - FLASHING
2190 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002191 @Override
2192 public int getCdmaEriIconMode(String callingPackage) {
2193 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002197 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002199 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002200 return -1;
2201 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002202
2203 final long identity = Binder.clearCallingIdentity();
2204 try {
2205 final Phone phone = getPhone(subId);
2206 if (phone != null) {
2207 return phone.getCdmaEriIconMode();
2208 } else {
2209 return -1;
2210 }
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 }
2215
2216 /**
2217 * Returns the CDMA ERI text,
2218 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002219 @Override
2220 public String getCdmaEriText(String callingPackage) {
2221 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002222 }
2223
Sanket Padawe356d7632015-06-22 14:03:32 -07002224 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002225 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002226 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002227 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002228 return null;
2229 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002230
2231 final long identity = Binder.clearCallingIdentity();
2232 try {
2233 final Phone phone = getPhone(subId);
2234 if (phone != null) {
2235 return phone.getCdmaEriText();
2236 } else {
2237 return null;
2238 }
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 }
2243
2244 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002245 * Returns the CDMA MDN.
2246 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002248 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2250 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002251
2252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 final Phone phone = getPhone(subId);
2255 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2256 return phone.getLine1Number();
2257 } else {
2258 return null;
2259 }
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002262 }
2263 }
2264
2265 /**
2266 * Returns the CDMA MIN.
2267 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002268 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002269 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2271 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002272
2273 final long identity = Binder.clearCallingIdentity();
2274 try {
2275 final Phone phone = getPhone(subId);
2276 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2277 return phone.getCdmaMin();
2278 } else {
2279 return null;
2280 }
2281 } finally {
2282 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002283 }
2284 }
2285
2286 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 * Returns true if CDMA provisioning needs to run.
2288 */
2289 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 return mPhone.needsOtaServiceProvisioning();
2293 } finally {
2294 Binder.restoreCallingIdentity(identity);
2295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 }
2297
2298 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002299 * Sets the voice mail number of a given subId.
2300 */
2301 @Override
2302 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002303 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002304
2305 final long identity = Binder.clearCallingIdentity();
2306 try {
2307 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2308 new Pair<String, String>(alphaTag, number), new Integer(subId));
2309 return success;
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
2312 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002313 }
2314
Ta-wei Yen87c49842016-05-13 21:19:52 -07002315 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002316 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2317 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2318 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2319 if (!TextUtils.equals(callingPackage, systemDialer)) {
2320 throw new SecurityException("caller must be system dialer");
2321 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002322
2323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2326 if (phoneAccountHandle == null) {
2327 return null;
2328 }
2329 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002332 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002333 }
2334
2335 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002336 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002339 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002340 return null;
2341 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002342
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 return RemoteVvmTaskManager
2346 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
2349 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002350 }
2351
2352 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002353 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2354 VisualVoicemailSmsFilterSettings settings) {
2355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2360 mPhone.getContext(), callingPackage, subId, settings);
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
2363 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002364 }
2365
2366 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002367 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002369
2370 final long identity = Binder.clearCallingIdentity();
2371 try {
2372 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2373 mPhone.getContext(), callingPackage, subId);
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
2376 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002377 }
2378
2379 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002380 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2381 String callingPackage, int subId) {
2382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002383
2384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2387 mPhone.getContext(), callingPackage, subId);
2388 } finally {
2389 Binder.restoreCallingIdentity(identity);
2390 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002391 }
2392
2393 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002394 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002395 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002396
2397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2400 mPhone.getContext(), subId);
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002404 }
2405
2406 @Override
2407 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2408 String number, int port, String text, PendingIntent sentIntent) {
2409 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002410 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002411 enforceSendSmsPermission();
2412 // Make the calls as the phone process.
2413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2416 if (port == 0) {
2417 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2418 sentIntent, null, false);
2419 } else {
2420 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2421 smsManager.sendDataMessageWithSelfPermissions(number, null,
2422 (short) port, data, sentIntent, null);
2423 }
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002427 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002428 /**
fionaxu0152e512016-11-14 13:36:14 -08002429 * Sets the voice activation state of a given subId.
2430 */
2431 @Override
2432 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2434 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002435
2436 final long identity = Binder.clearCallingIdentity();
2437 try {
2438 final Phone phone = getPhone(subId);
2439 if (phone != null) {
2440 phone.setVoiceActivationState(activationState);
2441 } else {
2442 loge("setVoiceActivationState fails with invalid subId: " + subId);
2443 }
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002446 }
2447 }
2448
2449 /**
2450 * Sets the data activation state of a given subId.
2451 */
2452 @Override
2453 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2455 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002456
2457 final long identity = Binder.clearCallingIdentity();
2458 try {
2459 final Phone phone = getPhone(subId);
2460 if (phone != null) {
2461 phone.setDataActivationState(activationState);
2462 } else {
2463 loge("setVoiceActivationState fails with invalid subId: " + subId);
2464 }
2465 } finally {
2466 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002467 }
2468 }
2469
2470 /**
2471 * Returns the voice activation state of a given subId.
2472 */
2473 @Override
2474 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002475 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002476
fionaxu0152e512016-11-14 13:36:14 -08002477 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 if (phone != null) {
2481 return phone.getVoiceActivationState();
2482 } else {
2483 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2484 }
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002487 }
2488 }
2489
2490 /**
2491 * Returns the data activation state of a given subId.
2492 */
2493 @Override
2494 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002495 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002496
fionaxu0152e512016-11-14 13:36:14 -08002497 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 if (phone != null) {
2501 return phone.getDataActivationState();
2502 } else {
2503 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2504 }
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002507 }
2508 }
2509
2510 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 * Returns the unread count of voicemails
2512 */
2513 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002514 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002515 }
2516
2517 /**
2518 * Returns the unread count of voicemails for a subId
2519 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002520 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002521 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 final Phone phone = getPhone(subId);
2525 if (phone != null) {
2526 return phone.getVoiceMessageCount();
2527 } else {
2528 return 0;
2529 }
2530 } finally {
2531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 }
2534
2535 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002536 * returns true, if the device is in a state where both voice and data
2537 * are supported simultaneously. This can change based on location or network condition.
2538 */
2539 @Override
2540 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002541 final long identity = Binder.clearCallingIdentity();
2542 try {
2543 final Phone phone = getPhone(subId);
2544 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002548 }
2549
2550 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002551 * Send the dialer code if called from the current default dialer or the caller has
2552 * carrier privilege.
2553 * @param inputCode The dialer code to send
2554 */
2555 @Override
2556 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2557 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2558 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2559 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002560 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2561 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002562 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002563
2564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 mPhone.sendDialerSpecialCode(inputCode);
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
2569 }
fionaxu235cc5e2017-03-06 22:25:57 -08002570 }
2571
2572 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002573 * Returns the data network type.
2574 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 *
2576 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2577 */
2578 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002579 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002580 final long identity = Binder.clearCallingIdentity();
2581 try {
2582 final Phone phone = getPhone(getDefaultSubscription());
2583 if (phone != null) {
2584 return phone.getServiceState().getDataNetworkType();
2585 } else {
2586 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2587 }
2588 } finally {
2589 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002590 }
Wink Saville36469e72014-06-11 15:17:00 -07002591 }
2592
Pengquan Meng0c05b502018-09-06 09:59:22 -07002593 @Override
2594 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002595 if (!isActiveSubscription(subId)) {
2596 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2597 }
2598
Pengquan Meng0c05b502018-09-06 09:59:22 -07002599 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2600 }
2601
Wink Saville36469e72014-06-11 15:17:00 -07002602 /**
2603 * Returns the network type for a subId
2604 */
2605 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002606 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002608 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002609 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2610 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002611
Malcolm Chenaabec062018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 final Phone phone = getPhone(subId);
2615 if (phone != null) {
2616 return phone.getServiceState().getDataNetworkType();
2617 } else {
2618 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2619 }
2620 } finally {
2621 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 }
2624
2625 /**
2626 * Returns the data network type
2627 */
2628 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002629 public int getDataNetworkType(String callingPackage) {
2630 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002631 }
2632
2633 /**
2634 * Returns the data network type for a subId
2635 */
2636 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002637 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002639 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002640 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2641 }
2642
Malcolm Chenaabec062018-02-28 15:00:40 -08002643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 final Phone phone = getPhone(subId);
2646 if (phone != null) {
2647 return phone.getServiceState().getDataNetworkType();
2648 } else {
2649 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2650 }
2651 } finally {
2652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 }
2655
2656 /**
Wink Saville36469e72014-06-11 15:17:00 -07002657 * Returns the Voice network type for a subId
2658 */
2659 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002660 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002661 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002662 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002663 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2664 }
2665
Malcolm Chenaabec062018-02-28 15:00:40 -08002666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 final Phone phone = getPhone(subId);
2669 if (phone != null) {
2670 return phone.getServiceState().getVoiceNetworkType();
2671 } else {
2672 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2673 }
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 }
2678
2679 /**
2680 * @return true if a ICC card is present
2681 */
2682 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002683 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002684 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2685 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002686 }
2687
2688 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002689 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002690 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002691 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002692 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002693 final long identity = Binder.clearCallingIdentity();
2694 try {
2695 final Phone phone = PhoneFactory.getPhone(slotIndex);
2696 if (phone != null) {
2697 return phone.getIccCard().hasIccCard();
2698 } else {
2699 return false;
2700 }
2701 } finally {
2702 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 }
2705
2706 /**
2707 * Return if the current radio is LTE on CDMA. This
2708 * is a tri-state return value as for a period of time
2709 * the mode may be unknown.
2710 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002711 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002713 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002715 @Override
2716 public int getLteOnCdmaMode(String callingPackage) {
2717 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002718 }
2719
Sanket Padawe356d7632015-06-22 14:03:32 -07002720 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002721 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002722 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002723 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002724 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2725 }
2726
Malcolm Chenaabec062018-02-28 15:00:40 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 final Phone phone = getPhone(subId);
2730 if (phone == null) {
2731 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2732 } else {
2733 return phone.getLteOnCdmaMode();
2734 }
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002737 }
Wink Saville36469e72014-06-11 15:17:00 -07002738 }
2739
2740 public void setPhone(Phone phone) {
2741 mPhone = phone;
2742 }
2743
2744 /**
2745 * {@hide}
2746 * Returns Default subId, 0 in the case of single standby.
2747 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002748 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002749 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002750 }
2751
Shishir Agrawala9f32182016-04-12 12:00:16 -07002752 private int getSlotForDefaultSubscription() {
2753 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2754 }
2755
Wink Savilleb564aae2014-10-23 10:18:09 -07002756 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002757 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002759
Pengquan Meng466e2482018-09-21 15:54:48 -07002760 private boolean isActiveSubscription(int subId) {
2761 return mSubscriptionController.isActiveSubId(subId);
2762 }
2763
Ihab Awadf2177b72013-11-25 13:33:23 -08002764 /**
2765 * @see android.telephony.TelephonyManager.WifiCallingChoices
2766 */
2767 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2771 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2772 getWhenToMakeWifiCallsDefaultPreference());
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002776 }
2777
2778 /**
2779 * @see android.telephony.TelephonyManager.WifiCallingChoices
2780 */
2781 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2785 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2786 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
2789 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002790 }
2791
Sailesh Nepald1e68152013-12-12 19:08:02 -08002792 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002793 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002794 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002795 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002796
Shishir Agrawal566b7612013-10-28 14:41:00 -07002797 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002798 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2799 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2801 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002802 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002803
Malcolm Chenaabec062018-02-28 15:00:40 -08002804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 if (TextUtils.equals(ISDR_AID, aid)) {
2807 // Only allows LPA to open logical channel to ISD-R.
2808 ComponentInfo bestComponent =
2809 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2810 if (bestComponent == null
2811 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2812 loge("The calling package is not allowed to access ISD-R.");
2813 throw new SecurityException(
2814 "The calling package is not allowed to access ISD-R.");
2815 }
Derek Tan740e1672017-06-27 14:56:27 -07002816 }
Derek Tan740e1672017-06-27 14:56:27 -07002817
Malcolm Chenaabec062018-02-28 15:00:40 -08002818 if (DBG) {
2819 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2820 }
2821 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2822 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2823 if (DBG) log("iccOpenLogicalChannel: " + response);
2824 return response;
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
2827 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002828 }
2829
2830 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002831 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2833 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002834
Malcolm Chenaabec062018-02-28 15:00:40 -08002835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2838 if (channel < 0) {
2839 return false;
2840 }
2841 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2842 if (DBG) log("iccCloseLogicalChannel: " + success);
2843 return success;
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002846 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002847 }
2848
2849 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002850 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002851 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2853 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002854
Malcolm Chenaabec062018-02-28 15:00:40 -08002855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 if (DBG) {
2858 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2859 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2860 + p3 + " data=" + data);
2861 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002862
Malcolm Chenaabec062018-02-28 15:00:40 -08002863 if (channel < 0) {
2864 return "";
2865 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002866
Malcolm Chenaabec062018-02-28 15:00:40 -08002867 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2868 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2869 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002870
Malcolm Chenaabec062018-02-28 15:00:40 -08002871 // Append the returned status code to the end of the response payload.
2872 String s = Integer.toHexString(
2873 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2874 if (response.payload != null) {
2875 s = IccUtils.bytesToHexString(response.payload) + s;
2876 }
2877 return s;
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002880 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002881 }
Jake Hambye994d462014-02-03 13:10:13 -08002882
Evan Charltonc66da362014-05-16 14:06:40 -07002883 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002884 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2885 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2887 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002888 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002889
Malcolm Chenaabec062018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2893 && TextUtils.equals(ISDR_AID, data)) {
2894 // Only allows LPA to select ISD-R.
2895 ComponentInfo bestComponent =
2896 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2897 if (bestComponent == null
2898 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2899 loge("The calling package is not allowed to select ISD-R.");
2900 throw new SecurityException(
2901 "The calling package is not allowed to select ISD-R.");
2902 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002903 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002904
Malcolm Chenaabec062018-02-28 15:00:40 -08002905 if (DBG) {
2906 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2907 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2908 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002909
Malcolm Chenaabec062018-02-28 15:00:40 -08002910 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2911 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2912 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002913
Malcolm Chenaabec062018-02-28 15:00:40 -08002914 // Append the returned status code to the end of the response payload.
2915 String s = Integer.toHexString(
2916 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2917 if (response.payload != null) {
2918 s = IccUtils.bytesToHexString(response.payload) + s;
2919 }
2920 return s;
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002923 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002924 }
2925
2926 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002927 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002928 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2930 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002931
Malcolm Chenaabec062018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 if (DBG) {
2935 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2936 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2937 }
2938
2939 IccIoResult response =
2940 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2941 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2942 subId);
2943
2944 if (DBG) {
2945 log("Exchange SIM_IO [R]" + response);
2946 }
2947
2948 byte[] result = null;
2949 int length = 2;
2950 if (response.payload != null) {
2951 length = 2 + response.payload.length;
2952 result = new byte[length];
2953 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2954 } else {
2955 result = new byte[length];
2956 }
2957
2958 result[length - 1] = (byte) response.sw2;
2959 result[length - 2] = (byte) response.sw1;
2960 return result;
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002963 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002964 }
2965
Nathan Haroldb3014052017-01-25 15:57:32 -08002966 /**
2967 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2968 * on a particular subscription
2969 */
sqianb6e41952018-03-12 14:54:01 -07002970 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2972 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2973 return null;
2974 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002975 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2976 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2977 return null;
2978 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002979
2980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2983 if (response instanceof String[]) {
2984 return (String[]) response;
2985 }
2986 // Response is an Exception of some kind,
2987 // which is signalled to the user as a NULL retval
2988 return null;
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002991 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002992 }
2993
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002994 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002995 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2997 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002998
Malcolm Chenaabec062018-02-28 15:00:40 -08002999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3002 if (response.payload == null) {
3003 return "";
3004 }
Evan Charltonc66da362014-05-16 14:06:40 -07003005
Malcolm Chenaabec062018-02-28 15:00:40 -08003006 // Append the returned status code to the end of the response payload.
3007 String s = Integer.toHexString(
3008 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3009 s = IccUtils.bytesToHexString(response.payload) + s;
3010 return s;
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
Evan Charltonc66da362014-05-16 14:06:40 -07003014 }
3015
Jake Hambye994d462014-02-03 13:10:13 -08003016 /**
3017 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3018 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3019 *
3020 * @param itemID the ID of the item to read
3021 * @return the NV item as a String, or null on error.
3022 */
3023 @Override
3024 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003025 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3027 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003028
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003032 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003033 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3034 return value;
3035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
Jake Hambye994d462014-02-03 13:10:13 -08003038 }
3039
3040 /**
3041 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3042 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3043 *
3044 * @param itemID the ID of the item to read
3045 * @param itemValue the value to write, as a String
3046 * @return true on success; false on any failure
3047 */
3048 @Override
3049 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003050 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3052 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003053
3054 final long identity = Binder.clearCallingIdentity();
3055 try {
3056 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3057 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003058 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003059 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3060 return success;
3061 } finally {
3062 Binder.restoreCallingIdentity(identity);
3063 }
Jake Hambye994d462014-02-03 13:10:13 -08003064 }
3065
3066 /**
3067 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3068 * Used for device configuration by some CDMA operators.
3069 *
3070 * @param preferredRoamingList byte array containing the new PRL
3071 * @return true on success; false on any failure
3072 */
3073 @Override
3074 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3076 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003077
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3081 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3082 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3083 return success;
3084 } finally {
3085 Binder.restoreCallingIdentity(identity);
3086 }
Jake Hambye994d462014-02-03 13:10:13 -08003087 }
3088
3089 /**
3090 * Perform the specified type of NV config reset.
3091 * Used for device configuration by some CDMA operators.
3092 *
3093 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3094 * @return true on success; false on any failure
3095 */
3096 @Override
3097 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3099 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003100
3101 final long identity = Binder.clearCallingIdentity();
3102 try {
3103 if (DBG) log("nvResetConfig: type " + resetType);
3104 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3105 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3106 return success;
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
Jake Hambye994d462014-02-03 13:10:13 -08003110 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003111
Svet Ganovb320e182015-04-16 12:30:10 -07003112 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003113 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003114 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003115 return new String[0];
3116 }
3117
Malcolm Chenaabec062018-02-28 15:00:40 -08003118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 return mPhone.getPcscfAddress(apnType);
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
3123 }
Wink Saville36469e72014-06-11 15:17:00 -07003124 }
3125
Brad Ebinger51f743a2017-01-23 13:50:20 -08003126 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003127 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3128 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003129 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003130 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003131 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003132
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 PhoneFactory.getImsResolver().enableIms(slotId);
3136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003139 }
3140
3141 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003142 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3143 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003144 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003145 public void disableIms(int slotId) {
3146 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003147
3148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 PhoneFactory.getImsResolver().disableIms(slotId);
3151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003154 }
3155
3156 /**
3157 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3158 * feature or {@link null} if the service is not available. If the feature is available, the
3159 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3160 */
3161 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003162 IImsServiceFeatureCallback callback) {
3163 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003164
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003171 }
3172
3173 /**
3174 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3175 * feature during emergency calling or {@link null} if the service is not available. If the
3176 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3177 * listener for feature updates.
3178 */
3179 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3180 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003181
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003188 }
3189
Brad Ebinger5f64b052017-12-14 14:26:15 -08003190 /**
3191 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3192 * specified.
3193 */
3194 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3195 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003196
3197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
3202 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003203 }
3204
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003205 /**
3206 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3207 * specified.
3208 */
3209 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3210 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003211
3212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003218 }
3219
Brad Ebinger884c07b2018-02-15 16:17:40 -08003220 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003221 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3222 * available, false if the IMS resolver is idle.
3223 */
3224 public boolean isResolvingImsBinding() {
3225 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003226
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 return PhoneFactory.getImsResolver().isResolvingBinding();
3230 } finally {
3231 Binder.restoreCallingIdentity(identity);
3232 }
Brad Ebinger67801702018-03-02 13:43:36 -08003233 }
3234
Brad Ebingerdac2f002018-04-03 15:17:52 -07003235 /**
3236 * Sets the ImsService Package Name that Telephony will bind to.
3237 *
3238 * @param slotId the slot ID that the ImsService should bind for.
3239 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3240 * ImsService is the device default ImsService.
3241 * @param packageName The package name of the application that contains the ImsService to bind
3242 * to.
3243 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3244 * @hide
3245 */
3246 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003247 int[] subIds = SubscriptionManager.getSubId(slotId);
3248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3249 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3250 "setImsService");
3251
Malcolm Chenaabec062018-02-28 15:00:40 -08003252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3255 isCarrierImsService, packageName);
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003259 }
3260
3261 /**
3262 * Return the ImsService configuration.
3263 *
3264 * @param slotId The slot that the ImsService is associated with.
3265 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3266 * the device default.
3267 * @return the package name of the ImsService configuration.
3268 */
3269 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003270 int[] subIds = SubscriptionManager.getSubId(slotId);
3271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3272 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3273 "getImsService");
3274
Malcolm Chenaabec062018-02-28 15:00:40 -08003275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3278 isCarrierImsService);
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003282 }
3283
Wink Saville36469e72014-06-11 15:17:00 -07003284 public void setImsRegistrationState(boolean registered) {
3285 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003286
3287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 mPhone.setImsRegistrationState(registered);
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
Wink Saville36469e72014-06-11 15:17:00 -07003293 }
3294
3295 /**
Stuart Scott54788802015-03-30 13:18:01 -07003296 * Set the network selection mode to automatic.
3297 *
3298 */
3299 @Override
3300 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3302 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003303
Pengquan Meng466e2482018-09-21 15:54:48 -07003304 if (!isActiveSubscription(subId)) {
3305 return;
3306 }
3307
Malcolm Chenaabec062018-02-28 15:00:40 -08003308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3311 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3312 } finally {
3313 Binder.restoreCallingIdentity(identity);
3314 }
Stuart Scott54788802015-03-30 13:18:01 -07003315 }
3316
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003317 /**
3318 * Ask the radio to connect to the input network and change selection mode to manual.
3319 *
3320 * @param subId the id of the subscription.
3321 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3322 * the operator to attach to.
3323 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3324 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3325 * normal network selection next time.
3326 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003327 */
3328 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003329 public boolean setNetworkSelectionModeManual(
3330 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3332 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003333
3334 if (!isActiveSubscription(subId)) {
3335 return false;
3336 }
3337
Malcolm Chenaabec062018-02-28 15:00:40 -08003338 final long identity = Binder.clearCallingIdentity();
3339 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003340 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaabec062018-02-28 15:00:40 -08003341 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003342 if (DBG) {
3343 log("setNetworkSelectionModeManual: subId: " + subId
3344 + " operator: " + operatorInfo);
3345 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003346 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003350 }
3351
3352 /**
3353 * Scans for available networks.
3354 */
3355 @Override
3356 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3358 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003359
Pengquan Meng0c05b502018-09-06 09:59:22 -07003360 long identity = Binder.clearCallingIdentity();
Malcolm Chenaabec062018-02-28 15:00:40 -08003361 try {
3362 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003363 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaabec062018-02-28 15:00:40 -08003364 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08003365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003368 }
3369
3370 /**
yinxub1bed742017-04-17 11:45:04 -07003371 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003372 *
yinxub1bed742017-04-17 11:45:04 -07003373 * @param subId id of the subscription
3374 * @param request contains the radio access networks with bands/channels to scan
3375 * @param messenger callback messenger for scan results or errors
3376 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003377 * @return the id of the requested scan which can be used to stop the scan.
3378 */
3379 @Override
3380 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3381 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3383 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003384
3385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 return mNetworkScanRequestTracker.startNetworkScan(
3388 request, messenger, binder, getPhone(subId));
3389 } finally {
3390 Binder.restoreCallingIdentity(identity);
3391 }
yinxu504e1392017-04-12 16:03:22 -07003392 }
3393
3394 /**
3395 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003396 *
3397 * @param subId id of the subscription
3398 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003399 */
3400 @Override
3401 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3403 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003404
3405 final long identity = Binder.clearCallingIdentity();
3406 try {
3407 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
yinxu504e1392017-04-12 16:03:22 -07003411 }
3412
3413 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003414 * Get the calculated preferred network type.
3415 * Used for debugging incorrect network type.
3416 *
3417 * @return the preferred network type, defined in RILConstants.java.
3418 */
3419 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003420 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003422 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003423 return RILConstants.PREFERRED_NETWORK_MODE;
3424 }
3425
Malcolm Chenaabec062018-02-28 15:00:40 -08003426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 // FIXME: need to get SubId from somewhere.
3429 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
Junda Liu84d15a22014-07-02 11:21:04 -07003433 }
3434
3435 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003436 * Get the preferred network type.
3437 * Used for device configuration by some CDMA operators.
3438 *
3439 * @return the preferred network type, defined in RILConstants.java.
3440 */
3441 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003442 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3444 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003445
3446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 if (DBG) log("getPreferredNetworkType");
3449 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3450 int networkType = (result != null ? result[0] : -1);
3451 if (DBG) log("getPreferredNetworkType: " + networkType);
3452 return networkType;
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003456 }
3457
3458 /**
3459 * Set the preferred network type.
3460 * Used for device configuration by some CDMA operators.
3461 *
3462 * @param networkType the preferred network type, defined in RILConstants.java.
3463 * @return true on success; false on any failure.
3464 */
3465 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003466 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3468 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003469
3470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3473 Boolean success = (Boolean) sendRequest(
3474 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3475 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3476 if (success) {
3477 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3478 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3479 }
3480 return success;
3481 } finally {
3482 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003483 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003484 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003485
3486 /**
Junda Liu475951f2014-11-07 16:45:03 -08003487 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3488 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3489 * tethering.
3490 *
3491 * @return 0: Not required. 1: required. 2: Not set.
3492 * @hide
3493 */
3494 @Override
3495 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003496 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003497
3498 final long identity = Binder.clearCallingIdentity();
3499 try {
3500 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3501 Settings.Global.TETHER_DUN_REQUIRED, 2);
3502 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3503 // config_tether_apndata.
3504 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3505 dunRequired = 1;
3506 }
3507 return dunRequired;
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003510 }
Junda Liu475951f2014-11-07 16:45:03 -08003511 }
3512
3513 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003514 * Set mobile data enabled
3515 * Used by the user through settings etc to turn on/off mobile data
3516 *
3517 * @param enable {@code true} turn turn data on, else {@code false}
3518 */
3519 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003520 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3522 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003523
3524 final long identity = Binder.clearCallingIdentity();
3525 try {
3526 int phoneId = mSubscriptionController.getPhoneId(subId);
3527 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3528 Phone phone = PhoneFactory.getPhone(phoneId);
3529 if (phone != null) {
3530 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3531 phone.setUserDataEnabled(enable);
3532 } else {
3533 loge("setUserDataEnabled: no phone for subId=" + subId);
3534 }
3535 } finally {
3536 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003537 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003538 }
3539
3540 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003541 * Get the user enabled state of Mobile Data.
3542 *
3543 * TODO: remove and use isUserDataEnabled.
3544 * This can't be removed now because some vendor codes
3545 * calls through ITelephony directly while they should
3546 * use TelephonyManager.
3547 *
3548 * @return true on enabled
3549 */
3550 @Override
3551 public boolean getDataEnabled(int subId) {
3552 return isUserDataEnabled(subId);
3553 }
3554
3555 /**
3556 * Get whether mobile data is enabled per user setting.
3557 *
3558 * There are other factors deciding whether mobile data is actually enabled, but they are
3559 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003560 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003561 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003562 *
3563 * @return {@code true} if data is enabled else {@code false}
3564 */
3565 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003566 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003567 try {
3568 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3569 null);
3570 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3572 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003573 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003574
3575 final long identity = Binder.clearCallingIdentity();
3576 try {
3577 int phoneId = mSubscriptionController.getPhoneId(subId);
3578 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3579 Phone phone = PhoneFactory.getPhone(phoneId);
3580 if (phone != null) {
3581 boolean retVal = phone.isUserDataEnabled();
3582 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3583 return retVal;
3584 } else {
3585 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3586 return false;
3587 }
3588 } finally {
3589 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003590 }
3591 }
3592
3593 /**
3594 * Get whether mobile data is enabled.
3595 *
3596 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3597 * whether mobile data is actually enabled.
3598 *
3599 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3600 *
3601 * @return {@code true} if data is enabled else {@code false}
3602 */
3603 @Override
3604 public boolean isDataEnabled(int subId) {
3605 try {
3606 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3607 null);
3608 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3610 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003611 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003612
3613 final long identity = Binder.clearCallingIdentity();
3614 try {
3615 int phoneId = mSubscriptionController.getPhoneId(subId);
3616 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3617 Phone phone = PhoneFactory.getPhone(phoneId);
3618 if (phone != null) {
3619 boolean retVal = phone.isDataEnabled();
3620 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3621 return retVal;
3622 } else {
3623 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3624 return false;
3625 }
3626 } finally {
3627 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003628 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003629 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003630
3631 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003632 public int getCarrierPrivilegeStatus(int subId) {
3633 final Phone phone = getPhone(subId);
3634 if (phone == null) {
3635 loge("getCarrierPrivilegeStatus: Invalid subId");
3636 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3637 }
3638 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003639 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003640 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003641 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3642 }
3643 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003644 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003645 }
Junda Liu29340342014-07-10 15:23:27 -07003646
3647 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3649 final Phone phone = getPhone(subId);
3650 if (phone == null) {
3651 loge("getCarrierPrivilegeStatus: Invalid subId");
3652 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3653 }
3654 UiccProfile profile =
3655 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3656 if (profile == null) {
3657 loge("getCarrierPrivilegeStatus: No UICC");
3658 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3659 }
3660 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3661 }
3662
3663 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003664 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003665 if (TextUtils.isEmpty(pkgName))
3666 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003667 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003668 if (card == null) {
3669 loge("checkCarrierPrivilegesForPackage: No UICC");
3670 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3671 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003672 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3673 }
3674
3675 @Override
3676 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003677 if (TextUtils.isEmpty(pkgName))
3678 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003679 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3680 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3681 UiccCard card = UiccController.getInstance().getUiccCard(i);
3682 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003683 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003684 continue;
3685 }
3686
3687 result = card.getCarrierPrivilegeStatus(
3688 mPhone.getContext().getPackageManager(), pkgName);
3689 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3690 break;
3691 }
3692 }
3693
3694 return result;
Junda Liu29340342014-07-10 15:23:27 -07003695 }
Derek Tan89e89d42014-07-08 17:00:10 -07003696
3697 @Override
Junda Liue64de782015-04-16 17:19:16 -07003698 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3699 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3700 loge("phoneId " + phoneId + " is not valid.");
3701 return null;
3702 }
3703 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003704 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003705 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003706 return null ;
3707 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003708 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003709 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003710 }
3711
Amith Yamasani6e118872016-02-19 12:53:51 -08003712 @Override
3713 public List<String> getPackagesWithCarrierPrivileges() {
3714 PackageManager pm = mPhone.getContext().getPackageManager();
3715 List<String> privilegedPackages = new ArrayList<>();
3716 List<PackageInfo> packages = null;
3717 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3718 UiccCard card = UiccController.getInstance().getUiccCard(i);
3719 if (card == null) {
3720 // No UICC in that slot.
3721 continue;
3722 }
3723 if (card.hasCarrierPrivilegeRules()) {
3724 if (packages == null) {
3725 // Only check packages in user 0 for now
3726 packages = pm.getInstalledPackagesAsUser(
3727 PackageManager.MATCH_DISABLED_COMPONENTS
3728 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3729 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3730 }
3731 for (int p = packages.size() - 1; p >= 0; p--) {
3732 PackageInfo pkgInfo = packages.get(p);
3733 if (pkgInfo != null && pkgInfo.packageName != null
3734 && card.getCarrierPrivilegeStatus(pkgInfo)
3735 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3736 privilegedPackages.add(pkgInfo.packageName);
3737 }
3738 }
3739 }
3740 }
3741 return privilegedPackages;
3742 }
3743
Wink Savilleb564aae2014-10-23 10:18:09 -07003744 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003745 final Phone phone = getPhone(subId);
3746 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003747 if (card == null) {
3748 loge("getIccId: No UICC");
3749 return null;
3750 }
3751 String iccId = card.getIccId();
3752 if (TextUtils.isEmpty(iccId)) {
3753 loge("getIccId: ICC ID is null or empty.");
3754 return null;
3755 }
3756 return iccId;
3757 }
3758
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003759 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003760 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3761 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003762 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3763 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003764
Malcolm Chenaabec062018-02-28 15:00:40 -08003765 final long identity = Binder.clearCallingIdentity();
3766 try {
3767 final String iccId = getIccId(subId);
3768 final Phone phone = getPhone(subId);
3769 if (phone == null) {
3770 return false;
3771 }
3772 final String subscriberId = phone.getSubscriberId();
3773
3774 if (DBG_MERGE) {
3775 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3776 + subscriberId + " to " + number);
3777 }
3778
3779 if (TextUtils.isEmpty(iccId)) {
3780 return false;
3781 }
3782
3783 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3784
3785 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3786 if (alphaTag == null) {
3787 editor.remove(alphaTagPrefKey);
3788 } else {
3789 editor.putString(alphaTagPrefKey, alphaTag);
3790 }
3791
3792 // Record both the line number and IMSI for this ICCID, since we need to
3793 // track all merged IMSIs based on line number
3794 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3795 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3796 if (number == null) {
3797 editor.remove(numberPrefKey);
3798 editor.remove(subscriberPrefKey);
3799 } else {
3800 editor.putString(numberPrefKey, number);
3801 editor.putString(subscriberPrefKey, subscriberId);
3802 }
3803
3804 editor.commit();
3805 return true;
3806 } finally {
3807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003808 }
Derek Tan7226c842014-07-02 17:42:23 -07003809 }
3810
3811 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003812 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003813 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003815 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003816 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003817 return null;
3818 }
Derek Tan97ebb422014-09-05 16:55:38 -07003819
Malcolm Chenaabec062018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 String iccId = getIccId(subId);
3823 if (iccId != null) {
3824 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3825 if (DBG_MERGE) {
3826 log("getLine1NumberForDisplay returning "
3827 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3828 }
3829 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003830 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003831 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3832 return null;
3833 } finally {
3834 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003835 }
Derek Tan7226c842014-07-02 17:42:23 -07003836 }
3837
3838 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003839 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003841 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003842 return null;
3843 }
Derek Tan97ebb422014-09-05 16:55:38 -07003844
Malcolm Chenaabec062018-02-28 15:00:40 -08003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 String iccId = getIccId(subId);
3848 if (iccId != null) {
3849 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3850 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3851 }
3852 return null;
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003855 }
Derek Tan7226c842014-07-02 17:42:23 -07003856 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003857
3858 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003859 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003860 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3861 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003863 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3864 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003865 return null;
3866 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003867
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003868 final long identity = Binder.clearCallingIdentity();
3869 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003870 final Context context = mPhone.getContext();
3871 final TelephonyManager tele = TelephonyManager.from(context);
3872 final SubscriptionManager sub = SubscriptionManager.from(context);
3873
3874 // Figure out what subscribers are currently active
3875 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3876 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3877 // the process, where TelephonyManager was instantiated.
3878 // Otherwise AppOps check will fail.
3879
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003880 final int[] subIds = sub.getActiveSubscriptionIdList();
3881 for (int subId : subIds) {
3882 activeSubscriberIds.add(tele.getSubscriberId(subId));
3883 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003884
3885 // First pass, find a number override for an active subscriber
3886 String mergeNumber = null;
3887 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3888 for (String key : prefs.keySet()) {
3889 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3890 final String subscriberId = (String) prefs.get(key);
3891 if (activeSubscriberIds.contains(subscriberId)) {
3892 final String iccId = key.substring(
3893 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3894 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3895 mergeNumber = (String) prefs.get(numberKey);
3896 if (DBG_MERGE) {
3897 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3898 + " for active subscriber " + subscriberId);
3899 }
3900 if (!TextUtils.isEmpty(mergeNumber)) {
3901 break;
3902 }
3903 }
3904 }
3905 }
3906
3907 // Shortcut when no active merged subscribers
3908 if (TextUtils.isEmpty(mergeNumber)) {
3909 return null;
3910 }
3911
3912 // Second pass, find all subscribers under that line override
3913 final ArraySet<String> result = new ArraySet<>();
3914 for (String key : prefs.keySet()) {
3915 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3916 final String number = (String) prefs.get(key);
3917 if (mergeNumber.equals(number)) {
3918 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3919 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3920 final String subscriberId = (String) prefs.get(subscriberKey);
3921 if (!TextUtils.isEmpty(subscriberId)) {
3922 result.add(subscriberId);
3923 }
3924 }
3925 }
3926 }
3927
3928 final String[] resultArray = result.toArray(new String[result.size()]);
3929 Arrays.sort(resultArray);
3930 if (DBG_MERGE) {
3931 Slog.d(LOG_TAG,
3932 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3933 }
3934 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003935 } finally {
3936 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003937 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003938 }
3939
3940 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003941 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003942 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3943 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003944
3945 final long identity = Binder.clearCallingIdentity();
3946 try {
3947 final Phone phone = getPhone(subId);
3948 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3949 } finally {
3950 Binder.restoreCallingIdentity(identity);
3951 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003952 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003953
3954 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003955 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003956 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3957 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003958 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003959
3960 final long identity = Binder.clearCallingIdentity();
3961 try {
3962 final Phone phone = getPhone(subId);
3963 if (phone == null) {
3964 return false;
3965 }
3966 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3967 cdmaNonRoamingList);
3968 } finally {
3969 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003970 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003971 }
3972
3973 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003974 @Deprecated
3975 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3976 enforceModifyPermission();
3977
3978 int returnValue = 0;
3979 try {
vagdevie435a3e2018-08-15 16:01:53 -07003980 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003981 if(result.exception == null) {
3982 if (result.result != null) {
3983 byte[] responseData = (byte[])(result.result);
3984 if(responseData.length > oemResp.length) {
3985 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3986 responseData.length + "bytes. Buffer Size is " +
3987 oemResp.length + "bytes.");
3988 }
3989 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3990 returnValue = responseData.length;
3991 }
3992 } else {
3993 CommandException ex = (CommandException) result.exception;
3994 returnValue = ex.getCommandError().ordinal();
3995 if(returnValue > 0) returnValue *= -1;
3996 }
3997 } catch (RuntimeException e) {
3998 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3999 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4000 if(returnValue > 0) returnValue *= -1;
4001 }
4002
4003 return returnValue;
4004 }
4005
4006 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004007 public void setRadioCapability(RadioAccessFamily[] rafs) {
4008 try {
4009 ProxyController.getInstance().setRadioCapability(rafs);
4010 } catch (RuntimeException e) {
4011 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4012 }
4013 }
4014
4015 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004016 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004017 Phone phone = PhoneFactory.getPhone(phoneId);
4018 if (phone == null) {
4019 return RadioAccessFamily.RAF_UNKNOWN;
4020 }
4021 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004023 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004024 return RadioAccessFamily.RAF_UNKNOWN;
4025 }
4026
Malcolm Chenaabec062018-02-28 15:00:40 -08004027 final long identity = Binder.clearCallingIdentity();
4028 try {
4029 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4030 } finally {
4031 Binder.restoreCallingIdentity(identity);
4032 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004033 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004034
4035 @Override
4036 public void enableVideoCalling(boolean enable) {
4037 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004038
4039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4042 } finally {
4043 Binder.restoreCallingIdentity(identity);
4044 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004045 }
4046
4047 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004048 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4050 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4051 return false;
4052 }
Svet Ganovb320e182015-04-16 12:30:10 -07004053
Malcolm Chenaabec062018-02-28 15:00:40 -08004054 final long identity = Binder.clearCallingIdentity();
4055 try {
4056 // Check the user preference and the system-level IMS setting. Even if the user has
4057 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4058 // In the long run, we may instead need to check if there exists a connection service
4059 // which can support video calling.
4060 ImsManager imsManager =
4061 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4062 return imsManager.isVtEnabledByPlatform()
4063 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4064 && imsManager.isVtEnabledByUser();
4065 } finally {
4066 Binder.restoreCallingIdentity(identity);
4067 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004068 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004069
Andrew Leea1239f22015-03-02 17:44:07 -08004070 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004071 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4073 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4074 return false;
4075 }
4076
4077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 CarrierConfigManager configManager =
4080 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4081 return configManager.getConfigForSubId(mPhone.getSubId())
4082 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
Andrew Leea1239f22015-03-02 17:44:07 -08004086 }
4087
4088 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004089 public boolean isWorldPhone(int subId, String callingPackage) {
4090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4091 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4092 return false;
4093 }
4094
4095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 CarrierConfigManager configManager =
4098 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4099 return configManager.getConfigForSubId(mPhone.getSubId())
4100 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
Andrew Leea1239f22015-03-02 17:44:07 -08004104 }
4105
Andrew Lee9431b832015-03-09 18:46:45 -07004106 @Override
4107 public boolean isTtyModeSupported() {
4108 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004109 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004110 }
4111
4112 @Override
4113 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
Andrew Lee9431b832015-03-09 18:46:45 -07004120 }
4121
Hall Liu98187582018-01-22 19:15:32 -08004122 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4126 mPhone.getSubId()).getBoolean(
4127 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4128 boolean isDeviceSupported =
4129 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4130 return isCarrierSupported && isDeviceSupported;
4131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
Hall Liu98187582018-01-22 19:15:32 -08004134 }
4135
Hall Liu3ad5f012018-04-06 16:23:39 -07004136 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 return isRttSupported() && Settings.Secure.getInt(
4140 mPhone.getContext().getContentResolver(),
4141 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4142 } finally {
4143 Binder.restoreCallingIdentity(identity);
4144 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004145 }
4146
Sanket Padawe7310cc72015-01-14 09:53:20 -08004147 /**
4148 * Returns the unique device ID of phone, for example, the IMEI for
4149 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4150 *
4151 * <p>Requires Permission:
4152 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4153 */
4154 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004155 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004156 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004157 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004158 return null;
4159 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004160 int subId = phone.getSubId();
4161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4162 mApp, subId, callingPackage, "getDeviceId")) {
4163 return null;
4164 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004165
4166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 return phone.getDeviceId();
4169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004172 }
4173
Ping Sunc67b7c22016-03-02 19:16:45 +08004174 /**
4175 * {@hide}
4176 * Returns the IMS Registration Status on a particular subid
4177 *
4178 * @param subId
4179 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004180 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004181 Phone phone = getPhone(subId);
4182 if (phone != null) {
4183 return phone.isImsRegistered();
4184 } else {
4185 return false;
4186 }
4187 }
4188
Santos Cordon7a1885b2015-02-03 11:15:19 -08004189 @Override
4190 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004191 final long identity = Binder.clearCallingIdentity();
4192 try {
4193 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4194 } finally {
4195 Binder.restoreCallingIdentity(identity);
4196 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004197 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004198
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004199 /**
4200 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004201 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004202 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 Phone phone = getPhone(subId);
4206 if (phone != null) {
4207 return phone.isWifiCallingEnabled();
4208 } else {
4209 return false;
4210 }
4211 } finally {
4212 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004213 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004214 }
4215
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004216 /**
4217 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004218 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004219 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 Phone phone = getPhone(subId);
4223 if (phone != null) {
4224 return phone.isVolteEnabled();
4225 } else {
4226 return false;
4227 }
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004230 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004231 }
Svet Ganovb320e182015-04-16 12:30:10 -07004232
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004233 /**
4234 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004235 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004236 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004237 final long identity = Binder.clearCallingIdentity();
4238 try {
4239 Phone phone = getPhone(subId);
4240 if (phone != null) {
4241 return phone.isVideoEnabled();
4242 } else {
4243 return false;
4244 }
4245 } finally {
4246 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004247 }
4248 }
4249
4250 /**
4251 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4252 * defined in {@link ImsRegistrationImplBase}.
4253 */
4254 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004255 final long identity = Binder.clearCallingIdentity();
4256 try {
4257 Phone phone = getPhone(subId);
4258 if (phone != null) {
4259 return phone.getImsRegistrationTech();
4260 } else {
4261 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4262 }
4263 } finally {
4264 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004265 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004266 }
4267
Stuart Scott8eef64f2015-04-08 15:13:54 -07004268 @Override
4269 public void factoryReset(int subId) {
4270 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004271 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4272 return;
4273 }
4274
Svet Ganovcc087f82015-05-12 20:35:54 -07004275 final long identity = Binder.clearCallingIdentity();
4276 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004277 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4278 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004279 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004280 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004281 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4282 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004283 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004284 }
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004287 }
4288 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004289
4290 @Override
4291 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004292 final long identity = Binder.clearCallingIdentity();
4293 try {
4294 // We query all subscriptions instead of just the active ones, because
4295 // this might be called early on in the provisioning flow when the
4296 // subscriptions potentially aren't active yet.
4297 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4298 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004299 return null;
4300 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004301
Malcolm Chenaabec062018-02-28 15:00:40 -08004302 // This function may be called very early, say, from the setup wizard, at
4303 // which point we won't have a default subscription set. If that's the case
4304 // we just choose the first, which will be valid in "most cases".
4305 final int defaultSubId = getDefaultSubscription();
4306 SubscriptionInfo info = null;
4307 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4308 info = slist.get(0);
4309 } else {
4310 for (SubscriptionInfo item : slist) {
4311 if (item.getSubscriptionId() == defaultSubId) {
4312 info = item;
4313 break;
4314 }
4315 }
4316
4317 if (info == null) {
4318 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004319 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004320 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004321
Malcolm Chenaabec062018-02-28 15:00:40 -08004322 // Try and fetch the locale from the carrier properties or from the SIM language
4323 // preferences (EF-PL and EF-LI)...
4324 final int mcc = info.getMcc();
4325 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4326 String simLanguage = null;
4327 if (defaultPhone != null) {
4328 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4329 if (localeFromDefaultSim != null) {
4330 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4331 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4332 return localeFromDefaultSim.toLanguageTag();
4333 } else {
4334 simLanguage = localeFromDefaultSim.getLanguage();
4335 }
4336 }
4337 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004338
Malcolm Chenaabec062018-02-28 15:00:40 -08004339 // The SIM language preferences only store a language (e.g. fr = French), not an
4340 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4341 // the SIM and carrier preferences does not include a country we add the country
4342 // determined from the SIM MCC to provide an exact locale.
4343 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4344 simLanguage);
4345 if (mccLocale != null) {
4346 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4347 return mccLocale.toLanguageTag();
4348 }
4349
4350 if (DBG) log("No locale found - returning null");
4351 return null;
4352 } finally {
4353 Binder.restoreCallingIdentity(identity);
4354 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004355 }
4356
4357 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004358 return mSubscriptionController.getAllSubInfoList(
4359 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004360 }
4361
Malcolm Chenaabec062018-02-28 15:00:40 -08004362 /**
4363 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4364 */
4365 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4366 return mSubscriptionController.getActiveSubscriptionInfoList(
4367 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004368 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004369
Chenjie Yu1ba97252018-01-11 18:16:20 -08004370 private final ModemActivityInfo mLastModemActivityInfo =
4371 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4372
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004373 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004374 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4375 * representing the state of the modem.
4376 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004377 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4378 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004379 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004380 */
4381 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004382 public void requestModemActivityInfo(ResultReceiver result) {
4383 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004384 ModemActivityInfo ret = null;
vagdevie435a3e2018-08-15 16:01:53 -07004385 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Adam Lesinski903a54c2016-04-11 14:49:52 -07004386
Malcolm Chenaabec062018-02-28 15:00:40 -08004387 final long identity = Binder.clearCallingIdentity();
4388 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004389 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004390 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4391 CMD_GET_MODEM_ACTIVITY_INFO,
4392 null, workSource);
Siddharth Rayc339f892018-06-17 15:02:38 -07004393 if (isModemActivityInfoValid(info)) {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004394 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4395 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4396 mergedTxTimeMs[i] =
4397 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4398 }
4399 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4400 mLastModemActivityInfo.setSleepTimeMillis(
4401 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4402 mLastModemActivityInfo.setIdleTimeMillis(
4403 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4404 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4405 mLastModemActivityInfo.setRxTimeMillis(
4406 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4407 mLastModemActivityInfo.setEnergyUsed(
4408 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004409 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004410 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4411 mLastModemActivityInfo.getSleepTimeMillis(),
4412 mLastModemActivityInfo.getIdleTimeMillis(),
4413 mLastModemActivityInfo.getTxTimeMillis(),
4414 mLastModemActivityInfo.getRxTimeMillis(),
4415 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004416 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004417 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004418 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004419 result.send(0, bundle);
4420 } finally {
4421 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004422 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004423 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004424
Siddharth Rayc339f892018-06-17 15:02:38 -07004425 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4426 // less than total activity duration.
4427 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4428 if (info == null) {
4429 return false;
4430 }
4431 int activityDurationMs =
4432 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4433 int totalTxTimeMs = 0;
4434 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4435 totalTxTimeMs += info.getTxTimeMillis()[i];
4436 }
4437 return (info.isValid()
4438 && (info.getSleepTimeMillis() <= activityDurationMs)
4439 && (info.getIdleTimeMillis() <= activityDurationMs)
4440 && (info.getRxTimeMillis() <= activityDurationMs)
4441 && (totalTxTimeMs <= activityDurationMs));
4442 }
4443
Jack Yu85bd38a2015-11-09 11:34:32 -08004444 /**
4445 * {@hide}
4446 * Returns the service state information on specified subscription.
4447 */
4448 @Override
4449 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004451 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004452 return null;
4453 }
4454
Malcolm Chenaabec062018-02-28 15:00:40 -08004455 final long identity = Binder.clearCallingIdentity();
4456 try {
4457 final Phone phone = getPhone(subId);
4458 if (phone == null) {
4459 return null;
4460 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004461
Malcolm Chenaabec062018-02-28 15:00:40 -08004462 return phone.getServiceState();
4463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004466 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004467
4468 /**
4469 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4470 *
4471 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4472 * voicemail ringtone.
4473 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4474 * PhoneAccount.
4475 */
4476 @Override
4477 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004478 final long identity = Binder.clearCallingIdentity();
4479 try {
4480 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4481 if (phone == null) {
4482 phone = mPhone;
4483 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004484
Malcolm Chenaabec062018-02-28 15:00:40 -08004485 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004489 }
4490
4491 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004492 * Sets the per-account voicemail ringtone.
4493 *
4494 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4495 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4496 *
4497 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4498 * voicemail ringtone.
4499 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4500 * PhoneAccount.
4501 */
4502 @Override
4503 public void setVoicemailRingtoneUri(String callingPackage,
4504 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4505 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4506 if (!TextUtils.equals(callingPackage,
4507 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4509 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4510 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004511 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004512
4513 final long identity = Binder.clearCallingIdentity();
4514 try {
4515 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4516 if (phone == null) {
4517 phone = mPhone;
4518 }
4519 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4520 } finally {
4521 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004522 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004523 }
4524
4525 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004526 * Returns whether vibration is set for voicemail notification in Phone settings.
4527 *
4528 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4529 * voicemail vibration setting.
4530 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4531 */
4532 @Override
4533 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004534 final long identity = Binder.clearCallingIdentity();
4535 try {
4536 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4537 if (phone == null) {
4538 phone = mPhone;
4539 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004540
Malcolm Chenaabec062018-02-28 15:00:40 -08004541 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4542 } finally {
4543 Binder.restoreCallingIdentity(identity);
4544 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004545 }
4546
Youhan Wange64578a2016-05-02 15:32:42 -07004547 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004548 * Sets the per-account voicemail vibration.
4549 *
4550 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4551 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4552 *
4553 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4554 * voicemail vibration setting.
4555 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4556 * specific PhoneAccount.
4557 */
4558 @Override
4559 public void setVoicemailVibrationEnabled(String callingPackage,
4560 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4561 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4562 if (!TextUtils.equals(callingPackage,
4563 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4565 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4566 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004567 }
4568
Malcolm Chenaabec062018-02-28 15:00:40 -08004569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4572 if (phone == null) {
4573 phone = mPhone;
4574 }
4575 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4576 } finally {
4577 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004578 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004579 }
4580
4581 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004582 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4583 *
4584 * @throws SecurityException if the caller does not have the required permission
4585 */
4586 private void enforceReadPrivilegedPermission() {
4587 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4588 null);
4589 }
4590
4591 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004592 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4593 * permission.
4594 *
4595 * @throws SecurityException if the caller does not have the required permission
4596 */
4597 private void enforceSendSmsPermission() {
4598 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4599 }
4600
4601 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004602 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004603 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004604 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004605 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004606 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004607 final long identity = Binder.clearCallingIdentity();
4608 try {
4609 ComponentName componentName =
4610 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4611 if (componentName == null) {
4612 throw new SecurityException(
4613 "Caller not current active visual voicemail package[null]");
4614 }
4615 String vvmPackage = componentName.getPackageName();
4616 if (!callingPackage.equals(vvmPackage)) {
4617 throw new SecurityException("Caller not current active visual voicemail package["
4618 + vvmPackage + "]");
4619 }
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004622 }
4623 }
4624
4625 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004626 * Return the application ID for the app type.
4627 *
4628 * @param subId the subscription ID that this request applies to.
4629 * @param appType the uicc app type.
4630 * @return Application ID for specificied app type, or null if no uicc.
4631 */
4632 @Override
4633 public String getAidForAppType(int subId, int appType) {
4634 enforceReadPrivilegedPermission();
4635 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004636
4637 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004638 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004639 if (phone == null) {
4640 return null;
4641 }
4642 String aid = null;
4643 try {
4644 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4645 .getApplicationByType(appType).getAid();
4646 } catch (Exception e) {
4647 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4648 }
4649 return aid;
4650 } finally {
4651 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004652 }
Youhan Wange64578a2016-05-02 15:32:42 -07004653 }
4654
Youhan Wang4001d252016-05-11 10:29:41 -07004655 /**
4656 * Return the Electronic Serial Number.
4657 *
4658 * @param subId the subscription ID that this request applies to.
4659 * @return ESN or null if error.
4660 */
4661 @Override
4662 public String getEsn(int subId) {
4663 enforceReadPrivilegedPermission();
4664 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004665
4666 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004667 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004668 if (phone == null) {
4669 return null;
4670 }
4671 String esn = null;
4672 try {
4673 esn = phone.getEsn();
4674 } catch (Exception e) {
4675 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4676 }
4677 return esn;
4678 } finally {
4679 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004680 }
Youhan Wang4001d252016-05-11 10:29:41 -07004681 }
4682
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004683 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004684 * Return the Preferred Roaming List Version.
4685 *
4686 * @param subId the subscription ID that this request applies to.
4687 * @return PRLVersion or null if error.
4688 */
4689 @Override
4690 public String getCdmaPrlVersion(int subId) {
4691 enforceReadPrivilegedPermission();
4692 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004693
4694 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004695 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004696 if (phone == null) {
4697 return null;
4698 }
4699 String cdmaPrlVersion = null;
4700 try {
4701 cdmaPrlVersion = phone.getCdmaPrlVersion();
4702 } catch (Exception e) {
4703 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4704 }
4705 return cdmaPrlVersion;
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004708 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004709 }
4710
4711 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004712 * Get snapshot of Telephony histograms
4713 * @return List of Telephony histograms
4714 * @hide
4715 */
4716 @Override
4717 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4719 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004720
4721 final long identity = Binder.clearCallingIdentity();
4722 try {
4723 return RIL.getTelephonyRILTimingHistograms();
4724 } finally {
4725 Binder.restoreCallingIdentity(identity);
4726 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004727 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004728
4729 /**
4730 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004731 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004732 * Require system privileges. In the future we may add this to carrier APIs.
4733 *
4734 * @return The number of carriers set successfully, should match length of carriers
4735 */
4736 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004737 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004738 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004739 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004740
Meng Wang9b7c4e92017-02-17 11:41:27 -08004741 if (carriers == null) {
4742 throw new NullPointerException("carriers cannot be null");
4743 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004744
Malcolm Chenaabec062018-02-28 15:00:40 -08004745 final long identity = Binder.clearCallingIdentity();
4746 try {
4747 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004748 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4749 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004750 return retVal[0];
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
4753 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004754 }
4755
4756 /**
4757 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004758 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004759 * Require system privileges. In the future we may add this to carrier APIs.
4760 *
4761 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4762 * means all carriers are allowed.
4763 */
4764 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004765 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004766 enforceReadPrivilegedPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004767 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08004768
4769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004772 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4773 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004774 } finally {
4775 Binder.restoreCallingIdentity(identity);
4776 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004777 }
4778
fionaxu59545b42016-05-25 15:53:37 -07004779 /**
4780 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4781 * @param subId the subscription ID that this action applies to.
4782 * @param enabled control enable or disable metered apns.
4783 * {@hide}
4784 */
4785 @Override
4786 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4787 enforceModifyPermission();
4788 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004789
4790 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004791 if (phone == null) {
4792 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4793 return;
4794 }
4795 try {
4796 phone.carrierActionSetMeteredApnsEnabled(enabled);
4797 } catch (Exception e) {
4798 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004799 } finally {
4800 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004801 }
4802 }
4803
4804 /**
4805 * Action set from carrier signalling broadcast receivers to enable/disable radio
4806 * @param subId the subscription ID that this action applies to.
4807 * @param enabled control enable or disable radio.
4808 * {@hide}
4809 */
4810 @Override
4811 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4812 enforceModifyPermission();
4813 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004814
4815 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004816 if (phone == null) {
4817 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4818 return;
4819 }
4820 try {
4821 phone.carrierActionSetRadioEnabled(enabled);
4822 } catch (Exception e) {
4823 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004824 } finally {
4825 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004826 }
4827 }
4828
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004829 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004830 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4831 * network status based on which carrier apps could apply actions accordingly,
4832 * enable/disable default url handler for example.
4833 *
4834 * @param subId the subscription ID that this action applies to.
4835 * @param report control start/stop reporting the default network status.
4836 * {@hide}
4837 */
4838 @Override
4839 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4840 enforceModifyPermission();
4841 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004842
4843 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004844 if (phone == null) {
4845 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4846 return;
4847 }
4848 try {
4849 phone.carrierActionReportDefaultNetworkStatus(report);
4850 } catch (Exception e) {
4851 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004852 } finally {
4853 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004854 }
4855 }
4856
4857 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004858 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4859 * bug report is being generated.
4860 */
4861 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004862 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004863 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4864 != PackageManager.PERMISSION_GRANTED) {
4865 writer.println("Permission Denial: can't dump Phone from pid="
4866 + Binder.getCallingPid()
4867 + ", uid=" + Binder.getCallingUid()
4868 + "without permission "
4869 + android.Manifest.permission.DUMP);
4870 return;
4871 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004872 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004873 }
Jack Yueb89b242016-06-22 13:27:47 -07004874
Brad Ebingerdac2f002018-04-03 15:17:52 -07004875 @Override
4876 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4877 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4878 throws RemoteException {
4879 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4880 }
4881
Jack Yueb89b242016-06-22 13:27:47 -07004882 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004883 * Get aggregated video call data usage since boot.
4884 *
4885 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4886 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004887 * {@hide}
4888 */
4889 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004890 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004891 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4892 null);
4893
Malcolm Chenaabec062018-02-28 15:00:40 -08004894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 // NetworkStatsService keeps tracking the active network interface and identity. It
4897 // records the delta with the corresponding network identity.
4898 // We just return the total video call data usage snapshot since boot.
4899 Phone phone = getPhone(subId);
4900 if (phone != null) {
4901 return phone.getVtDataUsage(perUidStats);
4902 }
4903 return null;
4904 } finally {
4905 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004906 }
Jack Yueb89b242016-06-22 13:27:47 -07004907 }
Jack Yu75ab2952016-07-08 14:29:33 -07004908
4909 /**
4910 * Policy control of data connection. Usually used when data limit is passed.
4911 * @param enabled True if enabling the data, otherwise disabling.
4912 * @param subId Subscription index
4913 * {@hide}
4914 */
4915 @Override
4916 public void setPolicyDataEnabled(boolean enabled, int subId) {
4917 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004918
4919 final long identity = Binder.clearCallingIdentity();
4920 try {
4921 Phone phone = getPhone(subId);
4922 if (phone != null) {
4923 phone.setPolicyDataEnabled(enabled);
4924 }
4925 } finally {
4926 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004927 }
4928 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004929
4930 /**
4931 * Get Client request stats
4932 * @return List of Client Request Stats
4933 * @hide
4934 */
4935 @Override
4936 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004938 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004939 return null;
4940 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004941 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004942
Malcolm Chenaabec062018-02-28 15:00:40 -08004943 final long identity = Binder.clearCallingIdentity();
4944 try {
4945 if (phone != null) {
4946 return phone.getClientRequestStats();
4947 }
4948
4949 return null;
4950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004953 }
4954
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004955 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004956 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004957 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004958 }
Jack Yueb4124c2017-02-16 15:32:43 -08004959
4960 /**
Grace Chen70990072017-03-24 17:21:30 -07004961 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004962 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004963 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004964 * @param state State of SIM (power down, power up, pass through)
4965 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4966 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4967 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004968 *
4969 **/
4970 @Override
Grace Chen70990072017-03-24 17:21:30 -07004971 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004972 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004973 Phone phone = PhoneFactory.getPhone(slotIndex);
4974
vagdevie435a3e2018-08-15 16:01:53 -07004975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4976
Malcolm Chenaabec062018-02-28 15:00:40 -08004977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07004980 phone.setSimPowerState(state, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004981 }
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004984 }
4985 }
Shuo Qiandd210312017-04-12 22:11:33 +00004986
Tyler Gunn65d45c22017-06-05 11:22:26 -07004987 private boolean isUssdApiAllowed(int subId) {
4988 CarrierConfigManager configManager =
4989 (CarrierConfigManager) mPhone.getContext().getSystemService(
4990 Context.CARRIER_CONFIG_SERVICE);
4991 if (configManager == null) {
4992 return false;
4993 }
4994 PersistableBundle pb = configManager.getConfigForSubId(subId);
4995 if (pb == null) {
4996 return false;
4997 }
4998 return pb.getBoolean(
4999 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5000 }
5001
Shuo Qiandd210312017-04-12 22:11:33 +00005002 /**
5003 * Check if phone is in emergency callback mode
5004 * @return true if phone is in emergency callback mode
5005 * @param subId sub id
5006 */
goneil9c5f4872017-12-05 14:07:56 -08005007 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005008 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08005009 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00005010 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08005011
5012 final long identity = Binder.clearCallingIdentity();
5013 try {
5014 if (phone != null) {
5015 return phone.isInEcm();
5016 } else {
5017 return false;
5018 }
5019 } finally {
5020 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005021 }
5022 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005023
5024 /**
5025 * Get the current signal strength information for the given subscription.
5026 * Because this information is not updated when the device is in a low power state
5027 * it should not be relied-upon to be current.
5028 * @param subId Subscription index
5029 * @return the most recent cached signal strength info from the modem
5030 */
5031 @Override
5032 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08005033 final long identity = Binder.clearCallingIdentity();
5034 try {
5035 Phone p = getPhone(subId);
5036 if (p == null) {
5037 return null;
5038 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005039
Malcolm Chenaabec062018-02-28 15:00:40 -08005040 return p.getSignalStrength();
5041 } finally {
5042 Binder.restoreCallingIdentity(identity);
5043 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005044 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005045
Pengquan Meng9140aec2018-08-22 14:49:57 -07005046 /**
5047 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5048 *
5049 * <p>Requires one of the following permissions:
5050 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5051 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5052 * privileges.
5053 *
5054 * @param subId subscription id
5055 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5056 * {@code false}.
5057 */
5058 @Override
5059 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005060 boolean isEnabled = false;
5061 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005062 try {
5063 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005064 null /* message */);
5065 Phone phone = getPhone(subId);
5066 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005067 } catch (Exception e) {
5068 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5069 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005070 } finally {
5071 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005072 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005073 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005074 }
5075
5076
5077 /**
5078 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5079 *
5080 * <p> Requires permission:
5081 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5082 * privileges.
5083 *
5084 * @param subId subscription id
5085 * @param isEnabled {@code true} means enable, {@code false} means disable.
5086 */
5087 @Override
5088 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5092 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005093
Pengquan Meng0c05b502018-09-06 09:59:22 -07005094 Phone phone = getPhone(subId);
5095 if (phone != null) {
5096 phone.setDataRoamingEnabled(isEnabled);
5097 }
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005100 }
5101 }
5102
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005103 @Override
5104 public UiccSlotInfo[] getUiccSlotsInfo() {
5105 enforceReadPrivilegedPermission();
5106
Malcolm Chenaabec062018-02-28 15:00:40 -08005107 final long identity = Binder.clearCallingIdentity();
5108 try {
5109 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005110 if (slots == null) {
5111 Rlog.i(LOG_TAG, "slots is null.");
5112 return null;
5113 }
5114
Malcolm Chenaabec062018-02-28 15:00:40 -08005115 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5116 for (int i = 0; i < slots.length; i++) {
5117 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005118 if (slot == null) {
5119 continue;
5120 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005121
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005122 String cardId;
5123 UiccCard card = slot.getUiccCard();
5124 if (card != null) {
5125 cardId = card.getCardId();
5126 } else {
5127 cardId = slot.getIccId();
5128 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005129
Malcolm Chenaabec062018-02-28 15:00:40 -08005130 int cardState = 0;
5131 switch (slot.getCardState()) {
5132 case CARDSTATE_ABSENT:
5133 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5134 break;
5135 case CARDSTATE_PRESENT:
5136 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5137 break;
5138 case CARDSTATE_ERROR:
5139 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5140 break;
5141 case CARDSTATE_RESTRICTED:
5142 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5143 break;
5144 default:
5145 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005146
Malcolm Chenaabec062018-02-28 15:00:40 -08005147 }
5148
5149 infos[i] = new UiccSlotInfo(
5150 slot.isActive(),
5151 slot.isEuicc(),
5152 cardId,
5153 cardState,
5154 slot.getPhoneId(),
5155 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005156 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005157 return infos;
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005160 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005161 }
5162
5163 @Override
5164 public boolean switchSlots(int[] physicalSlots) {
5165 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005166
5167 final long identity = Binder.clearCallingIdentity();
5168 try {
5169 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5170 } finally {
5171 Binder.restoreCallingIdentity(identity);
5172 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005173 }
Jack Yu4c988042018-02-27 15:30:01 -08005174
5175 @Override
5176 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5177 enforceModifyPermission();
5178 final Phone phone = getPhone(subId);
5179 if (phone == null) {
5180 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5181 return;
5182 }
5183
Malcolm Chenaabec062018-02-28 15:00:40 -08005184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 phone.setRadioIndicationUpdateMode(filters, mode);
5187 } finally {
5188 Binder.restoreCallingIdentity(identity);
5189 }
Jack Yu4c988042018-02-27 15:30:01 -08005190 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005191
5192 /**
goneil47ffb6e2018-04-06 15:40:58 -07005193 * A test API to reload the UICC profile.
5194 *
5195 * <p>Requires that the calling app has permission
5196 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5197 * @hide
5198 */
5199 @Override
5200 public void refreshUiccProfile(int subId) {
5201 enforceModifyPermission();
5202
5203 final long identity = Binder.clearCallingIdentity();
5204 try {
5205 Phone phone = getPhone(subId);
5206 if (phone == null) {
5207 return;
5208 }
5209 UiccCard uiccCard = phone.getUiccCard();
5210 if (uiccCard == null) {
5211 return;
5212 }
5213 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5214 if (uiccProfile == null) {
5215 return;
5216 }
5217 uiccProfile.refresh();
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
5221 }
5222
5223 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005224 * Returns false if the mobile data is disabled by default, otherwise return true.
5225 */
5226 private boolean getDefaultDataEnabled() {
5227 return "true".equalsIgnoreCase(
5228 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5229 }
5230
5231 /**
5232 * Returns true if the data roaming is enabled by default, i.e the system property
5233 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5234 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5235 */
5236 private boolean getDefaultDataRoamingEnabled(int subId) {
5237 final CarrierConfigManager configMgr = (CarrierConfigManager)
5238 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5239 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5240 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5241 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5242 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5243 return isDataRoamingEnabled;
5244 }
5245
5246 /**
5247 * Returns the default network type for the given {@code subId}, if the default network type is
5248 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5249 */
5250 private int getDefaultNetworkType(int subId) {
5251 return Integer.parseInt(
5252 TelephonyManager.getTelephonyProperty(
5253 mSubscriptionController.getPhoneId(subId),
5254 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5255 String.valueOf(Phone.PREFERRED_NT_MODE)));
5256 }
fionaxua13278b2018-03-21 00:08:13 -07005257
5258 @Override
5259 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5260 gid1, String gid2, String plmn, String spn) {
5261 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005262
5263 final long identity = Binder.clearCallingIdentity();
5264 try {
5265 final Phone phone = getPhone(subId);
5266 if (phone == null) {
5267 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5268 return;
5269 }
5270 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5271 } finally {
5272 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005273 }
fionaxua13278b2018-03-21 00:08:13 -07005274 }
5275
5276 @Override
5277 public int getCarrierIdListVersion(int subId) {
5278 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005279
5280 final long identity = Binder.clearCallingIdentity();
5281 try {
5282 final Phone phone = getPhone(subId);
5283 if (phone == null) {
5284 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5285 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5286 }
5287 return phone.getCarrierIdListVersion();
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005290 }
fionaxua13278b2018-03-21 00:08:13 -07005291 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005292
5293 @Override
5294 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5296 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5297 return -1;
5298 }
5299
5300 final long identity = Binder.clearCallingIdentity();
5301 try {
5302 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
5306 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005307
5308 @Override
5309 public int getCdmaRoamingMode(int subId) {
5310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5311 mApp, subId, "getCdmaRoamingMode");
5312
5313 final long identity = Binder.clearCallingIdentity();
5314 try {
5315 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
5319 }
5320
5321 @Override
5322 public boolean setCdmaRoamingMode(int subId, int mode) {
5323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5324 mApp, subId, "setCdmaRoamingMode");
5325
5326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
5331 }
5332 }
5333
5334 @Override
5335 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5337 mApp, subId, "setCdmaSubscriptionMode");
5338
5339 final long identity = Binder.clearCallingIdentity();
5340 try {
5341 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5342 } finally {
5343 Binder.restoreCallingIdentity(identity);
5344 }
5345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005346}