blob: cef0e5314a2883176c6478c76e6133234d79968f [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 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001261 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001262 }
1263
Wink Savilleb564aae2014-10-23 10:18:09 -07001264 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001265 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001266 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1267 }
1268
1269 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001270 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001271 }
1272
Wink Savilleb564aae2014-10-23 10:18:09 -07001273 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001274 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001275 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1276 }
1277
1278 /** {@hide} */
1279 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001280 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
Wink Savilleb564aae2014-10-23 10:18:09 -07001283 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001285
1286 final long identity = Binder.clearCallingIdentity();
1287 try {
1288 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1289 checkSimPin.start();
1290 return checkSimPin.unlockSim(null, pin);
1291 } finally {
1292 Binder.restoreCallingIdentity(identity);
1293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001294 }
1295
Wink Saville9de0f752013-10-22 19:04:03 -07001296 /** {@hide} */
1297 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001298 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001299 }
1300
Wink Savilleb564aae2014-10-23 10:18:09 -07001301 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001303
1304 final long identity = Binder.clearCallingIdentity();
1305 try {
1306 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1307 checkSimPuk.start();
1308 return checkSimPuk.unlockSim(puk, pin);
1309 } finally {
1310 Binder.restoreCallingIdentity(identity);
1311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 }
1313
1314 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001315 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 * a synchronous one.
1317 */
1318 private static class UnlockSim extends Thread {
1319
1320 private final IccCard mSimCard;
1321
1322 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001323 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1324 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325
1326 // For replies from SimCard interface
1327 private Handler mHandler;
1328
1329 // For async handler to identify request type
1330 private static final int SUPPLY_PIN_COMPLETE = 100;
1331
1332 public UnlockSim(IccCard simCard) {
1333 mSimCard = simCard;
1334 }
1335
1336 @Override
1337 public void run() {
1338 Looper.prepare();
1339 synchronized (UnlockSim.this) {
1340 mHandler = new Handler() {
1341 @Override
1342 public void handleMessage(Message msg) {
1343 AsyncResult ar = (AsyncResult) msg.obj;
1344 switch (msg.what) {
1345 case SUPPLY_PIN_COMPLETE:
1346 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1347 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001348 mRetryCount = msg.arg1;
1349 if (ar.exception != null) {
1350 if (ar.exception instanceof CommandException &&
1351 ((CommandException)(ar.exception)).getCommandError()
1352 == CommandException.Error.PASSWORD_INCORRECT) {
1353 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1354 } else {
1355 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1356 }
1357 } else {
1358 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 mDone = true;
1361 UnlockSim.this.notifyAll();
1362 }
1363 break;
1364 }
1365 }
1366 };
1367 UnlockSim.this.notifyAll();
1368 }
1369 Looper.loop();
1370 }
1371
1372 /*
1373 * Use PIN or PUK to unlock SIM card
1374 *
1375 * If PUK is null, unlock SIM card with PIN
1376 *
1377 * If PUK is not null, unlock SIM card with PUK and set PIN code
1378 */
Wink Saville9de0f752013-10-22 19:04:03 -07001379 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380
1381 while (mHandler == null) {
1382 try {
1383 wait();
1384 } catch (InterruptedException e) {
1385 Thread.currentThread().interrupt();
1386 }
1387 }
1388 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1389
1390 if (puk == null) {
1391 mSimCard.supplyPin(pin, callback);
1392 } else {
1393 mSimCard.supplyPuk(puk, pin, callback);
1394 }
1395
1396 while (!mDone) {
1397 try {
1398 Log.d(LOG_TAG, "wait for done");
1399 wait();
1400 } catch (InterruptedException e) {
1401 // Restore the interrupted status
1402 Thread.currentThread().interrupt();
1403 }
1404 }
1405 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001406 int[] resultArray = new int[2];
1407 resultArray[0] = mResult;
1408 resultArray[1] = mRetryCount;
1409 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 }
1411 }
1412
1413 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001414 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001415
1416 }
1417
Wink Savilleb564aae2014-10-23 10:18:09 -07001418 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 // No permission check needed here: this call is harmless, and it's
1420 // needed for the ServiceState.requestStateUpdate() call (which is
1421 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001422 final long identity = Binder.clearCallingIdentity();
1423 try {
1424 final Phone phone = getPhone(subId);
1425 if (phone != null) {
1426 phone.updateServiceLocation();
1427 }
1428 } finally {
1429 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 }
1432
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001433 @Override
1434 public boolean isRadioOn(String callingPackage) {
1435 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001436 }
1437
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001438 @Override
1439 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001441 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001442 return false;
1443 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001444
1445 final long identity = Binder.clearCallingIdentity();
1446 try {
1447 return isRadioOnForSubscriber(subId);
1448 } finally {
1449 Binder.restoreCallingIdentity(identity);
1450 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001451 }
1452
1453 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001454 final long identity = Binder.clearCallingIdentity();
1455 try {
1456 final Phone phone = getPhone(subId);
1457 if (phone != null) {
1458 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1459 } else {
1460 return false;
1461 }
1462 } finally {
1463 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 }
1466
1467 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001468 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 }
Wink Saville36469e72014-06-11 15:17:00 -07001470
Wink Savilleb564aae2014-10-23 10:18:09 -07001471 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001473
1474 final long identity = Binder.clearCallingIdentity();
1475 try {
1476 final Phone phone = getPhone(subId);
1477 if (phone != null) {
1478 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1479 }
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001482 }
Wink Saville36469e72014-06-11 15:17:00 -07001483 }
1484
1485 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001490 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001491
1492 final long identity = Binder.clearCallingIdentity();
1493 try {
1494 final Phone phone = getPhone(subId);
1495 if (phone == null) {
1496 return false;
1497 }
1498 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1499 toggleRadioOnOffForSubscriber(subId);
1500 }
1501 return true;
1502 } finally {
1503 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 }
Wink Saville36469e72014-06-11 15:17:00 -07001506
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001507 public boolean needMobileRadioShutdown() {
1508 /*
1509 * If any of the Radios are available, it will need to be
1510 * shutdown. So return true if any Radio is available.
1511 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001512 final long identity = Binder.clearCallingIdentity();
1513 try {
1514 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1515 Phone phone = PhoneFactory.getPhone(i);
1516 if (phone != null && phone.isRadioAvailable()) return true;
1517 }
1518 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1519 return false;
1520 } finally {
1521 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001522 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001523 }
1524
Malcolm Chenaabec062018-02-28 15:00:40 -08001525 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001526 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001527 enforceModifyPermission();
1528
1529 final long identity = Binder.clearCallingIdentity();
1530 try {
1531 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1532 logv("Shutting down Phone " + i);
1533 shutdownRadioUsingPhoneId(i);
1534 }
1535 } finally {
1536 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001537 }
1538 }
1539
1540 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001541 Phone phone = PhoneFactory.getPhone(phoneId);
1542 if (phone != null && phone.isRadioAvailable()) {
1543 phone.shutdownRadio();
1544 }
1545 }
1546
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001548 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001549
1550 final long identity = Binder.clearCallingIdentity();
1551 try {
1552 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1553 if (defaultPhone != null) {
1554 defaultPhone.setRadioPower(turnOn);
1555 return true;
1556 } else {
1557 loge("There's no default phone.");
1558 return false;
1559 }
1560 } finally {
1561 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001562 }
Wink Saville36469e72014-06-11 15:17:00 -07001563 }
1564
Wink Savilleb564aae2014-10-23 10:18:09 -07001565 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001567
1568 final long identity = Binder.clearCallingIdentity();
1569 try {
1570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
1572 phone.setRadioPower(turnOn);
1573 return true;
1574 } else {
1575 return false;
1576 }
1577 } finally {
1578 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 }
1581
Wink Saville36469e72014-06-11 15:17:00 -07001582 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001583 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 public boolean enableDataConnectivity() {
1585 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001586
1587 final long identity = Binder.clearCallingIdentity();
1588 try {
1589 int subId = mSubscriptionController.getDefaultDataSubId();
1590 final Phone phone = getPhone(subId);
1591 if (phone != null) {
1592 phone.setUserDataEnabled(true);
1593 return true;
1594 } else {
1595 return false;
1596 }
1597 } finally {
1598 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
1601
Wink Saville36469e72014-06-11 15:17:00 -07001602 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001603 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 public boolean disableDataConnectivity() {
1605 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001606
1607 final long identity = Binder.clearCallingIdentity();
1608 try {
1609 int subId = mSubscriptionController.getDefaultDataSubId();
1610 final Phone phone = getPhone(subId);
1611 if (phone != null) {
1612 phone.setUserDataEnabled(false);
1613 return true;
1614 } else {
1615 return false;
1616 }
1617 } finally {
1618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Sanket Padawe356d7632015-06-22 14:03:32 -07001622 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001623 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001624 final long identity = Binder.clearCallingIdentity();
1625 try {
1626 final Phone phone = getPhone(subId);
1627 if (phone != null) {
1628 return phone.isDataAllowed();
1629 } else {
1630 return false;
1631 }
1632 } finally {
1633 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 }
1636
1637 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001638 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001639 }
1640
pkanwarae03a6b2016-11-06 20:37:09 -08001641 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001642 enforceCallPermission();
1643
1644 final long identity = Binder.clearCallingIdentity();
1645 try {
1646 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1647 return;
1648 }
1649 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1650 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
1653 }
pkanwar32d516d2016-10-14 19:37:38 -07001654 };
1655
Wink Savilleb564aae2014-10-23 10:18:09 -07001656 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001658
1659 final long identity = Binder.clearCallingIdentity();
1660 try {
1661 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1662 return false;
1663 }
1664 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1665 } finally {
1666 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 }
1669
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001671 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001674 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001675 final long identity = Binder.clearCallingIdentity();
1676 try {
1677 Phone phone = PhoneFactory.getPhone(slotIndex);
1678 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1679 PhoneConstantConversions.convertCallState(phone.getState());
1680 } finally {
1681 Binder.restoreCallingIdentity(identity);
1682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 }
1684
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001687 final long identity = Binder.clearCallingIdentity();
1688 try {
1689 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1690 if (phone != null) {
1691 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1692 } else {
1693 return PhoneConstantConversions.convertDataState(
1694 PhoneConstants.DataState.DISCONNECTED);
1695 }
1696 } finally {
1697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001703 final long identity = Binder.clearCallingIdentity();
1704 try {
1705 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1706 if (phone != null) {
1707 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1708 } else {
1709 return TelephonyManager.DATA_ACTIVITY_NONE;
1710 }
1711 } finally {
1712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 }
1715
1716 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001717 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001718 mPhone.getContext().getSystemService(AppOpsManager.class)
1719 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001720 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001721 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001722 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 }
1724
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001725 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001726 final long identity = Binder.clearCallingIdentity();
1727 try {
1728 if (DBG_LOC) log("getCellLocation: is active user");
1729 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001730 int subId = mSubscriptionController.getDefaultDataSubId();
1731 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1732 cl.fillInNotifierBundle(data);
Malcolm Chenaabec062018-02-28 15:00:40 -08001733 return data;
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
1736 }
Svetoslav64fad262015-04-14 14:35:21 -07001737 }
1738
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001740 public String getNetworkCountryIsoForPhone(int phoneId) {
1741 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1742 // registered cell info, so return a NULL country instead.
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001746 // Todo: fix this when we can get the actual cellular network info when the device
1747 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001748 if (TelephonyManager.NETWORK_TYPE_IWLAN
1749 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1750 return "";
1751 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001752 Phone phone = PhoneFactory.getPhone(phoneId);
1753 if (phone != null) {
1754 ServiceStateTracker sst = phone.getServiceStateTracker();
1755 if (sst != null) {
1756 LocaleTracker lt = sst.getLocaleTracker();
1757 if (lt != null) {
1758 return lt.getCurrentCountry();
1759 }
1760 }
1761 }
1762 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001763 } finally {
1764 Binder.restoreCallingIdentity(identity);
1765 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001766 }
1767
1768 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001770 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001771 }
1772
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001774 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 mApp.enforceCallingOrSelfPermission(
1776 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001777
1778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 final Phone phone = getPhone(subId);
1781 if (phone != null) {
1782 phone.enableLocationUpdates();
1783 }
1784 } finally {
1785 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 }
1788
1789 @Override
1790 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001791 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001792 }
1793
Sanket Padawe356d7632015-06-22 14:03:32 -07001794 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001795 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 mApp.enforceCallingOrSelfPermission(
1797 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001798
1799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 final Phone phone = getPhone(subId);
1802 if (phone != null) {
1803 phone.disableLocationUpdates();
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
1810 @Override
1811 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001812 public List<NeighboringCellInfo>
1813 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001814 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1815 throw new SecurityException(
1816 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1817 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001818
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1820 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1821 return null;
1822 }
Svetoslav64fad262015-04-14 14:35:21 -07001823
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001824 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825
Nathan Haroldf180aac2018-06-01 18:43:55 -07001826 List<CellInfo> info = getAllCellInfo(callingPackage);
1827 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828
Nathan Haroldf180aac2018-06-01 18:43:55 -07001829 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1830 for (CellInfo ci : info) {
1831 if (ci instanceof CellInfoGsm) {
1832 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1833 } else if (ci instanceof CellInfoWcdma) {
1834 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001837 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 }
1839
1840
1841 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001842 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001843 mPhone.getContext().getSystemService(AppOpsManager.class)
1844 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001845 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001846 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001847 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001850 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001851 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1855 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001856 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1857 CMD_GET_ALL_CELL_INFO,
1858 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaabec062018-02-28 15:00:40 -08001859 if (info != null) cellInfos.addAll(info);
1860 }
1861 return cellInfos;
1862 } finally {
1863 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 }
1865 }
1866
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001867 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001869 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001870 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001871
1872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 mPhone.setCellInfoListRate(rateInMillis, workSource);
1875 } finally {
1876 Binder.restoreCallingIdentity(identity);
1877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 }
1879
Shishir Agrawala9f32182016-04-12 12:00:16 -07001880 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001881 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001882 Phone phone = PhoneFactory.getPhone(slotIndex);
1883 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001884 return null;
1885 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001886 int subId = phone.getSubId();
1887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1888 mApp, subId, callingPackage, "getImeiForSlot")) {
1889 return null;
1890 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001891
1892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 return phone.getImei();
1895 } finally {
1896 Binder.restoreCallingIdentity(identity);
1897 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001898 }
1899
1900 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001901 public String getTypeAllocationCodeForSlot(int slotIndex) {
1902 Phone phone = PhoneFactory.getPhone(slotIndex);
1903 String tac = null;
1904 if (phone != null) {
1905 String imei = phone.getImei();
1906 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1907 }
1908 return tac;
1909 }
1910
1911 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001912 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001913 Phone phone = PhoneFactory.getPhone(slotIndex);
1914 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001915 return null;
1916 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001917 int subId = phone.getSubId();
1918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1919 mApp, subId, callingPackage, "getMeidForSlot")) {
1920 return null;
1921 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001922
1923 final long identity = Binder.clearCallingIdentity();
1924 try {
1925 return phone.getMeid();
1926 } finally {
1927 Binder.restoreCallingIdentity(identity);
1928 }
Jack Yu2af8d712017-03-15 17:14:14 -07001929 }
1930
1931 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001932 public String getManufacturerCodeForSlot(int slotIndex) {
1933 Phone phone = PhoneFactory.getPhone(slotIndex);
1934 String manufacturerCode = null;
1935 if (phone != null) {
1936 String meid = phone.getMeid();
1937 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1938 }
1939 return manufacturerCode;
1940 }
1941
1942 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001943 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001944 Phone phone = PhoneFactory.getPhone(slotIndex);
1945 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001946 return null;
1947 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001948 int subId = phone.getSubId();
1949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1950 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1951 return null;
1952 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001953
1954 final long identity = Binder.clearCallingIdentity();
1955 try {
1956 return phone.getDeviceSvn();
1957 } finally {
1958 Binder.restoreCallingIdentity(identity);
1959 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001960 }
1961
fionaxu43304da2017-11-27 22:51:16 -08001962 @Override
1963 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001964 final long identity = Binder.clearCallingIdentity();
1965 try {
1966 final Phone phone = getPhone(subId);
1967 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1968 } finally {
1969 Binder.restoreCallingIdentity(identity);
1970 }
fionaxu43304da2017-11-27 22:51:16 -08001971 }
1972
1973 @Override
1974 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001975 final long identity = Binder.clearCallingIdentity();
1976 try {
1977 final Phone phone = getPhone(subId);
1978 return phone == null ? null : phone.getCarrierName();
1979 } finally {
1980 Binder.restoreCallingIdentity(identity);
1981 }
fionaxu43304da2017-11-27 22:51:16 -08001982 }
1983
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 //
1985 // Internal helper methods.
1986 //
1987
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001988 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1990 *
1991 * @throws SecurityException if the caller does not have the required permission
1992 */
1993 private void enforceModifyPermission() {
1994 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1995 }
1996
1997 /**
1998 * Make sure the caller has the CALL_PHONE permission.
1999 *
2000 * @throws SecurityException if the caller does not have the required permission
2001 */
2002 private void enforceCallPermission() {
2003 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2004 }
2005
Stuart Scott8eef64f2015-04-08 15:13:54 -07002006 private void enforceConnectivityInternalPermission() {
2007 mApp.enforceCallingOrSelfPermission(
2008 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2009 "ConnectivityService");
2010 }
2011
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 private String createTelUrl(String number) {
2013 if (TextUtils.isEmpty(number)) {
2014 return null;
2015 }
2016
Jake Hambye994d462014-02-03 13:10:13 -08002017 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 }
2019
Ihab Awadf9e92732013-12-05 18:02:52 -08002020 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2022 }
2023
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002024 private static void logv(String msg) {
2025 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2026 }
2027
Ihab Awadf9e92732013-12-05 18:02:52 -08002028 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2030 }
2031
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002032 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002034 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002035 }
2036
Sanket Padawe356d7632015-06-22 14:03:32 -07002037 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002038 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002039 final long identity = Binder.clearCallingIdentity();
2040 try {
2041 final Phone phone = PhoneFactory.getPhone(slotIndex);
2042 if (phone == null) {
2043 return PhoneConstants.PHONE_TYPE_NONE;
2044 } else {
2045 return phone.getPhoneType();
2046 }
2047 } finally {
2048 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002049 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050 }
2051
2052 /**
2053 * Returns the CDMA ERI icon index to display
2054 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002055 @Override
2056 public int getCdmaEriIconIndex(String callingPackage) {
2057 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002058 }
2059
Sanket Padawe356d7632015-06-22 14:03:32 -07002060 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002061 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002063 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002064 return -1;
2065 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002066
2067 final long identity = Binder.clearCallingIdentity();
2068 try {
2069 final Phone phone = getPhone(subId);
2070 if (phone != null) {
2071 return phone.getCdmaEriIconIndex();
2072 } else {
2073 return -1;
2074 }
2075 } finally {
2076 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002077 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 }
2079
2080 /**
2081 * Returns the CDMA ERI icon mode,
2082 * 0 - ON
2083 * 1 - FLASHING
2084 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002085 @Override
2086 public int getCdmaEriIconMode(String callingPackage) {
2087 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002088 }
2089
Sanket Padawe356d7632015-06-22 14:03:32 -07002090 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002091 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002093 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002094 return -1;
2095 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002096
2097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 final Phone phone = getPhone(subId);
2100 if (phone != null) {
2101 return phone.getCdmaEriIconMode();
2102 } else {
2103 return -1;
2104 }
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109
2110 /**
2111 * Returns the CDMA ERI text,
2112 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002113 @Override
2114 public String getCdmaEriText(String callingPackage) {
2115 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002116 }
2117
Sanket Padawe356d7632015-06-22 14:03:32 -07002118 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002119 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002121 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002122 return null;
2123 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002124
2125 final long identity = Binder.clearCallingIdentity();
2126 try {
2127 final Phone phone = getPhone(subId);
2128 if (phone != null) {
2129 return phone.getCdmaEriText();
2130 } else {
2131 return null;
2132 }
2133 } finally {
2134 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 }
2137
2138 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002139 * Returns the CDMA MDN.
2140 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002141 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002142 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2144 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002145
2146 final long identity = Binder.clearCallingIdentity();
2147 try {
2148 final Phone phone = getPhone(subId);
2149 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2150 return phone.getLine1Number();
2151 } else {
2152 return null;
2153 }
2154 } finally {
2155 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002156 }
2157 }
2158
2159 /**
2160 * Returns the CDMA MIN.
2161 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002162 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002163 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2165 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002166
2167 final long identity = Binder.clearCallingIdentity();
2168 try {
2169 final Phone phone = getPhone(subId);
2170 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2171 return phone.getCdmaMin();
2172 } else {
2173 return null;
2174 }
2175 } finally {
2176 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002177 }
2178 }
2179
2180 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 * Returns true if CDMA provisioning needs to run.
2182 */
2183 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002184 final long identity = Binder.clearCallingIdentity();
2185 try {
2186 return mPhone.needsOtaServiceProvisioning();
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
2189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 }
2191
2192 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002193 * Sets the voice mail number of a given subId.
2194 */
2195 @Override
2196 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002197 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002198
2199 final long identity = Binder.clearCallingIdentity();
2200 try {
2201 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2202 new Pair<String, String>(alphaTag, number), new Integer(subId));
2203 return success;
2204 } finally {
2205 Binder.restoreCallingIdentity(identity);
2206 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002207 }
2208
Ta-wei Yen87c49842016-05-13 21:19:52 -07002209 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002210 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2211 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2212 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2213 if (!TextUtils.equals(callingPackage, systemDialer)) {
2214 throw new SecurityException("caller must be system dialer");
2215 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002216
2217 final long identity = Binder.clearCallingIdentity();
2218 try {
2219 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2220 if (phoneAccountHandle == null) {
2221 return null;
2222 }
2223 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2224 } finally {
2225 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002226 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002227 }
2228
2229 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002230 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002231 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002233 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002234 return null;
2235 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002236
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002237 final long identity = Binder.clearCallingIdentity();
2238 try {
2239 return RemoteVvmTaskManager
2240 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2241 } finally {
2242 Binder.restoreCallingIdentity(identity);
2243 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002244 }
2245
2246 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002247 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2248 VisualVoicemailSmsFilterSettings settings) {
2249 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002250
2251 final long identity = Binder.clearCallingIdentity();
2252 try {
2253 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2254 mPhone.getContext(), callingPackage, subId, settings);
2255 } finally {
2256 Binder.restoreCallingIdentity(identity);
2257 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002258 }
2259
2260 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002261 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2262 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002263
2264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2267 mPhone.getContext(), callingPackage, subId);
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
2270 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002271 }
2272
2273 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002274 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2275 String callingPackage, int subId) {
2276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002277
2278 final long identity = Binder.clearCallingIdentity();
2279 try {
2280 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2281 mPhone.getContext(), callingPackage, subId);
2282 } finally {
2283 Binder.restoreCallingIdentity(identity);
2284 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002285 }
2286
2287 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002288 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002289 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002290
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
2293 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2294 mPhone.getContext(), subId);
2295 } finally {
2296 Binder.restoreCallingIdentity(identity);
2297 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002298 }
2299
2300 @Override
2301 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2302 String number, int port, String text, PendingIntent sentIntent) {
2303 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002304 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002305 enforceSendSmsPermission();
2306 // Make the calls as the phone process.
2307 final long identity = Binder.clearCallingIdentity();
2308 try {
2309 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2310 if (port == 0) {
2311 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2312 sentIntent, null, false);
2313 } else {
2314 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2315 smsManager.sendDataMessageWithSelfPermissions(number, null,
2316 (short) port, data, sentIntent, null);
2317 }
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
2320 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002321 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002322 /**
fionaxu0152e512016-11-14 13:36:14 -08002323 * Sets the voice activation state of a given subId.
2324 */
2325 @Override
2326 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2328 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002329
2330 final long identity = Binder.clearCallingIdentity();
2331 try {
2332 final Phone phone = getPhone(subId);
2333 if (phone != null) {
2334 phone.setVoiceActivationState(activationState);
2335 } else {
2336 loge("setVoiceActivationState fails with invalid subId: " + subId);
2337 }
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002340 }
2341 }
2342
2343 /**
2344 * Sets the data activation state of a given subId.
2345 */
2346 @Override
2347 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2349 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002350
2351 final long identity = Binder.clearCallingIdentity();
2352 try {
2353 final Phone phone = getPhone(subId);
2354 if (phone != null) {
2355 phone.setDataActivationState(activationState);
2356 } else {
2357 loge("setVoiceActivationState fails with invalid subId: " + subId);
2358 }
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002361 }
2362 }
2363
2364 /**
2365 * Returns the voice activation state of a given subId.
2366 */
2367 @Override
2368 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002369 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002370
fionaxu0152e512016-11-14 13:36:14 -08002371 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002372 final long identity = Binder.clearCallingIdentity();
2373 try {
2374 if (phone != null) {
2375 return phone.getVoiceActivationState();
2376 } else {
2377 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2378 }
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002381 }
2382 }
2383
2384 /**
2385 * Returns the data activation state of a given subId.
2386 */
2387 @Override
2388 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002389 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002390
fionaxu0152e512016-11-14 13:36:14 -08002391 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 if (phone != null) {
2395 return phone.getDataActivationState();
2396 } else {
2397 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2398 }
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002401 }
2402 }
2403
2404 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 * Returns the unread count of voicemails
2406 */
2407 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002408 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002409 }
2410
2411 /**
2412 * Returns the unread count of voicemails for a subId
2413 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002414 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002415 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002416 final long identity = Binder.clearCallingIdentity();
2417 try {
2418 final Phone phone = getPhone(subId);
2419 if (phone != null) {
2420 return phone.getVoiceMessageCount();
2421 } else {
2422 return 0;
2423 }
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 }
2428
2429 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002430 * returns true, if the device is in a state where both voice and data
2431 * are supported simultaneously. This can change based on location or network condition.
2432 */
2433 @Override
2434 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002435 final long identity = Binder.clearCallingIdentity();
2436 try {
2437 final Phone phone = getPhone(subId);
2438 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
2441 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002442 }
2443
2444 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002445 * Send the dialer code if called from the current default dialer or the caller has
2446 * carrier privilege.
2447 * @param inputCode The dialer code to send
2448 */
2449 @Override
2450 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2452 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2453 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002454 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2455 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002456 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002457
2458 final long identity = Binder.clearCallingIdentity();
2459 try {
2460 mPhone.sendDialerSpecialCode(inputCode);
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
2463 }
fionaxu235cc5e2017-03-06 22:25:57 -08002464 }
2465
2466 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002467 * Returns the data network type.
2468 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 *
2470 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2471 */
2472 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002473 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(getDefaultSubscription());
2477 if (phone != null) {
2478 return phone.getServiceState().getDataNetworkType();
2479 } else {
2480 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002484 }
Wink Saville36469e72014-06-11 15:17:00 -07002485 }
2486
Pengquan Meng0c05b502018-09-06 09:59:22 -07002487 @Override
2488 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002489 if (!isActiveSubscription(subId)) {
2490 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2491 }
2492
Pengquan Meng0c05b502018-09-06 09:59:22 -07002493 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2494 }
2495
Wink Saville36469e72014-06-11 15:17:00 -07002496 /**
2497 * Returns the network type for a subId
2498 */
2499 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002500 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002502 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002503 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2504 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002505
Malcolm Chenaabec062018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = getPhone(subId);
2509 if (phone != null) {
2510 return phone.getServiceState().getDataNetworkType();
2511 } else {
2512 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
2519 /**
2520 * Returns the data network type
2521 */
2522 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002523 public int getDataNetworkType(String callingPackage) {
2524 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002525 }
2526
2527 /**
2528 * Returns the data network type for a subId
2529 */
2530 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002533 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002534 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2535 }
2536
Malcolm Chenaabec062018-02-28 15:00:40 -08002537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 final Phone phone = getPhone(subId);
2540 if (phone != null) {
2541 return phone.getServiceState().getDataNetworkType();
2542 } else {
2543 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2544 }
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 }
2549
2550 /**
Wink Saville36469e72014-06-11 15:17:00 -07002551 * Returns the Voice network type for a subId
2552 */
2553 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002554 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002556 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002557 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2558 }
2559
Malcolm Chenaabec062018-02-28 15:00:40 -08002560 final long identity = Binder.clearCallingIdentity();
2561 try {
2562 final Phone phone = getPhone(subId);
2563 if (phone != null) {
2564 return phone.getServiceState().getVoiceNetworkType();
2565 } else {
2566 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2567 }
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 }
2572
2573 /**
2574 * @return true if a ICC card is present
2575 */
2576 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002577 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002578 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2579 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002580 }
2581
2582 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002583 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002584 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002586 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002587 final long identity = Binder.clearCallingIdentity();
2588 try {
2589 final Phone phone = PhoneFactory.getPhone(slotIndex);
2590 if (phone != null) {
2591 return phone.getIccCard().hasIccCard();
2592 } else {
2593 return false;
2594 }
2595 } finally {
2596 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598 }
2599
2600 /**
2601 * Return if the current radio is LTE on CDMA. This
2602 * is a tri-state return value as for a period of time
2603 * the mode may be unknown.
2604 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002605 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002607 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002609 @Override
2610 public int getLteOnCdmaMode(String callingPackage) {
2611 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002612 }
2613
Sanket Padawe356d7632015-06-22 14:03:32 -07002614 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002615 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002617 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002618 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2619 }
2620
Malcolm Chenaabec062018-02-28 15:00:40 -08002621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 final Phone phone = getPhone(subId);
2624 if (phone == null) {
2625 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2626 } else {
2627 return phone.getLteOnCdmaMode();
2628 }
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002631 }
Wink Saville36469e72014-06-11 15:17:00 -07002632 }
2633
2634 public void setPhone(Phone phone) {
2635 mPhone = phone;
2636 }
2637
2638 /**
2639 * {@hide}
2640 * Returns Default subId, 0 in the case of single standby.
2641 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002642 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002643 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002644 }
2645
Shishir Agrawala9f32182016-04-12 12:00:16 -07002646 private int getSlotForDefaultSubscription() {
2647 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2648 }
2649
Wink Savilleb564aae2014-10-23 10:18:09 -07002650 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002651 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002653
Pengquan Meng466e2482018-09-21 15:54:48 -07002654 private boolean isActiveSubscription(int subId) {
2655 return mSubscriptionController.isActiveSubId(subId);
2656 }
2657
Ihab Awadf2177b72013-11-25 13:33:23 -08002658 /**
2659 * @see android.telephony.TelephonyManager.WifiCallingChoices
2660 */
2661 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2665 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2666 getWhenToMakeWifiCallsDefaultPreference());
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002670 }
2671
2672 /**
2673 * @see android.telephony.TelephonyManager.WifiCallingChoices
2674 */
2675 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2679 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2680 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002684 }
2685
Sailesh Nepald1e68152013-12-12 19:08:02 -08002686 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002687 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002688 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002689 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002690
Shishir Agrawal566b7612013-10-28 14:41:00 -07002691 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002692 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2693 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2695 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002697
Malcolm Chenaabec062018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 if (TextUtils.equals(ISDR_AID, aid)) {
2701 // Only allows LPA to open logical channel to ISD-R.
2702 ComponentInfo bestComponent =
2703 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2704 if (bestComponent == null
2705 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2706 loge("The calling package is not allowed to access ISD-R.");
2707 throw new SecurityException(
2708 "The calling package is not allowed to access ISD-R.");
2709 }
Derek Tan740e1672017-06-27 14:56:27 -07002710 }
Derek Tan740e1672017-06-27 14:56:27 -07002711
Malcolm Chenaabec062018-02-28 15:00:40 -08002712 if (DBG) {
2713 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2714 }
2715 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2716 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2717 if (DBG) log("iccOpenLogicalChannel: " + response);
2718 return response;
2719 } finally {
2720 Binder.restoreCallingIdentity(identity);
2721 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002722 }
2723
2724 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002725 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2727 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002728
Malcolm Chenaabec062018-02-28 15:00:40 -08002729 final long identity = Binder.clearCallingIdentity();
2730 try {
2731 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2732 if (channel < 0) {
2733 return false;
2734 }
2735 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2736 if (DBG) log("iccCloseLogicalChannel: " + success);
2737 return success;
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002740 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002741 }
2742
2743 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002744 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002745 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2747 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002748
Malcolm Chenaabec062018-02-28 15:00:40 -08002749 final long identity = Binder.clearCallingIdentity();
2750 try {
2751 if (DBG) {
2752 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2753 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2754 + p3 + " data=" + data);
2755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002756
Malcolm Chenaabec062018-02-28 15:00:40 -08002757 if (channel < 0) {
2758 return "";
2759 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002760
Malcolm Chenaabec062018-02-28 15:00:40 -08002761 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2762 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2763 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002764
Malcolm Chenaabec062018-02-28 15:00:40 -08002765 // Append the returned status code to the end of the response payload.
2766 String s = Integer.toHexString(
2767 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2768 if (response.payload != null) {
2769 s = IccUtils.bytesToHexString(response.payload) + s;
2770 }
2771 return s;
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002774 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002775 }
Jake Hambye994d462014-02-03 13:10:13 -08002776
Evan Charltonc66da362014-05-16 14:06:40 -07002777 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002778 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2779 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2781 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002782 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002783
Malcolm Chenaabec062018-02-28 15:00:40 -08002784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2787 && TextUtils.equals(ISDR_AID, data)) {
2788 // Only allows LPA to select ISD-R.
2789 ComponentInfo bestComponent =
2790 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2791 if (bestComponent == null
2792 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2793 loge("The calling package is not allowed to select ISD-R.");
2794 throw new SecurityException(
2795 "The calling package is not allowed to select ISD-R.");
2796 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002797 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002798
Malcolm Chenaabec062018-02-28 15:00:40 -08002799 if (DBG) {
2800 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2801 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2802 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002803
Malcolm Chenaabec062018-02-28 15:00:40 -08002804 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2805 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2806 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002807
Malcolm Chenaabec062018-02-28 15:00:40 -08002808 // Append the returned status code to the end of the response payload.
2809 String s = Integer.toHexString(
2810 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2811 if (response.payload != null) {
2812 s = IccUtils.bytesToHexString(response.payload) + s;
2813 }
2814 return s;
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002817 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002818 }
2819
2820 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002821 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002822 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2824 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002825
Malcolm Chenaabec062018-02-28 15:00:40 -08002826 final long identity = Binder.clearCallingIdentity();
2827 try {
2828 if (DBG) {
2829 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2830 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2831 }
2832
2833 IccIoResult response =
2834 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2835 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2836 subId);
2837
2838 if (DBG) {
2839 log("Exchange SIM_IO [R]" + response);
2840 }
2841
2842 byte[] result = null;
2843 int length = 2;
2844 if (response.payload != null) {
2845 length = 2 + response.payload.length;
2846 result = new byte[length];
2847 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2848 } else {
2849 result = new byte[length];
2850 }
2851
2852 result[length - 1] = (byte) response.sw2;
2853 result[length - 2] = (byte) response.sw1;
2854 return result;
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002857 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002858 }
2859
Nathan Haroldb3014052017-01-25 15:57:32 -08002860 /**
2861 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2862 * on a particular subscription
2863 */
sqianb6e41952018-03-12 14:54:01 -07002864 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2866 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2867 return null;
2868 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002869 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2870 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2871 return null;
2872 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002873
2874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2877 if (response instanceof String[]) {
2878 return (String[]) response;
2879 }
2880 // Response is an Exception of some kind,
2881 // which is signalled to the user as a NULL retval
2882 return null;
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002885 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002886 }
2887
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002888 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002889 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2891 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002892
Malcolm Chenaabec062018-02-28 15:00:40 -08002893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2896 if (response.payload == null) {
2897 return "";
2898 }
Evan Charltonc66da362014-05-16 14:06:40 -07002899
Malcolm Chenaabec062018-02-28 15:00:40 -08002900 // Append the returned status code to the end of the response payload.
2901 String s = Integer.toHexString(
2902 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2903 s = IccUtils.bytesToHexString(response.payload) + s;
2904 return s;
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
Evan Charltonc66da362014-05-16 14:06:40 -07002908 }
2909
Jake Hambye994d462014-02-03 13:10:13 -08002910 /**
2911 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2912 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2913 *
2914 * @param itemID the ID of the item to read
2915 * @return the NV item as a String, or null on error.
2916 */
2917 @Override
2918 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07002919 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2921 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08002922
2923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07002926 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08002927 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2928 return value;
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
2931 }
Jake Hambye994d462014-02-03 13:10:13 -08002932 }
2933
2934 /**
2935 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2936 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2937 *
2938 * @param itemID the ID of the item to read
2939 * @param itemValue the value to write, as a String
2940 * @return true on success; false on any failure
2941 */
2942 @Override
2943 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07002944 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2946 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08002947
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2951 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07002952 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08002953 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2954 return success;
2955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
Jake Hambye994d462014-02-03 13:10:13 -08002958 }
2959
2960 /**
2961 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2962 * Used for device configuration by some CDMA operators.
2963 *
2964 * @param preferredRoamingList byte array containing the new PRL
2965 * @return true on success; false on any failure
2966 */
2967 @Override
2968 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2970 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08002971
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2975 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2976 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2977 return success;
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
Jake Hambye994d462014-02-03 13:10:13 -08002981 }
2982
2983 /**
2984 * Perform the specified type of NV config reset.
2985 * Used for device configuration by some CDMA operators.
2986 *
2987 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2988 * @return true on success; false on any failure
2989 */
2990 @Override
2991 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2993 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08002994
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 if (DBG) log("nvResetConfig: type " + resetType);
2998 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2999 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3000 return success;
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
Jake Hambye994d462014-02-03 13:10:13 -08003004 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003005
Svet Ganovb320e182015-04-16 12:30:10 -07003006 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003008 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003009 return new String[0];
3010 }
3011
Malcolm Chenaabec062018-02-28 15:00:40 -08003012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 return mPhone.getPcscfAddress(apnType);
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
Wink Saville36469e72014-06-11 15:17:00 -07003018 }
3019
Brad Ebinger51f743a2017-01-23 13:50:20 -08003020 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003021 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3022 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003023 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003024 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003025 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003026
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 PhoneFactory.getImsResolver().enableIms(slotId);
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003033 }
3034
3035 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003036 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3037 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003038 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003039 public void disableIms(int slotId) {
3040 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003041
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 PhoneFactory.getImsResolver().disableIms(slotId);
3045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003048 }
3049
3050 /**
3051 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3052 * feature or {@link null} if the service is not available. If the feature is available, the
3053 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3054 */
3055 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003056 IImsServiceFeatureCallback callback) {
3057 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003058
3059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003065 }
3066
3067 /**
3068 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3069 * feature during emergency calling or {@link null} if the service is not available. If the
3070 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3071 * listener for feature updates.
3072 */
3073 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3074 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003075
3076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003082 }
3083
Brad Ebinger5f64b052017-12-14 14:26:15 -08003084 /**
3085 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3086 * specified.
3087 */
3088 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3089 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003090
3091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3094 } finally {
3095 Binder.restoreCallingIdentity(identity);
3096 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003097 }
3098
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003099 /**
3100 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3101 * specified.
3102 */
3103 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3104 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003105
3106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003112 }
3113
Brad Ebinger884c07b2018-02-15 16:17:40 -08003114 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003115 * Sets the ImsService Package Name that Telephony will bind to.
3116 *
3117 * @param slotId the slot ID that the ImsService should bind for.
3118 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3119 * ImsService is the device default ImsService.
3120 * @param packageName The package name of the application that contains the ImsService to bind
3121 * to.
3122 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3123 * @hide
3124 */
3125 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003126 int[] subIds = SubscriptionManager.getSubId(slotId);
3127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3128 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3129 "setImsService");
3130
Malcolm Chenaabec062018-02-28 15:00:40 -08003131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3134 isCarrierImsService, packageName);
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
3137 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003138 }
3139
3140 /**
3141 * Return the ImsService configuration.
3142 *
3143 * @param slotId The slot that the ImsService is associated with.
3144 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3145 * the device default.
3146 * @return the package name of the ImsService configuration.
3147 */
3148 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003149 int[] subIds = SubscriptionManager.getSubId(slotId);
3150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3151 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3152 "getImsService");
3153
Malcolm Chenaabec062018-02-28 15:00:40 -08003154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3157 isCarrierImsService);
3158 } finally {
3159 Binder.restoreCallingIdentity(identity);
3160 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003161 }
3162
Wink Saville36469e72014-06-11 15:17:00 -07003163 public void setImsRegistrationState(boolean registered) {
3164 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003165
3166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 mPhone.setImsRegistrationState(registered);
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
Wink Saville36469e72014-06-11 15:17:00 -07003172 }
3173
3174 /**
Stuart Scott54788802015-03-30 13:18:01 -07003175 * Set the network selection mode to automatic.
3176 *
3177 */
3178 @Override
3179 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3181 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003182
Pengquan Meng466e2482018-09-21 15:54:48 -07003183 if (!isActiveSubscription(subId)) {
3184 return;
3185 }
3186
Malcolm Chenaabec062018-02-28 15:00:40 -08003187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3190 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3191 } finally {
3192 Binder.restoreCallingIdentity(identity);
3193 }
Stuart Scott54788802015-03-30 13:18:01 -07003194 }
3195
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003196 /**
3197 * Ask the radio to connect to the input network and change selection mode to manual.
3198 *
3199 * @param subId the id of the subscription.
3200 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3201 * the operator to attach to.
3202 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3203 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3204 * normal network selection next time.
3205 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003206 */
3207 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003208 public boolean setNetworkSelectionModeManual(
3209 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3211 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003212
3213 if (!isActiveSubscription(subId)) {
3214 return false;
3215 }
3216
Malcolm Chenaabec062018-02-28 15:00:40 -08003217 final long identity = Binder.clearCallingIdentity();
3218 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003219 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaabec062018-02-28 15:00:40 -08003220 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003221 if (DBG) {
3222 log("setNetworkSelectionModeManual: subId: " + subId
3223 + " operator: " + operatorInfo);
3224 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003225 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3226 } finally {
3227 Binder.restoreCallingIdentity(identity);
3228 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003229 }
3230
3231 /**
3232 * Scans for available networks.
3233 */
3234 @Override
3235 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3237 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003238
Pengquan Meng0c05b502018-09-06 09:59:22 -07003239 long identity = Binder.clearCallingIdentity();
Malcolm Chenaabec062018-02-28 15:00:40 -08003240 try {
3241 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003242 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaabec062018-02-28 15:00:40 -08003243 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08003244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003247 }
3248
3249 /**
yinxub1bed742017-04-17 11:45:04 -07003250 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003251 *
yinxub1bed742017-04-17 11:45:04 -07003252 * @param subId id of the subscription
3253 * @param request contains the radio access networks with bands/channels to scan
3254 * @param messenger callback messenger for scan results or errors
3255 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003256 * @return the id of the requested scan which can be used to stop the scan.
3257 */
3258 @Override
3259 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3260 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3262 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003263
3264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 return mNetworkScanRequestTracker.startNetworkScan(
3267 request, messenger, binder, getPhone(subId));
3268 } finally {
3269 Binder.restoreCallingIdentity(identity);
3270 }
yinxu504e1392017-04-12 16:03:22 -07003271 }
3272
3273 /**
3274 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003275 *
3276 * @param subId id of the subscription
3277 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003278 */
3279 @Override
3280 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3282 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003283
3284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
yinxu504e1392017-04-12 16:03:22 -07003290 }
3291
3292 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003293 * Get the calculated preferred network type.
3294 * Used for debugging incorrect network type.
3295 *
3296 * @return the preferred network type, defined in RILConstants.java.
3297 */
3298 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003299 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003301 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003302 return RILConstants.PREFERRED_NETWORK_MODE;
3303 }
3304
Malcolm Chenaabec062018-02-28 15:00:40 -08003305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 // FIXME: need to get SubId from somewhere.
3308 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
Junda Liu84d15a22014-07-02 11:21:04 -07003312 }
3313
3314 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003315 * Get the preferred network type.
3316 * Used for device configuration by some CDMA operators.
3317 *
3318 * @return the preferred network type, defined in RILConstants.java.
3319 */
3320 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003321 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3323 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003324
3325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 if (DBG) log("getPreferredNetworkType");
3328 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3329 int networkType = (result != null ? result[0] : -1);
3330 if (DBG) log("getPreferredNetworkType: " + networkType);
3331 return networkType;
3332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003335 }
3336
3337 /**
3338 * Set the preferred network type.
3339 * Used for device configuration by some CDMA operators.
3340 *
3341 * @param networkType the preferred network type, defined in RILConstants.java.
3342 * @return true on success; false on any failure.
3343 */
3344 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003345 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3347 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003348
3349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3352 Boolean success = (Boolean) sendRequest(
3353 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3354 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3355 if (success) {
3356 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3357 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3358 }
3359 return success;
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003362 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003363 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003364
3365 /**
Junda Liu475951f2014-11-07 16:45:03 -08003366 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3367 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3368 * tethering.
3369 *
3370 * @return 0: Not required. 1: required. 2: Not set.
3371 * @hide
3372 */
3373 @Override
3374 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003375 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003376
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3380 Settings.Global.TETHER_DUN_REQUIRED, 2);
3381 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3382 // config_tether_apndata.
3383 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3384 dunRequired = 1;
3385 }
3386 return dunRequired;
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003389 }
Junda Liu475951f2014-11-07 16:45:03 -08003390 }
3391
3392 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003393 * Set mobile data enabled
3394 * Used by the user through settings etc to turn on/off mobile data
3395 *
3396 * @param enable {@code true} turn turn data on, else {@code false}
3397 */
3398 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003399 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3401 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003402
3403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 int phoneId = mSubscriptionController.getPhoneId(subId);
3406 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3407 Phone phone = PhoneFactory.getPhone(phoneId);
3408 if (phone != null) {
3409 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3410 phone.setUserDataEnabled(enable);
3411 } else {
3412 loge("setUserDataEnabled: no phone for subId=" + subId);
3413 }
3414 } finally {
3415 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003416 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003417 }
3418
3419 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003420 * Get the user enabled state of Mobile Data.
3421 *
3422 * TODO: remove and use isUserDataEnabled.
3423 * This can't be removed now because some vendor codes
3424 * calls through ITelephony directly while they should
3425 * use TelephonyManager.
3426 *
3427 * @return true on enabled
3428 */
3429 @Override
3430 public boolean getDataEnabled(int subId) {
3431 return isUserDataEnabled(subId);
3432 }
3433
3434 /**
3435 * Get whether mobile data is enabled per user setting.
3436 *
3437 * There are other factors deciding whether mobile data is actually enabled, but they are
3438 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003439 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003440 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003441 *
3442 * @return {@code true} if data is enabled else {@code false}
3443 */
3444 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003445 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003446 try {
3447 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3448 null);
3449 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3451 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003452 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003453
3454 final long identity = Binder.clearCallingIdentity();
3455 try {
3456 int phoneId = mSubscriptionController.getPhoneId(subId);
3457 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3458 Phone phone = PhoneFactory.getPhone(phoneId);
3459 if (phone != null) {
3460 boolean retVal = phone.isUserDataEnabled();
3461 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3462 return retVal;
3463 } else {
3464 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3465 return false;
3466 }
3467 } finally {
3468 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003469 }
3470 }
3471
3472 /**
3473 * Get whether mobile data is enabled.
3474 *
3475 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3476 * whether mobile data is actually enabled.
3477 *
3478 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3479 *
3480 * @return {@code true} if data is enabled else {@code false}
3481 */
3482 @Override
3483 public boolean isDataEnabled(int subId) {
3484 try {
3485 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3486 null);
3487 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3489 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003490 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003491
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 int phoneId = mSubscriptionController.getPhoneId(subId);
3495 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3496 Phone phone = PhoneFactory.getPhone(phoneId);
3497 if (phone != null) {
3498 boolean retVal = phone.isDataEnabled();
3499 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3500 return retVal;
3501 } else {
3502 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3503 return false;
3504 }
3505 } finally {
3506 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003507 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003508 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003509
3510 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003511 public int getCarrierPrivilegeStatus(int subId) {
3512 final Phone phone = getPhone(subId);
3513 if (phone == null) {
3514 loge("getCarrierPrivilegeStatus: Invalid subId");
3515 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3516 }
3517 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003518 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003519 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003520 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3521 }
3522 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003523 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003524 }
Junda Liu29340342014-07-10 15:23:27 -07003525
3526 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003527 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3528 final Phone phone = getPhone(subId);
3529 if (phone == null) {
3530 loge("getCarrierPrivilegeStatus: Invalid subId");
3531 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3532 }
3533 UiccProfile profile =
3534 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3535 if (profile == null) {
3536 loge("getCarrierPrivilegeStatus: No UICC");
3537 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3538 }
3539 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3540 }
3541
3542 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003543 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003544 if (TextUtils.isEmpty(pkgName))
3545 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003546 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003547 if (card == null) {
3548 loge("checkCarrierPrivilegesForPackage: No UICC");
3549 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3550 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003551 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3552 }
3553
3554 @Override
3555 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003556 if (TextUtils.isEmpty(pkgName))
3557 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003558 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3559 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3560 UiccCard card = UiccController.getInstance().getUiccCard(i);
3561 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003562 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003563 continue;
3564 }
3565
3566 result = card.getCarrierPrivilegeStatus(
3567 mPhone.getContext().getPackageManager(), pkgName);
3568 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3569 break;
3570 }
3571 }
3572
3573 return result;
Junda Liu29340342014-07-10 15:23:27 -07003574 }
Derek Tan89e89d42014-07-08 17:00:10 -07003575
3576 @Override
Junda Liue64de782015-04-16 17:19:16 -07003577 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3578 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3579 loge("phoneId " + phoneId + " is not valid.");
3580 return null;
3581 }
3582 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003583 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003584 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003585 return null ;
3586 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003587 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003588 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003589 }
3590
Amith Yamasani6e118872016-02-19 12:53:51 -08003591 @Override
3592 public List<String> getPackagesWithCarrierPrivileges() {
3593 PackageManager pm = mPhone.getContext().getPackageManager();
3594 List<String> privilegedPackages = new ArrayList<>();
3595 List<PackageInfo> packages = null;
3596 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3597 UiccCard card = UiccController.getInstance().getUiccCard(i);
3598 if (card == null) {
3599 // No UICC in that slot.
3600 continue;
3601 }
3602 if (card.hasCarrierPrivilegeRules()) {
3603 if (packages == null) {
3604 // Only check packages in user 0 for now
3605 packages = pm.getInstalledPackagesAsUser(
3606 PackageManager.MATCH_DISABLED_COMPONENTS
3607 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3608 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3609 }
3610 for (int p = packages.size() - 1; p >= 0; p--) {
3611 PackageInfo pkgInfo = packages.get(p);
3612 if (pkgInfo != null && pkgInfo.packageName != null
3613 && card.getCarrierPrivilegeStatus(pkgInfo)
3614 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3615 privilegedPackages.add(pkgInfo.packageName);
3616 }
3617 }
3618 }
3619 }
3620 return privilegedPackages;
3621 }
3622
Wink Savilleb564aae2014-10-23 10:18:09 -07003623 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003624 final Phone phone = getPhone(subId);
3625 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003626 if (card == null) {
3627 loge("getIccId: No UICC");
3628 return null;
3629 }
3630 String iccId = card.getIccId();
3631 if (TextUtils.isEmpty(iccId)) {
3632 loge("getIccId: ICC ID is null or empty.");
3633 return null;
3634 }
3635 return iccId;
3636 }
3637
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003638 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003639 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3640 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003641 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3642 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003643
Malcolm Chenaabec062018-02-28 15:00:40 -08003644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 final String iccId = getIccId(subId);
3647 final Phone phone = getPhone(subId);
3648 if (phone == null) {
3649 return false;
3650 }
3651 final String subscriberId = phone.getSubscriberId();
3652
3653 if (DBG_MERGE) {
3654 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3655 + subscriberId + " to " + number);
3656 }
3657
3658 if (TextUtils.isEmpty(iccId)) {
3659 return false;
3660 }
3661
3662 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3663
3664 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3665 if (alphaTag == null) {
3666 editor.remove(alphaTagPrefKey);
3667 } else {
3668 editor.putString(alphaTagPrefKey, alphaTag);
3669 }
3670
3671 // Record both the line number and IMSI for this ICCID, since we need to
3672 // track all merged IMSIs based on line number
3673 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3674 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3675 if (number == null) {
3676 editor.remove(numberPrefKey);
3677 editor.remove(subscriberPrefKey);
3678 } else {
3679 editor.putString(numberPrefKey, number);
3680 editor.putString(subscriberPrefKey, subscriberId);
3681 }
3682
3683 editor.commit();
3684 return true;
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003687 }
Derek Tan7226c842014-07-02 17:42:23 -07003688 }
3689
3690 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003691 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003692 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003694 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003695 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003696 return null;
3697 }
Derek Tan97ebb422014-09-05 16:55:38 -07003698
Malcolm Chenaabec062018-02-28 15:00:40 -08003699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 String iccId = getIccId(subId);
3702 if (iccId != null) {
3703 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3704 if (DBG_MERGE) {
3705 log("getLine1NumberForDisplay returning "
3706 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3707 }
3708 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003709 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003710 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3711 return null;
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003714 }
Derek Tan7226c842014-07-02 17:42:23 -07003715 }
3716
3717 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003718 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003720 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003721 return null;
3722 }
Derek Tan97ebb422014-09-05 16:55:38 -07003723
Malcolm Chenaabec062018-02-28 15:00:40 -08003724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 String iccId = getIccId(subId);
3727 if (iccId != null) {
3728 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3729 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3730 }
3731 return null;
3732 } finally {
3733 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003734 }
Derek Tan7226c842014-07-02 17:42:23 -07003735 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003736
3737 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003738 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003739 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3740 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003742 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3743 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003744 return null;
3745 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003746
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003747 final long identity = Binder.clearCallingIdentity();
3748 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003749 final Context context = mPhone.getContext();
3750 final TelephonyManager tele = TelephonyManager.from(context);
3751 final SubscriptionManager sub = SubscriptionManager.from(context);
3752
3753 // Figure out what subscribers are currently active
3754 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3755 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3756 // the process, where TelephonyManager was instantiated.
3757 // Otherwise AppOps check will fail.
3758
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003759 final int[] subIds = sub.getActiveSubscriptionIdList();
3760 for (int subId : subIds) {
3761 activeSubscriberIds.add(tele.getSubscriberId(subId));
3762 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003763
3764 // First pass, find a number override for an active subscriber
3765 String mergeNumber = null;
3766 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3767 for (String key : prefs.keySet()) {
3768 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3769 final String subscriberId = (String) prefs.get(key);
3770 if (activeSubscriberIds.contains(subscriberId)) {
3771 final String iccId = key.substring(
3772 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3773 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3774 mergeNumber = (String) prefs.get(numberKey);
3775 if (DBG_MERGE) {
3776 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3777 + " for active subscriber " + subscriberId);
3778 }
3779 if (!TextUtils.isEmpty(mergeNumber)) {
3780 break;
3781 }
3782 }
3783 }
3784 }
3785
3786 // Shortcut when no active merged subscribers
3787 if (TextUtils.isEmpty(mergeNumber)) {
3788 return null;
3789 }
3790
3791 // Second pass, find all subscribers under that line override
3792 final ArraySet<String> result = new ArraySet<>();
3793 for (String key : prefs.keySet()) {
3794 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3795 final String number = (String) prefs.get(key);
3796 if (mergeNumber.equals(number)) {
3797 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3798 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3799 final String subscriberId = (String) prefs.get(subscriberKey);
3800 if (!TextUtils.isEmpty(subscriberId)) {
3801 result.add(subscriberId);
3802 }
3803 }
3804 }
3805 }
3806
3807 final String[] resultArray = result.toArray(new String[result.size()]);
3808 Arrays.sort(resultArray);
3809 if (DBG_MERGE) {
3810 Slog.d(LOG_TAG,
3811 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3812 }
3813 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003814 } finally {
3815 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003816 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003817 }
3818
3819 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003820 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003821 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3822 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003823
3824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 final Phone phone = getPhone(subId);
3827 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
3830 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003831 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003832
3833 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003834 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003835 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3836 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003837 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003838
3839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 final Phone phone = getPhone(subId);
3842 if (phone == null) {
3843 return false;
3844 }
3845 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3846 cdmaNonRoamingList);
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003849 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003850 }
3851
3852 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003853 @Deprecated
3854 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3855 enforceModifyPermission();
3856
3857 int returnValue = 0;
3858 try {
vagdevie435a3e2018-08-15 16:01:53 -07003859 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003860 if(result.exception == null) {
3861 if (result.result != null) {
3862 byte[] responseData = (byte[])(result.result);
3863 if(responseData.length > oemResp.length) {
3864 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3865 responseData.length + "bytes. Buffer Size is " +
3866 oemResp.length + "bytes.");
3867 }
3868 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3869 returnValue = responseData.length;
3870 }
3871 } else {
3872 CommandException ex = (CommandException) result.exception;
3873 returnValue = ex.getCommandError().ordinal();
3874 if(returnValue > 0) returnValue *= -1;
3875 }
3876 } catch (RuntimeException e) {
3877 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3878 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3879 if(returnValue > 0) returnValue *= -1;
3880 }
3881
3882 return returnValue;
3883 }
3884
3885 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003886 public void setRadioCapability(RadioAccessFamily[] rafs) {
3887 try {
3888 ProxyController.getInstance().setRadioCapability(rafs);
3889 } catch (RuntimeException e) {
3890 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3891 }
3892 }
3893
3894 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003895 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003896 Phone phone = PhoneFactory.getPhone(phoneId);
3897 if (phone == null) {
3898 return RadioAccessFamily.RAF_UNKNOWN;
3899 }
3900 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003901 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003902 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003903 return RadioAccessFamily.RAF_UNKNOWN;
3904 }
3905
Malcolm Chenaabec062018-02-28 15:00:40 -08003906 final long identity = Binder.clearCallingIdentity();
3907 try {
3908 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3909 } finally {
3910 Binder.restoreCallingIdentity(identity);
3911 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003912 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003913
3914 @Override
3915 public void enableVideoCalling(boolean enable) {
3916 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003917
3918 final long identity = Binder.clearCallingIdentity();
3919 try {
3920 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003924 }
3925
3926 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003927 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3929 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3930 return false;
3931 }
Svet Ganovb320e182015-04-16 12:30:10 -07003932
Malcolm Chenaabec062018-02-28 15:00:40 -08003933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 // Check the user preference and the system-level IMS setting. Even if the user has
3936 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3937 // In the long run, we may instead need to check if there exists a connection service
3938 // which can support video calling.
3939 ImsManager imsManager =
3940 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3941 return imsManager.isVtEnabledByPlatform()
3942 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3943 && imsManager.isVtEnabledByUser();
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003947 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003948
Andrew Leea1239f22015-03-02 17:44:07 -08003949 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08003950 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
3951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3952 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
3953 return false;
3954 }
3955
3956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 CarrierConfigManager configManager =
3959 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
3960 return configManager.getConfigForSubId(mPhone.getSubId())
3961 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
Andrew Leea1239f22015-03-02 17:44:07 -08003965 }
3966
3967 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08003968 public boolean isWorldPhone(int subId, String callingPackage) {
3969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3970 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
3971 return false;
3972 }
3973
3974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 CarrierConfigManager configManager =
3977 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
3978 return configManager.getConfigForSubId(mPhone.getSubId())
3979 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
3980 } finally {
3981 Binder.restoreCallingIdentity(identity);
3982 }
Andrew Leea1239f22015-03-02 17:44:07 -08003983 }
3984
Andrew Lee9431b832015-03-09 18:46:45 -07003985 @Override
3986 public boolean isTtyModeSupported() {
3987 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003988 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003989 }
3990
3991 @Override
3992 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08003993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3996 } finally {
3997 Binder.restoreCallingIdentity(identity);
3998 }
Andrew Lee9431b832015-03-09 18:46:45 -07003999 }
4000
Hall Liu98187582018-01-22 19:15:32 -08004001 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4005 mPhone.getSubId()).getBoolean(
4006 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4007 boolean isDeviceSupported =
4008 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4009 return isCarrierSupported && isDeviceSupported;
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
Hall Liu98187582018-01-22 19:15:32 -08004013 }
4014
Hall Liu3ad5f012018-04-06 16:23:39 -07004015 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 return isRttSupported() && Settings.Secure.getInt(
4019 mPhone.getContext().getContentResolver(),
4020 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4021 } finally {
4022 Binder.restoreCallingIdentity(identity);
4023 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004024 }
4025
Sanket Padawe7310cc72015-01-14 09:53:20 -08004026 /**
4027 * Returns the unique device ID of phone, for example, the IMEI for
4028 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4029 *
4030 * <p>Requires Permission:
4031 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4032 */
4033 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004034 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004035 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004036 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004037 return null;
4038 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004039 int subId = phone.getSubId();
4040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4041 mApp, subId, callingPackage, "getDeviceId")) {
4042 return null;
4043 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004044
4045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 return phone.getDeviceId();
4048 } finally {
4049 Binder.restoreCallingIdentity(identity);
4050 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004051 }
4052
Ping Sunc67b7c22016-03-02 19:16:45 +08004053 /**
4054 * {@hide}
4055 * Returns the IMS Registration Status on a particular subid
4056 *
4057 * @param subId
4058 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004059 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004060 Phone phone = getPhone(subId);
4061 if (phone != null) {
4062 return phone.isImsRegistered();
4063 } else {
4064 return false;
4065 }
4066 }
4067
Santos Cordon7a1885b2015-02-03 11:15:19 -08004068 @Override
4069 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4073 } finally {
4074 Binder.restoreCallingIdentity(identity);
4075 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004076 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004077
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004078 /**
4079 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004080 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004081 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 Phone phone = getPhone(subId);
4085 if (phone != null) {
4086 return phone.isWifiCallingEnabled();
4087 } else {
4088 return false;
4089 }
4090 } finally {
4091 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004092 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004093 }
4094
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004095 /**
4096 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004097 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004098 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 Phone phone = getPhone(subId);
4102 if (phone != null) {
4103 return phone.isVolteEnabled();
4104 } else {
4105 return false;
4106 }
4107 } finally {
4108 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004109 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004110 }
Svet Ganovb320e182015-04-16 12:30:10 -07004111
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004112 /**
4113 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004114 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004115 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 Phone phone = getPhone(subId);
4119 if (phone != null) {
4120 return phone.isVideoEnabled();
4121 } else {
4122 return false;
4123 }
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004126 }
4127 }
4128
4129 /**
4130 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4131 * defined in {@link ImsRegistrationImplBase}.
4132 */
4133 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 Phone phone = getPhone(subId);
4137 if (phone != null) {
4138 return phone.getImsRegistrationTech();
4139 } else {
4140 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4141 }
4142 } finally {
4143 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004144 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004145 }
4146
Stuart Scott8eef64f2015-04-08 15:13:54 -07004147 @Override
4148 public void factoryReset(int subId) {
4149 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004150 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4151 return;
4152 }
4153
Svet Ganovcc087f82015-05-12 20:35:54 -07004154 final long identity = Binder.clearCallingIdentity();
4155 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004156 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4157 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004158 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004159 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004160 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4161 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004162 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004163 }
4164 } finally {
4165 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004166 }
4167 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004168
4169 @Override
4170 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004171 final long identity = Binder.clearCallingIdentity();
4172 try {
4173 // We query all subscriptions instead of just the active ones, because
4174 // this might be called early on in the provisioning flow when the
4175 // subscriptions potentially aren't active yet.
4176 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4177 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004178 return null;
4179 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004180
Malcolm Chenaabec062018-02-28 15:00:40 -08004181 // This function may be called very early, say, from the setup wizard, at
4182 // which point we won't have a default subscription set. If that's the case
4183 // we just choose the first, which will be valid in "most cases".
4184 final int defaultSubId = getDefaultSubscription();
4185 SubscriptionInfo info = null;
4186 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4187 info = slist.get(0);
4188 } else {
4189 for (SubscriptionInfo item : slist) {
4190 if (item.getSubscriptionId() == defaultSubId) {
4191 info = item;
4192 break;
4193 }
4194 }
4195
4196 if (info == null) {
4197 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004198 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004199 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004200
Malcolm Chenaabec062018-02-28 15:00:40 -08004201 // Try and fetch the locale from the carrier properties or from the SIM language
4202 // preferences (EF-PL and EF-LI)...
4203 final int mcc = info.getMcc();
4204 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4205 String simLanguage = null;
4206 if (defaultPhone != null) {
4207 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4208 if (localeFromDefaultSim != null) {
4209 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4210 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4211 return localeFromDefaultSim.toLanguageTag();
4212 } else {
4213 simLanguage = localeFromDefaultSim.getLanguage();
4214 }
4215 }
4216 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004217
Malcolm Chenaabec062018-02-28 15:00:40 -08004218 // The SIM language preferences only store a language (e.g. fr = French), not an
4219 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4220 // the SIM and carrier preferences does not include a country we add the country
4221 // determined from the SIM MCC to provide an exact locale.
4222 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4223 simLanguage);
4224 if (mccLocale != null) {
4225 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4226 return mccLocale.toLanguageTag();
4227 }
4228
4229 if (DBG) log("No locale found - returning null");
4230 return null;
4231 } finally {
4232 Binder.restoreCallingIdentity(identity);
4233 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004234 }
4235
4236 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004237 return mSubscriptionController.getAllSubInfoList(
4238 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004239 }
4240
Malcolm Chenaabec062018-02-28 15:00:40 -08004241 /**
4242 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4243 */
4244 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4245 return mSubscriptionController.getActiveSubscriptionInfoList(
4246 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004247 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004248
Chenjie Yu1ba97252018-01-11 18:16:20 -08004249 private final ModemActivityInfo mLastModemActivityInfo =
4250 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4251
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004252 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004253 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4254 * representing the state of the modem.
4255 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004256 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4257 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004258 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004259 */
4260 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004261 public void requestModemActivityInfo(ResultReceiver result) {
4262 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004263 ModemActivityInfo ret = null;
vagdevie435a3e2018-08-15 16:01:53 -07004264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Adam Lesinski903a54c2016-04-11 14:49:52 -07004265
Malcolm Chenaabec062018-02-28 15:00:40 -08004266 final long identity = Binder.clearCallingIdentity();
4267 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004268 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004269 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4270 CMD_GET_MODEM_ACTIVITY_INFO,
4271 null, workSource);
Siddharth Rayc339f892018-06-17 15:02:38 -07004272 if (isModemActivityInfoValid(info)) {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004273 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4274 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4275 mergedTxTimeMs[i] =
4276 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4277 }
4278 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4279 mLastModemActivityInfo.setSleepTimeMillis(
4280 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4281 mLastModemActivityInfo.setIdleTimeMillis(
4282 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4283 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4284 mLastModemActivityInfo.setRxTimeMillis(
4285 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4286 mLastModemActivityInfo.setEnergyUsed(
4287 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004288 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004289 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4290 mLastModemActivityInfo.getSleepTimeMillis(),
4291 mLastModemActivityInfo.getIdleTimeMillis(),
4292 mLastModemActivityInfo.getTxTimeMillis(),
4293 mLastModemActivityInfo.getRxTimeMillis(),
4294 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004295 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004296 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004297 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004298 result.send(0, bundle);
4299 } finally {
4300 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004301 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004302 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004303
Siddharth Rayc339f892018-06-17 15:02:38 -07004304 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4305 // less than total activity duration.
4306 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4307 if (info == null) {
4308 return false;
4309 }
4310 int activityDurationMs =
4311 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4312 int totalTxTimeMs = 0;
4313 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4314 totalTxTimeMs += info.getTxTimeMillis()[i];
4315 }
4316 return (info.isValid()
4317 && (info.getSleepTimeMillis() <= activityDurationMs)
4318 && (info.getIdleTimeMillis() <= activityDurationMs)
4319 && (info.getRxTimeMillis() <= activityDurationMs)
4320 && (totalTxTimeMs <= activityDurationMs));
4321 }
4322
Jack Yu85bd38a2015-11-09 11:34:32 -08004323 /**
4324 * {@hide}
4325 * Returns the service state information on specified subscription.
4326 */
4327 @Override
4328 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004330 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004331 return null;
4332 }
4333
Malcolm Chenaabec062018-02-28 15:00:40 -08004334 final long identity = Binder.clearCallingIdentity();
4335 try {
4336 final Phone phone = getPhone(subId);
4337 if (phone == null) {
4338 return null;
4339 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004340
Malcolm Chenaabec062018-02-28 15:00:40 -08004341 return phone.getServiceState();
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004345 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004346
4347 /**
4348 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4349 *
4350 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4351 * voicemail ringtone.
4352 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4353 * PhoneAccount.
4354 */
4355 @Override
4356 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4360 if (phone == null) {
4361 phone = mPhone;
4362 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004363
Malcolm Chenaabec062018-02-28 15:00:40 -08004364 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004368 }
4369
4370 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004371 * Sets the per-account voicemail ringtone.
4372 *
4373 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4374 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4375 *
4376 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4377 * voicemail ringtone.
4378 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4379 * PhoneAccount.
4380 */
4381 @Override
4382 public void setVoicemailRingtoneUri(String callingPackage,
4383 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4384 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4385 if (!TextUtils.equals(callingPackage,
4386 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4388 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4389 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004390 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004391
4392 final long identity = Binder.clearCallingIdentity();
4393 try {
4394 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4395 if (phone == null) {
4396 phone = mPhone;
4397 }
4398 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4399 } finally {
4400 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004401 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004402 }
4403
4404 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004405 * Returns whether vibration is set for voicemail notification in Phone settings.
4406 *
4407 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4408 * voicemail vibration setting.
4409 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4410 */
4411 @Override
4412 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004413 final long identity = Binder.clearCallingIdentity();
4414 try {
4415 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4416 if (phone == null) {
4417 phone = mPhone;
4418 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004419
Malcolm Chenaabec062018-02-28 15:00:40 -08004420 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4421 } finally {
4422 Binder.restoreCallingIdentity(identity);
4423 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004424 }
4425
Youhan Wange64578a2016-05-02 15:32:42 -07004426 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004427 * Sets the per-account voicemail vibration.
4428 *
4429 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4430 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4431 *
4432 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4433 * voicemail vibration setting.
4434 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4435 * specific PhoneAccount.
4436 */
4437 @Override
4438 public void setVoicemailVibrationEnabled(String callingPackage,
4439 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4440 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4441 if (!TextUtils.equals(callingPackage,
4442 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4444 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4445 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004446 }
4447
Malcolm Chenaabec062018-02-28 15:00:40 -08004448 final long identity = Binder.clearCallingIdentity();
4449 try {
4450 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4451 if (phone == null) {
4452 phone = mPhone;
4453 }
4454 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4455 } finally {
4456 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004457 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004458 }
4459
4460 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004461 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4462 *
4463 * @throws SecurityException if the caller does not have the required permission
4464 */
4465 private void enforceReadPrivilegedPermission() {
4466 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4467 null);
4468 }
4469
4470 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004471 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4472 * permission.
4473 *
4474 * @throws SecurityException if the caller does not have the required permission
4475 */
4476 private void enforceSendSmsPermission() {
4477 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4478 }
4479
4480 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004481 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004482 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004483 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004484 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004485 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004486 final long identity = Binder.clearCallingIdentity();
4487 try {
4488 ComponentName componentName =
4489 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4490 if (componentName == null) {
4491 throw new SecurityException(
4492 "Caller not current active visual voicemail package[null]");
4493 }
4494 String vvmPackage = componentName.getPackageName();
4495 if (!callingPackage.equals(vvmPackage)) {
4496 throw new SecurityException("Caller not current active visual voicemail package["
4497 + vvmPackage + "]");
4498 }
4499 } finally {
4500 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004501 }
4502 }
4503
4504 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004505 * Return the application ID for the app type.
4506 *
4507 * @param subId the subscription ID that this request applies to.
4508 * @param appType the uicc app type.
4509 * @return Application ID for specificied app type, or null if no uicc.
4510 */
4511 @Override
4512 public String getAidForAppType(int subId, int appType) {
4513 enforceReadPrivilegedPermission();
4514 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004515
4516 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004517 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004518 if (phone == null) {
4519 return null;
4520 }
4521 String aid = null;
4522 try {
4523 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4524 .getApplicationByType(appType).getAid();
4525 } catch (Exception e) {
4526 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4527 }
4528 return aid;
4529 } finally {
4530 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004531 }
Youhan Wange64578a2016-05-02 15:32:42 -07004532 }
4533
Youhan Wang4001d252016-05-11 10:29:41 -07004534 /**
4535 * Return the Electronic Serial Number.
4536 *
4537 * @param subId the subscription ID that this request applies to.
4538 * @return ESN or null if error.
4539 */
4540 @Override
4541 public String getEsn(int subId) {
4542 enforceReadPrivilegedPermission();
4543 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004544
4545 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004546 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004547 if (phone == null) {
4548 return null;
4549 }
4550 String esn = null;
4551 try {
4552 esn = phone.getEsn();
4553 } catch (Exception e) {
4554 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4555 }
4556 return esn;
4557 } finally {
4558 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004559 }
Youhan Wang4001d252016-05-11 10:29:41 -07004560 }
4561
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004562 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004563 * Return the Preferred Roaming List Version.
4564 *
4565 * @param subId the subscription ID that this request applies to.
4566 * @return PRLVersion or null if error.
4567 */
4568 @Override
4569 public String getCdmaPrlVersion(int subId) {
4570 enforceReadPrivilegedPermission();
4571 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004572
4573 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004574 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004575 if (phone == null) {
4576 return null;
4577 }
4578 String cdmaPrlVersion = null;
4579 try {
4580 cdmaPrlVersion = phone.getCdmaPrlVersion();
4581 } catch (Exception e) {
4582 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4583 }
4584 return cdmaPrlVersion;
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004587 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004588 }
4589
4590 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004591 * Get snapshot of Telephony histograms
4592 * @return List of Telephony histograms
4593 * @hide
4594 */
4595 @Override
4596 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4598 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004599
4600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 return RIL.getTelephonyRILTimingHistograms();
4603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004606 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004607
4608 /**
4609 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004610 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004611 * Require system privileges. In the future we may add this to carrier APIs.
4612 *
4613 * @return The number of carriers set successfully, should match length of carriers
4614 */
4615 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004616 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004617 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004618 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004619
Meng Wang9b7c4e92017-02-17 11:41:27 -08004620 if (carriers == null) {
4621 throw new NullPointerException("carriers cannot be null");
4622 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004623
Malcolm Chenaabec062018-02-28 15:00:40 -08004624 final long identity = Binder.clearCallingIdentity();
4625 try {
4626 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004627 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4628 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004629 return retVal[0];
4630 } finally {
4631 Binder.restoreCallingIdentity(identity);
4632 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004633 }
4634
4635 /**
4636 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004637 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004638 * Require system privileges. In the future we may add this to carrier APIs.
4639 *
4640 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4641 * means all carriers are allowed.
4642 */
4643 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004644 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004645 enforceReadPrivilegedPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004646 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08004647
4648 final long identity = Binder.clearCallingIdentity();
4649 try {
4650 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004651 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4652 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004656 }
4657
fionaxu59545b42016-05-25 15:53:37 -07004658 /**
4659 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4660 * @param subId the subscription ID that this action applies to.
4661 * @param enabled control enable or disable metered apns.
4662 * {@hide}
4663 */
4664 @Override
4665 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4666 enforceModifyPermission();
4667 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004668
4669 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004670 if (phone == null) {
4671 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4672 return;
4673 }
4674 try {
4675 phone.carrierActionSetMeteredApnsEnabled(enabled);
4676 } catch (Exception e) {
4677 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004678 } finally {
4679 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004680 }
4681 }
4682
4683 /**
4684 * Action set from carrier signalling broadcast receivers to enable/disable radio
4685 * @param subId the subscription ID that this action applies to.
4686 * @param enabled control enable or disable radio.
4687 * {@hide}
4688 */
4689 @Override
4690 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4691 enforceModifyPermission();
4692 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004693
4694 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004695 if (phone == null) {
4696 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4697 return;
4698 }
4699 try {
4700 phone.carrierActionSetRadioEnabled(enabled);
4701 } catch (Exception e) {
4702 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004703 } finally {
4704 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004705 }
4706 }
4707
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004708 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004709 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4710 * network status based on which carrier apps could apply actions accordingly,
4711 * enable/disable default url handler for example.
4712 *
4713 * @param subId the subscription ID that this action applies to.
4714 * @param report control start/stop reporting the default network status.
4715 * {@hide}
4716 */
4717 @Override
4718 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4719 enforceModifyPermission();
4720 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004721
4722 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004723 if (phone == null) {
4724 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4725 return;
4726 }
4727 try {
4728 phone.carrierActionReportDefaultNetworkStatus(report);
4729 } catch (Exception e) {
4730 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004731 } finally {
4732 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004733 }
4734 }
4735
4736 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004737 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4738 * bug report is being generated.
4739 */
4740 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004741 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004742 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4743 != PackageManager.PERMISSION_GRANTED) {
4744 writer.println("Permission Denial: can't dump Phone from pid="
4745 + Binder.getCallingPid()
4746 + ", uid=" + Binder.getCallingUid()
4747 + "without permission "
4748 + android.Manifest.permission.DUMP);
4749 return;
4750 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004751 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004752 }
Jack Yueb89b242016-06-22 13:27:47 -07004753
Brad Ebingerdac2f002018-04-03 15:17:52 -07004754 @Override
4755 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4756 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4757 throws RemoteException {
4758 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4759 }
4760
Jack Yueb89b242016-06-22 13:27:47 -07004761 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004762 * Get aggregated video call data usage since boot.
4763 *
4764 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4765 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004766 * {@hide}
4767 */
4768 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004769 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004770 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4771 null);
4772
Malcolm Chenaabec062018-02-28 15:00:40 -08004773 final long identity = Binder.clearCallingIdentity();
4774 try {
4775 // NetworkStatsService keeps tracking the active network interface and identity. It
4776 // records the delta with the corresponding network identity.
4777 // We just return the total video call data usage snapshot since boot.
4778 Phone phone = getPhone(subId);
4779 if (phone != null) {
4780 return phone.getVtDataUsage(perUidStats);
4781 }
4782 return null;
4783 } finally {
4784 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004785 }
Jack Yueb89b242016-06-22 13:27:47 -07004786 }
Jack Yu75ab2952016-07-08 14:29:33 -07004787
4788 /**
4789 * Policy control of data connection. Usually used when data limit is passed.
4790 * @param enabled True if enabling the data, otherwise disabling.
4791 * @param subId Subscription index
4792 * {@hide}
4793 */
4794 @Override
4795 public void setPolicyDataEnabled(boolean enabled, int subId) {
4796 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004797
4798 final long identity = Binder.clearCallingIdentity();
4799 try {
4800 Phone phone = getPhone(subId);
4801 if (phone != null) {
4802 phone.setPolicyDataEnabled(enabled);
4803 }
4804 } finally {
4805 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004806 }
4807 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004808
4809 /**
4810 * Get Client request stats
4811 * @return List of Client Request Stats
4812 * @hide
4813 */
4814 @Override
4815 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004816 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004817 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004818 return null;
4819 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004820 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004821
Malcolm Chenaabec062018-02-28 15:00:40 -08004822 final long identity = Binder.clearCallingIdentity();
4823 try {
4824 if (phone != null) {
4825 return phone.getClientRequestStats();
4826 }
4827
4828 return null;
4829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004832 }
4833
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004834 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004835 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004836 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004837 }
Jack Yueb4124c2017-02-16 15:32:43 -08004838
4839 /**
Grace Chen70990072017-03-24 17:21:30 -07004840 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004841 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004842 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004843 * @param state State of SIM (power down, power up, pass through)
4844 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4845 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4846 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004847 *
4848 **/
4849 @Override
Grace Chen70990072017-03-24 17:21:30 -07004850 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004851 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004852 Phone phone = PhoneFactory.getPhone(slotIndex);
4853
vagdevie435a3e2018-08-15 16:01:53 -07004854 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4855
Malcolm Chenaabec062018-02-28 15:00:40 -08004856 final long identity = Binder.clearCallingIdentity();
4857 try {
4858 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07004859 phone.setSimPowerState(state, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004860 }
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004863 }
4864 }
Shuo Qiandd210312017-04-12 22:11:33 +00004865
Tyler Gunn65d45c22017-06-05 11:22:26 -07004866 private boolean isUssdApiAllowed(int subId) {
4867 CarrierConfigManager configManager =
4868 (CarrierConfigManager) mPhone.getContext().getSystemService(
4869 Context.CARRIER_CONFIG_SERVICE);
4870 if (configManager == null) {
4871 return false;
4872 }
4873 PersistableBundle pb = configManager.getConfigForSubId(subId);
4874 if (pb == null) {
4875 return false;
4876 }
4877 return pb.getBoolean(
4878 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4879 }
4880
Shuo Qiandd210312017-04-12 22:11:33 +00004881 /**
4882 * Check if phone is in emergency callback mode
4883 * @return true if phone is in emergency callback mode
4884 * @param subId sub id
4885 */
goneil9c5f4872017-12-05 14:07:56 -08004886 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004887 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004888 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004889 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004890
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 if (phone != null) {
4894 return phone.isInEcm();
4895 } else {
4896 return false;
4897 }
4898 } finally {
4899 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004900 }
4901 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004902
4903 /**
4904 * Get the current signal strength information for the given subscription.
4905 * Because this information is not updated when the device is in a low power state
4906 * it should not be relied-upon to be current.
4907 * @param subId Subscription index
4908 * @return the most recent cached signal strength info from the modem
4909 */
4910 @Override
4911 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 Phone p = getPhone(subId);
4915 if (p == null) {
4916 return null;
4917 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004918
Malcolm Chenaabec062018-02-28 15:00:40 -08004919 return p.getSignalStrength();
4920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004923 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004924
Pengquan Meng9140aec2018-08-22 14:49:57 -07004925 /**
4926 * Checks if data roaming is enabled on the subscription with id {@code subId}.
4927 *
4928 * <p>Requires one of the following permissions:
4929 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
4930 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
4931 * privileges.
4932 *
4933 * @param subId subscription id
4934 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
4935 * {@code false}.
4936 */
4937 @Override
4938 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07004939 boolean isEnabled = false;
4940 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07004941 try {
4942 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07004943 null /* message */);
4944 Phone phone = getPhone(subId);
4945 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07004946 } catch (Exception e) {
4947 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
4948 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07004949 } finally {
4950 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07004951 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07004952 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07004953 }
4954
4955
4956 /**
4957 * Enables/Disables the data roaming on the subscription with id {@code subId}.
4958 *
4959 * <p> Requires permission:
4960 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
4961 * privileges.
4962 *
4963 * @param subId subscription id
4964 * @param isEnabled {@code true} means enable, {@code false} means disable.
4965 */
4966 @Override
4967 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07004968 final long identity = Binder.clearCallingIdentity();
4969 try {
4970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4971 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07004972
Pengquan Meng0c05b502018-09-06 09:59:22 -07004973 Phone phone = getPhone(subId);
4974 if (phone != null) {
4975 phone.setDataRoamingEnabled(isEnabled);
4976 }
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07004979 }
4980 }
4981
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004982 @Override
4983 public UiccSlotInfo[] getUiccSlotsInfo() {
4984 enforceReadPrivilegedPermission();
4985
Malcolm Chenaabec062018-02-28 15:00:40 -08004986 final long identity = Binder.clearCallingIdentity();
4987 try {
4988 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004989 if (slots == null) {
4990 Rlog.i(LOG_TAG, "slots is null.");
4991 return null;
4992 }
4993
Malcolm Chenaabec062018-02-28 15:00:40 -08004994 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4995 for (int i = 0; i < slots.length; i++) {
4996 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004997 if (slot == null) {
4998 continue;
4999 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005000
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005001 String cardId;
5002 UiccCard card = slot.getUiccCard();
5003 if (card != null) {
5004 cardId = card.getCardId();
5005 } else {
5006 cardId = slot.getIccId();
5007 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005008
Malcolm Chenaabec062018-02-28 15:00:40 -08005009 int cardState = 0;
5010 switch (slot.getCardState()) {
5011 case CARDSTATE_ABSENT:
5012 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5013 break;
5014 case CARDSTATE_PRESENT:
5015 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5016 break;
5017 case CARDSTATE_ERROR:
5018 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5019 break;
5020 case CARDSTATE_RESTRICTED:
5021 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5022 break;
5023 default:
5024 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005025
Malcolm Chenaabec062018-02-28 15:00:40 -08005026 }
5027
5028 infos[i] = new UiccSlotInfo(
5029 slot.isActive(),
5030 slot.isEuicc(),
5031 cardId,
5032 cardState,
5033 slot.getPhoneId(),
5034 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005035 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005036 return infos;
5037 } finally {
5038 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005039 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005040 }
5041
5042 @Override
5043 public boolean switchSlots(int[] physicalSlots) {
5044 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005045
5046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005052 }
Jack Yu4c988042018-02-27 15:30:01 -08005053
5054 @Override
5055 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5056 enforceModifyPermission();
5057 final Phone phone = getPhone(subId);
5058 if (phone == null) {
5059 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5060 return;
5061 }
5062
Malcolm Chenaabec062018-02-28 15:00:40 -08005063 final long identity = Binder.clearCallingIdentity();
5064 try {
5065 phone.setRadioIndicationUpdateMode(filters, mode);
5066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
Jack Yu4c988042018-02-27 15:30:01 -08005069 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005070
5071 /**
goneil47ffb6e2018-04-06 15:40:58 -07005072 * A test API to reload the UICC profile.
5073 *
5074 * <p>Requires that the calling app has permission
5075 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5076 * @hide
5077 */
5078 @Override
5079 public void refreshUiccProfile(int subId) {
5080 enforceModifyPermission();
5081
5082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 Phone phone = getPhone(subId);
5085 if (phone == null) {
5086 return;
5087 }
5088 UiccCard uiccCard = phone.getUiccCard();
5089 if (uiccCard == null) {
5090 return;
5091 }
5092 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5093 if (uiccProfile == null) {
5094 return;
5095 }
5096 uiccProfile.refresh();
5097 } finally {
5098 Binder.restoreCallingIdentity(identity);
5099 }
5100 }
5101
5102 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005103 * Returns false if the mobile data is disabled by default, otherwise return true.
5104 */
5105 private boolean getDefaultDataEnabled() {
5106 return "true".equalsIgnoreCase(
5107 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5108 }
5109
5110 /**
5111 * Returns true if the data roaming is enabled by default, i.e the system property
5112 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5113 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5114 */
5115 private boolean getDefaultDataRoamingEnabled(int subId) {
5116 final CarrierConfigManager configMgr = (CarrierConfigManager)
5117 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5118 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5119 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5120 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5121 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5122 return isDataRoamingEnabled;
5123 }
5124
5125 /**
5126 * Returns the default network type for the given {@code subId}, if the default network type is
5127 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5128 */
5129 private int getDefaultNetworkType(int subId) {
5130 return Integer.parseInt(
5131 TelephonyManager.getTelephonyProperty(
5132 mSubscriptionController.getPhoneId(subId),
5133 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5134 String.valueOf(Phone.PREFERRED_NT_MODE)));
5135 }
fionaxua13278b2018-03-21 00:08:13 -07005136
5137 @Override
5138 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5139 gid1, String gid2, String plmn, String spn) {
5140 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005141
5142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 final Phone phone = getPhone(subId);
5145 if (phone == null) {
5146 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5147 return;
5148 }
5149 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005152 }
fionaxua13278b2018-03-21 00:08:13 -07005153 }
5154
5155 @Override
5156 public int getCarrierIdListVersion(int subId) {
5157 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005158
5159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 final Phone phone = getPhone(subId);
5162 if (phone == null) {
5163 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5164 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5165 }
5166 return phone.getCarrierIdListVersion();
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005169 }
fionaxua13278b2018-03-21 00:08:13 -07005170 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005171
5172 @Override
5173 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5175 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5176 return -1;
5177 }
5178
5179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
5184 }
5185 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005186
5187 @Override
5188 public int getCdmaRoamingMode(int subId) {
5189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5190 mApp, subId, "getCdmaRoamingMode");
5191
5192 final long identity = Binder.clearCallingIdentity();
5193 try {
5194 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5195 } finally {
5196 Binder.restoreCallingIdentity(identity);
5197 }
5198 }
5199
5200 @Override
5201 public boolean setCdmaRoamingMode(int subId, int mode) {
5202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5203 mApp, subId, "setCdmaRoamingMode");
5204
5205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
5211 }
5212
5213 @Override
5214 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5216 mApp, subId, "setCdmaSubscriptionMode");
5217
5218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5221 } finally {
5222 Binder.restoreCallingIdentity(identity);
5223 }
5224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005225}