blob: e6f90793b818cb814e0d492ad7c5520eea0f9504 [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 Chen2c63d402018-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 Menga1bb6272018-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 Chen2c63d402018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-09-06 09:59:22 -0700349 request.result = true;
350 notifyRequester(request);
351 return;
352 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700353
Pengquan Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Chen2c63d402018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001206 if (!isValid) {
1207 return;
1208 }
Wink Saville08874612014-08-31 19:19:58 -07001209
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001238
1239 final long identity = Binder.clearCallingIdentity();
1240 try {
1241 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1242 } finally {
1243 Binder.restoreCallingIdentity(identity);
1244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 }
1246
1247 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001248 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001249 }
1250
Wink Savilleb564aae2014-10-23 10:18:09 -07001251 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 if (DBG) log("answerRingingCall...");
1253 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1254 // but that can probably wait till the big TelephonyManager API overhaul.
1255 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001257
1258 final long identity = Binder.clearCallingIdentity();
1259 try {
1260 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1261 } finally {
1262 Binder.restoreCallingIdentity(identity);
1263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 }
1265
1266 /**
1267 * Make the actual telephony calls to implement answerRingingCall().
1268 * This should only be called from the main thread of the Phone app.
1269 * @see #answerRingingCall
1270 *
1271 * TODO: it would be nice to return true if we answered the call, or
1272 * false if there wasn't actually a ringing incoming call, or some
1273 * other error occurred. (In other words, pass back the return value
1274 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1275 * But that would require calling this method via sendRequest() rather
1276 * than sendRequestAsync(), and right now we don't actually *need* that
1277 * return value, so let's just return void for now.
1278 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001279 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001280 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001282 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1283 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 if (hasActiveCall && hasHoldingCall) {
1285 // Both lines are in use!
1286 // TODO: provide a flag to let the caller specify what
1287 // policy to use if both lines are in use. (The current
1288 // behavior is hardwired to "answer incoming, end ongoing",
1289 // which is how the CALL button is specced to behave.)
1290 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1291 return;
1292 } else {
1293 // answerCall() will automatically hold the current active
1294 // call, if there is one.
1295 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1296 return;
1297 }
1298 } else {
1299 // No call was ringing.
1300 return;
1301 }
1302 }
1303
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001305 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001307 public void silenceRinger() {
1308 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 }
1310
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001311 @Override
1312 public boolean isOffhook(String callingPackage) {
1313 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001316 @Override
1317 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001318 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001319 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001320 return false;
1321 }
1322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001323 final long identity = Binder.clearCallingIdentity();
1324 try {
1325 final Phone phone = getPhone(subId);
1326 if (phone != null) {
1327 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1328 } else {
1329 return false;
1330 }
1331 } finally {
1332 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 }
1335
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001336 @Override
1337 public boolean isRinging(String callingPackage) {
1338 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001339 }
1340
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001341 @Override
1342 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001344 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001345 return false;
1346 }
1347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001348 final long identity = Binder.clearCallingIdentity();
1349 try {
1350 final Phone phone = getPhone(subId);
1351 if (phone != null) {
1352 return (phone.getState() == PhoneConstants.State.RINGING);
1353 } else {
1354 return false;
1355 }
1356 } finally {
1357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 }
1360
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001361 @Override
1362 public boolean isIdle(String callingPackage) {
1363 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001364 }
1365
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001366 @Override
1367 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001369 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001370 return false;
1371 }
1372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001373 final long identity = Binder.clearCallingIdentity();
1374 try {
1375 final Phone phone = getPhone(subId);
1376 if (phone != null) {
1377 return (phone.getState() == PhoneConstants.State.IDLE);
1378 } else {
1379 return false;
1380 }
1381 } finally {
1382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 }
1385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001387 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001388 }
1389
Wink Savilleb564aae2014-10-23 10:18:09 -07001390 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001391 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001392 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1393 }
1394
1395 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001396 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001397 }
1398
Wink Savilleb564aae2014-10-23 10:18:09 -07001399 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001400 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001401 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1402 }
1403
1404 /** {@hide} */
1405 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001406 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001407 }
1408
Wink Savilleb564aae2014-10-23 10:18:09 -07001409 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001411
1412 final long identity = Binder.clearCallingIdentity();
1413 try {
1414 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1415 checkSimPin.start();
1416 return checkSimPin.unlockSim(null, pin);
1417 } finally {
1418 Binder.restoreCallingIdentity(identity);
1419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 }
1421
Wink Saville9de0f752013-10-22 19:04:03 -07001422 /** {@hide} */
1423 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001424 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001425 }
1426
Wink Savilleb564aae2014-10-23 10:18:09 -07001427 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001429
1430 final long identity = Binder.clearCallingIdentity();
1431 try {
1432 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1433 checkSimPuk.start();
1434 return checkSimPuk.unlockSim(puk, pin);
1435 } finally {
1436 Binder.restoreCallingIdentity(identity);
1437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438 }
1439
1440 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001441 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442 * a synchronous one.
1443 */
1444 private static class UnlockSim extends Thread {
1445
1446 private final IccCard mSimCard;
1447
1448 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001449 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1450 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451
1452 // For replies from SimCard interface
1453 private Handler mHandler;
1454
1455 // For async handler to identify request type
1456 private static final int SUPPLY_PIN_COMPLETE = 100;
1457
1458 public UnlockSim(IccCard simCard) {
1459 mSimCard = simCard;
1460 }
1461
1462 @Override
1463 public void run() {
1464 Looper.prepare();
1465 synchronized (UnlockSim.this) {
1466 mHandler = new Handler() {
1467 @Override
1468 public void handleMessage(Message msg) {
1469 AsyncResult ar = (AsyncResult) msg.obj;
1470 switch (msg.what) {
1471 case SUPPLY_PIN_COMPLETE:
1472 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1473 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001474 mRetryCount = msg.arg1;
1475 if (ar.exception != null) {
1476 if (ar.exception instanceof CommandException &&
1477 ((CommandException)(ar.exception)).getCommandError()
1478 == CommandException.Error.PASSWORD_INCORRECT) {
1479 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1480 } else {
1481 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1482 }
1483 } else {
1484 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 mDone = true;
1487 UnlockSim.this.notifyAll();
1488 }
1489 break;
1490 }
1491 }
1492 };
1493 UnlockSim.this.notifyAll();
1494 }
1495 Looper.loop();
1496 }
1497
1498 /*
1499 * Use PIN or PUK to unlock SIM card
1500 *
1501 * If PUK is null, unlock SIM card with PIN
1502 *
1503 * If PUK is not null, unlock SIM card with PUK and set PIN code
1504 */
Wink Saville9de0f752013-10-22 19:04:03 -07001505 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506
1507 while (mHandler == null) {
1508 try {
1509 wait();
1510 } catch (InterruptedException e) {
1511 Thread.currentThread().interrupt();
1512 }
1513 }
1514 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1515
1516 if (puk == null) {
1517 mSimCard.supplyPin(pin, callback);
1518 } else {
1519 mSimCard.supplyPuk(puk, pin, callback);
1520 }
1521
1522 while (!mDone) {
1523 try {
1524 Log.d(LOG_TAG, "wait for done");
1525 wait();
1526 } catch (InterruptedException e) {
1527 // Restore the interrupted status
1528 Thread.currentThread().interrupt();
1529 }
1530 }
1531 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001532 int[] resultArray = new int[2];
1533 resultArray[0] = mResult;
1534 resultArray[1] = mRetryCount;
1535 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537 }
1538
1539 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001541
1542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 // No permission check needed here: this call is harmless, and it's
1546 // needed for the ServiceState.requestStateUpdate() call (which is
1547 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001548 final long identity = Binder.clearCallingIdentity();
1549 try {
1550 final Phone phone = getPhone(subId);
1551 if (phone != null) {
1552 phone.updateServiceLocation();
1553 }
1554 } finally {
1555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 }
1558
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001559 @Override
1560 public boolean isRadioOn(String callingPackage) {
1561 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001562 }
1563
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001564 @Override
1565 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001567 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001568 return false;
1569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001570
1571 final long identity = Binder.clearCallingIdentity();
1572 try {
1573 return isRadioOnForSubscriber(subId);
1574 } finally {
1575 Binder.restoreCallingIdentity(identity);
1576 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001577 }
1578
1579 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001580 final long identity = Binder.clearCallingIdentity();
1581 try {
1582 final Phone phone = getPhone(subId);
1583 if (phone != null) {
1584 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1585 } else {
1586 return false;
1587 }
1588 } finally {
1589 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 }
1592
1593 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001594 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 }
Wink Saville36469e72014-06-11 15:17:00 -07001596
Wink Savilleb564aae2014-10-23 10:18:09 -07001597 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001599
1600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 final Phone phone = getPhone(subId);
1603 if (phone != null) {
1604 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1605 }
1606 } finally {
1607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 }
Wink Saville36469e72014-06-11 15:17:00 -07001609 }
1610
1611 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001612 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001613 }
1614
Wink Savilleb564aae2014-10-23 10:18:09 -07001615 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001616 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001617
1618 final long identity = Binder.clearCallingIdentity();
1619 try {
1620 final Phone phone = getPhone(subId);
1621 if (phone == null) {
1622 return false;
1623 }
1624 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1625 toggleRadioOnOffForSubscriber(subId);
1626 }
1627 return true;
1628 } finally {
1629 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 }
Wink Saville36469e72014-06-11 15:17:00 -07001632
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001633 public boolean needMobileRadioShutdown() {
1634 /*
1635 * If any of the Radios are available, it will need to be
1636 * shutdown. So return true if any Radio is available.
1637 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1641 Phone phone = PhoneFactory.getPhone(i);
1642 if (phone != null && phone.isRadioAvailable()) return true;
1643 }
1644 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1645 return false;
1646 } finally {
1647 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001648 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001649 }
1650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001651 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001652 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001653 enforceModifyPermission();
1654
1655 final long identity = Binder.clearCallingIdentity();
1656 try {
1657 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1658 logv("Shutting down Phone " + i);
1659 shutdownRadioUsingPhoneId(i);
1660 }
1661 } finally {
1662 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001663 }
1664 }
1665
1666 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001667 Phone phone = PhoneFactory.getPhone(phoneId);
1668 if (phone != null && phone.isRadioAvailable()) {
1669 phone.shutdownRadio();
1670 }
1671 }
1672
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001675
1676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1679 if (defaultPhone != null) {
1680 defaultPhone.setRadioPower(turnOn);
1681 return true;
1682 } else {
1683 loge("There's no default phone.");
1684 return false;
1685 }
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001688 }
Wink Saville36469e72014-06-11 15:17:00 -07001689 }
1690
Wink Savilleb564aae2014-10-23 10:18:09 -07001691 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001693
1694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 phone.setRadioPower(turnOn);
1699 return true;
1700 } else {
1701 return false;
1702 }
1703 } finally {
1704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 }
1707
Wink Saville36469e72014-06-11 15:17:00 -07001708 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 public boolean enableDataConnectivity() {
1711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001712
1713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 int subId = mSubscriptionController.getDefaultDataSubId();
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.setUserDataEnabled(true);
1719 return true;
1720 } else {
1721 return false;
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
Wink Saville36469e72014-06-11 15:17:00 -07001728 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001729 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 public boolean disableDataConnectivity() {
1731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001732
1733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 int subId = mSubscriptionController.getDefaultDataSubId();
1736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
1738 phone.setUserDataEnabled(false);
1739 return true;
1740 } else {
1741 return false;
1742 }
1743 } finally {
1744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
1747
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001749 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 final Phone phone = getPhone(subId);
1753 if (phone != null) {
1754 return phone.isDataAllowed();
1755 } else {
1756 return false;
1757 }
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 }
1762
1763 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001764 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001765 }
1766
pkanwarae03a6b2016-11-06 20:37:09 -08001767 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768 enforceCallPermission();
1769
1770 final long identity = Binder.clearCallingIdentity();
1771 try {
1772 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1773 return;
1774 }
1775 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1776 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1777 } finally {
1778 Binder.restoreCallingIdentity(identity);
1779 }
pkanwar32d516d2016-10-14 19:37:38 -07001780 };
1781
Wink Savilleb564aae2014-10-23 10:18:09 -07001782 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784
1785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1788 return false;
1789 }
1790 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1791 } finally {
1792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 }
1795
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001797 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001798 }
1799
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001800 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 Phone phone = PhoneFactory.getPhone(slotIndex);
1804 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1805 PhoneConstantConversions.convertCallState(phone.getState());
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
1808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1816 if (phone != null) {
1817 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1818 } else {
1819 return PhoneConstantConversions.convertDataState(
1820 PhoneConstants.DataState.DISCONNECTED);
1821 }
1822 } finally {
1823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 }
1826
Sanket Padawe356d7632015-06-22 14:03:32 -07001827 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1832 if (phone != null) {
1833 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1834 } else {
1835 return TelephonyManager.DATA_ACTIVITY_NONE;
1836 }
1837 } finally {
1838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
1842 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001843 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001844 mPhone.getContext().getSystemService(AppOpsManager.class)
1845 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001846 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001847 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001848 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 }
1850
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001851 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 if (DBG_LOC) log("getCellLocation: is active user");
1855 Bundle data = new Bundle();
1856 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1857 if (phone == null) {
1858 return null;
1859 }
1860
1861 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1862 return data;
1863 } finally {
1864 Binder.restoreCallingIdentity(identity);
1865 }
Svetoslav64fad262015-04-14 14:35:21 -07001866 }
1867
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001869 public String getNetworkCountryIsoForPhone(int phoneId) {
1870 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1871 // registered cell info, so return a NULL country instead.
1872 final long identity = Binder.clearCallingIdentity();
1873 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001874 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1875 // Get default phone in this case.
1876 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1877 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001878 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001879 // Todo: fix this when we can get the actual cellular network info when the device
1880 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001881 if (TelephonyManager.NETWORK_TYPE_IWLAN
1882 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1883 return "";
1884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 Phone phone = PhoneFactory.getPhone(phoneId);
1886 if (phone != null) {
1887 ServiceStateTracker sst = phone.getServiceStateTracker();
1888 if (sst != null) {
1889 LocaleTracker lt = sst.getLocaleTracker();
1890 if (lt != null) {
1891 return lt.getCurrentCountry();
1892 }
1893 }
1894 }
1895 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001896 } finally {
1897 Binder.restoreCallingIdentity(identity);
1898 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001899 }
1900
1901 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001903 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001904 }
1905
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001907 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 mApp.enforceCallingOrSelfPermission(
1909 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001910
1911 final long identity = Binder.clearCallingIdentity();
1912 try {
1913 final Phone phone = getPhone(subId);
1914 if (phone != null) {
1915 phone.enableLocationUpdates();
1916 }
1917 } finally {
1918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
1922 @Override
1923 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001924 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001925 }
1926
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001928 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 mApp.enforceCallingOrSelfPermission(
1930 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001931
1932 final long identity = Binder.clearCallingIdentity();
1933 try {
1934 final Phone phone = getPhone(subId);
1935 if (phone != null) {
1936 phone.disableLocationUpdates();
1937 }
1938 } finally {
1939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942
1943 @Override
1944 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001945 public List<NeighboringCellInfo>
1946 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001947 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1948 throw new SecurityException(
1949 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1950 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001951
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1953 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1954 return null;
1955 }
Svetoslav64fad262015-04-14 14:35:21 -07001956
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001957 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958
Nathan Haroldf180aac2018-06-01 18:43:55 -07001959 List<CellInfo> info = getAllCellInfo(callingPackage);
1960 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961
Nathan Haroldf180aac2018-06-01 18:43:55 -07001962 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1963 for (CellInfo ci : info) {
1964 if (ci instanceof CellInfoGsm) {
1965 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1966 } else if (ci instanceof CellInfoWcdma) {
1967 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001970 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 }
1972
1973
1974 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001975 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001976 mPhone.getContext().getSystemService(AppOpsManager.class)
1977 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001978 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001979 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001980 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
1982
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001983 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001984 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1988 for (Phone phone : PhoneFactory.getPhones()) {
1989 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1990 if (info != null) cellInfos.addAll(info);
1991 }
1992 return cellInfos;
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
1996 }
1997
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001998 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002000 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002001 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002002
2003 final long identity = Binder.clearCallingIdentity();
2004 try {
2005 mPhone.setCellInfoListRate(rateInMillis, workSource);
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
2008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
Shishir Agrawala9f32182016-04-12 12:00:16 -07002011 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002012 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002013 Phone phone = PhoneFactory.getPhone(slotIndex);
2014 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002015 return null;
2016 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002017 int subId = phone.getSubId();
2018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2019 mApp, subId, callingPackage, "getImeiForSlot")) {
2020 return null;
2021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022
2023 final long identity = Binder.clearCallingIdentity();
2024 try {
2025 return phone.getImei();
2026 } finally {
2027 Binder.restoreCallingIdentity(identity);
2028 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002029 }
2030
2031 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002032 public String getTypeAllocationCodeForSlot(int slotIndex) {
2033 Phone phone = PhoneFactory.getPhone(slotIndex);
2034 String tac = null;
2035 if (phone != null) {
2036 String imei = phone.getImei();
2037 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2038 }
2039 return tac;
2040 }
2041
2042 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002043 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002044 Phone phone = PhoneFactory.getPhone(slotIndex);
2045 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002046 return null;
2047 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002048 int subId = phone.getSubId();
2049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2050 mApp, subId, callingPackage, "getMeidForSlot")) {
2051 return null;
2052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002053
2054 final long identity = Binder.clearCallingIdentity();
2055 try {
2056 return phone.getMeid();
2057 } finally {
2058 Binder.restoreCallingIdentity(identity);
2059 }
Jack Yu2af8d712017-03-15 17:14:14 -07002060 }
2061
2062 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002063 public String getManufacturerCodeForSlot(int slotIndex) {
2064 Phone phone = PhoneFactory.getPhone(slotIndex);
2065 String manufacturerCode = null;
2066 if (phone != null) {
2067 String meid = phone.getMeid();
2068 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2069 }
2070 return manufacturerCode;
2071 }
2072
2073 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002074 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002075 Phone phone = PhoneFactory.getPhone(slotIndex);
2076 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002077 return null;
2078 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002079 int subId = phone.getSubId();
2080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2081 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2082 return null;
2083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002084
2085 final long identity = Binder.clearCallingIdentity();
2086 try {
2087 return phone.getDeviceSvn();
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
2090 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002091 }
2092
fionaxu43304da2017-11-27 22:51:16 -08002093 @Override
2094 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002095 final long identity = Binder.clearCallingIdentity();
2096 try {
2097 final Phone phone = getPhone(subId);
2098 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2099 } finally {
2100 Binder.restoreCallingIdentity(identity);
2101 }
fionaxu43304da2017-11-27 22:51:16 -08002102 }
2103
2104 @Override
2105 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106 final long identity = Binder.clearCallingIdentity();
2107 try {
2108 final Phone phone = getPhone(subId);
2109 return phone == null ? null : phone.getCarrierName();
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
2112 }
fionaxu43304da2017-11-27 22:51:16 -08002113 }
2114
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 //
2116 // Internal helper methods.
2117 //
2118
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002119 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2121 *
2122 * @throws SecurityException if the caller does not have the required permission
2123 */
2124 private void enforceModifyPermission() {
2125 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2126 }
2127
2128 /**
2129 * Make sure the caller has the CALL_PHONE permission.
2130 *
2131 * @throws SecurityException if the caller does not have the required permission
2132 */
2133 private void enforceCallPermission() {
2134 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2135 }
2136
Stuart Scott8eef64f2015-04-08 15:13:54 -07002137 private void enforceConnectivityInternalPermission() {
2138 mApp.enforceCallingOrSelfPermission(
2139 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2140 "ConnectivityService");
2141 }
2142
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 private String createTelUrl(String number) {
2144 if (TextUtils.isEmpty(number)) {
2145 return null;
2146 }
2147
Jake Hambye994d462014-02-03 13:10:13 -08002148 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 }
2150
Ihab Awadf9e92732013-12-05 18:02:52 -08002151 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2153 }
2154
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002155 private static void logv(String msg) {
2156 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2157 }
2158
Ihab Awadf9e92732013-12-05 18:02:52 -08002159 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2161 }
2162
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002163 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002165 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
2167
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002169 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 final Phone phone = PhoneFactory.getPhone(slotIndex);
2173 if (phone == null) {
2174 return PhoneConstants.PHONE_TYPE_NONE;
2175 } else {
2176 return phone.getPhoneType();
2177 }
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182
2183 /**
2184 * Returns the CDMA ERI icon index to display
2185 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002186 @Override
2187 public int getCdmaEriIconIndex(String callingPackage) {
2188 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002189 }
2190
Sanket Padawe356d7632015-06-22 14:03:32 -07002191 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002192 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002193 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002194 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002195 return -1;
2196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002197
2198 final long identity = Binder.clearCallingIdentity();
2199 try {
2200 final Phone phone = getPhone(subId);
2201 if (phone != null) {
2202 return phone.getCdmaEriIconIndex();
2203 } else {
2204 return -1;
2205 }
2206 } finally {
2207 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 }
2210
2211 /**
2212 * Returns the CDMA ERI icon mode,
2213 * 0 - ON
2214 * 1 - FLASHING
2215 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002216 @Override
2217 public int getCdmaEriIconMode(String callingPackage) {
2218 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
2220
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002222 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002224 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002225 return -1;
2226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227
2228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 final Phone phone = getPhone(subId);
2231 if (phone != null) {
2232 return phone.getCdmaEriIconMode();
2233 } else {
2234 return -1;
2235 }
2236 } finally {
2237 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
2241 /**
2242 * Returns the CDMA ERI text,
2243 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002244 @Override
2245 public String getCdmaEriText(String callingPackage) {
2246 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002247 }
2248
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002250 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002252 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002253 return null;
2254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255
2256 final long identity = Binder.clearCallingIdentity();
2257 try {
2258 final Phone phone = getPhone(subId);
2259 if (phone != null) {
2260 return phone.getCdmaEriText();
2261 } else {
2262 return null;
2263 }
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
2269 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002270 * Returns the CDMA MDN.
2271 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002273 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2275 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276
2277 final long identity = Binder.clearCallingIdentity();
2278 try {
2279 final Phone phone = getPhone(subId);
2280 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2281 return phone.getLine1Number();
2282 } else {
2283 return null;
2284 }
2285 } finally {
2286 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002287 }
2288 }
2289
2290 /**
2291 * Returns the CDMA MIN.
2292 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002293 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002294 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2296 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297
2298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 final Phone phone = getPhone(subId);
2301 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2302 return phone.getCdmaMin();
2303 } else {
2304 return null;
2305 }
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002308 }
2309 }
2310
2311 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 * Returns true if CDMA provisioning needs to run.
2313 */
2314 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002315 final long identity = Binder.clearCallingIdentity();
2316 try {
2317 return mPhone.needsOtaServiceProvisioning();
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
2320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 }
2322
2323 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002324 * Sets the voice mail number of a given subId.
2325 */
2326 @Override
2327 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002328 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002329
2330 final long identity = Binder.clearCallingIdentity();
2331 try {
2332 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2333 new Pair<String, String>(alphaTag, number), new Integer(subId));
2334 return success;
2335 } finally {
2336 Binder.restoreCallingIdentity(identity);
2337 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002338 }
2339
Ta-wei Yen87c49842016-05-13 21:19:52 -07002340 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002341 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2342 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2343 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2344 if (!TextUtils.equals(callingPackage, systemDialer)) {
2345 throw new SecurityException("caller must be system dialer");
2346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2351 if (phoneAccountHandle == null) {
2352 return null;
2353 }
2354 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002357 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002358 }
2359
2360 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002361 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002362 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002363 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002364 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002365 return null;
2366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002368 final long identity = Binder.clearCallingIdentity();
2369 try {
2370 return RemoteVvmTaskManager
2371 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
2374 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002375 }
2376
2377 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002378 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2379 VisualVoicemailSmsFilterSettings settings) {
2380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002381
2382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2385 mPhone.getContext(), callingPackage, subId, settings);
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002389 }
2390
2391 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002392 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002394
2395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2398 mPhone.getContext(), callingPackage, subId);
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
2401 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002402 }
2403
2404 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002405 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2406 String callingPackage, int subId) {
2407 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002408
2409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2412 mPhone.getContext(), callingPackage, subId);
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002416 }
2417
2418 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002419 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002420 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421
2422 final long identity = Binder.clearCallingIdentity();
2423 try {
2424 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2425 mPhone.getContext(), subId);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002429 }
2430
2431 @Override
2432 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2433 String number, int port, String text, PendingIntent sentIntent) {
2434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002435 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002436 enforceSendSmsPermission();
2437 // Make the calls as the phone process.
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2441 if (port == 0) {
2442 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2443 sentIntent, null, false);
2444 } else {
2445 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2446 smsManager.sendDataMessageWithSelfPermissions(number, null,
2447 (short) port, data, sentIntent, null);
2448 }
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
2451 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002452 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002453 /**
fionaxu0152e512016-11-14 13:36:14 -08002454 * Sets the voice activation state of a given subId.
2455 */
2456 @Override
2457 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2459 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460
2461 final long identity = Binder.clearCallingIdentity();
2462 try {
2463 final Phone phone = getPhone(subId);
2464 if (phone != null) {
2465 phone.setVoiceActivationState(activationState);
2466 } else {
2467 loge("setVoiceActivationState fails with invalid subId: " + subId);
2468 }
2469 } finally {
2470 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002471 }
2472 }
2473
2474 /**
2475 * Sets the data activation state of a given subId.
2476 */
2477 @Override
2478 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2480 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481
2482 final long identity = Binder.clearCallingIdentity();
2483 try {
2484 final Phone phone = getPhone(subId);
2485 if (phone != null) {
2486 phone.setDataActivationState(activationState);
2487 } else {
2488 loge("setVoiceActivationState fails with invalid subId: " + subId);
2489 }
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002492 }
2493 }
2494
2495 /**
2496 * Returns the voice activation state of a given subId.
2497 */
2498 @Override
2499 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002500 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501
fionaxu0152e512016-11-14 13:36:14 -08002502 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 if (phone != null) {
2506 return phone.getVoiceActivationState();
2507 } else {
2508 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2509 }
2510 } finally {
2511 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002512 }
2513 }
2514
2515 /**
2516 * Returns the data activation state of a given subId.
2517 */
2518 @Override
2519 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002520 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521
fionaxu0152e512016-11-14 13:36:14 -08002522 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 final long identity = Binder.clearCallingIdentity();
2524 try {
2525 if (phone != null) {
2526 return phone.getDataActivationState();
2527 } else {
2528 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2529 }
2530 } finally {
2531 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002532 }
2533 }
2534
2535 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536 * Returns the unread count of voicemails
2537 */
2538 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002539 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002540 }
2541
2542 /**
2543 * Returns the unread count of voicemails for a subId
2544 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002545 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002546 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547 final long identity = Binder.clearCallingIdentity();
2548 try {
2549 final Phone phone = getPhone(subId);
2550 if (phone != null) {
2551 return phone.getVoiceMessageCount();
2552 } else {
2553 return 0;
2554 }
2555 } finally {
2556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 }
2559
2560 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002561 * returns true, if the device is in a state where both voice and data
2562 * are supported simultaneously. This can change based on location or network condition.
2563 */
2564 @Override
2565 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 final Phone phone = getPhone(subId);
2569 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
2572 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002573 }
2574
2575 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002576 * Send the dialer code if called from the current default dialer or the caller has
2577 * carrier privilege.
2578 * @param inputCode The dialer code to send
2579 */
2580 @Override
2581 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2583 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2584 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002585 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2586 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002587 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588
2589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 mPhone.sendDialerSpecialCode(inputCode);
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
2594 }
fionaxu235cc5e2017-03-06 22:25:57 -08002595 }
2596
2597 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002598 * Returns the data network type.
2599 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600 *
2601 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2602 */
2603 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002604 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(getDefaultSubscription());
2608 if (phone != null) {
2609 return phone.getServiceState().getDataNetworkType();
2610 } else {
2611 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2612 }
2613 } finally {
2614 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002615 }
Wink Saville36469e72014-06-11 15:17:00 -07002616 }
2617
Pengquan Menga1bb6272018-09-06 09:59:22 -07002618 @Override
2619 public int getNetworkSelectionMode(int subId) {
2620 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2621 }
2622
Wink Saville36469e72014-06-11 15:17:00 -07002623 /**
2624 * Returns the network type for a subId
2625 */
2626 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002627 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002629 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2631 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 final Phone phone = getPhone(subId);
2636 if (phone != null) {
2637 return phone.getServiceState().getDataNetworkType();
2638 } else {
2639 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2640 }
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 }
2645
2646 /**
2647 * Returns the data network type
2648 */
2649 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002650 public int getDataNetworkType(String callingPackage) {
2651 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002652 }
2653
2654 /**
2655 * Returns the data network type for a subId
2656 */
2657 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002658 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002660 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002661 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2662 }
2663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664 final long identity = Binder.clearCallingIdentity();
2665 try {
2666 final Phone phone = getPhone(subId);
2667 if (phone != null) {
2668 return phone.getServiceState().getDataNetworkType();
2669 } else {
2670 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2671 }
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 }
2676
2677 /**
Wink Saville36469e72014-06-11 15:17:00 -07002678 * Returns the Voice network type for a subId
2679 */
2680 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002681 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002683 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002684 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2685 }
2686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 final Phone phone = getPhone(subId);
2690 if (phone != null) {
2691 return phone.getServiceState().getVoiceNetworkType();
2692 } else {
2693 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2694 }
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
2700 /**
2701 * @return true if a ICC card is present
2702 */
2703 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002704 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002705 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2706 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002707 }
2708
2709 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002710 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002711 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002712 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002713 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 final Phone phone = PhoneFactory.getPhone(slotIndex);
2717 if (phone != null) {
2718 return phone.getIccCard().hasIccCard();
2719 } else {
2720 return false;
2721 }
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 }
2726
2727 /**
2728 * Return if the current radio is LTE on CDMA. This
2729 * is a tri-state return value as for a period of time
2730 * the mode may be unknown.
2731 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002732 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002734 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002736 @Override
2737 public int getLteOnCdmaMode(String callingPackage) {
2738 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002739 }
2740
Sanket Padawe356d7632015-06-22 14:03:32 -07002741 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002742 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002744 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002745 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2746 }
2747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 final Phone phone = getPhone(subId);
2751 if (phone == null) {
2752 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2753 } else {
2754 return phone.getLteOnCdmaMode();
2755 }
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 }
Wink Saville36469e72014-06-11 15:17:00 -07002759 }
2760
2761 public void setPhone(Phone phone) {
2762 mPhone = phone;
2763 }
2764
2765 /**
2766 * {@hide}
2767 * Returns Default subId, 0 in the case of single standby.
2768 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002769 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002770 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002771 }
2772
Shishir Agrawala9f32182016-04-12 12:00:16 -07002773 private int getSlotForDefaultSubscription() {
2774 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2775 }
2776
Wink Savilleb564aae2014-10-23 10:18:09 -07002777 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002778 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002780
2781 /**
2782 * @see android.telephony.TelephonyManager.WifiCallingChoices
2783 */
2784 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2788 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2789 getWhenToMakeWifiCallsDefaultPreference());
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
2792 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002793 }
2794
2795 /**
2796 * @see android.telephony.TelephonyManager.WifiCallingChoices
2797 */
2798 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2802 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2803 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2804 } finally {
2805 Binder.restoreCallingIdentity(identity);
2806 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002807 }
2808
Sailesh Nepald1e68152013-12-12 19:08:02 -08002809 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002810 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002811 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002812 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002813
Shishir Agrawal566b7612013-10-28 14:41:00 -07002814 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002815 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2816 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2818 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 if (TextUtils.equals(ISDR_AID, aid)) {
2824 // Only allows LPA to open logical channel to ISD-R.
2825 ComponentInfo bestComponent =
2826 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2827 if (bestComponent == null
2828 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2829 loge("The calling package is not allowed to access ISD-R.");
2830 throw new SecurityException(
2831 "The calling package is not allowed to access ISD-R.");
2832 }
Derek Tan740e1672017-06-27 14:56:27 -07002833 }
Derek Tan740e1672017-06-27 14:56:27 -07002834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 if (DBG) {
2836 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2837 }
2838 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2839 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2840 if (DBG) log("iccOpenLogicalChannel: " + response);
2841 return response;
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
2844 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002845 }
2846
2847 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002848 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2850 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2855 if (channel < 0) {
2856 return false;
2857 }
2858 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2859 if (DBG) log("iccCloseLogicalChannel: " + success);
2860 return success;
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002863 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002864 }
2865
2866 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002867 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002868 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2870 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 final long identity = Binder.clearCallingIdentity();
2873 try {
2874 if (DBG) {
2875 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2876 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2877 + p3 + " data=" + data);
2878 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 if (channel < 0) {
2881 return "";
2882 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2885 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2886 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888 // Append the returned status code to the end of the response payload.
2889 String s = Integer.toHexString(
2890 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2891 if (response.payload != null) {
2892 s = IccUtils.bytesToHexString(response.payload) + s;
2893 }
2894 return s;
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002897 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002898 }
Jake Hambye994d462014-02-03 13:10:13 -08002899
Evan Charltonc66da362014-05-16 14:06:40 -07002900 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002901 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2902 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2904 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2910 && TextUtils.equals(ISDR_AID, data)) {
2911 // Only allows LPA to select ISD-R.
2912 ComponentInfo bestComponent =
2913 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2914 if (bestComponent == null
2915 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2916 loge("The calling package is not allowed to select ISD-R.");
2917 throw new SecurityException(
2918 "The calling package is not allowed to select ISD-R.");
2919 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002920 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 if (DBG) {
2923 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2924 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2925 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2928 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2929 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931 // Append the returned status code to the end of the response payload.
2932 String s = Integer.toHexString(
2933 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2934 if (response.payload != null) {
2935 s = IccUtils.bytesToHexString(response.payload) + s;
2936 }
2937 return s;
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002940 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002941 }
2942
2943 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002944 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002945 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2947 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 if (DBG) {
2952 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2953 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2954 }
2955
2956 IccIoResult response =
2957 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2958 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2959 subId);
2960
2961 if (DBG) {
2962 log("Exchange SIM_IO [R]" + response);
2963 }
2964
2965 byte[] result = null;
2966 int length = 2;
2967 if (response.payload != null) {
2968 length = 2 + response.payload.length;
2969 result = new byte[length];
2970 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2971 } else {
2972 result = new byte[length];
2973 }
2974
2975 result[length - 1] = (byte) response.sw2;
2976 result[length - 2] = (byte) response.sw1;
2977 return result;
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002980 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002981 }
2982
Nathan Haroldb3014052017-01-25 15:57:32 -08002983 /**
2984 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2985 * on a particular subscription
2986 */
sqianb6e41952018-03-12 14:54:01 -07002987 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2989 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2990 return null;
2991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 if (appType != TelephonyManager.APPTYPE_USIM
2996 && appType != TelephonyManager.APPTYPE_SIM) {
2997 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2998 return null;
2999 }
3000 Object response = sendRequest(
3001 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3002 if (response instanceof String[]) {
3003 return (String[]) response;
3004 }
3005 // Response is an Exception of some kind,
3006 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003007 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003010 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003011 }
3012
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003013 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003014 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3016 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3021 if (response.payload == null) {
3022 return "";
3023 }
Evan Charltonc66da362014-05-16 14:06:40 -07003024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 // Append the returned status code to the end of the response payload.
3026 String s = Integer.toHexString(
3027 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3028 s = IccUtils.bytesToHexString(response.payload) + s;
3029 return s;
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
Evan Charltonc66da362014-05-16 14:06:40 -07003033 }
3034
Jake Hambye994d462014-02-03 13:10:13 -08003035 /**
3036 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3037 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3038 *
3039 * @param itemID the ID of the item to read
3040 * @return the NV item as a String, or null on error.
3041 */
3042 @Override
3043 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3045 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046
3047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 if (DBG) log("nvReadItem: item " + itemID);
3050 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3051 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3052 return value;
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
Jake Hambye994d462014-02-03 13:10:13 -08003056 }
3057
3058 /**
3059 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3060 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3061 *
3062 * @param itemID the ID of the item to read
3063 * @param itemValue the value to write, as a String
3064 * @return true on success; false on any failure
3065 */
3066 @Override
3067 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3069 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3074 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3075 new Pair<Integer, String>(itemID, itemValue));
3076 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3077 return success;
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
Jake Hambye994d462014-02-03 13:10:13 -08003081 }
3082
3083 /**
3084 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3085 * Used for device configuration by some CDMA operators.
3086 *
3087 * @param preferredRoamingList byte array containing the new PRL
3088 * @return true on success; false on any failure
3089 */
3090 @Override
3091 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3093 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094
3095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3098 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3099 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3100 return success;
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
Jake Hambye994d462014-02-03 13:10:13 -08003104 }
3105
3106 /**
3107 * Perform the specified type of NV config reset.
3108 * Used for device configuration by some CDMA operators.
3109 *
3110 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3111 * @return true on success; false on any failure
3112 */
3113 @Override
3114 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3116 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117
3118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 if (DBG) log("nvResetConfig: type " + resetType);
3121 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3122 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3123 return success;
3124 } finally {
3125 Binder.restoreCallingIdentity(identity);
3126 }
Jake Hambye994d462014-02-03 13:10:13 -08003127 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003128
Svet Ganovb320e182015-04-16 12:30:10 -07003129 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003131 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003132 return new String[0];
3133 }
3134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 return mPhone.getPcscfAddress(apnType);
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
3140 }
Wink Saville36469e72014-06-11 15:17:00 -07003141 }
3142
Brad Ebinger51f743a2017-01-23 13:50:20 -08003143 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003144 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3145 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003146 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003147 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003148 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 PhoneFactory.getImsResolver().enableIms(slotId);
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003156 }
3157
3158 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003159 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3160 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003161 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003162 public void disableIms(int slotId) {
3163 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 PhoneFactory.getImsResolver().disableIms(slotId);
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003171 }
3172
3173 /**
3174 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3175 * feature or {@link null} if the service is not available. If the feature is available, the
3176 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3177 */
3178 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003179 IImsServiceFeatureCallback callback) {
3180 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003188 }
3189
3190 /**
3191 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3192 * feature during emergency calling or {@link null} if the service is not available. If the
3193 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3194 * listener for feature updates.
3195 */
3196 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3197 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198
3199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
3204 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003205 }
3206
Brad Ebinger5f64b052017-12-14 14:26:15 -08003207 /**
3208 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3209 * specified.
3210 */
3211 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3212 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213
3214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003220 }
3221
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003222 /**
3223 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3224 * specified.
3225 */
3226 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3227 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003235 }
3236
Brad Ebinger884c07b2018-02-15 16:17:40 -08003237 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003238 * Sets the ImsService Package Name that Telephony will bind to.
3239 *
3240 * @param slotId the slot ID that the ImsService should bind for.
3241 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3242 * ImsService is the device default ImsService.
3243 * @param packageName The package name of the application that contains the ImsService to bind
3244 * to.
3245 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3246 * @hide
3247 */
3248 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003249 int[] subIds = SubscriptionManager.getSubId(slotId);
3250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3251 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3252 "setImsService");
3253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254 final long identity = Binder.clearCallingIdentity();
3255 try {
3256 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3257 isCarrierImsService, packageName);
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003261 }
3262
3263 /**
3264 * Return the ImsService configuration.
3265 *
3266 * @param slotId The slot that the ImsService is associated with.
3267 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3268 * the device default.
3269 * @return the package name of the ImsService configuration.
3270 */
3271 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003272 int[] subIds = SubscriptionManager.getSubId(slotId);
3273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3274 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3275 "getImsService");
3276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277 final long identity = Binder.clearCallingIdentity();
3278 try {
3279 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3280 isCarrierImsService);
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003284 }
3285
Wink Saville36469e72014-06-11 15:17:00 -07003286 public void setImsRegistrationState(boolean registered) {
3287 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288
3289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 mPhone.setImsRegistrationState(registered);
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
Wink Saville36469e72014-06-11 15:17:00 -07003295 }
3296
3297 /**
Stuart Scott54788802015-03-30 13:18:01 -07003298 * Set the network selection mode to automatic.
3299 *
3300 */
3301 @Override
3302 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3304 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305
3306 final long identity = Binder.clearCallingIdentity();
3307 try {
3308 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3309 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
3312 }
Stuart Scott54788802015-03-30 13:18:01 -07003313 }
3314
Pengquan Mengea84e042018-09-20 14:57:26 -07003315 /**
3316 * Ask the radio to connect to the input network and change selection mode to manual.
3317 *
3318 * @param subId the id of the subscription.
3319 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3320 * the operator to attach to.
3321 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3322 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3323 * normal network selection next time.
3324 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003325 */
3326 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003327 public boolean setNetworkSelectionModeManual(
3328 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3330 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331 final long identity = Binder.clearCallingIdentity();
3332 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003333 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003335 if (DBG) {
3336 log("setNetworkSelectionModeManual: subId: " + subId
3337 + " operator: " + operatorInfo);
3338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003343 }
3344
3345 /**
3346 * Scans for available networks.
3347 */
3348 @Override
3349 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3351 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352
Pengquan Menga1bb6272018-09-06 09:59:22 -07003353 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 try {
3355 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003356 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 } finally {
3359 Binder.restoreCallingIdentity(identity);
3360 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003361 }
3362
3363 /**
yinxub1bed742017-04-17 11:45:04 -07003364 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003365 *
yinxub1bed742017-04-17 11:45:04 -07003366 * @param subId id of the subscription
3367 * @param request contains the radio access networks with bands/channels to scan
3368 * @param messenger callback messenger for scan results or errors
3369 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003370 * @return the id of the requested scan which can be used to stop the scan.
3371 */
3372 @Override
3373 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3374 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3376 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003377
3378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 return mNetworkScanRequestTracker.startNetworkScan(
3381 request, messenger, binder, getPhone(subId));
3382 } finally {
3383 Binder.restoreCallingIdentity(identity);
3384 }
yinxu504e1392017-04-12 16:03:22 -07003385 }
3386
3387 /**
3388 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003389 *
3390 * @param subId id of the subscription
3391 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003392 */
3393 @Override
3394 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3396 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397
3398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
yinxu504e1392017-04-12 16:03:22 -07003404 }
3405
3406 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003407 * Get the calculated preferred network type.
3408 * Used for debugging incorrect network type.
3409 *
3410 * @return the preferred network type, defined in RILConstants.java.
3411 */
3412 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003413 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003415 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003416 return RILConstants.PREFERRED_NETWORK_MODE;
3417 }
3418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 // FIXME: need to get SubId from somewhere.
3422 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
Junda Liu84d15a22014-07-02 11:21:04 -07003426 }
3427
3428 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003429 * Get the preferred network type.
3430 * Used for device configuration by some CDMA operators.
3431 *
3432 * @return the preferred network type, defined in RILConstants.java.
3433 */
3434 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003435 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3437 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003438
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 if (DBG) log("getPreferredNetworkType");
3442 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3443 int networkType = (result != null ? result[0] : -1);
3444 if (DBG) log("getPreferredNetworkType: " + networkType);
3445 return networkType;
3446 } finally {
3447 Binder.restoreCallingIdentity(identity);
3448 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003449 }
3450
3451 /**
3452 * Set the preferred network type.
3453 * Used for device configuration by some CDMA operators.
3454 *
3455 * @param networkType the preferred network type, defined in RILConstants.java.
3456 * @return true on success; false on any failure.
3457 */
3458 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003459 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3461 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462
3463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3466 Boolean success = (Boolean) sendRequest(
3467 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3468 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3469 if (success) {
3470 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3471 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3472 }
3473 return success;
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003476 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003477 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003478
3479 /**
Junda Liu475951f2014-11-07 16:45:03 -08003480 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3481 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3482 * tethering.
3483 *
3484 * @return 0: Not required. 1: required. 2: Not set.
3485 * @hide
3486 */
3487 @Override
3488 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003490
3491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3494 Settings.Global.TETHER_DUN_REQUIRED, 2);
3495 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3496 // config_tether_apndata.
3497 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3498 dunRequired = 1;
3499 }
3500 return dunRequired;
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003503 }
Junda Liu475951f2014-11-07 16:45:03 -08003504 }
3505
3506 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003507 * Set mobile data enabled
3508 * Used by the user through settings etc to turn on/off mobile data
3509 *
3510 * @param enable {@code true} turn turn data on, else {@code false}
3511 */
3512 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003513 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3515 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003516
3517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 int phoneId = mSubscriptionController.getPhoneId(subId);
3520 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3521 Phone phone = PhoneFactory.getPhone(phoneId);
3522 if (phone != null) {
3523 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3524 phone.setUserDataEnabled(enable);
3525 } else {
3526 loge("setUserDataEnabled: no phone for subId=" + subId);
3527 }
3528 } finally {
3529 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003530 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003531 }
3532
3533 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003534 * Get the user enabled state of Mobile Data.
3535 *
3536 * TODO: remove and use isUserDataEnabled.
3537 * This can't be removed now because some vendor codes
3538 * calls through ITelephony directly while they should
3539 * use TelephonyManager.
3540 *
3541 * @return true on enabled
3542 */
3543 @Override
3544 public boolean getDataEnabled(int subId) {
3545 return isUserDataEnabled(subId);
3546 }
3547
3548 /**
3549 * Get whether mobile data is enabled per user setting.
3550 *
3551 * There are other factors deciding whether mobile data is actually enabled, but they are
3552 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003553 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003554 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003555 *
3556 * @return {@code true} if data is enabled else {@code false}
3557 */
3558 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003559 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003560 try {
3561 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3562 null);
3563 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3565 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567
3568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 int phoneId = mSubscriptionController.getPhoneId(subId);
3571 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3572 Phone phone = PhoneFactory.getPhone(phoneId);
3573 if (phone != null) {
3574 boolean retVal = phone.isUserDataEnabled();
3575 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3576 return retVal;
3577 } else {
3578 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3579 return false;
3580 }
3581 } finally {
3582 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003583 }
3584 }
3585
3586 /**
3587 * Get whether mobile data is enabled.
3588 *
3589 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3590 * whether mobile data is actually enabled.
3591 *
3592 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3593 *
3594 * @return {@code true} if data is enabled else {@code false}
3595 */
3596 @Override
3597 public boolean isDataEnabled(int subId) {
3598 try {
3599 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3600 null);
3601 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3603 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605
3606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 int phoneId = mSubscriptionController.getPhoneId(subId);
3609 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3610 Phone phone = PhoneFactory.getPhone(phoneId);
3611 if (phone != null) {
3612 boolean retVal = phone.isDataEnabled();
3613 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3614 return retVal;
3615 } else {
3616 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3617 return false;
3618 }
3619 } finally {
3620 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003621 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003622 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003623
3624 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003625 public int getCarrierPrivilegeStatus(int subId) {
3626 final Phone phone = getPhone(subId);
3627 if (phone == null) {
3628 loge("getCarrierPrivilegeStatus: Invalid subId");
3629 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3630 }
3631 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003632 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003633 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003634 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3635 }
3636 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003637 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003638 }
Junda Liu29340342014-07-10 15:23:27 -07003639
3640 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003641 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3642 final Phone phone = getPhone(subId);
3643 if (phone == null) {
3644 loge("getCarrierPrivilegeStatus: Invalid subId");
3645 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3646 }
3647 UiccProfile profile =
3648 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3649 if (profile == null) {
3650 loge("getCarrierPrivilegeStatus: No UICC");
3651 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3652 }
3653 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3654 }
3655
3656 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003657 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003658 if (TextUtils.isEmpty(pkgName))
3659 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003660 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003661 if (card == null) {
3662 loge("checkCarrierPrivilegesForPackage: No UICC");
3663 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3664 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003665 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3666 }
3667
3668 @Override
3669 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003670 if (TextUtils.isEmpty(pkgName))
3671 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003672 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3673 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3674 UiccCard card = UiccController.getInstance().getUiccCard(i);
3675 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003676 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003677 continue;
3678 }
3679
3680 result = card.getCarrierPrivilegeStatus(
3681 mPhone.getContext().getPackageManager(), pkgName);
3682 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3683 break;
3684 }
3685 }
3686
3687 return result;
Junda Liu29340342014-07-10 15:23:27 -07003688 }
Derek Tan89e89d42014-07-08 17:00:10 -07003689
3690 @Override
Junda Liue64de782015-04-16 17:19:16 -07003691 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3692 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3693 loge("phoneId " + phoneId + " is not valid.");
3694 return null;
3695 }
3696 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003697 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003698 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003699 return null ;
3700 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003701 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003702 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003703 }
3704
Amith Yamasani6e118872016-02-19 12:53:51 -08003705 @Override
3706 public List<String> getPackagesWithCarrierPrivileges() {
3707 PackageManager pm = mPhone.getContext().getPackageManager();
3708 List<String> privilegedPackages = new ArrayList<>();
3709 List<PackageInfo> packages = null;
3710 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3711 UiccCard card = UiccController.getInstance().getUiccCard(i);
3712 if (card == null) {
3713 // No UICC in that slot.
3714 continue;
3715 }
3716 if (card.hasCarrierPrivilegeRules()) {
3717 if (packages == null) {
3718 // Only check packages in user 0 for now
3719 packages = pm.getInstalledPackagesAsUser(
3720 PackageManager.MATCH_DISABLED_COMPONENTS
3721 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3722 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3723 }
3724 for (int p = packages.size() - 1; p >= 0; p--) {
3725 PackageInfo pkgInfo = packages.get(p);
3726 if (pkgInfo != null && pkgInfo.packageName != null
3727 && card.getCarrierPrivilegeStatus(pkgInfo)
3728 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3729 privilegedPackages.add(pkgInfo.packageName);
3730 }
3731 }
3732 }
3733 }
3734 return privilegedPackages;
3735 }
3736
Wink Savilleb564aae2014-10-23 10:18:09 -07003737 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003738 final Phone phone = getPhone(subId);
3739 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003740 if (card == null) {
3741 loge("getIccId: No UICC");
3742 return null;
3743 }
3744 String iccId = card.getIccId();
3745 if (TextUtils.isEmpty(iccId)) {
3746 loge("getIccId: ICC ID is null or empty.");
3747 return null;
3748 }
3749 return iccId;
3750 }
3751
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003752 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003753 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3754 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003755 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3756 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758 final long identity = Binder.clearCallingIdentity();
3759 try {
3760 final String iccId = getIccId(subId);
3761 final Phone phone = getPhone(subId);
3762 if (phone == null) {
3763 return false;
3764 }
3765 final String subscriberId = phone.getSubscriberId();
3766
3767 if (DBG_MERGE) {
3768 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3769 + subscriberId + " to " + number);
3770 }
3771
3772 if (TextUtils.isEmpty(iccId)) {
3773 return false;
3774 }
3775
3776 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3777
3778 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3779 if (alphaTag == null) {
3780 editor.remove(alphaTagPrefKey);
3781 } else {
3782 editor.putString(alphaTagPrefKey, alphaTag);
3783 }
3784
3785 // Record both the line number and IMSI for this ICCID, since we need to
3786 // track all merged IMSIs based on line number
3787 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3788 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3789 if (number == null) {
3790 editor.remove(numberPrefKey);
3791 editor.remove(subscriberPrefKey);
3792 } else {
3793 editor.putString(numberPrefKey, number);
3794 editor.putString(subscriberPrefKey, subscriberId);
3795 }
3796
3797 editor.commit();
3798 return true;
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003801 }
Derek Tan7226c842014-07-02 17:42:23 -07003802 }
3803
3804 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003805 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003806 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003808 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003809 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003810 return null;
3811 }
Derek Tan97ebb422014-09-05 16:55:38 -07003812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 String iccId = getIccId(subId);
3816 if (iccId != null) {
3817 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3818 if (DBG_MERGE) {
3819 log("getLine1NumberForDisplay returning "
3820 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3821 }
3822 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3825 return null;
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003828 }
Derek Tan7226c842014-07-02 17:42:23 -07003829 }
3830
3831 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003832 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003834 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003835 return null;
3836 }
Derek Tan97ebb422014-09-05 16:55:38 -07003837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 String iccId = getIccId(subId);
3841 if (iccId != null) {
3842 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3843 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3844 }
3845 return null;
3846 } finally {
3847 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003848 }
Derek Tan7226c842014-07-02 17:42:23 -07003849 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003850
3851 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003852 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003853 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3854 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003856 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3857 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003858 return null;
3859 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003860
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003861 final long identity = Binder.clearCallingIdentity();
3862 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863 final Context context = mPhone.getContext();
3864 final TelephonyManager tele = TelephonyManager.from(context);
3865 final SubscriptionManager sub = SubscriptionManager.from(context);
3866
3867 // Figure out what subscribers are currently active
3868 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3869 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3870 // the process, where TelephonyManager was instantiated.
3871 // Otherwise AppOps check will fail.
3872
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003873 final int[] subIds = sub.getActiveSubscriptionIdList();
3874 for (int subId : subIds) {
3875 activeSubscriberIds.add(tele.getSubscriberId(subId));
3876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003877
3878 // First pass, find a number override for an active subscriber
3879 String mergeNumber = null;
3880 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3881 for (String key : prefs.keySet()) {
3882 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3883 final String subscriberId = (String) prefs.get(key);
3884 if (activeSubscriberIds.contains(subscriberId)) {
3885 final String iccId = key.substring(
3886 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3887 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3888 mergeNumber = (String) prefs.get(numberKey);
3889 if (DBG_MERGE) {
3890 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3891 + " for active subscriber " + subscriberId);
3892 }
3893 if (!TextUtils.isEmpty(mergeNumber)) {
3894 break;
3895 }
3896 }
3897 }
3898 }
3899
3900 // Shortcut when no active merged subscribers
3901 if (TextUtils.isEmpty(mergeNumber)) {
3902 return null;
3903 }
3904
3905 // Second pass, find all subscribers under that line override
3906 final ArraySet<String> result = new ArraySet<>();
3907 for (String key : prefs.keySet()) {
3908 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3909 final String number = (String) prefs.get(key);
3910 if (mergeNumber.equals(number)) {
3911 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3912 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3913 final String subscriberId = (String) prefs.get(subscriberKey);
3914 if (!TextUtils.isEmpty(subscriberId)) {
3915 result.add(subscriberId);
3916 }
3917 }
3918 }
3919 }
3920
3921 final String[] resultArray = result.toArray(new String[result.size()]);
3922 Arrays.sort(resultArray);
3923 if (DBG_MERGE) {
3924 Slog.d(LOG_TAG,
3925 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3926 }
3927 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003928 } finally {
3929 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003930 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003931 }
3932
3933 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003934 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003935 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3936 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937
3938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 final Phone phone = getPhone(subId);
3941 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3942 } finally {
3943 Binder.restoreCallingIdentity(identity);
3944 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003945 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003946
3947 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003948 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003949 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3950 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003951 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952
3953 final long identity = Binder.clearCallingIdentity();
3954 try {
3955 final Phone phone = getPhone(subId);
3956 if (phone == null) {
3957 return false;
3958 }
3959 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3960 cdmaNonRoamingList);
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003963 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003964 }
3965
3966 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003967 @Deprecated
3968 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3969 enforceModifyPermission();
3970
3971 int returnValue = 0;
3972 try {
3973 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3974 if(result.exception == null) {
3975 if (result.result != null) {
3976 byte[] responseData = (byte[])(result.result);
3977 if(responseData.length > oemResp.length) {
3978 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3979 responseData.length + "bytes. Buffer Size is " +
3980 oemResp.length + "bytes.");
3981 }
3982 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3983 returnValue = responseData.length;
3984 }
3985 } else {
3986 CommandException ex = (CommandException) result.exception;
3987 returnValue = ex.getCommandError().ordinal();
3988 if(returnValue > 0) returnValue *= -1;
3989 }
3990 } catch (RuntimeException e) {
3991 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3992 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3993 if(returnValue > 0) returnValue *= -1;
3994 }
3995
3996 return returnValue;
3997 }
3998
3999 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004000 public void setRadioCapability(RadioAccessFamily[] rafs) {
4001 try {
4002 ProxyController.getInstance().setRadioCapability(rafs);
4003 } catch (RuntimeException e) {
4004 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4005 }
4006 }
4007
4008 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004009 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004010 Phone phone = PhoneFactory.getPhone(phoneId);
4011 if (phone == null) {
4012 return RadioAccessFamily.RAF_UNKNOWN;
4013 }
4014 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004016 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004017 return RadioAccessFamily.RAF_UNKNOWN;
4018 }
4019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4023 } finally {
4024 Binder.restoreCallingIdentity(identity);
4025 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004026 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004027
4028 @Override
4029 public void enableVideoCalling(boolean enable) {
4030 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004038 }
4039
4040 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004041 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4043 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4044 return false;
4045 }
Svet Ganovb320e182015-04-16 12:30:10 -07004046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 // Check the user preference and the system-level IMS setting. Even if the user has
4050 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4051 // In the long run, we may instead need to check if there exists a connection service
4052 // which can support video calling.
4053 ImsManager imsManager =
4054 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4055 return imsManager.isVtEnabledByPlatform()
4056 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4057 && imsManager.isVtEnabledByUser();
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004061 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004062
Andrew Leea1239f22015-03-02 17:44:07 -08004063 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4066 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4067 return false;
4068 }
4069
4070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 CarrierConfigManager configManager =
4073 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4074 return configManager.getConfigForSubId(mPhone.getSubId())
4075 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4076 } finally {
4077 Binder.restoreCallingIdentity(identity);
4078 }
Andrew Leea1239f22015-03-02 17:44:07 -08004079 }
4080
4081 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 public boolean isWorldPhone(int subId, String callingPackage) {
4083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4084 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4085 return false;
4086 }
4087
4088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 CarrierConfigManager configManager =
4091 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4092 return configManager.getConfigForSubId(mPhone.getSubId())
4093 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4094 } finally {
4095 Binder.restoreCallingIdentity(identity);
4096 }
Andrew Leea1239f22015-03-02 17:44:07 -08004097 }
4098
Andrew Lee9431b832015-03-09 18:46:45 -07004099 @Override
4100 public boolean isTtyModeSupported() {
4101 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004102 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004103 }
4104
4105 @Override
4106 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107 final long identity = Binder.clearCallingIdentity();
4108 try {
4109 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
Andrew Lee9431b832015-03-09 18:46:45 -07004113 }
4114
Hall Liu98187582018-01-22 19:15:32 -08004115 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4119 mPhone.getSubId()).getBoolean(
4120 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4121 boolean isDeviceSupported =
4122 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4123 return isCarrierSupported && isDeviceSupported;
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
Hall Liu98187582018-01-22 19:15:32 -08004127 }
4128
Hall Liu3ad5f012018-04-06 16:23:39 -07004129 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 return isRttSupported() && Settings.Secure.getInt(
4133 mPhone.getContext().getContentResolver(),
4134 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4135 } finally {
4136 Binder.restoreCallingIdentity(identity);
4137 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004138 }
4139
Sanket Padawe7310cc72015-01-14 09:53:20 -08004140 /**
4141 * Returns the unique device ID of phone, for example, the IMEI for
4142 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4143 *
4144 * <p>Requires Permission:
4145 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4146 */
4147 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004148 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004149 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004150 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004151 return null;
4152 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004153 int subId = phone.getSubId();
4154 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4155 mApp, subId, callingPackage, "getDeviceId")) {
4156 return null;
4157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004158
4159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 return phone.getDeviceId();
4162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004165 }
4166
Ping Sunc67b7c22016-03-02 19:16:45 +08004167 /**
4168 * {@hide}
4169 * Returns the IMS Registration Status on a particular subid
4170 *
4171 * @param subId
4172 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004173 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004174 Phone phone = getPhone(subId);
4175 if (phone != null) {
4176 return phone.isImsRegistered();
4177 } else {
4178 return false;
4179 }
4180 }
4181
Santos Cordon7a1885b2015-02-03 11:15:19 -08004182 @Override
4183 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184 final long identity = Binder.clearCallingIdentity();
4185 try {
4186 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4187 } finally {
4188 Binder.restoreCallingIdentity(identity);
4189 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004190 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004191
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004192 /**
4193 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004194 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004195 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196 final long identity = Binder.clearCallingIdentity();
4197 try {
4198 Phone phone = getPhone(subId);
4199 if (phone != null) {
4200 return phone.isWifiCallingEnabled();
4201 } else {
4202 return false;
4203 }
4204 } finally {
4205 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004206 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004207 }
4208
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004209 /**
4210 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004211 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004212 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 Phone phone = getPhone(subId);
4216 if (phone != null) {
4217 return phone.isVolteEnabled();
4218 } else {
4219 return false;
4220 }
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004223 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004224 }
Svet Ganovb320e182015-04-16 12:30:10 -07004225
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004226 /**
4227 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004228 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004229 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 final long identity = Binder.clearCallingIdentity();
4231 try {
4232 Phone phone = getPhone(subId);
4233 if (phone != null) {
4234 return phone.isVideoEnabled();
4235 } else {
4236 return false;
4237 }
4238 } finally {
4239 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004240 }
4241 }
4242
4243 /**
4244 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4245 * defined in {@link ImsRegistrationImplBase}.
4246 */
4247 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248 final long identity = Binder.clearCallingIdentity();
4249 try {
4250 Phone phone = getPhone(subId);
4251 if (phone != null) {
4252 return phone.getImsRegistrationTech();
4253 } else {
4254 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4255 }
4256 } finally {
4257 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004258 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004259 }
4260
Stuart Scott8eef64f2015-04-08 15:13:54 -07004261 @Override
4262 public void factoryReset(int subId) {
4263 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004264 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4265 return;
4266 }
4267
Svet Ganovcc087f82015-05-12 20:35:54 -07004268 final long identity = Binder.clearCallingIdentity();
4269 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004270 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4271 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004272 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004273 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004274 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4275 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004276 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004277 }
4278 } finally {
4279 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004280 }
4281 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004282
4283 @Override
4284 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 final long identity = Binder.clearCallingIdentity();
4286 try {
4287 // We query all subscriptions instead of just the active ones, because
4288 // this might be called early on in the provisioning flow when the
4289 // subscriptions potentially aren't active yet.
4290 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4291 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004292 return null;
4293 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295 // This function may be called very early, say, from the setup wizard, at
4296 // which point we won't have a default subscription set. If that's the case
4297 // we just choose the first, which will be valid in "most cases".
4298 final int defaultSubId = getDefaultSubscription();
4299 SubscriptionInfo info = null;
4300 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4301 info = slist.get(0);
4302 } else {
4303 for (SubscriptionInfo item : slist) {
4304 if (item.getSubscriptionId() == defaultSubId) {
4305 info = item;
4306 break;
4307 }
4308 }
4309
4310 if (info == null) {
4311 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004312 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004313 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315 // Try and fetch the locale from the carrier properties or from the SIM language
4316 // preferences (EF-PL and EF-LI)...
4317 final int mcc = info.getMcc();
4318 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4319 String simLanguage = null;
4320 if (defaultPhone != null) {
4321 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4322 if (localeFromDefaultSim != null) {
4323 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4324 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4325 return localeFromDefaultSim.toLanguageTag();
4326 } else {
4327 simLanguage = localeFromDefaultSim.getLanguage();
4328 }
4329 }
4330 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332 // The SIM language preferences only store a language (e.g. fr = French), not an
4333 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4334 // the SIM and carrier preferences does not include a country we add the country
4335 // determined from the SIM MCC to provide an exact locale.
4336 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4337 simLanguage);
4338 if (mccLocale != null) {
4339 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4340 return mccLocale.toLanguageTag();
4341 }
4342
4343 if (DBG) log("No locale found - returning null");
4344 return null;
4345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004348 }
4349
4350 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351 return mSubscriptionController.getAllSubInfoList(
4352 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004353 }
4354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355 /**
4356 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4357 */
4358 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4359 return mSubscriptionController.getActiveSubscriptionInfoList(
4360 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004361 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004362
Chenjie Yu1ba97252018-01-11 18:16:20 -08004363 private final ModemActivityInfo mLastModemActivityInfo =
4364 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4365
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004366 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004367 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4368 * representing the state of the modem.
4369 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004370 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4371 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004372 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004373 */
4374 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004375 public void requestModemActivityInfo(ResultReceiver result) {
4376 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377
4378 final long identity = Binder.clearCallingIdentity();
4379 try {
4380 ModemActivityInfo ret = null;
4381 synchronized (mLastModemActivityInfo) {
4382 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4383 CMD_GET_MODEM_ACTIVITY_INFO,
4384 null);
Siddharth Rayb8114062018-06-17 15:02:38 -07004385 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4387 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4388 mergedTxTimeMs[i] =
4389 info.getTxTimeMillis()[i]
4390 + mLastModemActivityInfo.getTxTimeMillis()[i];
4391 }
4392 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4393 mLastModemActivityInfo.setSleepTimeMillis(
4394 info.getSleepTimeMillis()
4395 + mLastModemActivityInfo.getSleepTimeMillis());
4396 mLastModemActivityInfo.setIdleTimeMillis(
4397 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4398 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4399 mLastModemActivityInfo.setRxTimeMillis(
4400 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4401 mLastModemActivityInfo.setEnergyUsed(
4402 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4405 mLastModemActivityInfo.getSleepTimeMillis(),
4406 mLastModemActivityInfo.getIdleTimeMillis(),
4407 mLastModemActivityInfo.getTxTimeMillis(),
4408 mLastModemActivityInfo.getRxTimeMillis(),
4409 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004411 Bundle bundle = new Bundle();
4412 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4413 result.send(0, bundle);
4414 } finally {
4415 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004416 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004417 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004418
Siddharth Rayb8114062018-06-17 15:02:38 -07004419 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4420 // less than total activity duration.
4421 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4422 if (info == null) {
4423 return false;
4424 }
4425 int activityDurationMs =
4426 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4427 int totalTxTimeMs = 0;
4428 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4429 totalTxTimeMs += info.getTxTimeMillis()[i];
4430 }
4431 return (info.isValid()
4432 && (info.getSleepTimeMillis() <= activityDurationMs)
4433 && (info.getIdleTimeMillis() <= activityDurationMs)
4434 && (info.getRxTimeMillis() <= activityDurationMs)
4435 && (totalTxTimeMs <= activityDurationMs));
4436 }
4437
Jack Yu85bd38a2015-11-09 11:34:32 -08004438 /**
4439 * {@hide}
4440 * Returns the service state information on specified subscription.
4441 */
4442 @Override
4443 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004444 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004445 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004446 return null;
4447 }
4448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 final long identity = Binder.clearCallingIdentity();
4450 try {
4451 final Phone phone = getPhone(subId);
4452 if (phone == null) {
4453 return null;
4454 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 return phone.getServiceState();
4457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004460 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004461
4462 /**
4463 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4464 *
4465 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4466 * voicemail ringtone.
4467 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4468 * PhoneAccount.
4469 */
4470 @Override
4471 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 final long identity = Binder.clearCallingIdentity();
4473 try {
4474 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4475 if (phone == null) {
4476 phone = mPhone;
4477 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004483 }
4484
4485 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004486 * Sets the per-account voicemail ringtone.
4487 *
4488 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4489 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4490 *
4491 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4492 * voicemail ringtone.
4493 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4494 * PhoneAccount.
4495 */
4496 @Override
4497 public void setVoicemailRingtoneUri(String callingPackage,
4498 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4500 if (!TextUtils.equals(callingPackage,
4501 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4503 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4504 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004505 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004506
4507 final long identity = Binder.clearCallingIdentity();
4508 try {
4509 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4510 if (phone == null) {
4511 phone = mPhone;
4512 }
4513 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4514 } finally {
4515 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004516 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004517 }
4518
4519 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004520 * Returns whether vibration is set for voicemail notification in Phone settings.
4521 *
4522 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4523 * voicemail vibration setting.
4524 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4525 */
4526 @Override
4527 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 final long identity = Binder.clearCallingIdentity();
4529 try {
4530 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4531 if (phone == null) {
4532 phone = mPhone;
4533 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004539 }
4540
Youhan Wange64578a2016-05-02 15:32:42 -07004541 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004542 * Sets the per-account voicemail vibration.
4543 *
4544 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4545 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4546 *
4547 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4548 * voicemail vibration setting.
4549 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4550 * specific PhoneAccount.
4551 */
4552 @Override
4553 public void setVoicemailVibrationEnabled(String callingPackage,
4554 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4556 if (!TextUtils.equals(callingPackage,
4557 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4559 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4560 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004561 }
4562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563 final long identity = Binder.clearCallingIdentity();
4564 try {
4565 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4566 if (phone == null) {
4567 phone = mPhone;
4568 }
4569 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4570 } finally {
4571 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004572 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004573 }
4574
4575 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004576 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4577 *
4578 * @throws SecurityException if the caller does not have the required permission
4579 */
4580 private void enforceReadPrivilegedPermission() {
4581 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4582 null);
4583 }
4584
4585 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004586 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4587 * permission.
4588 *
4589 * @throws SecurityException if the caller does not have the required permission
4590 */
4591 private void enforceSendSmsPermission() {
4592 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4593 }
4594
4595 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004596 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004597 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004598 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004599 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004600 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 final long identity = Binder.clearCallingIdentity();
4602 try {
4603 ComponentName componentName =
4604 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4605 if (componentName == null) {
4606 throw new SecurityException(
4607 "Caller not current active visual voicemail package[null]");
4608 }
4609 String vvmPackage = componentName.getPackageName();
4610 if (!callingPackage.equals(vvmPackage)) {
4611 throw new SecurityException("Caller not current active visual voicemail package["
4612 + vvmPackage + "]");
4613 }
4614 } finally {
4615 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004616 }
4617 }
4618
4619 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004620 * Return the application ID for the app type.
4621 *
4622 * @param subId the subscription ID that this request applies to.
4623 * @param appType the uicc app type.
4624 * @return Application ID for specificied app type, or null if no uicc.
4625 */
4626 @Override
4627 public String getAidForAppType(int subId, int appType) {
4628 enforceReadPrivilegedPermission();
4629 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630
4631 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004632 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 if (phone == null) {
4634 return null;
4635 }
4636 String aid = null;
4637 try {
4638 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4639 .getApplicationByType(appType).getAid();
4640 } catch (Exception e) {
4641 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4642 }
4643 return aid;
4644 } finally {
4645 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004646 }
Youhan Wange64578a2016-05-02 15:32:42 -07004647 }
4648
Youhan Wang4001d252016-05-11 10:29:41 -07004649 /**
4650 * Return the Electronic Serial Number.
4651 *
4652 * @param subId the subscription ID that this request applies to.
4653 * @return ESN or null if error.
4654 */
4655 @Override
4656 public String getEsn(int subId) {
4657 enforceReadPrivilegedPermission();
4658 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659
4660 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004661 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 if (phone == null) {
4663 return null;
4664 }
4665 String esn = null;
4666 try {
4667 esn = phone.getEsn();
4668 } catch (Exception e) {
4669 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4670 }
4671 return esn;
4672 } finally {
4673 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004674 }
Youhan Wang4001d252016-05-11 10:29:41 -07004675 }
4676
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004677 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004678 * Return the Preferred Roaming List Version.
4679 *
4680 * @param subId the subscription ID that this request applies to.
4681 * @return PRLVersion or null if error.
4682 */
4683 @Override
4684 public String getCdmaPrlVersion(int subId) {
4685 enforceReadPrivilegedPermission();
4686 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687
4688 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004689 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690 if (phone == null) {
4691 return null;
4692 }
4693 String cdmaPrlVersion = null;
4694 try {
4695 cdmaPrlVersion = phone.getCdmaPrlVersion();
4696 } catch (Exception e) {
4697 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4698 }
4699 return cdmaPrlVersion;
4700 } finally {
4701 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004702 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004703 }
4704
4705 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004706 * Get snapshot of Telephony histograms
4707 * @return List of Telephony histograms
4708 * @hide
4709 */
4710 @Override
4711 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4713 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004714
4715 final long identity = Binder.clearCallingIdentity();
4716 try {
4717 return RIL.getTelephonyRILTimingHistograms();
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004721 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004722
4723 /**
4724 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004725 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004726 * Require system privileges. In the future we may add this to carrier APIs.
4727 *
4728 * @return The number of carriers set successfully, should match length of carriers
4729 */
4730 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004731 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004732 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004733
Meng Wang9b7c4e92017-02-17 11:41:27 -08004734 if (carriers == null) {
4735 throw new NullPointerException("carriers cannot be null");
4736 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4741 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4742 return retVal[0];
4743 } finally {
4744 Binder.restoreCallingIdentity(identity);
4745 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004746 }
4747
4748 /**
4749 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004750 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004751 * Require system privileges. In the future we may add this to carrier APIs.
4752 *
4753 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4754 * means all carriers are allowed.
4755 */
4756 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004757 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004758 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759
4760 final long identity = Binder.clearCallingIdentity();
4761 try {
4762 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4763 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4764 } finally {
4765 Binder.restoreCallingIdentity(identity);
4766 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004767 }
4768
fionaxu59545b42016-05-25 15:53:37 -07004769 /**
4770 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4771 * @param subId the subscription ID that this action applies to.
4772 * @param enabled control enable or disable metered apns.
4773 * {@hide}
4774 */
4775 @Override
4776 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4777 enforceModifyPermission();
4778 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779
4780 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004781 if (phone == null) {
4782 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4783 return;
4784 }
4785 try {
4786 phone.carrierActionSetMeteredApnsEnabled(enabled);
4787 } catch (Exception e) {
4788 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 } finally {
4790 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004791 }
4792 }
4793
4794 /**
4795 * Action set from carrier signalling broadcast receivers to enable/disable radio
4796 * @param subId the subscription ID that this action applies to.
4797 * @param enabled control enable or disable radio.
4798 * {@hide}
4799 */
4800 @Override
4801 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4802 enforceModifyPermission();
4803 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804
4805 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004806 if (phone == null) {
4807 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4808 return;
4809 }
4810 try {
4811 phone.carrierActionSetRadioEnabled(enabled);
4812 } catch (Exception e) {
4813 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814 } finally {
4815 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004816 }
4817 }
4818
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004819 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004820 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4821 * network status based on which carrier apps could apply actions accordingly,
4822 * enable/disable default url handler for example.
4823 *
4824 * @param subId the subscription ID that this action applies to.
4825 * @param report control start/stop reporting the default network status.
4826 * {@hide}
4827 */
4828 @Override
4829 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4830 enforceModifyPermission();
4831 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832
4833 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004834 if (phone == null) {
4835 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4836 return;
4837 }
4838 try {
4839 phone.carrierActionReportDefaultNetworkStatus(report);
4840 } catch (Exception e) {
4841 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 } finally {
4843 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004844 }
4845 }
4846
4847 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004848 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4849 * bug report is being generated.
4850 */
4851 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004852 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004853 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4854 != PackageManager.PERMISSION_GRANTED) {
4855 writer.println("Permission Denial: can't dump Phone from pid="
4856 + Binder.getCallingPid()
4857 + ", uid=" + Binder.getCallingUid()
4858 + "without permission "
4859 + android.Manifest.permission.DUMP);
4860 return;
4861 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004862 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004863 }
Jack Yueb89b242016-06-22 13:27:47 -07004864
Brad Ebingerdac2f002018-04-03 15:17:52 -07004865 @Override
4866 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4867 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4868 throws RemoteException {
4869 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4870 }
4871
Jack Yueb89b242016-06-22 13:27:47 -07004872 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004873 * Get aggregated video call data usage since boot.
4874 *
4875 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4876 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004877 * {@hide}
4878 */
4879 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004880 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004881 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4882 null);
4883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 final long identity = Binder.clearCallingIdentity();
4885 try {
4886 // NetworkStatsService keeps tracking the active network interface and identity. It
4887 // records the delta with the corresponding network identity.
4888 // We just return the total video call data usage snapshot since boot.
4889 Phone phone = getPhone(subId);
4890 if (phone != null) {
4891 return phone.getVtDataUsage(perUidStats);
4892 }
4893 return null;
4894 } finally {
4895 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004896 }
Jack Yueb89b242016-06-22 13:27:47 -07004897 }
Jack Yu75ab2952016-07-08 14:29:33 -07004898
4899 /**
4900 * Policy control of data connection. Usually used when data limit is passed.
4901 * @param enabled True if enabling the data, otherwise disabling.
4902 * @param subId Subscription index
4903 * {@hide}
4904 */
4905 @Override
4906 public void setPolicyDataEnabled(boolean enabled, int subId) {
4907 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908
4909 final long identity = Binder.clearCallingIdentity();
4910 try {
4911 Phone phone = getPhone(subId);
4912 if (phone != null) {
4913 phone.setPolicyDataEnabled(enabled);
4914 }
4915 } finally {
4916 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004917 }
4918 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004919
4920 /**
4921 * Get Client request stats
4922 * @return List of Client Request Stats
4923 * @hide
4924 */
4925 @Override
4926 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004927 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004928 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004929 return null;
4930 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004931 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 final long identity = Binder.clearCallingIdentity();
4934 try {
4935 if (phone != null) {
4936 return phone.getClientRequestStats();
4937 }
4938
4939 return null;
4940 } finally {
4941 Binder.restoreCallingIdentity(identity);
4942 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004943 }
4944
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004945 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004946 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004947 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004948 }
Jack Yueb4124c2017-02-16 15:32:43 -08004949
4950 /**
Grace Chen70990072017-03-24 17:21:30 -07004951 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004952 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004953 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004954 * @param state State of SIM (power down, power up, pass through)
4955 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4956 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4957 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004958 *
4959 **/
4960 @Override
Grace Chen70990072017-03-24 17:21:30 -07004961 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004962 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004963 Phone phone = PhoneFactory.getPhone(slotIndex);
4964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965 final long identity = Binder.clearCallingIdentity();
4966 try {
4967 if (phone != null) {
4968 phone.setSimPowerState(state);
4969 }
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004972 }
4973 }
Shuo Qiandd210312017-04-12 22:11:33 +00004974
Tyler Gunn65d45c22017-06-05 11:22:26 -07004975 private boolean isUssdApiAllowed(int subId) {
4976 CarrierConfigManager configManager =
4977 (CarrierConfigManager) mPhone.getContext().getSystemService(
4978 Context.CARRIER_CONFIG_SERVICE);
4979 if (configManager == null) {
4980 return false;
4981 }
4982 PersistableBundle pb = configManager.getConfigForSubId(subId);
4983 if (pb == null) {
4984 return false;
4985 }
4986 return pb.getBoolean(
4987 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4988 }
4989
Shuo Qiandd210312017-04-12 22:11:33 +00004990 /**
4991 * Check if phone is in emergency callback mode
4992 * @return true if phone is in emergency callback mode
4993 * @param subId sub id
4994 */
goneil9c5f4872017-12-05 14:07:56 -08004995 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004996 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004997 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004998 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999
5000 final long identity = Binder.clearCallingIdentity();
5001 try {
5002 if (phone != null) {
5003 return phone.isInEcm();
5004 } else {
5005 return false;
5006 }
5007 } finally {
5008 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005009 }
5010 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005011
5012 /**
5013 * Get the current signal strength information for the given subscription.
5014 * Because this information is not updated when the device is in a low power state
5015 * it should not be relied-upon to be current.
5016 * @param subId Subscription index
5017 * @return the most recent cached signal strength info from the modem
5018 */
5019 @Override
5020 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021 final long identity = Binder.clearCallingIdentity();
5022 try {
5023 Phone p = getPhone(subId);
5024 if (p == null) {
5025 return null;
5026 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 return p.getSignalStrength();
5029 } finally {
5030 Binder.restoreCallingIdentity(identity);
5031 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005032 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005033
Pengquan Meng77b7f132018-08-22 14:49:57 -07005034 /**
5035 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5036 *
5037 * <p>Requires one of the following permissions:
5038 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5039 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5040 * privileges.
5041 *
5042 * @param subId subscription id
5043 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5044 * {@code false}.
5045 */
5046 @Override
5047 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005048 boolean isEnabled = false;
5049 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005050 try {
5051 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005052 null /* message */);
5053 Phone phone = getPhone(subId);
5054 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005055 } catch (Exception e) {
5056 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5057 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005058 } finally {
5059 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005060 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005061 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005062 }
5063
5064
5065 /**
5066 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5067 *
5068 * <p> Requires permission:
5069 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5070 * privileges.
5071 *
5072 * @param subId subscription id
5073 * @param isEnabled {@code true} means enable, {@code false} means disable.
5074 */
5075 @Override
5076 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5080 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005081
Pengquan Menga1bb6272018-09-06 09:59:22 -07005082 Phone phone = getPhone(subId);
5083 if (phone != null) {
5084 phone.setDataRoamingEnabled(isEnabled);
5085 }
5086 } finally {
5087 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005088 }
5089 }
5090
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005091 @Override
5092 public UiccSlotInfo[] getUiccSlotsInfo() {
5093 enforceReadPrivilegedPermission();
5094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
5097 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5098 if (slots == null) {
5099 Rlog.i(LOG_TAG, "slots is null.");
5100 return null;
5101 }
5102
5103 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5104 for (int i = 0; i < slots.length; i++) {
5105 UiccSlot slot = slots[i];
5106 if (slot == null) {
5107 continue;
5108 }
5109
5110 String cardId;
5111 UiccCard card = slot.getUiccCard();
5112 if (card != null) {
5113 cardId = card.getCardId();
5114 } else {
5115 cardId = slot.getIccId();
5116 }
5117
5118 int cardState = 0;
5119 switch (slot.getCardState()) {
5120 case CARDSTATE_ABSENT:
5121 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5122 break;
5123 case CARDSTATE_PRESENT:
5124 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5125 break;
5126 case CARDSTATE_ERROR:
5127 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5128 break;
5129 case CARDSTATE_RESTRICTED:
5130 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5131 break;
5132 default:
5133 break;
5134
5135 }
5136
5137 infos[i] = new UiccSlotInfo(
5138 slot.isActive(),
5139 slot.isEuicc(),
5140 cardId,
5141 cardState,
5142 slot.getPhoneId(),
5143 slot.isExtendedApduSupported());
5144 }
5145 return infos;
5146 } finally {
5147 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005148 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005149 }
5150
5151 @Override
5152 public boolean switchSlots(int[] physicalSlots) {
5153 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154
5155 final long identity = Binder.clearCallingIdentity();
5156 try {
5157 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005161 }
Jack Yu4c988042018-02-27 15:30:01 -08005162
5163 @Override
5164 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5165 enforceModifyPermission();
5166 final Phone phone = getPhone(subId);
5167 if (phone == null) {
5168 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5169 return;
5170 }
5171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 final long identity = Binder.clearCallingIdentity();
5173 try {
5174 phone.setRadioIndicationUpdateMode(filters, mode);
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
Jack Yu4c988042018-02-27 15:30:01 -08005178 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005179
5180 /**
goneil47ffb6e2018-04-06 15:40:58 -07005181 * A test API to reload the UICC profile.
5182 *
5183 * <p>Requires that the calling app has permission
5184 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5185 * @hide
5186 */
5187 @Override
5188 public void refreshUiccProfile(int subId) {
5189 enforceModifyPermission();
5190
5191 final long identity = Binder.clearCallingIdentity();
5192 try {
5193 Phone phone = getPhone(subId);
5194 if (phone == null) {
5195 return;
5196 }
5197 UiccCard uiccCard = phone.getUiccCard();
5198 if (uiccCard == null) {
5199 return;
5200 }
5201 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5202 if (uiccProfile == null) {
5203 return;
5204 }
5205 uiccProfile.refresh();
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
5208 }
5209 }
5210
5211 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005212 * Returns false if the mobile data is disabled by default, otherwise return true.
5213 */
5214 private boolean getDefaultDataEnabled() {
5215 return "true".equalsIgnoreCase(
5216 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5217 }
5218
5219 /**
5220 * Returns true if the data roaming is enabled by default, i.e the system property
5221 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5222 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5223 */
5224 private boolean getDefaultDataRoamingEnabled(int subId) {
5225 final CarrierConfigManager configMgr = (CarrierConfigManager)
5226 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5227 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5228 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5229 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5230 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5231 return isDataRoamingEnabled;
5232 }
5233
5234 /**
5235 * Returns the default network type for the given {@code subId}, if the default network type is
5236 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5237 */
5238 private int getDefaultNetworkType(int subId) {
5239 return Integer.parseInt(
5240 TelephonyManager.getTelephonyProperty(
5241 mSubscriptionController.getPhoneId(subId),
5242 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5243 String.valueOf(Phone.PREFERRED_NT_MODE)));
5244 }
fionaxua13278b2018-03-21 00:08:13 -07005245
5246 @Override
5247 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5248 gid1, String gid2, String plmn, String spn) {
5249 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250
5251 final long identity = Binder.clearCallingIdentity();
5252 try {
5253 final Phone phone = getPhone(subId);
5254 if (phone == null) {
5255 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5256 return;
5257 }
5258 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005261 }
fionaxua13278b2018-03-21 00:08:13 -07005262 }
5263
5264 @Override
5265 public int getCarrierIdListVersion(int subId) {
5266 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267
5268 final long identity = Binder.clearCallingIdentity();
5269 try {
5270 final Phone phone = getPhone(subId);
5271 if (phone == null) {
5272 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5273 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5274 }
5275 return phone.getCarrierIdListVersion();
5276 } finally {
5277 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005278 }
fionaxua13278b2018-03-21 00:08:13 -07005279 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005280
5281 @Override
5282 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5284 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5285 return -1;
5286 }
5287
5288 final long identity = Binder.clearCallingIdentity();
5289 try {
5290 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
5294 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005295
5296 @Override
5297 public int getCdmaRoamingMode(int subId) {
5298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5299 mApp, subId, "getCdmaRoamingMode");
5300
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
5306 }
5307 }
5308
5309 @Override
5310 public boolean setCdmaRoamingMode(int subId, int mode) {
5311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5312 mApp, subId, "setCdmaRoamingMode");
5313
5314 final long identity = Binder.clearCallingIdentity();
5315 try {
5316 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
5320 }
5321
5322 @Override
5323 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5325 mApp, subId, "setCdmaSubscriptionMode");
5326
5327 final long identity = Binder.clearCallingIdentity();
5328 try {
5329 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
5332 }
5333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005334}