blob: 75476d5600512cc081742980097911d6fe2d0e06 [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;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070060import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070061import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080062import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070063import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080064import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070065import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070066import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070067import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080069import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070070import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080071import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080072import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070073import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070074import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000075import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070076import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080078import android.telephony.ims.aidl.IImsConfig;
79import android.telephony.ims.aidl.IImsMmTelFeature;
80import android.telephony.ims.aidl.IImsRcsFeature;
81import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080082import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080085import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080087import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080089
Andrew Lee312e8172014-10-23 17:01:36 -070090import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080091import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070092import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070093import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070094import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070095import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070096import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080099import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700100import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100101import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700102import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700103import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700105import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800106import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700107import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700108import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700110import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700111import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700112import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800113import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800114import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700115import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.uicc.IccIoResult;
117import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800118import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700119import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800120import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800122import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000123import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700124import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800125import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700126import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800127import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700128import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700129import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700131import java.io.FileDescriptor;
132import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800133import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800135import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800136import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100137import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139
140/**
141 * Implementation of the ITelephony interface.
142 */
Santos Cordon117fee72014-05-16 17:56:12 -0700143public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144 private static final String LOG_TAG = "PhoneInterfaceManager";
145 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
146 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800147 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148
149 // Message codes used with mMainThreadHandler
150 private static final int CMD_HANDLE_PIN_MMI = 1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 private static final int CMD_ANSWER_RINGING_CALL = 4;
152 private static final int CMD_END_CALL = 5; // not used yet
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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800207 // Parameters of select command.
208 private static final int SELECT_COMMAND = 0xA4;
209 private static final int SELECT_P1 = 0x04;
210 private static final int SELECT_P2 = 0;
211 private static final int SELECT_P3 = 0x10;
212
Pengquan Meng85728fb2018-03-12 16:31:21 -0700213 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
214 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
215 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
216
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 /** The singleton instance. */
218 private static PhoneInterfaceManager sInstance;
219
Wink Saville3ab207e2014-11-20 13:07:20 -0800220 private PhoneGlobals mApp;
221 private Phone mPhone;
222 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700223 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800224 private AppOpsManager mAppOps;
225 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800226 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800227 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700228 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
Derek Tan97ebb422014-09-05 16:55:38 -0700230 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
231 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700233
Derek Tan740e1672017-06-27 14:56:27 -0700234 // The AID of ISD-R.
235 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
236
yinxub1bed742017-04-17 11:45:04 -0700237 private NetworkScanRequestTracker mNetworkScanRequestTracker;
238
David Kelly5e06a7f2018-03-12 14:10:59 +0000239 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
240 private static final int MANUFACTURER_CODE_LENGTH = 8;
241
Derek Tan89e89d42014-07-08 17:00:10 -0700242 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243 * A request object to use for transmitting data to an ICC.
244 */
245 private static final class IccAPDUArgument {
246 public int channel, cla, command, p1, p2, p3;
247 public String data;
248
249 public IccAPDUArgument(int channel, int cla, int command,
250 int p1, int p2, int p3, String data) {
251 this.channel = channel;
252 this.cla = cla;
253 this.command = command;
254 this.p1 = p1;
255 this.p2 = p2;
256 this.p3 = p3;
257 this.data = data;
258 }
259 }
260
261 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700262 * A request object to use for transmitting data to an ICC.
263 */
264 private static final class ManualNetworkSelectionArgument {
265 public OperatorInfo operatorInfo;
266 public boolean persistSelection;
267
268 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
269 this.operatorInfo = operatorInfo;
270 this.persistSelection = persistSelection;
271 }
272 }
273
274 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
276 * request after sending. The main thread will notify the request when it is complete.
277 */
278 private static final class MainThreadRequest {
279 /** The argument to use for the request */
280 public Object argument;
281 /** The result of the request that is run on the main thread */
282 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800283 // The subscriber id that this request applies to. Defaults to
284 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
285 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
287 public MainThreadRequest(Object argument) {
288 this.argument = argument;
289 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800290
291 public MainThreadRequest(Object argument, Integer subId) {
292 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800293 if (subId != null) {
294 this.subId = subId;
295 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 }
298
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800299 private static final class IncomingThirdPartyCallArgs {
300 public final ComponentName component;
301 public final String callId;
302 public final String callerDisplayName;
303
304 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
305 String callerDisplayName) {
306 this.component = component;
307 this.callId = callId;
308 this.callerDisplayName = callerDisplayName;
309 }
310 }
311
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 /**
313 * A handler that processes messages on the main thread in the phone process. Since many
314 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
315 * inbound binder threads to the main thread in the phone process. The Binder thread
316 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
317 * on, which will be notified when the operation completes and will contain the result of the
318 * request.
319 *
320 * <p>If a MainThreadRequest object is provided in the msg.obj field,
321 * note that request.result must be set to something non-null for the calling thread to
322 * unblock.
323 */
324 private final class MainThreadHandler extends Handler {
325 @Override
326 public void handleMessage(Message msg) {
327 MainThreadRequest request;
328 Message onCompleted;
329 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800330 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700331 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332
333 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700334 case CMD_HANDLE_USSD_REQUEST: {
335 request = (MainThreadRequest) msg.obj;
336 final Phone phone = getPhoneFromRequest(request);
337 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
338 String ussdRequest = ussdObject.first;
339 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700340
Pengquan Meng0c05b502018-09-06 09:59:22 -0700341 if (!isUssdApiAllowed(request.subId)) {
342 // Carrier does not support use of this API, return failure.
343 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
344 UssdResponse response = new UssdResponse(ussdRequest, null);
345 Bundle returnData = new Bundle();
346 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
347 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700348
Pengquan Meng0c05b502018-09-06 09:59:22 -0700349 request.result = true;
350 notifyRequester(request);
351 return;
352 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700353
Pengquan Meng0c05b502018-09-06 09:59:22 -0700354 try {
355 request.result = phone != null
356 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
357 } catch (CallStateException cse) {
358 request.result = false;
359 }
360 // Wake up the requesting thread
361 notifyRequester(request);
362 break;
pkanwar32d516d2016-10-14 19:37:38 -0700363 }
364
Yorke Lee716f67e2015-06-17 15:39:16 -0700365 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700367 final Phone phone = getPhoneFromRequest(request);
368 request.result = phone != null ?
369 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
370 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700372 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700377 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800378 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700379 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800380 request.result = ""; // dummy result for notifying the waiting thread
381 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700382 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 break;
384
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 case CMD_END_CALL:
386 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800387 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700388 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700389 Phone phone = getPhone(end_subId);
390 if (phone == null) {
391 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
392 break;
393 }
394 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
396 // CDMA: If the user presses the Power button we treat it as
397 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700398 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
400 // GSM: End the call as per the Phone state
401 hungUp = PhoneUtils.hangup(mCM);
402 } else {
403 throw new IllegalStateException("Unexpected phone type: " + phoneType);
404 }
405 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
406 request.result = hungUp;
407 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700408 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 break;
410
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700412 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800414 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700415 if (uiccCard == null) {
416 loge("iccTransmitApduLogicalChannel: No UICC");
417 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700418 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700419 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
421 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 iccArgument.channel, iccArgument.cla, iccArgument.command,
424 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700427 break;
428
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 ar = (AsyncResult) msg.obj;
431 request = (MainThreadRequest) ar.userObj;
432 if (ar.exception == null && ar.result != null) {
433 request.result = ar.result;
434 } else {
435 request.result = new IccIoResult(0x6F, 0, (byte[])null);
436 if (ar.result == null) {
437 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800438 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800440 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700441 } else {
442 loge("iccTransmitApduLogicalChannel: Unknown exception");
443 }
444 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700445 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 break;
447
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
449 request = (MainThreadRequest) msg.obj;
450 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800451 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 if (uiccCard == null) {
453 loge("iccTransmitApduBasicChannel: No UICC");
454 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700455 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 } else {
457 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
458 request);
459 uiccCard.iccTransmitApduBasicChannel(
460 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
461 iccArgument.p3, iccArgument.data, onCompleted);
462 }
463 break;
464
465 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
466 ar = (AsyncResult) msg.obj;
467 request = (MainThreadRequest) ar.userObj;
468 if (ar.exception == null && ar.result != null) {
469 request.result = ar.result;
470 } else {
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
472 if (ar.result == null) {
473 loge("iccTransmitApduBasicChannel: Empty response");
474 } else if (ar.exception instanceof CommandException) {
475 loge("iccTransmitApduBasicChannel: CommandException: " +
476 ar.exception);
477 } else {
478 loge("iccTransmitApduBasicChannel: Unknown exception");
479 }
480 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 break;
483
484 case CMD_EXCHANGE_SIM_IO:
485 request = (MainThreadRequest) msg.obj;
486 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800487 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 if (uiccCard == null) {
489 loge("iccExchangeSimIO: No UICC");
490 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700491 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 } else {
493 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
494 request);
495 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
496 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
497 iccArgument.data, onCompleted);
498 }
499 break;
500
501 case EVENT_EXCHANGE_SIM_IO_DONE:
502 ar = (AsyncResult) msg.obj;
503 request = (MainThreadRequest) ar.userObj;
504 if (ar.exception == null && ar.result != null) {
505 request.result = ar.result;
506 } else {
507 request.result = new IccIoResult(0x6f, 0, (byte[])null);
508 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700509 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700510 break;
511
Derek Tan4d5e5c12014-02-04 11:54:58 -0800512 case CMD_SEND_ENVELOPE:
513 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800514 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700515 if (uiccCard == null) {
516 loge("sendEnvelopeWithStatus: No UICC");
517 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700518 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700519 } else {
520 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
521 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
522 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800523 break;
524
525 case EVENT_SEND_ENVELOPE_DONE:
526 ar = (AsyncResult) msg.obj;
527 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700528 if (ar.exception == null && ar.result != null) {
529 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
532 if (ar.result == null) {
533 loge("sendEnvelopeWithStatus: Empty response");
534 } else if (ar.exception instanceof CommandException) {
535 loge("sendEnvelopeWithStatus: CommandException: " +
536 ar.exception);
537 } else {
538 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
539 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700541 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800542 break;
543
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 case CMD_OPEN_CHANNEL:
545 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800546 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800547 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700548 if (uiccCard == null) {
549 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800550 request.result = new IccOpenLogicalChannelResponse(-1,
551 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700552 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 } else {
554 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800555 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
556 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 break;
559
560 case EVENT_OPEN_CHANNEL_DONE:
561 ar = (AsyncResult) msg.obj;
562 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 int[] result = (int[]) ar.result;
566 int channelId = result[0];
567 byte[] selectResponse = null;
568 if (result.length > 1) {
569 selectResponse = new byte[result.length - 1];
570 for (int i = 1; i < result.length; ++i) {
571 selectResponse[i - 1] = (byte) result[i];
572 }
573 }
574 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700575 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 if (ar.result == null) {
578 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 if (ar.exception != null) {
581 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
582 }
583
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700584 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700585 if (ar.exception instanceof CommandException) {
586 CommandException.Error error =
587 ((CommandException) (ar.exception)).getCommandError();
588 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700589 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700590 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700591 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 }
593 }
594 openChannelResp = new IccOpenLogicalChannelResponse(
595 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700597 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 break;
600
601 case CMD_CLOSE_CHANNEL:
602 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800603 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 if (uiccCard == null) {
605 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900606 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700607 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 } else {
609 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
610 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
611 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 break;
613
614 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800615 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
616 break;
617
618 case CMD_NV_READ_ITEM:
619 request = (MainThreadRequest) msg.obj;
620 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
621 mPhone.nvReadItem((Integer) request.argument, onCompleted);
622 break;
623
624 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 ar = (AsyncResult) msg.obj;
626 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800627 if (ar.exception == null && ar.result != null) {
628 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800630 request.result = "";
631 if (ar.result == null) {
632 loge("nvReadItem: Empty response");
633 } else if (ar.exception instanceof CommandException) {
634 loge("nvReadItem: CommandException: " +
635 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800637 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 }
639 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 break;
642
Jake Hambye994d462014-02-03 13:10:13 -0800643 case CMD_NV_WRITE_ITEM:
644 request = (MainThreadRequest) msg.obj;
645 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
646 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
647 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
648 break;
649
650 case EVENT_NV_WRITE_ITEM_DONE:
651 handleNullReturnEvent(msg, "nvWriteItem");
652 break;
653
654 case CMD_NV_WRITE_CDMA_PRL:
655 request = (MainThreadRequest) msg.obj;
656 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
657 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
658 break;
659
660 case EVENT_NV_WRITE_CDMA_PRL_DONE:
661 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
662 break;
663
664 case CMD_NV_RESET_CONFIG:
665 request = (MainThreadRequest) msg.obj;
666 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
667 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
668 break;
669
670 case EVENT_NV_RESET_CONFIG_DONE:
671 handleNullReturnEvent(msg, "nvResetConfig");
672 break;
673
Jake Hamby7c27be32014-03-03 13:25:59 -0800674 case CMD_GET_PREFERRED_NETWORK_TYPE:
675 request = (MainThreadRequest) msg.obj;
676 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700677 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800678 break;
679
680 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
681 ar = (AsyncResult) msg.obj;
682 request = (MainThreadRequest) ar.userObj;
683 if (ar.exception == null && ar.result != null) {
684 request.result = ar.result; // Integer
685 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800686 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 if (ar.result == null) {
688 loge("getPreferredNetworkType: Empty response");
689 } else if (ar.exception instanceof CommandException) {
690 loge("getPreferredNetworkType: CommandException: " +
691 ar.exception);
692 } else {
693 loge("getPreferredNetworkType: Unknown exception");
694 }
695 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700696 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 break;
698
699 case CMD_SET_PREFERRED_NETWORK_TYPE:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
702 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700703 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
707 handleNullReturnEvent(msg, "setPreferredNetworkType");
708 break;
709
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000710 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
711 request = (MainThreadRequest)msg.obj;
712 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
713 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
714 break;
715
716 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
717 ar = (AsyncResult)msg.obj;
718 request = (MainThreadRequest)ar.userObj;
719 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700720 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000721 break;
722
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800723 case CMD_SET_VOICEMAIL_NUMBER:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
726 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800727 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
728 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800729 break;
730
731 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
732 handleNullReturnEvent(msg, "setVoicemailNumber");
733 break;
734
Stuart Scott54788802015-03-30 13:18:01 -0700735 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
738 request);
739 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
740 break;
741
742 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
743 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
744 break;
745
Shishir Agrawal302c8692015-06-19 13:49:39 -0700746 case CMD_PERFORM_NETWORK_SCAN:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
749 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
750 break;
751
752 case EVENT_PERFORM_NETWORK_SCAN_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 CellNetworkScanResult cellScanResult;
756 if (ar.exception == null && ar.result != null) {
757 cellScanResult = new CellNetworkScanResult(
758 CellNetworkScanResult.STATUS_SUCCESS,
759 (List<OperatorInfo>) ar.result);
760 } else {
761 if (ar.result == null) {
762 loge("getCellNetworkScanResults: Empty response");
763 }
764 if (ar.exception != null) {
765 loge("getCellNetworkScanResults: Exception: " + ar.exception);
766 }
767 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
768 if (ar.exception instanceof CommandException) {
769 CommandException.Error error =
770 ((CommandException) (ar.exception)).getCommandError();
771 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
772 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
773 } else if (error == CommandException.Error.GENERIC_FAILURE) {
774 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
775 }
776 }
777 cellScanResult = new CellNetworkScanResult(errorCode, null);
778 }
779 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700781 break;
782
783 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
784 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700785 ManualNetworkSelectionArgument selArg =
786 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700787 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
788 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700789 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
790 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 break;
792
793 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
794 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
795 break;
796
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700797 case CMD_GET_MODEM_ACTIVITY_INFO:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700800 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700801 break;
802
803 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 if (ar.exception == null && ar.result != null) {
807 request.result = ar.result;
808 } else {
809 if (ar.result == null) {
810 loge("queryModemActivityInfo: Empty response");
811 } else if (ar.exception instanceof CommandException) {
812 loge("queryModemActivityInfo: CommandException: " +
813 ar.exception);
814 } else {
815 loge("queryModemActivityInfo: Unknown exception");
816 }
817 }
Amit Mahajand4766222016-01-28 15:28:28 -0800818 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
819 if (request.result == null) {
820 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
821 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700822 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700823 break;
824
Meng Wang1a7c35a2016-05-05 20:56:15 -0700825 case CMD_SET_ALLOWED_CARRIERS:
826 request = (MainThreadRequest) msg.obj;
827 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
828 mPhone.setAllowedCarriers(
829 (List<CarrierIdentifier>) request.argument,
830 onCompleted);
831 break;
832
833 case EVENT_SET_ALLOWED_CARRIERS_DONE:
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null && ar.result != null) {
837 request.result = ar.result;
838 } else {
839 if (ar.result == null) {
840 loge("setAllowedCarriers: Empty response");
841 } else if (ar.exception instanceof CommandException) {
842 loge("setAllowedCarriers: CommandException: " +
843 ar.exception);
844 } else {
845 loge("setAllowedCarriers: Unknown exception");
846 }
847 }
848 // Result cannot be null. Return -1 on error.
849 if (request.result == null) {
850 request.result = new int[]{-1};
851 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700852 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 break;
854
855 case CMD_GET_ALLOWED_CARRIERS:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
858 mPhone.getAllowedCarriers(onCompleted);
859 break;
860
861 case EVENT_GET_ALLOWED_CARRIERS_DONE:
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null && ar.result != null) {
865 request.result = ar.result;
866 } else {
867 if (ar.result == null) {
868 loge("getAllowedCarriers: Empty response");
869 } else if (ar.exception instanceof CommandException) {
870 loge("getAllowedCarriers: CommandException: " +
871 ar.exception);
872 } else {
873 loge("getAllowedCarriers: Unknown exception");
874 }
875 }
876 // Result cannot be null. Return empty list of CarrierIdentifier.
877 if (request.result == null) {
878 request.result = new ArrayList<CarrierIdentifier>(0);
879 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700880 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 break;
882
Nathan Haroldb3014052017-01-25 15:57:32 -0800883 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
889 request.result = new IllegalArgumentException(
890 "Failed to retrieve Forbidden Plmns");
891 if (ar.result == null) {
892 loge("getForbiddenPlmns: Empty response");
893 } else {
894 loge("getForbiddenPlmns: Unknown exception");
895 }
896 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700897 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800898 break;
899
900 case CMD_GET_FORBIDDEN_PLMNS:
901 request = (MainThreadRequest) msg.obj;
902 uiccCard = getUiccCardFromRequest(request);
903 if (uiccCard == null) {
904 loge("getForbiddenPlmns() UiccCard is null");
905 request.result = new IllegalArgumentException(
906 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700907 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800908 break;
909 }
910 Integer appType = (Integer) request.argument;
911 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
912 if (uiccApp == null) {
913 loge("getForbiddenPlmns() no app with specified type -- "
914 + appType);
915 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700916 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800917 break;
918 } else {
919 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
920 + " specified type -- " + appType);
921 }
922 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
923 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
924 onCompleted);
925 break;
926
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000927 case CMD_SWITCH_SLOTS:
928 request = (MainThreadRequest) msg.obj;
929 int[] physicalSlots = (int[]) request.argument;
930 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
931 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
932 break;
933
934 case EVENT_SWITCH_SLOTS_DONE:
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700938 notifyRequester(request);
939 break;
940 case CMD_GET_NETWORK_SELECTION_MODE:
941 request = (MainThreadRequest) msg.obj;
942 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
943 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
944 break;
945
946 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
947 ar = (AsyncResult) msg.obj;
948 request = (MainThreadRequest) ar.userObj;
949 if (ar.exception != null) {
950 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
951 } else {
952 int mode = ((int[]) ar.result)[0];
953 if (mode == 0) {
954 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
955 } else {
956 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
957 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000958 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700959 notifyRequester(request);
960 break;
961 case CMD_GET_CDMA_ROAMING_MODE:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
964 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
965 break;
966 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 if (ar.exception != null) {
970 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
971 } else {
972 request.result = ((int[]) ar.result)[0];
973 }
974 notifyRequester(request);
975 break;
976 case CMD_SET_CDMA_ROAMING_MODE:
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
979 int mode = (int) request.argument;
980 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
981 break;
982 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 request.result = ar.exception == null;
986 notifyRequester(request);
987 break;
988 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
991 int subscriptionMode = (int) request.argument;
992 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
993 break;
994 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 request.result = ar.exception == null;
998 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000999 break;
1000
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001001 default:
1002 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1003 break;
1004 }
1005 }
Jake Hambye994d462014-02-03 13:10:13 -08001006
Pengquan Meng0c05b502018-09-06 09:59:22 -07001007 private void notifyRequester(MainThreadRequest request) {
1008 synchronized (request) {
1009 request.notifyAll();
1010 }
1011 }
1012
Jake Hambye994d462014-02-03 13:10:13 -08001013 private void handleNullReturnEvent(Message msg, String command) {
1014 AsyncResult ar = (AsyncResult) msg.obj;
1015 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception == null) {
1017 request.result = true;
1018 } else {
1019 request.result = false;
1020 if (ar.exception instanceof CommandException) {
1021 loge(command + ": CommandException: " + ar.exception);
1022 } else {
1023 loge(command + ": Unknown exception");
1024 }
1025 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001026 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001028 }
1029
1030 /**
1031 * Posts the specified command to be executed on the main thread,
1032 * waits for the request to complete, and returns the result.
1033 * @see #sendRequestAsync
1034 */
1035 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001036 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001037 }
1038
1039 /**
1040 * Posts the specified command to be executed on the main thread,
1041 * waits for the request to complete, and returns the result.
1042 * @see #sendRequestAsync
1043 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001044 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1046 throw new RuntimeException("This method will deadlock if called from the main thread.");
1047 }
1048
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001049 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001050 Message msg = mMainThreadHandler.obtainMessage(command, request);
1051 msg.sendToTarget();
1052
1053 // Wait for the request to complete
1054 synchronized (request) {
1055 while (request.result == null) {
1056 try {
1057 request.wait();
1058 } catch (InterruptedException e) {
1059 // Do nothing, go back and wait until the request is complete
1060 }
1061 }
1062 }
1063 return request.result;
1064 }
1065
1066 /**
1067 * Asynchronous ("fire and forget") version of sendRequest():
1068 * Posts the specified command to be executed on the main thread, and
1069 * returns immediately.
1070 * @see #sendRequest
1071 */
1072 private void sendRequestAsync(int command) {
1073 mMainThreadHandler.sendEmptyMessage(command);
1074 }
1075
1076 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001077 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1078 * @see {@link #sendRequest(int,Object)}
1079 */
1080 private void sendRequestAsync(int command, Object argument) {
1081 MainThreadRequest request = new MainThreadRequest(argument);
1082 Message msg = mMainThreadHandler.obtainMessage(command, request);
1083 msg.sendToTarget();
1084 }
1085
1086 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 * Initialize the singleton PhoneInterfaceManager instance.
1088 * This is only done once, at startup, from PhoneApp.onCreate().
1089 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001090 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 synchronized (PhoneInterfaceManager.class) {
1092 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001093 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001094 } else {
1095 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1096 }
1097 return sInstance;
1098 }
1099 }
1100
1101 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001102 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 mApp = app;
1104 mPhone = phone;
1105 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001106 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001107 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1108 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001109 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001110 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001111 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001112 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001113 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001114
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001115 publish();
1116 }
1117
1118 private void publish() {
1119 if (DBG) log("publish: " + this);
1120
1121 ServiceManager.addService("phone", this);
1122 }
1123
Stuart Scott584921c2015-01-15 17:10:34 -08001124 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001125 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1126 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001127 }
1128
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001129 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1130 Phone phone = getPhoneFromRequest(request);
1131 return phone == null ? null :
1132 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1133 }
1134
Wink Saville36469e72014-06-11 15:17:00 -07001135 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001136 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001137 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 //
1140 // Implementation of the ITelephony interface.
1141 //
1142
1143 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001144 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001145 }
1146
Wink Savilleb564aae2014-10-23 10:18:09 -07001147 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 if (DBG) log("dial: " + number);
1149 // No permission check needed here: This is just a wrapper around the
1150 // ACTION_DIAL intent, which is available to any app since it puts up
1151 // the UI before it does anything.
1152
Malcolm Chenaabec062018-02-28 15:00:40 -08001153 final long identity = Binder.clearCallingIdentity();
1154 try {
1155 String url = createTelUrl(number);
1156 if (url == null) {
1157 return;
1158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001159
Malcolm Chenaabec062018-02-28 15:00:40 -08001160 // PENDING: should we just silently fail if phone is offhook or ringing?
1161 PhoneConstants.State state = mCM.getState(subId);
1162 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1163 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1164 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1165 mApp.startActivity(intent);
1166 }
1167 } finally {
1168 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 }
1170 }
1171
1172 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001173 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001174 }
1175
Wink Savilleb564aae2014-10-23 10:18:09 -07001176 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001177 if (DBG) log("call: " + number);
1178
1179 // This is just a wrapper around the ACTION_CALL intent, but we still
1180 // need to do a permission check since we're calling startActivity()
1181 // from the context of the phone app.
1182 enforceCallPermission();
1183
1184 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1185 != AppOpsManager.MODE_ALLOWED) {
1186 return;
1187 }
1188
Malcolm Chenaabec062018-02-28 15:00:40 -08001189 final long identity = Binder.clearCallingIdentity();
1190 try {
1191 String url = createTelUrl(number);
1192 if (url == null) {
1193 return;
1194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195
Malcolm Chenaabec062018-02-28 15:00:40 -08001196 boolean isValid = false;
1197 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1198 if (slist != null) {
1199 for (SubscriptionInfo subInfoRecord : slist) {
1200 if (subInfoRecord.getSubscriptionId() == subId) {
1201 isValid = true;
1202 break;
1203 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001204 }
Wink Saville08874612014-08-31 19:19:58 -07001205 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001206 if (!isValid) {
1207 return;
1208 }
Wink Saville08874612014-08-31 19:19:58 -07001209
Malcolm Chenaabec062018-02-28 15:00:40 -08001210 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1211 intent.putExtra(SUBSCRIPTION_KEY, subId);
1212 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1213 mApp.startActivity(intent);
1214 } finally {
1215 Binder.restoreCallingIdentity(identity);
1216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 }
1218
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 /**
1220 * End a call based on call state
1221 * @return true is a call was ended
1222 */
1223 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001224 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001225 }
1226
1227 /**
1228 * End a call based on the call state of the subId
1229 * @return true is a call was ended
1230 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001231 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001232 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1233 != PackageManager.PERMISSION_GRANTED) {
1234 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1235 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1236 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1237 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001238 final long identity = Binder.clearCallingIdentity();
1239 try {
1240 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1241 } finally {
1242 Binder.restoreCallingIdentity(identity);
1243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 }
1245
1246 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001247 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001248 }
1249
Wink Savilleb564aae2014-10-23 10:18:09 -07001250 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 if (DBG) log("answerRingingCall...");
1252 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1253 // but that can probably wait till the big TelephonyManager API overhaul.
1254 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1255 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001256
1257 final long identity = Binder.clearCallingIdentity();
1258 try {
1259 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1260 } finally {
1261 Binder.restoreCallingIdentity(identity);
1262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 }
1264
1265 /**
1266 * Make the actual telephony calls to implement answerRingingCall().
1267 * This should only be called from the main thread of the Phone app.
1268 * @see #answerRingingCall
1269 *
1270 * TODO: it would be nice to return true if we answered the call, or
1271 * false if there wasn't actually a ringing incoming call, or some
1272 * other error occurred. (In other words, pass back the return value
1273 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1274 * But that would require calling this method via sendRequest() rather
1275 * than sendRequestAsync(), and right now we don't actually *need* that
1276 * return value, so let's just return void for now.
1277 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001278 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001279 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001281 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1282 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 if (hasActiveCall && hasHoldingCall) {
1284 // Both lines are in use!
1285 // TODO: provide a flag to let the caller specify what
1286 // policy to use if both lines are in use. (The current
1287 // behavior is hardwired to "answer incoming, end ongoing",
1288 // which is how the CALL button is specced to behave.)
1289 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1290 return;
1291 } else {
1292 // answerCall() will automatically hold the current active
1293 // call, if there is one.
1294 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1295 return;
1296 }
1297 } else {
1298 // No call was ringing.
1299 return;
1300 }
1301 }
1302
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001304 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001306 public void silenceRinger() {
1307 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 }
1309
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001310 @Override
1311 public boolean isOffhook(String callingPackage) {
1312 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001313 }
1314
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001315 @Override
1316 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001318 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001319 return false;
1320 }
1321
Malcolm Chenaabec062018-02-28 15:00:40 -08001322 final long identity = Binder.clearCallingIdentity();
1323 try {
1324 final Phone phone = getPhone(subId);
1325 if (phone != null) {
1326 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1327 } else {
1328 return false;
1329 }
1330 } finally {
1331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 }
1334
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001335 @Override
1336 public boolean isRinging(String callingPackage) {
1337 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001338 }
1339
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001340 @Override
1341 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001343 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001344 return false;
1345 }
1346
Malcolm Chenaabec062018-02-28 15:00:40 -08001347 final long identity = Binder.clearCallingIdentity();
1348 try {
1349 final Phone phone = getPhone(subId);
1350 if (phone != null) {
1351 return (phone.getState() == PhoneConstants.State.RINGING);
1352 } else {
1353 return false;
1354 }
1355 } finally {
1356 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 }
1359
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001360 @Override
1361 public boolean isIdle(String callingPackage) {
1362 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001363 }
1364
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001365 @Override
1366 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001368 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001369 return false;
1370 }
1371
Malcolm Chenaabec062018-02-28 15:00:40 -08001372 final long identity = Binder.clearCallingIdentity();
1373 try {
1374 final Phone phone = getPhone(subId);
1375 if (phone != null) {
1376 return (phone.getState() == PhoneConstants.State.IDLE);
1377 } else {
1378 return false;
1379 }
1380 } finally {
1381 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 }
1384
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001386 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001387 }
1388
Wink Savilleb564aae2014-10-23 10:18:09 -07001389 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001390 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001391 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1392 }
1393
1394 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001395 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001396 }
1397
Wink Savilleb564aae2014-10-23 10:18:09 -07001398 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001400 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1401 }
1402
1403 /** {@hide} */
1404 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001405 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001406 }
1407
Wink Savilleb564aae2014-10-23 10:18:09 -07001408 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001410
1411 final long identity = Binder.clearCallingIdentity();
1412 try {
1413 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1414 checkSimPin.start();
1415 return checkSimPin.unlockSim(null, pin);
1416 } finally {
1417 Binder.restoreCallingIdentity(identity);
1418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 }
1420
Wink Saville9de0f752013-10-22 19:04:03 -07001421 /** {@hide} */
1422 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001423 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
1425
Wink Savilleb564aae2014-10-23 10:18:09 -07001426 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001428
1429 final long identity = Binder.clearCallingIdentity();
1430 try {
1431 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1432 checkSimPuk.start();
1433 return checkSimPuk.unlockSim(puk, pin);
1434 } finally {
1435 Binder.restoreCallingIdentity(identity);
1436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001437 }
1438
1439 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001440 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441 * a synchronous one.
1442 */
1443 private static class UnlockSim extends Thread {
1444
1445 private final IccCard mSimCard;
1446
1447 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001448 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1449 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450
1451 // For replies from SimCard interface
1452 private Handler mHandler;
1453
1454 // For async handler to identify request type
1455 private static final int SUPPLY_PIN_COMPLETE = 100;
1456
1457 public UnlockSim(IccCard simCard) {
1458 mSimCard = simCard;
1459 }
1460
1461 @Override
1462 public void run() {
1463 Looper.prepare();
1464 synchronized (UnlockSim.this) {
1465 mHandler = new Handler() {
1466 @Override
1467 public void handleMessage(Message msg) {
1468 AsyncResult ar = (AsyncResult) msg.obj;
1469 switch (msg.what) {
1470 case SUPPLY_PIN_COMPLETE:
1471 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1472 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001473 mRetryCount = msg.arg1;
1474 if (ar.exception != null) {
1475 if (ar.exception instanceof CommandException &&
1476 ((CommandException)(ar.exception)).getCommandError()
1477 == CommandException.Error.PASSWORD_INCORRECT) {
1478 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1479 } else {
1480 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1481 }
1482 } else {
1483 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485 mDone = true;
1486 UnlockSim.this.notifyAll();
1487 }
1488 break;
1489 }
1490 }
1491 };
1492 UnlockSim.this.notifyAll();
1493 }
1494 Looper.loop();
1495 }
1496
1497 /*
1498 * Use PIN or PUK to unlock SIM card
1499 *
1500 * If PUK is null, unlock SIM card with PIN
1501 *
1502 * If PUK is not null, unlock SIM card with PUK and set PIN code
1503 */
Wink Saville9de0f752013-10-22 19:04:03 -07001504 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505
1506 while (mHandler == null) {
1507 try {
1508 wait();
1509 } catch (InterruptedException e) {
1510 Thread.currentThread().interrupt();
1511 }
1512 }
1513 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1514
1515 if (puk == null) {
1516 mSimCard.supplyPin(pin, callback);
1517 } else {
1518 mSimCard.supplyPuk(puk, pin, callback);
1519 }
1520
1521 while (!mDone) {
1522 try {
1523 Log.d(LOG_TAG, "wait for done");
1524 wait();
1525 } catch (InterruptedException e) {
1526 // Restore the interrupted status
1527 Thread.currentThread().interrupt();
1528 }
1529 }
1530 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001531 int[] resultArray = new int[2];
1532 resultArray[0] = mResult;
1533 resultArray[1] = mRetryCount;
1534 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 }
1536 }
1537
1538 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001540
1541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 // No permission check needed here: this call is harmless, and it's
1545 // needed for the ServiceState.requestStateUpdate() call (which is
1546 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001547 final long identity = Binder.clearCallingIdentity();
1548 try {
1549 final Phone phone = getPhone(subId);
1550 if (phone != null) {
1551 phone.updateServiceLocation();
1552 }
1553 } finally {
1554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001558 @Override
1559 public boolean isRadioOn(String callingPackage) {
1560 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001561 }
1562
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001563 @Override
1564 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001566 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001567 return false;
1568 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001569
1570 final long identity = Binder.clearCallingIdentity();
1571 try {
1572 return isRadioOnForSubscriber(subId);
1573 } finally {
1574 Binder.restoreCallingIdentity(identity);
1575 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001576 }
1577
1578 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001579 final long identity = Binder.clearCallingIdentity();
1580 try {
1581 final Phone phone = getPhone(subId);
1582 if (phone != null) {
1583 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1584 } else {
1585 return false;
1586 }
1587 } finally {
1588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 }
1591
1592 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001593 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 }
Wink Saville36469e72014-06-11 15:17:00 -07001595
Wink Savilleb564aae2014-10-23 10:18:09 -07001596 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001598
1599 final long identity = Binder.clearCallingIdentity();
1600 try {
1601 final Phone phone = getPhone(subId);
1602 if (phone != null) {
1603 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1604 }
1605 } finally {
1606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 }
Wink Saville36469e72014-06-11 15:17:00 -07001608 }
1609
1610 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001611 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001612 }
1613
Wink Savilleb564aae2014-10-23 10:18:09 -07001614 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001615 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001616
1617 final long identity = Binder.clearCallingIdentity();
1618 try {
1619 final Phone phone = getPhone(subId);
1620 if (phone == null) {
1621 return false;
1622 }
1623 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1624 toggleRadioOnOffForSubscriber(subId);
1625 }
1626 return true;
1627 } finally {
1628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 }
Wink Saville36469e72014-06-11 15:17:00 -07001631
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001632 public boolean needMobileRadioShutdown() {
1633 /*
1634 * If any of the Radios are available, it will need to be
1635 * shutdown. So return true if any Radio is available.
1636 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1640 Phone phone = PhoneFactory.getPhone(i);
1641 if (phone != null && phone.isRadioAvailable()) return true;
1642 }
1643 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1644 return false;
1645 } finally {
1646 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001647 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001648 }
1649
Malcolm Chenaabec062018-02-28 15:00:40 -08001650 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001651 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001652 enforceModifyPermission();
1653
1654 final long identity = Binder.clearCallingIdentity();
1655 try {
1656 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1657 logv("Shutting down Phone " + i);
1658 shutdownRadioUsingPhoneId(i);
1659 }
1660 } finally {
1661 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001662 }
1663 }
1664
1665 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001666 Phone phone = PhoneFactory.getPhone(phoneId);
1667 if (phone != null && phone.isRadioAvailable()) {
1668 phone.shutdownRadio();
1669 }
1670 }
1671
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001673 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001674
1675 final long identity = Binder.clearCallingIdentity();
1676 try {
1677 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1678 if (defaultPhone != null) {
1679 defaultPhone.setRadioPower(turnOn);
1680 return true;
1681 } else {
1682 loge("There's no default phone.");
1683 return false;
1684 }
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001687 }
Wink Saville36469e72014-06-11 15:17:00 -07001688 }
1689
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001692
1693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
1697 phone.setRadioPower(turnOn);
1698 return true;
1699 } else {
1700 return false;
1701 }
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
Wink Saville36469e72014-06-11 15:17:00 -07001707 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 public boolean enableDataConnectivity() {
1710 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001711
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 int subId = mSubscriptionController.getDefaultDataSubId();
1715 final Phone phone = getPhone(subId);
1716 if (phone != null) {
1717 phone.setUserDataEnabled(true);
1718 return true;
1719 } else {
1720 return false;
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
Wink Saville36469e72014-06-11 15:17:00 -07001727 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 public boolean disableDataConnectivity() {
1730 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001731
1732 final long identity = Binder.clearCallingIdentity();
1733 try {
1734 int subId = mSubscriptionController.getDefaultDataSubId();
1735 final Phone phone = getPhone(subId);
1736 if (phone != null) {
1737 phone.setUserDataEnabled(false);
1738 return true;
1739 } else {
1740 return false;
1741 }
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001748 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 final Phone phone = getPhone(subId);
1752 if (phone != null) {
1753 return phone.isDataAllowed();
1754 } else {
1755 return false;
1756 }
1757 } finally {
1758 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 }
1761
1762 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001763 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001764 }
1765
pkanwarae03a6b2016-11-06 20:37:09 -08001766 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001767 enforceCallPermission();
1768
1769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1772 return;
1773 }
1774 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1775 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1776 } finally {
1777 Binder.restoreCallingIdentity(identity);
1778 }
pkanwar32d516d2016-10-14 19:37:38 -07001779 };
1780
Wink Savilleb564aae2014-10-23 10:18:09 -07001781 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001783
1784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1787 return false;
1788 }
1789 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001796 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001797 }
1798
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001799 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001800 final long identity = Binder.clearCallingIdentity();
1801 try {
1802 Phone phone = PhoneFactory.getPhone(slotIndex);
1803 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1804 PhoneConstantConversions.convertCallState(phone.getState());
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
1807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Sanket Padawe356d7632015-06-22 14:03:32 -07001810 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001812 final long identity = Binder.clearCallingIdentity();
1813 try {
1814 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1815 if (phone != null) {
1816 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1817 } else {
1818 return PhoneConstantConversions.convertDataState(
1819 PhoneConstants.DataState.DISCONNECTED);
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
Sanket Padawe356d7632015-06-22 14:03:32 -07001826 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001828 final long identity = Binder.clearCallingIdentity();
1829 try {
1830 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1831 if (phone != null) {
1832 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1833 } else {
1834 return TelephonyManager.DATA_ACTIVITY_NONE;
1835 }
1836 } finally {
1837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 }
1840
1841 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001842 public Bundle getCellLocation(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
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001850 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001851 final long identity = Binder.clearCallingIdentity();
1852 try {
1853 if (DBG_LOC) log("getCellLocation: is active user");
1854 Bundle data = new Bundle();
1855 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1856 if (phone == null) {
1857 return null;
1858 }
1859
1860 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1861 return data;
1862 } finally {
1863 Binder.restoreCallingIdentity(identity);
1864 }
Svetoslav64fad262015-04-14 14:35:21 -07001865 }
1866
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001868 public String getNetworkCountryIsoForPhone(int phoneId) {
1869 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1870 // registered cell info, so return a NULL country instead.
1871 final long identity = Binder.clearCallingIdentity();
1872 try {
1873 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001874 // Todo: fix this when we can get the actual cellular network info when the device
1875 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001876 if (TelephonyManager.NETWORK_TYPE_IWLAN
1877 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1878 return "";
1879 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001880 Phone phone = PhoneFactory.getPhone(phoneId);
1881 if (phone != null) {
1882 ServiceStateTracker sst = phone.getServiceStateTracker();
1883 if (sst != null) {
1884 LocaleTracker lt = sst.getLocaleTracker();
1885 if (lt != null) {
1886 return lt.getCurrentCountry();
1887 }
1888 }
1889 }
1890 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001894 }
1895
1896 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001898 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001902 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 mApp.enforceCallingOrSelfPermission(
1904 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001905
1906 final long identity = Binder.clearCallingIdentity();
1907 try {
1908 final Phone phone = getPhone(subId);
1909 if (phone != null) {
1910 phone.enableLocationUpdates();
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917 @Override
1918 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001919 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001920 }
1921
Sanket Padawe356d7632015-06-22 14:03:32 -07001922 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001923 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 mApp.enforceCallingOrSelfPermission(
1925 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001926
1927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 final Phone phone = getPhone(subId);
1930 if (phone != null) {
1931 phone.disableLocationUpdates();
1932 }
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
1938 @Override
1939 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001940 public List<NeighboringCellInfo>
1941 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001942 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1943 throw new SecurityException(
1944 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1945 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001946
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1948 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1949 return null;
1950 }
Svetoslav64fad262015-04-14 14:35:21 -07001951
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001952 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953
Nathan Haroldf180aac2018-06-01 18:43:55 -07001954 List<CellInfo> info = getAllCellInfo(callingPackage);
1955 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956
Nathan Haroldf180aac2018-06-01 18:43:55 -07001957 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1958 for (CellInfo ci : info) {
1959 if (ci instanceof CellInfoGsm) {
1960 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1961 } else if (ci instanceof CellInfoWcdma) {
1962 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001965 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
1968
1969 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001970 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001971 mPhone.getContext().getSystemService(AppOpsManager.class)
1972 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001973 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001974 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001975 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 }
1977
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001978 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001980 final long identity = Binder.clearCallingIdentity();
1981 try {
1982 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1983 for (Phone phone : PhoneFactory.getPhones()) {
1984 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1985 if (info != null) cellInfos.addAll(info);
1986 }
1987 return cellInfos;
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 }
1991 }
1992
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001993 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001995 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001996 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001997
1998 final long identity = Binder.clearCallingIdentity();
1999 try {
2000 mPhone.setCellInfoListRate(rateInMillis, workSource);
2001 } finally {
2002 Binder.restoreCallingIdentity(identity);
2003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004 }
2005
Shishir Agrawala9f32182016-04-12 12:00:16 -07002006 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002007 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002008 Phone phone = PhoneFactory.getPhone(slotIndex);
2009 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002010 return null;
2011 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002012 int subId = phone.getSubId();
2013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2014 mApp, subId, callingPackage, "getImeiForSlot")) {
2015 return null;
2016 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002017
2018 final long identity = Binder.clearCallingIdentity();
2019 try {
2020 return phone.getImei();
2021 } finally {
2022 Binder.restoreCallingIdentity(identity);
2023 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002024 }
2025
2026 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002027 public String getTypeAllocationCodeForSlot(int slotIndex) {
2028 Phone phone = PhoneFactory.getPhone(slotIndex);
2029 String tac = null;
2030 if (phone != null) {
2031 String imei = phone.getImei();
2032 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2033 }
2034 return tac;
2035 }
2036
2037 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002038 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002039 Phone phone = PhoneFactory.getPhone(slotIndex);
2040 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002041 return null;
2042 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002043 int subId = phone.getSubId();
2044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2045 mApp, subId, callingPackage, "getMeidForSlot")) {
2046 return null;
2047 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002048
2049 final long identity = Binder.clearCallingIdentity();
2050 try {
2051 return phone.getMeid();
2052 } finally {
2053 Binder.restoreCallingIdentity(identity);
2054 }
Jack Yu2af8d712017-03-15 17:14:14 -07002055 }
2056
2057 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002058 public String getManufacturerCodeForSlot(int slotIndex) {
2059 Phone phone = PhoneFactory.getPhone(slotIndex);
2060 String manufacturerCode = null;
2061 if (phone != null) {
2062 String meid = phone.getMeid();
2063 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2064 }
2065 return manufacturerCode;
2066 }
2067
2068 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002069 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002070 Phone phone = PhoneFactory.getPhone(slotIndex);
2071 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002072 return null;
2073 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002074 int subId = phone.getSubId();
2075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2076 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2077 return null;
2078 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002079
2080 final long identity = Binder.clearCallingIdentity();
2081 try {
2082 return phone.getDeviceSvn();
2083 } finally {
2084 Binder.restoreCallingIdentity(identity);
2085 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002086 }
2087
fionaxu43304da2017-11-27 22:51:16 -08002088 @Override
2089 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002090 final long identity = Binder.clearCallingIdentity();
2091 try {
2092 final Phone phone = getPhone(subId);
2093 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
2096 }
fionaxu43304da2017-11-27 22:51:16 -08002097 }
2098
2099 @Override
2100 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002101 final long identity = Binder.clearCallingIdentity();
2102 try {
2103 final Phone phone = getPhone(subId);
2104 return phone == null ? null : phone.getCarrierName();
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
2107 }
fionaxu43304da2017-11-27 22:51:16 -08002108 }
2109
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 //
2111 // Internal helper methods.
2112 //
2113
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002114 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2116 *
2117 * @throws SecurityException if the caller does not have the required permission
2118 */
2119 private void enforceModifyPermission() {
2120 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2121 }
2122
2123 /**
2124 * Make sure the caller has the CALL_PHONE permission.
2125 *
2126 * @throws SecurityException if the caller does not have the required permission
2127 */
2128 private void enforceCallPermission() {
2129 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2130 }
2131
Stuart Scott8eef64f2015-04-08 15:13:54 -07002132 private void enforceConnectivityInternalPermission() {
2133 mApp.enforceCallingOrSelfPermission(
2134 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2135 "ConnectivityService");
2136 }
2137
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 private String createTelUrl(String number) {
2139 if (TextUtils.isEmpty(number)) {
2140 return null;
2141 }
2142
Jake Hambye994d462014-02-03 13:10:13 -08002143 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 }
2145
Ihab Awadf9e92732013-12-05 18:02:52 -08002146 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2148 }
2149
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002150 private static void logv(String msg) {
2151 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2152 }
2153
Ihab Awadf9e92732013-12-05 18:02:52 -08002154 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2156 }
2157
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002158 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002160 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002161 }
2162
Sanket Padawe356d7632015-06-22 14:03:32 -07002163 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002164 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002165 final long identity = Binder.clearCallingIdentity();
2166 try {
2167 final Phone phone = PhoneFactory.getPhone(slotIndex);
2168 if (phone == null) {
2169 return PhoneConstants.PHONE_TYPE_NONE;
2170 } else {
2171 return phone.getPhoneType();
2172 }
2173 } finally {
2174 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 }
2177
2178 /**
2179 * Returns the CDMA ERI icon index to display
2180 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002181 @Override
2182 public int getCdmaEriIconIndex(String callingPackage) {
2183 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002184 }
2185
Sanket Padawe356d7632015-06-22 14:03:32 -07002186 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002187 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002189 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002190 return -1;
2191 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002192
2193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 final Phone phone = getPhone(subId);
2196 if (phone != null) {
2197 return phone.getCdmaEriIconIndex();
2198 } else {
2199 return -1;
2200 }
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 }
2205
2206 /**
2207 * Returns the CDMA ERI icon mode,
2208 * 0 - ON
2209 * 1 - FLASHING
2210 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002211 @Override
2212 public int getCdmaEriIconMode(String callingPackage) {
2213 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002214 }
2215
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002217 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002219 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002220 return -1;
2221 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002222
2223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 final Phone phone = getPhone(subId);
2226 if (phone != null) {
2227 return phone.getCdmaEriIconMode();
2228 } else {
2229 return -1;
2230 }
2231 } finally {
2232 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235
2236 /**
2237 * Returns the CDMA ERI text,
2238 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002239 @Override
2240 public String getCdmaEriText(String callingPackage) {
2241 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002242 }
2243
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002247 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002248 return null;
2249 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002250
2251 final long identity = Binder.clearCallingIdentity();
2252 try {
2253 final Phone phone = getPhone(subId);
2254 if (phone != null) {
2255 return phone.getCdmaEriText();
2256 } else {
2257 return null;
2258 }
2259 } finally {
2260 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 }
2263
2264 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002265 * Returns the CDMA MDN.
2266 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002268 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2270 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002271
2272 final long identity = Binder.clearCallingIdentity();
2273 try {
2274 final Phone phone = getPhone(subId);
2275 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2276 return phone.getLine1Number();
2277 } else {
2278 return null;
2279 }
2280 } finally {
2281 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002282 }
2283 }
2284
2285 /**
2286 * Returns the CDMA MIN.
2287 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002289 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2291 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
2295 final Phone phone = getPhone(subId);
2296 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2297 return phone.getCdmaMin();
2298 } else {
2299 return null;
2300 }
2301 } finally {
2302 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002303 }
2304 }
2305
2306 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 * Returns true if CDMA provisioning needs to run.
2308 */
2309 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 return mPhone.needsOtaServiceProvisioning();
2313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 }
2317
2318 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002319 * Sets the voice mail number of a given subId.
2320 */
2321 @Override
2322 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002323 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2328 new Pair<String, String>(alphaTag, number), new Integer(subId));
2329 return success;
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002333 }
2334
Ta-wei Yen87c49842016-05-13 21:19:52 -07002335 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002336 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2338 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2339 if (!TextUtils.equals(callingPackage, systemDialer)) {
2340 throw new SecurityException("caller must be system dialer");
2341 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2346 if (phoneAccountHandle == null) {
2347 return null;
2348 }
2349 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002352 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002353 }
2354
2355 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002356 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002359 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002360 return null;
2361 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002362
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002363 final long identity = Binder.clearCallingIdentity();
2364 try {
2365 return RemoteVvmTaskManager
2366 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2367 } finally {
2368 Binder.restoreCallingIdentity(identity);
2369 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002370 }
2371
2372 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002373 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2374 VisualVoicemailSmsFilterSettings settings) {
2375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002376
2377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2380 mPhone.getContext(), callingPackage, subId, settings);
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002384 }
2385
2386 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002387 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002389
2390 final long identity = Binder.clearCallingIdentity();
2391 try {
2392 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2393 mPhone.getContext(), callingPackage, subId);
2394 } finally {
2395 Binder.restoreCallingIdentity(identity);
2396 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002397 }
2398
2399 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002400 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2401 String callingPackage, int subId) {
2402 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002403
2404 final long identity = Binder.clearCallingIdentity();
2405 try {
2406 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2407 mPhone.getContext(), callingPackage, subId);
2408 } finally {
2409 Binder.restoreCallingIdentity(identity);
2410 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002411 }
2412
2413 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002414 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002415 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002416
2417 final long identity = Binder.clearCallingIdentity();
2418 try {
2419 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2420 mPhone.getContext(), subId);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
2423 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002424 }
2425
2426 @Override
2427 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2428 String number, int port, String text, PendingIntent sentIntent) {
2429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002430 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002431 enforceSendSmsPermission();
2432 // Make the calls as the phone process.
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2436 if (port == 0) {
2437 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2438 sentIntent, null, false);
2439 } else {
2440 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2441 smsManager.sendDataMessageWithSelfPermissions(number, null,
2442 (short) port, data, sentIntent, null);
2443 }
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
2446 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002447 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002448 /**
fionaxu0152e512016-11-14 13:36:14 -08002449 * Sets the voice activation state of a given subId.
2450 */
2451 @Override
2452 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2454 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002455
2456 final long identity = Binder.clearCallingIdentity();
2457 try {
2458 final Phone phone = getPhone(subId);
2459 if (phone != null) {
2460 phone.setVoiceActivationState(activationState);
2461 } else {
2462 loge("setVoiceActivationState fails with invalid subId: " + subId);
2463 }
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002466 }
2467 }
2468
2469 /**
2470 * Sets the data activation state of a given subId.
2471 */
2472 @Override
2473 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2475 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002476
2477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 final Phone phone = getPhone(subId);
2480 if (phone != null) {
2481 phone.setDataActivationState(activationState);
2482 } else {
2483 loge("setVoiceActivationState fails with invalid subId: " + subId);
2484 }
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002487 }
2488 }
2489
2490 /**
2491 * Returns the voice activation state of a given subId.
2492 */
2493 @Override
2494 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002495 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002496
fionaxu0152e512016-11-14 13:36:14 -08002497 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 if (phone != null) {
2501 return phone.getVoiceActivationState();
2502 } else {
2503 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2504 }
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002507 }
2508 }
2509
2510 /**
2511 * Returns the data activation state of a given subId.
2512 */
2513 @Override
2514 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002515 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002516
fionaxu0152e512016-11-14 13:36:14 -08002517 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 if (phone != null) {
2521 return phone.getDataActivationState();
2522 } else {
2523 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2524 }
2525 } finally {
2526 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002527 }
2528 }
2529
2530 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 * Returns the unread count of voicemails
2532 */
2533 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002534 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002535 }
2536
2537 /**
2538 * Returns the unread count of voicemails for a subId
2539 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002540 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002541 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 final Phone phone = getPhone(subId);
2545 if (phone != null) {
2546 return phone.getVoiceMessageCount();
2547 } else {
2548 return 0;
2549 }
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554
2555 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002556 * returns true, if the device is in a state where both voice and data
2557 * are supported simultaneously. This can change based on location or network condition.
2558 */
2559 @Override
2560 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002561 final long identity = Binder.clearCallingIdentity();
2562 try {
2563 final Phone phone = getPhone(subId);
2564 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002568 }
2569
2570 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002571 * Send the dialer code if called from the current default dialer or the caller has
2572 * carrier privilege.
2573 * @param inputCode The dialer code to send
2574 */
2575 @Override
2576 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2578 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2579 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002580 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2581 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002582 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 mPhone.sendDialerSpecialCode(inputCode);
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
2589 }
fionaxu235cc5e2017-03-06 22:25:57 -08002590 }
2591
2592 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002593 * Returns the data network type.
2594 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 *
2596 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2597 */
2598 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002599 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 final Phone phone = getPhone(getDefaultSubscription());
2603 if (phone != null) {
2604 return phone.getServiceState().getDataNetworkType();
2605 } else {
2606 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002610 }
Wink Saville36469e72014-06-11 15:17:00 -07002611 }
2612
Pengquan Meng0c05b502018-09-06 09:59:22 -07002613 @Override
2614 public int getNetworkSelectionMode(int subId) {
2615 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2616 }
2617
Wink Saville36469e72014-06-11 15:17:00 -07002618 /**
2619 * Returns the network type for a subId
2620 */
2621 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002622 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002624 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002625 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2626 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002627
Malcolm Chenaabec062018-02-28 15:00:40 -08002628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 final Phone phone = getPhone(subId);
2631 if (phone != null) {
2632 return phone.getServiceState().getDataNetworkType();
2633 } else {
2634 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2635 }
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 }
2640
2641 /**
2642 * Returns the data network type
2643 */
2644 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002645 public int getDataNetworkType(String callingPackage) {
2646 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002647 }
2648
2649 /**
2650 * Returns the data network type for a subId
2651 */
2652 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002653 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002655 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002656 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2657 }
2658
Malcolm Chenaabec062018-02-28 15:00:40 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 final Phone phone = getPhone(subId);
2662 if (phone != null) {
2663 return phone.getServiceState().getDataNetworkType();
2664 } else {
2665 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2666 }
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
2672 /**
Wink Saville36469e72014-06-11 15:17:00 -07002673 * Returns the Voice network type for a subId
2674 */
2675 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002676 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002678 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002679 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2680 }
2681
Malcolm Chenaabec062018-02-28 15:00:40 -08002682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 final Phone phone = getPhone(subId);
2685 if (phone != null) {
2686 return phone.getServiceState().getVoiceNetworkType();
2687 } else {
2688 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2689 }
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
2694
2695 /**
2696 * @return true if a ICC card is present
2697 */
2698 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002699 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002700 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2701 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002702 }
2703
2704 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002705 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002706 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002707 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002708 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 final Phone phone = PhoneFactory.getPhone(slotIndex);
2712 if (phone != null) {
2713 return phone.getIccCard().hasIccCard();
2714 } else {
2715 return false;
2716 }
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 }
2721
2722 /**
2723 * Return if the current radio is LTE on CDMA. This
2724 * is a tri-state return value as for a period of time
2725 * the mode may be unknown.
2726 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002727 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002729 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002731 @Override
2732 public int getLteOnCdmaMode(String callingPackage) {
2733 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002734 }
2735
Sanket Padawe356d7632015-06-22 14:03:32 -07002736 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002737 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002739 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002740 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2741 }
2742
Malcolm Chenaabec062018-02-28 15:00:40 -08002743 final long identity = Binder.clearCallingIdentity();
2744 try {
2745 final Phone phone = getPhone(subId);
2746 if (phone == null) {
2747 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2748 } else {
2749 return phone.getLteOnCdmaMode();
2750 }
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 }
Wink Saville36469e72014-06-11 15:17:00 -07002754 }
2755
2756 public void setPhone(Phone phone) {
2757 mPhone = phone;
2758 }
2759
2760 /**
2761 * {@hide}
2762 * Returns Default subId, 0 in the case of single standby.
2763 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002764 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002765 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002766 }
2767
Shishir Agrawala9f32182016-04-12 12:00:16 -07002768 private int getSlotForDefaultSubscription() {
2769 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2770 }
2771
Wink Savilleb564aae2014-10-23 10:18:09 -07002772 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002773 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002775
2776 /**
2777 * @see android.telephony.TelephonyManager.WifiCallingChoices
2778 */
2779 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2783 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2784 getWhenToMakeWifiCallsDefaultPreference());
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
2787 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002788 }
2789
2790 /**
2791 * @see android.telephony.TelephonyManager.WifiCallingChoices
2792 */
2793 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2797 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2798 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002802 }
2803
Sailesh Nepald1e68152013-12-12 19:08:02 -08002804 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002805 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002806 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002807 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002808
Shishir Agrawal566b7612013-10-28 14:41:00 -07002809 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002810 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2811 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2813 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002814 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002815
Malcolm Chenaabec062018-02-28 15:00:40 -08002816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 if (TextUtils.equals(ISDR_AID, aid)) {
2819 // Only allows LPA to open logical channel to ISD-R.
2820 ComponentInfo bestComponent =
2821 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2822 if (bestComponent == null
2823 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2824 loge("The calling package is not allowed to access ISD-R.");
2825 throw new SecurityException(
2826 "The calling package is not allowed to access ISD-R.");
2827 }
Derek Tan740e1672017-06-27 14:56:27 -07002828 }
Derek Tan740e1672017-06-27 14:56:27 -07002829
Malcolm Chenaabec062018-02-28 15:00:40 -08002830 if (DBG) {
2831 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2832 }
2833 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2834 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2835 if (DBG) log("iccOpenLogicalChannel: " + response);
2836 return response;
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
2839 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002840 }
2841
2842 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002843 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2845 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002846
Malcolm Chenaabec062018-02-28 15:00:40 -08002847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2850 if (channel < 0) {
2851 return false;
2852 }
2853 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2854 if (DBG) log("iccCloseLogicalChannel: " + success);
2855 return success;
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002858 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002859 }
2860
2861 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002862 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002863 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2865 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002866
Malcolm Chenaabec062018-02-28 15:00:40 -08002867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 if (DBG) {
2870 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2871 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2872 + p3 + " data=" + data);
2873 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002874
Malcolm Chenaabec062018-02-28 15:00:40 -08002875 if (channel < 0) {
2876 return "";
2877 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002878
Malcolm Chenaabec062018-02-28 15:00:40 -08002879 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2880 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2881 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002882
Malcolm Chenaabec062018-02-28 15:00:40 -08002883 // Append the returned status code to the end of the response payload.
2884 String s = Integer.toHexString(
2885 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2886 if (response.payload != null) {
2887 s = IccUtils.bytesToHexString(response.payload) + s;
2888 }
2889 return s;
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002892 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002893 }
Jake Hambye994d462014-02-03 13:10:13 -08002894
Evan Charltonc66da362014-05-16 14:06:40 -07002895 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002896 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2897 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2899 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002900 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002901
Malcolm Chenaabec062018-02-28 15:00:40 -08002902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2905 && TextUtils.equals(ISDR_AID, data)) {
2906 // Only allows LPA to select ISD-R.
2907 ComponentInfo bestComponent =
2908 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2909 if (bestComponent == null
2910 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2911 loge("The calling package is not allowed to select ISD-R.");
2912 throw new SecurityException(
2913 "The calling package is not allowed to select ISD-R.");
2914 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002915 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002916
Malcolm Chenaabec062018-02-28 15:00:40 -08002917 if (DBG) {
2918 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2919 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2920 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002921
Malcolm Chenaabec062018-02-28 15:00:40 -08002922 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2923 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2924 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002925
Malcolm Chenaabec062018-02-28 15:00:40 -08002926 // Append the returned status code to the end of the response payload.
2927 String s = Integer.toHexString(
2928 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2929 if (response.payload != null) {
2930 s = IccUtils.bytesToHexString(response.payload) + s;
2931 }
2932 return s;
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002935 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002936 }
2937
2938 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002939 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002940 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2942 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002943
Malcolm Chenaabec062018-02-28 15:00:40 -08002944 final long identity = Binder.clearCallingIdentity();
2945 try {
2946 if (DBG) {
2947 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2948 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2949 }
2950
2951 IccIoResult response =
2952 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2953 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2954 subId);
2955
2956 if (DBG) {
2957 log("Exchange SIM_IO [R]" + response);
2958 }
2959
2960 byte[] result = null;
2961 int length = 2;
2962 if (response.payload != null) {
2963 length = 2 + response.payload.length;
2964 result = new byte[length];
2965 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2966 } else {
2967 result = new byte[length];
2968 }
2969
2970 result[length - 1] = (byte) response.sw2;
2971 result[length - 2] = (byte) response.sw1;
2972 return result;
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002975 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002976 }
2977
Nathan Haroldb3014052017-01-25 15:57:32 -08002978 /**
2979 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2980 * on a particular subscription
2981 */
sqianb6e41952018-03-12 14:54:01 -07002982 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2984 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2985 return null;
2986 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002987 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2988 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2989 return null;
2990 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002991
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2995 if (response instanceof String[]) {
2996 return (String[]) response;
2997 }
2998 // Response is an Exception of some kind,
2999 // which is signalled to the user as a NULL retval
3000 return null;
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003003 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003004 }
3005
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003006 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003007 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3009 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003010
Malcolm Chenaabec062018-02-28 15:00:40 -08003011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3014 if (response.payload == null) {
3015 return "";
3016 }
Evan Charltonc66da362014-05-16 14:06:40 -07003017
Malcolm Chenaabec062018-02-28 15:00:40 -08003018 // Append the returned status code to the end of the response payload.
3019 String s = Integer.toHexString(
3020 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3021 s = IccUtils.bytesToHexString(response.payload) + s;
3022 return s;
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
Evan Charltonc66da362014-05-16 14:06:40 -07003026 }
3027
Jake Hambye994d462014-02-03 13:10:13 -08003028 /**
3029 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3030 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3031 *
3032 * @param itemID the ID of the item to read
3033 * @return the NV item as a String, or null on error.
3034 */
3035 @Override
3036 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3038 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003039
3040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 if (DBG) log("nvReadItem: item " + itemID);
3043 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3044 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3045 return value;
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
Jake Hambye994d462014-02-03 13:10:13 -08003049 }
3050
3051 /**
3052 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3053 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3054 *
3055 * @param itemID the ID of the item to read
3056 * @param itemValue the value to write, as a String
3057 * @return true on success; false on any failure
3058 */
3059 @Override
3060 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3062 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003063
3064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3067 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3068 new Pair<Integer, String>(itemID, itemValue));
3069 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3070 return success;
3071 } finally {
3072 Binder.restoreCallingIdentity(identity);
3073 }
Jake Hambye994d462014-02-03 13:10:13 -08003074 }
3075
3076 /**
3077 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3078 * Used for device configuration by some CDMA operators.
3079 *
3080 * @param preferredRoamingList byte array containing the new PRL
3081 * @return true on success; false on any failure
3082 */
3083 @Override
3084 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3086 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003087
3088 final long identity = Binder.clearCallingIdentity();
3089 try {
3090 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3091 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3092 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3093 return success;
3094 } finally {
3095 Binder.restoreCallingIdentity(identity);
3096 }
Jake Hambye994d462014-02-03 13:10:13 -08003097 }
3098
3099 /**
3100 * Perform the specified type of NV config reset.
3101 * Used for device configuration by some CDMA operators.
3102 *
3103 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3104 * @return true on success; false on any failure
3105 */
3106 @Override
3107 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3109 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003110
3111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 if (DBG) log("nvResetConfig: type " + resetType);
3114 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3115 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3116 return success;
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
Jake Hambye994d462014-02-03 13:10:13 -08003120 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003121
Svet Ganovb320e182015-04-16 12:30:10 -07003122 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003124 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003125 return new String[0];
3126 }
3127
Malcolm Chenaabec062018-02-28 15:00:40 -08003128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 return mPhone.getPcscfAddress(apnType);
3131 } finally {
3132 Binder.restoreCallingIdentity(identity);
3133 }
Wink Saville36469e72014-06-11 15:17:00 -07003134 }
3135
Brad Ebinger51f743a2017-01-23 13:50:20 -08003136 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003137 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3138 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003139 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003140 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003141 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003142
3143 final long identity = Binder.clearCallingIdentity();
3144 try {
3145 PhoneFactory.getImsResolver().enableIms(slotId);
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
3148 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003149 }
3150
3151 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003152 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3153 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003154 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003155 public void disableIms(int slotId) {
3156 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003157
3158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 PhoneFactory.getImsResolver().disableIms(slotId);
3161 } finally {
3162 Binder.restoreCallingIdentity(identity);
3163 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003164 }
3165
3166 /**
3167 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3168 * feature or {@link null} if the service is not available. If the feature is available, the
3169 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3170 */
3171 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003172 IImsServiceFeatureCallback callback) {
3173 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003174
3175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3178 } finally {
3179 Binder.restoreCallingIdentity(identity);
3180 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003181 }
3182
3183 /**
3184 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3185 * feature during emergency calling or {@link null} if the service is not available. If the
3186 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3187 * listener for feature updates.
3188 */
3189 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3190 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003191
3192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
3197 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003198 }
3199
Brad Ebinger5f64b052017-12-14 14:26:15 -08003200 /**
3201 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3202 * specified.
3203 */
3204 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3205 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003206
3207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
3212 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003213 }
3214
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003215 /**
3216 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3217 * specified.
3218 */
3219 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3220 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003221
3222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3225 } finally {
3226 Binder.restoreCallingIdentity(identity);
3227 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003228 }
3229
Brad Ebinger884c07b2018-02-15 16:17:40 -08003230 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003231 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3232 * available, false if the IMS resolver is idle.
3233 */
3234 public boolean isResolvingImsBinding() {
3235 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003236
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 return PhoneFactory.getImsResolver().isResolvingBinding();
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
Brad Ebinger67801702018-03-02 13:43:36 -08003243 }
3244
Brad Ebingerdac2f002018-04-03 15:17:52 -07003245 /**
3246 * Sets the ImsService Package Name that Telephony will bind to.
3247 *
3248 * @param slotId the slot ID that the ImsService should bind for.
3249 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3250 * ImsService is the device default ImsService.
3251 * @param packageName The package name of the application that contains the ImsService to bind
3252 * to.
3253 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3254 * @hide
3255 */
3256 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003257 int[] subIds = SubscriptionManager.getSubId(slotId);
3258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3259 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3260 "setImsService");
3261
Malcolm Chenaabec062018-02-28 15:00:40 -08003262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3265 isCarrierImsService, packageName);
3266 } finally {
3267 Binder.restoreCallingIdentity(identity);
3268 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003269 }
3270
3271 /**
3272 * Return the ImsService configuration.
3273 *
3274 * @param slotId The slot that the ImsService is associated with.
3275 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3276 * the device default.
3277 * @return the package name of the ImsService configuration.
3278 */
3279 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003280 int[] subIds = SubscriptionManager.getSubId(slotId);
3281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3282 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3283 "getImsService");
3284
Malcolm Chenaabec062018-02-28 15:00:40 -08003285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3288 isCarrierImsService);
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
3291 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003292 }
3293
Wink Saville36469e72014-06-11 15:17:00 -07003294 public void setImsRegistrationState(boolean registered) {
3295 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003296
3297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 mPhone.setImsRegistrationState(registered);
3300 } finally {
3301 Binder.restoreCallingIdentity(identity);
3302 }
Wink Saville36469e72014-06-11 15:17:00 -07003303 }
3304
3305 /**
Stuart Scott54788802015-03-30 13:18:01 -07003306 * Set the network selection mode to automatic.
3307 *
3308 */
3309 @Override
3310 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3312 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003313
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3317 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
Stuart Scott54788802015-03-30 13:18:01 -07003321 }
3322
3323 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003324 * Set the network selection mode to manual with the selected carrier.
3325 */
3326 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003327 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003328 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3330 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaabec062018-02-28 15:00:40 -08003331
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003335 /* operatorAlphaLong */ "",
3336 /* operatorAlphaShort */ "",
Malcolm Chenaabec062018-02-28 15:00:40 -08003337 operatorNumeric);
3338 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3339 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3340 persistSelection);
3341 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003345 }
3346
3347 /**
3348 * Scans for available networks.
3349 */
3350 @Override
3351 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3353 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003354
Pengquan Meng0c05b502018-09-06 09:59:22 -07003355 long identity = Binder.clearCallingIdentity();
Malcolm Chenaabec062018-02-28 15:00:40 -08003356 try {
3357 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003358 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaabec062018-02-28 15:00:40 -08003359 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08003360 } finally {
3361 Binder.restoreCallingIdentity(identity);
3362 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003363 }
3364
3365 /**
yinxub1bed742017-04-17 11:45:04 -07003366 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003367 *
yinxub1bed742017-04-17 11:45:04 -07003368 * @param subId id of the subscription
3369 * @param request contains the radio access networks with bands/channels to scan
3370 * @param messenger callback messenger for scan results or errors
3371 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003372 * @return the id of the requested scan which can be used to stop the scan.
3373 */
3374 @Override
3375 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3376 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3378 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003379
3380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 return mNetworkScanRequestTracker.startNetworkScan(
3383 request, messenger, binder, getPhone(subId));
3384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
yinxu504e1392017-04-12 16:03:22 -07003387 }
3388
3389 /**
3390 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003391 *
3392 * @param subId id of the subscription
3393 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003394 */
3395 @Override
3396 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3398 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003399
3400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
yinxu504e1392017-04-12 16:03:22 -07003406 }
3407
3408 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003409 * Get the calculated preferred network type.
3410 * Used for debugging incorrect network type.
3411 *
3412 * @return the preferred network type, defined in RILConstants.java.
3413 */
3414 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003415 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003417 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003418 return RILConstants.PREFERRED_NETWORK_MODE;
3419 }
3420
Malcolm Chenaabec062018-02-28 15:00:40 -08003421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 // FIXME: need to get SubId from somewhere.
3424 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
Junda Liu84d15a22014-07-02 11:21:04 -07003428 }
3429
3430 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003431 * Get the preferred network type.
3432 * Used for device configuration by some CDMA operators.
3433 *
3434 * @return the preferred network type, defined in RILConstants.java.
3435 */
3436 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003437 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3439 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 if (DBG) log("getPreferredNetworkType");
3444 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3445 int networkType = (result != null ? result[0] : -1);
3446 if (DBG) log("getPreferredNetworkType: " + networkType);
3447 return networkType;
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003451 }
3452
3453 /**
3454 * Set the preferred network type.
3455 * Used for device configuration by some CDMA operators.
3456 *
3457 * @param networkType the preferred network type, defined in RILConstants.java.
3458 * @return true on success; false on any failure.
3459 */
3460 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003461 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3463 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003464
3465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3468 Boolean success = (Boolean) sendRequest(
3469 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3470 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3471 if (success) {
3472 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3473 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3474 }
3475 return success;
3476 } finally {
3477 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003478 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003479 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003480
3481 /**
Junda Liu475951f2014-11-07 16:45:03 -08003482 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3483 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3484 * tethering.
3485 *
3486 * @return 0: Not required. 1: required. 2: Not set.
3487 * @hide
3488 */
3489 @Override
3490 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003491 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003492
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3496 Settings.Global.TETHER_DUN_REQUIRED, 2);
3497 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3498 // config_tether_apndata.
3499 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3500 dunRequired = 1;
3501 }
3502 return dunRequired;
3503 } finally {
3504 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003505 }
Junda Liu475951f2014-11-07 16:45:03 -08003506 }
3507
3508 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003509 * Set mobile data enabled
3510 * Used by the user through settings etc to turn on/off mobile data
3511 *
3512 * @param enable {@code true} turn turn data on, else {@code false}
3513 */
3514 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003515 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3517 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003518
3519 final long identity = Binder.clearCallingIdentity();
3520 try {
3521 int phoneId = mSubscriptionController.getPhoneId(subId);
3522 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3523 Phone phone = PhoneFactory.getPhone(phoneId);
3524 if (phone != null) {
3525 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3526 phone.setUserDataEnabled(enable);
3527 } else {
3528 loge("setUserDataEnabled: no phone for subId=" + subId);
3529 }
3530 } finally {
3531 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003532 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003533 }
3534
3535 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003536 * Get the user enabled state of Mobile Data.
3537 *
3538 * TODO: remove and use isUserDataEnabled.
3539 * This can't be removed now because some vendor codes
3540 * calls through ITelephony directly while they should
3541 * use TelephonyManager.
3542 *
3543 * @return true on enabled
3544 */
3545 @Override
3546 public boolean getDataEnabled(int subId) {
3547 return isUserDataEnabled(subId);
3548 }
3549
3550 /**
3551 * Get whether mobile data is enabled per user setting.
3552 *
3553 * There are other factors deciding whether mobile data is actually enabled, but they are
3554 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003555 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003556 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003557 *
3558 * @return {@code true} if data is enabled else {@code false}
3559 */
3560 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003561 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003562 try {
3563 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3564 null);
3565 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3567 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003568 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003569
3570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 int phoneId = mSubscriptionController.getPhoneId(subId);
3573 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3574 Phone phone = PhoneFactory.getPhone(phoneId);
3575 if (phone != null) {
3576 boolean retVal = phone.isUserDataEnabled();
3577 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3578 return retVal;
3579 } else {
3580 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3581 return false;
3582 }
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003585 }
3586 }
3587
3588 /**
3589 * Get whether mobile data is enabled.
3590 *
3591 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3592 * whether mobile data is actually enabled.
3593 *
3594 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3595 *
3596 * @return {@code true} if data is enabled else {@code false}
3597 */
3598 @Override
3599 public boolean isDataEnabled(int subId) {
3600 try {
3601 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3602 null);
3603 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3605 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003606 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003607
3608 final long identity = Binder.clearCallingIdentity();
3609 try {
3610 int phoneId = mSubscriptionController.getPhoneId(subId);
3611 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3612 Phone phone = PhoneFactory.getPhone(phoneId);
3613 if (phone != null) {
3614 boolean retVal = phone.isDataEnabled();
3615 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3616 return retVal;
3617 } else {
3618 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3619 return false;
3620 }
3621 } finally {
3622 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003623 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003624 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003625
3626 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003627 public int getCarrierPrivilegeStatus(int subId) {
3628 final Phone phone = getPhone(subId);
3629 if (phone == null) {
3630 loge("getCarrierPrivilegeStatus: Invalid subId");
3631 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3632 }
3633 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003634 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003635 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003636 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3637 }
3638 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003639 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003640 }
Junda Liu29340342014-07-10 15:23:27 -07003641
3642 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003643 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3644 final Phone phone = getPhone(subId);
3645 if (phone == null) {
3646 loge("getCarrierPrivilegeStatus: Invalid subId");
3647 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3648 }
3649 UiccProfile profile =
3650 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3651 if (profile == null) {
3652 loge("getCarrierPrivilegeStatus: No UICC");
3653 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3654 }
3655 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3656 }
3657
3658 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003659 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003660 if (TextUtils.isEmpty(pkgName))
3661 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003662 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003663 if (card == null) {
3664 loge("checkCarrierPrivilegesForPackage: No UICC");
3665 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3666 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003667 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3668 }
3669
3670 @Override
3671 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003672 if (TextUtils.isEmpty(pkgName))
3673 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003674 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3675 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3676 UiccCard card = UiccController.getInstance().getUiccCard(i);
3677 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003678 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003679 continue;
3680 }
3681
3682 result = card.getCarrierPrivilegeStatus(
3683 mPhone.getContext().getPackageManager(), pkgName);
3684 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3685 break;
3686 }
3687 }
3688
3689 return result;
Junda Liu29340342014-07-10 15:23:27 -07003690 }
Derek Tan89e89d42014-07-08 17:00:10 -07003691
3692 @Override
Junda Liue64de782015-04-16 17:19:16 -07003693 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3694 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3695 loge("phoneId " + phoneId + " is not valid.");
3696 return null;
3697 }
3698 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003699 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003700 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003701 return null ;
3702 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003703 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003704 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003705 }
3706
Amith Yamasani6e118872016-02-19 12:53:51 -08003707 @Override
3708 public List<String> getPackagesWithCarrierPrivileges() {
3709 PackageManager pm = mPhone.getContext().getPackageManager();
3710 List<String> privilegedPackages = new ArrayList<>();
3711 List<PackageInfo> packages = null;
3712 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3713 UiccCard card = UiccController.getInstance().getUiccCard(i);
3714 if (card == null) {
3715 // No UICC in that slot.
3716 continue;
3717 }
3718 if (card.hasCarrierPrivilegeRules()) {
3719 if (packages == null) {
3720 // Only check packages in user 0 for now
3721 packages = pm.getInstalledPackagesAsUser(
3722 PackageManager.MATCH_DISABLED_COMPONENTS
3723 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3724 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3725 }
3726 for (int p = packages.size() - 1; p >= 0; p--) {
3727 PackageInfo pkgInfo = packages.get(p);
3728 if (pkgInfo != null && pkgInfo.packageName != null
3729 && card.getCarrierPrivilegeStatus(pkgInfo)
3730 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3731 privilegedPackages.add(pkgInfo.packageName);
3732 }
3733 }
3734 }
3735 }
3736 return privilegedPackages;
3737 }
3738
Wink Savilleb564aae2014-10-23 10:18:09 -07003739 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003740 final Phone phone = getPhone(subId);
3741 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003742 if (card == null) {
3743 loge("getIccId: No UICC");
3744 return null;
3745 }
3746 String iccId = card.getIccId();
3747 if (TextUtils.isEmpty(iccId)) {
3748 loge("getIccId: ICC ID is null or empty.");
3749 return null;
3750 }
3751 return iccId;
3752 }
3753
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003754 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003755 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3756 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003757 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3758 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003759
Malcolm Chenaabec062018-02-28 15:00:40 -08003760 final long identity = Binder.clearCallingIdentity();
3761 try {
3762 final String iccId = getIccId(subId);
3763 final Phone phone = getPhone(subId);
3764 if (phone == null) {
3765 return false;
3766 }
3767 final String subscriberId = phone.getSubscriberId();
3768
3769 if (DBG_MERGE) {
3770 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3771 + subscriberId + " to " + number);
3772 }
3773
3774 if (TextUtils.isEmpty(iccId)) {
3775 return false;
3776 }
3777
3778 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3779
3780 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3781 if (alphaTag == null) {
3782 editor.remove(alphaTagPrefKey);
3783 } else {
3784 editor.putString(alphaTagPrefKey, alphaTag);
3785 }
3786
3787 // Record both the line number and IMSI for this ICCID, since we need to
3788 // track all merged IMSIs based on line number
3789 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3790 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3791 if (number == null) {
3792 editor.remove(numberPrefKey);
3793 editor.remove(subscriberPrefKey);
3794 } else {
3795 editor.putString(numberPrefKey, number);
3796 editor.putString(subscriberPrefKey, subscriberId);
3797 }
3798
3799 editor.commit();
3800 return true;
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003803 }
Derek Tan7226c842014-07-02 17:42:23 -07003804 }
3805
3806 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003807 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003808 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003810 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003811 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003812 return null;
3813 }
Derek Tan97ebb422014-09-05 16:55:38 -07003814
Malcolm Chenaabec062018-02-28 15:00:40 -08003815 final long identity = Binder.clearCallingIdentity();
3816 try {
3817 String iccId = getIccId(subId);
3818 if (iccId != null) {
3819 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3820 if (DBG_MERGE) {
3821 log("getLine1NumberForDisplay returning "
3822 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3823 }
3824 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003825 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003826 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3827 return null;
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003830 }
Derek Tan7226c842014-07-02 17:42:23 -07003831 }
3832
3833 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003834 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003836 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003837 return null;
3838 }
Derek Tan97ebb422014-09-05 16:55:38 -07003839
Malcolm Chenaabec062018-02-28 15:00:40 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 String iccId = getIccId(subId);
3843 if (iccId != null) {
3844 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3845 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3846 }
3847 return null;
3848 } finally {
3849 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003850 }
Derek Tan7226c842014-07-02 17:42:23 -07003851 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003852
3853 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003854 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003855 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3856 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003858 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3859 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003860 return null;
3861 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003862
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003863 final long identity = Binder.clearCallingIdentity();
3864 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003865 final Context context = mPhone.getContext();
3866 final TelephonyManager tele = TelephonyManager.from(context);
3867 final SubscriptionManager sub = SubscriptionManager.from(context);
3868
3869 // Figure out what subscribers are currently active
3870 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3871 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3872 // the process, where TelephonyManager was instantiated.
3873 // Otherwise AppOps check will fail.
3874
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003875 final int[] subIds = sub.getActiveSubscriptionIdList();
3876 for (int subId : subIds) {
3877 activeSubscriberIds.add(tele.getSubscriberId(subId));
3878 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003879
3880 // First pass, find a number override for an active subscriber
3881 String mergeNumber = null;
3882 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3883 for (String key : prefs.keySet()) {
3884 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3885 final String subscriberId = (String) prefs.get(key);
3886 if (activeSubscriberIds.contains(subscriberId)) {
3887 final String iccId = key.substring(
3888 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3889 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3890 mergeNumber = (String) prefs.get(numberKey);
3891 if (DBG_MERGE) {
3892 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3893 + " for active subscriber " + subscriberId);
3894 }
3895 if (!TextUtils.isEmpty(mergeNumber)) {
3896 break;
3897 }
3898 }
3899 }
3900 }
3901
3902 // Shortcut when no active merged subscribers
3903 if (TextUtils.isEmpty(mergeNumber)) {
3904 return null;
3905 }
3906
3907 // Second pass, find all subscribers under that line override
3908 final ArraySet<String> result = new ArraySet<>();
3909 for (String key : prefs.keySet()) {
3910 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3911 final String number = (String) prefs.get(key);
3912 if (mergeNumber.equals(number)) {
3913 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3914 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3915 final String subscriberId = (String) prefs.get(subscriberKey);
3916 if (!TextUtils.isEmpty(subscriberId)) {
3917 result.add(subscriberId);
3918 }
3919 }
3920 }
3921 }
3922
3923 final String[] resultArray = result.toArray(new String[result.size()]);
3924 Arrays.sort(resultArray);
3925 if (DBG_MERGE) {
3926 Slog.d(LOG_TAG,
3927 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3928 }
3929 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003930 } finally {
3931 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003932 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003933 }
3934
3935 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003936 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003937 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3938 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003939
3940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 final Phone phone = getPhone(subId);
3943 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003947 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003948
3949 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003950 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003951 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3952 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003953 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003954
3955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 final Phone phone = getPhone(subId);
3958 if (phone == null) {
3959 return false;
3960 }
3961 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3962 cdmaNonRoamingList);
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003965 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003966 }
3967
3968 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003969 @Deprecated
3970 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3971 enforceModifyPermission();
3972
3973 int returnValue = 0;
3974 try {
3975 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3976 if(result.exception == null) {
3977 if (result.result != null) {
3978 byte[] responseData = (byte[])(result.result);
3979 if(responseData.length > oemResp.length) {
3980 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3981 responseData.length + "bytes. Buffer Size is " +
3982 oemResp.length + "bytes.");
3983 }
3984 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3985 returnValue = responseData.length;
3986 }
3987 } else {
3988 CommandException ex = (CommandException) result.exception;
3989 returnValue = ex.getCommandError().ordinal();
3990 if(returnValue > 0) returnValue *= -1;
3991 }
3992 } catch (RuntimeException e) {
3993 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3994 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3995 if(returnValue > 0) returnValue *= -1;
3996 }
3997
3998 return returnValue;
3999 }
4000
4001 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004002 public void setRadioCapability(RadioAccessFamily[] rafs) {
4003 try {
4004 ProxyController.getInstance().setRadioCapability(rafs);
4005 } catch (RuntimeException e) {
4006 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4007 }
4008 }
4009
4010 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004011 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004012 Phone phone = PhoneFactory.getPhone(phoneId);
4013 if (phone == null) {
4014 return RadioAccessFamily.RAF_UNKNOWN;
4015 }
4016 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004018 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004019 return RadioAccessFamily.RAF_UNKNOWN;
4020 }
4021
Malcolm Chenaabec062018-02-28 15:00:40 -08004022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004028 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004029
4030 @Override
4031 public void enableVideoCalling(boolean enable) {
4032 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004033
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4037 } finally {
4038 Binder.restoreCallingIdentity(identity);
4039 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004040 }
4041
4042 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004043 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4045 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4046 return false;
4047 }
Svet Ganovb320e182015-04-16 12:30:10 -07004048
Malcolm Chenaabec062018-02-28 15:00:40 -08004049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 // Check the user preference and the system-level IMS setting. Even if the user has
4052 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4053 // In the long run, we may instead need to check if there exists a connection service
4054 // which can support video calling.
4055 ImsManager imsManager =
4056 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4057 return imsManager.isVtEnabledByPlatform()
4058 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4059 && imsManager.isVtEnabledByUser();
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
4062 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004063 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004064
Andrew Leea1239f22015-03-02 17:44:07 -08004065 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004066 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4068 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4069 return false;
4070 }
4071
4072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 CarrierConfigManager configManager =
4075 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4076 return configManager.getConfigForSubId(mPhone.getSubId())
4077 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
Andrew Leea1239f22015-03-02 17:44:07 -08004081 }
4082
4083 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004084 public boolean isWorldPhone(int subId, String callingPackage) {
4085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4086 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4087 return false;
4088 }
4089
4090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 CarrierConfigManager configManager =
4093 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4094 return configManager.getConfigForSubId(mPhone.getSubId())
4095 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
4098 }
Andrew Leea1239f22015-03-02 17:44:07 -08004099 }
4100
Andrew Lee9431b832015-03-09 18:46:45 -07004101 @Override
4102 public boolean isTtyModeSupported() {
4103 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004104 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004105 }
4106
4107 @Override
4108 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
Andrew Lee9431b832015-03-09 18:46:45 -07004115 }
4116
Hall Liu98187582018-01-22 19:15:32 -08004117 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4121 mPhone.getSubId()).getBoolean(
4122 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4123 boolean isDeviceSupported =
4124 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4125 return isCarrierSupported && isDeviceSupported;
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
Hall Liu98187582018-01-22 19:15:32 -08004129 }
4130
Hall Liu3ad5f012018-04-06 16:23:39 -07004131 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004132 final long identity = Binder.clearCallingIdentity();
4133 try {
4134 return isRttSupported() && Settings.Secure.getInt(
4135 mPhone.getContext().getContentResolver(),
4136 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004140 }
4141
Sanket Padawe7310cc72015-01-14 09:53:20 -08004142 /**
4143 * Returns the unique device ID of phone, for example, the IMEI for
4144 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4145 *
4146 * <p>Requires Permission:
4147 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4148 */
4149 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004150 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004151 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004152 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004153 return null;
4154 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004155 int subId = phone.getSubId();
4156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4157 mApp, subId, callingPackage, "getDeviceId")) {
4158 return null;
4159 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004160
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 return phone.getDeviceId();
4164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004167 }
4168
Ping Sunc67b7c22016-03-02 19:16:45 +08004169 /**
4170 * {@hide}
4171 * Returns the IMS Registration Status on a particular subid
4172 *
4173 * @param subId
4174 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004175 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004176 Phone phone = getPhone(subId);
4177 if (phone != null) {
4178 return phone.isImsRegistered();
4179 } else {
4180 return false;
4181 }
4182 }
4183
Santos Cordon7a1885b2015-02-03 11:15:19 -08004184 @Override
4185 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004192 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004193
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004194 /**
4195 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004196 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004197 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 Phone phone = getPhone(subId);
4201 if (phone != null) {
4202 return phone.isWifiCallingEnabled();
4203 } else {
4204 return false;
4205 }
4206 } finally {
4207 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004208 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004209 }
4210
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004211 /**
4212 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004213 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004214 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 Phone phone = getPhone(subId);
4218 if (phone != null) {
4219 return phone.isVolteEnabled();
4220 } else {
4221 return false;
4222 }
4223 } finally {
4224 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004225 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004226 }
Svet Ganovb320e182015-04-16 12:30:10 -07004227
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004228 /**
4229 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004230 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004231 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004232 final long identity = Binder.clearCallingIdentity();
4233 try {
4234 Phone phone = getPhone(subId);
4235 if (phone != null) {
4236 return phone.isVideoEnabled();
4237 } else {
4238 return false;
4239 }
4240 } finally {
4241 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004242 }
4243 }
4244
4245 /**
4246 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4247 * defined in {@link ImsRegistrationImplBase}.
4248 */
4249 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004250 final long identity = Binder.clearCallingIdentity();
4251 try {
4252 Phone phone = getPhone(subId);
4253 if (phone != null) {
4254 return phone.getImsRegistrationTech();
4255 } else {
4256 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4257 }
4258 } finally {
4259 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004260 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004261 }
4262
Stuart Scott8eef64f2015-04-08 15:13:54 -07004263 @Override
4264 public void factoryReset(int subId) {
4265 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004266 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4267 return;
4268 }
4269
Svet Ganovcc087f82015-05-12 20:35:54 -07004270 final long identity = Binder.clearCallingIdentity();
4271 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004272 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4273 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004274 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004275 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004276 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4277 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004278 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004279 }
4280 } finally {
4281 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004282 }
4283 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004284
4285 @Override
4286 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004287 final long identity = Binder.clearCallingIdentity();
4288 try {
4289 // We query all subscriptions instead of just the active ones, because
4290 // this might be called early on in the provisioning flow when the
4291 // subscriptions potentially aren't active yet.
4292 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4293 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004294 return null;
4295 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004296
Malcolm Chenaabec062018-02-28 15:00:40 -08004297 // This function may be called very early, say, from the setup wizard, at
4298 // which point we won't have a default subscription set. If that's the case
4299 // we just choose the first, which will be valid in "most cases".
4300 final int defaultSubId = getDefaultSubscription();
4301 SubscriptionInfo info = null;
4302 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4303 info = slist.get(0);
4304 } else {
4305 for (SubscriptionInfo item : slist) {
4306 if (item.getSubscriptionId() == defaultSubId) {
4307 info = item;
4308 break;
4309 }
4310 }
4311
4312 if (info == null) {
4313 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004314 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004315 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004316
Malcolm Chenaabec062018-02-28 15:00:40 -08004317 // Try and fetch the locale from the carrier properties or from the SIM language
4318 // preferences (EF-PL and EF-LI)...
4319 final int mcc = info.getMcc();
4320 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4321 String simLanguage = null;
4322 if (defaultPhone != null) {
4323 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4324 if (localeFromDefaultSim != null) {
4325 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4326 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4327 return localeFromDefaultSim.toLanguageTag();
4328 } else {
4329 simLanguage = localeFromDefaultSim.getLanguage();
4330 }
4331 }
4332 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004333
Malcolm Chenaabec062018-02-28 15:00:40 -08004334 // The SIM language preferences only store a language (e.g. fr = French), not an
4335 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4336 // the SIM and carrier preferences does not include a country we add the country
4337 // determined from the SIM MCC to provide an exact locale.
4338 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4339 simLanguage);
4340 if (mccLocale != null) {
4341 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4342 return mccLocale.toLanguageTag();
4343 }
4344
4345 if (DBG) log("No locale found - returning null");
4346 return null;
4347 } finally {
4348 Binder.restoreCallingIdentity(identity);
4349 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004350 }
4351
4352 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004353 return mSubscriptionController.getAllSubInfoList(
4354 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004355 }
4356
Malcolm Chenaabec062018-02-28 15:00:40 -08004357 /**
4358 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4359 */
4360 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4361 return mSubscriptionController.getActiveSubscriptionInfoList(
4362 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004363 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004364
Chenjie Yu1ba97252018-01-11 18:16:20 -08004365 private final ModemActivityInfo mLastModemActivityInfo =
4366 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4367
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004368 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004369 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4370 * representing the state of the modem.
4371 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004372 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4373 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004374 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004375 */
4376 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004377 public void requestModemActivityInfo(ResultReceiver result) {
4378 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004379 ModemActivityInfo ret = null;
Adam Lesinski903a54c2016-04-11 14:49:52 -07004380
Malcolm Chenaabec062018-02-28 15:00:40 -08004381 final long identity = Binder.clearCallingIdentity();
4382 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004383 synchronized (mLastModemActivityInfo) {
4384 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
4385 null);
Siddharth Rayc339f892018-06-17 15:02:38 -07004386 if (isModemActivityInfoValid(info)) {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004387 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4388 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4389 mergedTxTimeMs[i] =
4390 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4391 }
4392 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4393 mLastModemActivityInfo.setSleepTimeMillis(
4394 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4395 mLastModemActivityInfo.setIdleTimeMillis(
4396 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4397 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4398 mLastModemActivityInfo.setRxTimeMillis(
4399 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4400 mLastModemActivityInfo.setEnergyUsed(
4401 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004402 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004403 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4404 mLastModemActivityInfo.getSleepTimeMillis(),
4405 mLastModemActivityInfo.getIdleTimeMillis(),
4406 mLastModemActivityInfo.getTxTimeMillis(),
4407 mLastModemActivityInfo.getRxTimeMillis(),
4408 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004409 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004410 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004411 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004412 result.send(0, bundle);
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004415 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004416 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004417
Siddharth Rayc339f892018-06-17 15:02:38 -07004418 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4419 // less than total activity duration.
4420 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4421 if (info == null) {
4422 return false;
4423 }
4424 int activityDurationMs =
4425 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4426 int totalTxTimeMs = 0;
4427 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4428 totalTxTimeMs += info.getTxTimeMillis()[i];
4429 }
4430 return (info.isValid()
4431 && (info.getSleepTimeMillis() <= activityDurationMs)
4432 && (info.getIdleTimeMillis() <= activityDurationMs)
4433 && (info.getRxTimeMillis() <= activityDurationMs)
4434 && (totalTxTimeMs <= activityDurationMs));
4435 }
4436
Jack Yu85bd38a2015-11-09 11:34:32 -08004437 /**
4438 * {@hide}
4439 * Returns the service state information on specified subscription.
4440 */
4441 @Override
4442 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004444 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004445 return null;
4446 }
4447
Malcolm Chenaabec062018-02-28 15:00:40 -08004448 final long identity = Binder.clearCallingIdentity();
4449 try {
4450 final Phone phone = getPhone(subId);
4451 if (phone == null) {
4452 return null;
4453 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004454
Malcolm Chenaabec062018-02-28 15:00:40 -08004455 return phone.getServiceState();
4456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004459 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004460
4461 /**
4462 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4463 *
4464 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4465 * voicemail ringtone.
4466 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4467 * PhoneAccount.
4468 */
4469 @Override
4470 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004471 final long identity = Binder.clearCallingIdentity();
4472 try {
4473 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4474 if (phone == null) {
4475 phone = mPhone;
4476 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004477
Malcolm Chenaabec062018-02-28 15:00:40 -08004478 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4479 } finally {
4480 Binder.restoreCallingIdentity(identity);
4481 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004482 }
4483
4484 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004485 * Sets the per-account voicemail ringtone.
4486 *
4487 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4488 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4489 *
4490 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4491 * voicemail ringtone.
4492 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4493 * PhoneAccount.
4494 */
4495 @Override
4496 public void setVoicemailRingtoneUri(String callingPackage,
4497 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4498 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4499 if (!TextUtils.equals(callingPackage,
4500 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4502 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4503 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004504 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004505
4506 final long identity = Binder.clearCallingIdentity();
4507 try {
4508 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4509 if (phone == null) {
4510 phone = mPhone;
4511 }
4512 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4513 } finally {
4514 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004515 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004516 }
4517
4518 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004519 * Returns whether vibration is set for voicemail notification in Phone settings.
4520 *
4521 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4522 * voicemail vibration setting.
4523 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4524 */
4525 @Override
4526 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004527 final long identity = Binder.clearCallingIdentity();
4528 try {
4529 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4530 if (phone == null) {
4531 phone = mPhone;
4532 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004533
Malcolm Chenaabec062018-02-28 15:00:40 -08004534 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004538 }
4539
Youhan Wange64578a2016-05-02 15:32:42 -07004540 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004541 * Sets the per-account voicemail vibration.
4542 *
4543 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4544 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4545 *
4546 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4547 * voicemail vibration setting.
4548 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4549 * specific PhoneAccount.
4550 */
4551 @Override
4552 public void setVoicemailVibrationEnabled(String callingPackage,
4553 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4554 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4555 if (!TextUtils.equals(callingPackage,
4556 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4558 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4559 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004560 }
4561
Malcolm Chenaabec062018-02-28 15:00:40 -08004562 final long identity = Binder.clearCallingIdentity();
4563 try {
4564 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4565 if (phone == null) {
4566 phone = mPhone;
4567 }
4568 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4569 } finally {
4570 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004571 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004572 }
4573
4574 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004575 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4576 *
4577 * @throws SecurityException if the caller does not have the required permission
4578 */
4579 private void enforceReadPrivilegedPermission() {
4580 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4581 null);
4582 }
4583
4584 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004585 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4586 * permission.
4587 *
4588 * @throws SecurityException if the caller does not have the required permission
4589 */
4590 private void enforceSendSmsPermission() {
4591 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4592 }
4593
4594 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004595 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004596 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004597 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004598 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004599 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 ComponentName componentName =
4603 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4604 if (componentName == null) {
4605 throw new SecurityException(
4606 "Caller not current active visual voicemail package[null]");
4607 }
4608 String vvmPackage = componentName.getPackageName();
4609 if (!callingPackage.equals(vvmPackage)) {
4610 throw new SecurityException("Caller not current active visual voicemail package["
4611 + vvmPackage + "]");
4612 }
4613 } finally {
4614 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004615 }
4616 }
4617
4618 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004619 * Return the application ID for the app type.
4620 *
4621 * @param subId the subscription ID that this request applies to.
4622 * @param appType the uicc app type.
4623 * @return Application ID for specificied app type, or null if no uicc.
4624 */
4625 @Override
4626 public String getAidForAppType(int subId, int appType) {
4627 enforceReadPrivilegedPermission();
4628 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004629
4630 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004631 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004632 if (phone == null) {
4633 return null;
4634 }
4635 String aid = null;
4636 try {
4637 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4638 .getApplicationByType(appType).getAid();
4639 } catch (Exception e) {
4640 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4641 }
4642 return aid;
4643 } finally {
4644 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004645 }
Youhan Wange64578a2016-05-02 15:32:42 -07004646 }
4647
Youhan Wang4001d252016-05-11 10:29:41 -07004648 /**
4649 * Return the Electronic Serial Number.
4650 *
4651 * @param subId the subscription ID that this request applies to.
4652 * @return ESN or null if error.
4653 */
4654 @Override
4655 public String getEsn(int subId) {
4656 enforceReadPrivilegedPermission();
4657 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004658
4659 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004660 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004661 if (phone == null) {
4662 return null;
4663 }
4664 String esn = null;
4665 try {
4666 esn = phone.getEsn();
4667 } catch (Exception e) {
4668 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4669 }
4670 return esn;
4671 } finally {
4672 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004673 }
Youhan Wang4001d252016-05-11 10:29:41 -07004674 }
4675
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004676 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004677 * Return the Preferred Roaming List Version.
4678 *
4679 * @param subId the subscription ID that this request applies to.
4680 * @return PRLVersion or null if error.
4681 */
4682 @Override
4683 public String getCdmaPrlVersion(int subId) {
4684 enforceReadPrivilegedPermission();
4685 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004686
4687 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004688 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004689 if (phone == null) {
4690 return null;
4691 }
4692 String cdmaPrlVersion = null;
4693 try {
4694 cdmaPrlVersion = phone.getCdmaPrlVersion();
4695 } catch (Exception e) {
4696 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4697 }
4698 return cdmaPrlVersion;
4699 } finally {
4700 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004701 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004702 }
4703
4704 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004705 * Get snapshot of Telephony histograms
4706 * @return List of Telephony histograms
4707 * @hide
4708 */
4709 @Override
4710 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4712 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004713
4714 final long identity = Binder.clearCallingIdentity();
4715 try {
4716 return RIL.getTelephonyRILTimingHistograms();
4717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004720 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004721
4722 /**
4723 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004724 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004725 * Require system privileges. In the future we may add this to carrier APIs.
4726 *
4727 * @return The number of carriers set successfully, should match length of carriers
4728 */
4729 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004730 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004731 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004732
Meng Wang9b7c4e92017-02-17 11:41:27 -08004733 if (carriers == null) {
4734 throw new NullPointerException("carriers cannot be null");
4735 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004736
Malcolm Chenaabec062018-02-28 15:00:40 -08004737 final long identity = Binder.clearCallingIdentity();
4738 try {
4739 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4740 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4741 return retVal[0];
4742 } finally {
4743 Binder.restoreCallingIdentity(identity);
4744 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004745 }
4746
4747 /**
4748 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004749 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004750 * Require system privileges. In the future we may add this to carrier APIs.
4751 *
4752 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4753 * means all carriers are allowed.
4754 */
4755 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004756 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004757 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004758
4759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4762 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004766 }
4767
fionaxu59545b42016-05-25 15:53:37 -07004768 /**
4769 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4770 * @param subId the subscription ID that this action applies to.
4771 * @param enabled control enable or disable metered apns.
4772 * {@hide}
4773 */
4774 @Override
4775 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4776 enforceModifyPermission();
4777 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004778
4779 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004780 if (phone == null) {
4781 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4782 return;
4783 }
4784 try {
4785 phone.carrierActionSetMeteredApnsEnabled(enabled);
4786 } catch (Exception e) {
4787 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004788 } finally {
4789 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004790 }
4791 }
4792
4793 /**
4794 * Action set from carrier signalling broadcast receivers to enable/disable radio
4795 * @param subId the subscription ID that this action applies to.
4796 * @param enabled control enable or disable radio.
4797 * {@hide}
4798 */
4799 @Override
4800 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4801 enforceModifyPermission();
4802 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004803
4804 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004805 if (phone == null) {
4806 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4807 return;
4808 }
4809 try {
4810 phone.carrierActionSetRadioEnabled(enabled);
4811 } catch (Exception e) {
4812 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004813 } finally {
4814 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004815 }
4816 }
4817
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004818 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004819 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4820 * network status based on which carrier apps could apply actions accordingly,
4821 * enable/disable default url handler for example.
4822 *
4823 * @param subId the subscription ID that this action applies to.
4824 * @param report control start/stop reporting the default network status.
4825 * {@hide}
4826 */
4827 @Override
4828 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4829 enforceModifyPermission();
4830 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004831
4832 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004833 if (phone == null) {
4834 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4835 return;
4836 }
4837 try {
4838 phone.carrierActionReportDefaultNetworkStatus(report);
4839 } catch (Exception e) {
4840 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004841 } finally {
4842 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004843 }
4844 }
4845
4846 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004847 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4848 * bug report is being generated.
4849 */
4850 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004851 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004852 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4853 != PackageManager.PERMISSION_GRANTED) {
4854 writer.println("Permission Denial: can't dump Phone from pid="
4855 + Binder.getCallingPid()
4856 + ", uid=" + Binder.getCallingUid()
4857 + "without permission "
4858 + android.Manifest.permission.DUMP);
4859 return;
4860 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004861 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004862 }
Jack Yueb89b242016-06-22 13:27:47 -07004863
Brad Ebingerdac2f002018-04-03 15:17:52 -07004864 @Override
4865 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4866 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4867 throws RemoteException {
4868 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4869 }
4870
Jack Yueb89b242016-06-22 13:27:47 -07004871 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004872 * Get aggregated video call data usage since boot.
4873 *
4874 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4875 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004876 * {@hide}
4877 */
4878 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004879 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004880 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4881 null);
4882
Malcolm Chenaabec062018-02-28 15:00:40 -08004883 final long identity = Binder.clearCallingIdentity();
4884 try {
4885 // NetworkStatsService keeps tracking the active network interface and identity. It
4886 // records the delta with the corresponding network identity.
4887 // We just return the total video call data usage snapshot since boot.
4888 Phone phone = getPhone(subId);
4889 if (phone != null) {
4890 return phone.getVtDataUsage(perUidStats);
4891 }
4892 return null;
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004895 }
Jack Yueb89b242016-06-22 13:27:47 -07004896 }
Jack Yu75ab2952016-07-08 14:29:33 -07004897
4898 /**
4899 * Policy control of data connection. Usually used when data limit is passed.
4900 * @param enabled True if enabling the data, otherwise disabling.
4901 * @param subId Subscription index
4902 * {@hide}
4903 */
4904 @Override
4905 public void setPolicyDataEnabled(boolean enabled, int subId) {
4906 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004907
4908 final long identity = Binder.clearCallingIdentity();
4909 try {
4910 Phone phone = getPhone(subId);
4911 if (phone != null) {
4912 phone.setPolicyDataEnabled(enabled);
4913 }
4914 } finally {
4915 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004916 }
4917 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004918
4919 /**
4920 * Get Client request stats
4921 * @return List of Client Request Stats
4922 * @hide
4923 */
4924 @Override
4925 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004927 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004928 return null;
4929 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004930 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004931
Malcolm Chenaabec062018-02-28 15:00:40 -08004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 if (phone != null) {
4935 return phone.getClientRequestStats();
4936 }
4937
4938 return null;
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004942 }
4943
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004944 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004945 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004946 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004947 }
Jack Yueb4124c2017-02-16 15:32:43 -08004948
4949 /**
Grace Chen70990072017-03-24 17:21:30 -07004950 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004951 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004952 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004953 * @param state State of SIM (power down, power up, pass through)
4954 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4955 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4956 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004957 *
4958 **/
4959 @Override
Grace Chen70990072017-03-24 17:21:30 -07004960 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004961 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004962 Phone phone = PhoneFactory.getPhone(slotIndex);
4963
Malcolm Chenaabec062018-02-28 15:00:40 -08004964 final long identity = Binder.clearCallingIdentity();
4965 try {
4966 if (phone != null) {
4967 phone.setSimPowerState(state);
4968 }
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004971 }
4972 }
Shuo Qiandd210312017-04-12 22:11:33 +00004973
Tyler Gunn65d45c22017-06-05 11:22:26 -07004974 private boolean isUssdApiAllowed(int subId) {
4975 CarrierConfigManager configManager =
4976 (CarrierConfigManager) mPhone.getContext().getSystemService(
4977 Context.CARRIER_CONFIG_SERVICE);
4978 if (configManager == null) {
4979 return false;
4980 }
4981 PersistableBundle pb = configManager.getConfigForSubId(subId);
4982 if (pb == null) {
4983 return false;
4984 }
4985 return pb.getBoolean(
4986 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4987 }
4988
Shuo Qiandd210312017-04-12 22:11:33 +00004989 /**
4990 * Check if phone is in emergency callback mode
4991 * @return true if phone is in emergency callback mode
4992 * @param subId sub id
4993 */
goneil9c5f4872017-12-05 14:07:56 -08004994 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004995 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004996 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004997 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004998
4999 final long identity = Binder.clearCallingIdentity();
5000 try {
5001 if (phone != null) {
5002 return phone.isInEcm();
5003 } else {
5004 return false;
5005 }
5006 } finally {
5007 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005008 }
5009 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005010
5011 /**
5012 * Get the current signal strength information for the given subscription.
5013 * Because this information is not updated when the device is in a low power state
5014 * it should not be relied-upon to be current.
5015 * @param subId Subscription index
5016 * @return the most recent cached signal strength info from the modem
5017 */
5018 @Override
5019 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08005020 final long identity = Binder.clearCallingIdentity();
5021 try {
5022 Phone p = getPhone(subId);
5023 if (p == null) {
5024 return null;
5025 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005026
Malcolm Chenaabec062018-02-28 15:00:40 -08005027 return p.getSignalStrength();
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005031 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005032
Pengquan Meng9140aec2018-08-22 14:49:57 -07005033 /**
5034 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5035 *
5036 * <p>Requires one of the following permissions:
5037 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5038 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5039 * privileges.
5040 *
5041 * @param subId subscription id
5042 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5043 * {@code false}.
5044 */
5045 @Override
5046 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005047 boolean isEnabled = false;
5048 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005049 try {
5050 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005051 null /* message */);
5052 Phone phone = getPhone(subId);
5053 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005054 } catch (Exception e) {
5055 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5056 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005059 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005060 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005061 }
5062
5063
5064 /**
5065 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5066 *
5067 * <p> Requires permission:
5068 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5069 * privileges.
5070 *
5071 * @param subId subscription id
5072 * @param isEnabled {@code true} means enable, {@code false} means disable.
5073 */
5074 @Override
5075 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5079 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005080
Pengquan Meng0c05b502018-09-06 09:59:22 -07005081 Phone phone = getPhone(subId);
5082 if (phone != null) {
5083 phone.setDataRoamingEnabled(isEnabled);
5084 }
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005087 }
5088 }
5089
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005090 @Override
5091 public UiccSlotInfo[] getUiccSlotsInfo() {
5092 enforceReadPrivilegedPermission();
5093
Malcolm Chenaabec062018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005097 if (slots == null) {
5098 Rlog.i(LOG_TAG, "slots is null.");
5099 return null;
5100 }
5101
Malcolm Chenaabec062018-02-28 15:00:40 -08005102 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5103 for (int i = 0; i < slots.length; i++) {
5104 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005105 if (slot == null) {
5106 continue;
5107 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005108
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005109 String cardId;
5110 UiccCard card = slot.getUiccCard();
5111 if (card != null) {
5112 cardId = card.getCardId();
5113 } else {
5114 cardId = slot.getIccId();
5115 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005116
Malcolm Chenaabec062018-02-28 15:00:40 -08005117 int cardState = 0;
5118 switch (slot.getCardState()) {
5119 case CARDSTATE_ABSENT:
5120 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5121 break;
5122 case CARDSTATE_PRESENT:
5123 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5124 break;
5125 case CARDSTATE_ERROR:
5126 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5127 break;
5128 case CARDSTATE_RESTRICTED:
5129 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5130 break;
5131 default:
5132 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005133
Malcolm Chenaabec062018-02-28 15:00:40 -08005134 }
5135
5136 infos[i] = new UiccSlotInfo(
5137 slot.isActive(),
5138 slot.isEuicc(),
5139 cardId,
5140 cardState,
5141 slot.getPhoneId(),
5142 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005143 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005144 return infos;
5145 } finally {
5146 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005147 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005148 }
5149
5150 @Override
5151 public boolean switchSlots(int[] physicalSlots) {
5152 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005153
5154 final long identity = Binder.clearCallingIdentity();
5155 try {
5156 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
5159 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005160 }
Jack Yu4c988042018-02-27 15:30:01 -08005161
5162 @Override
5163 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5164 enforceModifyPermission();
5165 final Phone phone = getPhone(subId);
5166 if (phone == null) {
5167 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5168 return;
5169 }
5170
Malcolm Chenaabec062018-02-28 15:00:40 -08005171 final long identity = Binder.clearCallingIdentity();
5172 try {
5173 phone.setRadioIndicationUpdateMode(filters, mode);
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Jack Yu4c988042018-02-27 15:30:01 -08005177 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005178
5179 /**
goneil47ffb6e2018-04-06 15:40:58 -07005180 * A test API to reload the UICC profile.
5181 *
5182 * <p>Requires that the calling app has permission
5183 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5184 * @hide
5185 */
5186 @Override
5187 public void refreshUiccProfile(int subId) {
5188 enforceModifyPermission();
5189
5190 final long identity = Binder.clearCallingIdentity();
5191 try {
5192 Phone phone = getPhone(subId);
5193 if (phone == null) {
5194 return;
5195 }
5196 UiccCard uiccCard = phone.getUiccCard();
5197 if (uiccCard == null) {
5198 return;
5199 }
5200 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5201 if (uiccProfile == null) {
5202 return;
5203 }
5204 uiccProfile.refresh();
5205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
5208 }
5209
5210 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005211 * Returns false if the mobile data is disabled by default, otherwise return true.
5212 */
5213 private boolean getDefaultDataEnabled() {
5214 return "true".equalsIgnoreCase(
5215 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5216 }
5217
5218 /**
5219 * Returns true if the data roaming is enabled by default, i.e the system property
5220 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5221 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5222 */
5223 private boolean getDefaultDataRoamingEnabled(int subId) {
5224 final CarrierConfigManager configMgr = (CarrierConfigManager)
5225 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5226 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5227 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5228 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5229 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5230 return isDataRoamingEnabled;
5231 }
5232
5233 /**
5234 * Returns the default network type for the given {@code subId}, if the default network type is
5235 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5236 */
5237 private int getDefaultNetworkType(int subId) {
5238 return Integer.parseInt(
5239 TelephonyManager.getTelephonyProperty(
5240 mSubscriptionController.getPhoneId(subId),
5241 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5242 String.valueOf(Phone.PREFERRED_NT_MODE)));
5243 }
fionaxua13278b2018-03-21 00:08:13 -07005244
5245 @Override
5246 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5247 gid1, String gid2, String plmn, String spn) {
5248 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005249
5250 final long identity = Binder.clearCallingIdentity();
5251 try {
5252 final Phone phone = getPhone(subId);
5253 if (phone == null) {
5254 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5255 return;
5256 }
5257 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005260 }
fionaxua13278b2018-03-21 00:08:13 -07005261 }
5262
5263 @Override
5264 public int getCarrierIdListVersion(int subId) {
5265 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005266
5267 final long identity = Binder.clearCallingIdentity();
5268 try {
5269 final Phone phone = getPhone(subId);
5270 if (phone == null) {
5271 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5272 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5273 }
5274 return phone.getCarrierIdListVersion();
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005277 }
fionaxua13278b2018-03-21 00:08:13 -07005278 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005279
5280 @Override
5281 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5283 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5284 return -1;
5285 }
5286
5287 final long identity = Binder.clearCallingIdentity();
5288 try {
5289 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5290 } finally {
5291 Binder.restoreCallingIdentity(identity);
5292 }
5293 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005294
5295 @Override
5296 public int getCdmaRoamingMode(int subId) {
5297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5298 mApp, subId, "getCdmaRoamingMode");
5299
5300 final long identity = Binder.clearCallingIdentity();
5301 try {
5302 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
5306 }
5307
5308 @Override
5309 public boolean setCdmaRoamingMode(int subId, int mode) {
5310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5311 mApp, subId, "setCdmaRoamingMode");
5312
5313 final long identity = Binder.clearCallingIdentity();
5314 try {
5315 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
5319 }
5320
5321 @Override
5322 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5324 mApp, subId, "setCdmaSubscriptionMode");
5325
5326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
5331 }
5332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005333}