blob: 393168b5bd0176a0b85372c75620acf8749fd774 [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;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070059import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080060import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070061import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080062import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070063import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070064import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070065import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080067import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070068import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080069import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080070import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070071import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000073import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070074import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070075import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080076import android.telephony.ims.aidl.IImsConfig;
77import android.telephony.ims.aidl.IImsMmTelFeature;
78import android.telephony.ims.aidl.IImsRcsFeature;
79import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080080import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080082import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080083import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080086import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080087
Andrew Lee312e8172014-10-23 17:01:36 -070088import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080089import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070091import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070092import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070093import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070094import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080097import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -070098import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +010099import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700100import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700101import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800103import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700105import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700106import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700107import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700108import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700109import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800110import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800111import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700112import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700113import com.android.internal.telephony.uicc.IccIoResult;
114import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800115import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700116import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800117import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800119import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000120import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700121import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800122import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700123import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800124import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700125import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700126import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800127
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700128import java.io.FileDescriptor;
129import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800133import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100134import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800135import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136
137/**
138 * Implementation of the ITelephony interface.
139 */
Santos Cordon117fee72014-05-16 17:56:12 -0700140public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141 private static final String LOG_TAG = "PhoneInterfaceManager";
142 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
143 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800144 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145
146 // Message codes used with mMainThreadHandler
147 private static final int CMD_HANDLE_PIN_MMI = 1;
148 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
149 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
150 private static final int CMD_ANSWER_RINGING_CALL = 4;
151 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700152 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
153 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154 private static final int CMD_OPEN_CHANNEL = 9;
155 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
156 private static final int CMD_CLOSE_CHANNEL = 11;
157 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800158 private static final int CMD_NV_READ_ITEM = 13;
159 private static final int EVENT_NV_READ_ITEM_DONE = 14;
160 private static final int CMD_NV_WRITE_ITEM = 15;
161 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
162 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
163 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
164 private static final int CMD_NV_RESET_CONFIG = 19;
165 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800166 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
167 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
168 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
169 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800170 private static final int CMD_SEND_ENVELOPE = 25;
171 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000172 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
173 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700174 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
175 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
176 private static final int CMD_EXCHANGE_SIM_IO = 31;
177 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800178 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
179 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700180 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
181 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700182 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
183 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700184 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
185 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
186 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
187 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700188 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
189 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
190 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
191 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700192 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800193 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
194 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000195 private static final int CMD_SWITCH_SLOTS = 50;
196 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800198 // Parameters of select command.
199 private static final int SELECT_COMMAND = 0xA4;
200 private static final int SELECT_P1 = 0x04;
201 private static final int SELECT_P2 = 0;
202 private static final int SELECT_P3 = 0x10;
203
Pengquan Meng85728fb2018-03-12 16:31:21 -0700204 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
205 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
206 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
207
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 /** The singleton instance. */
209 private static PhoneInterfaceManager sInstance;
210
Wink Saville3ab207e2014-11-20 13:07:20 -0800211 private PhoneGlobals mApp;
212 private Phone mPhone;
213 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700214 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800215 private AppOpsManager mAppOps;
216 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800217 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800218 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219
Derek Tan97ebb422014-09-05 16:55:38 -0700220 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
221 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700223
Derek Tan740e1672017-06-27 14:56:27 -0700224 // The AID of ISD-R.
225 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
226
yinxub1bed742017-04-17 11:45:04 -0700227 private NetworkScanRequestTracker mNetworkScanRequestTracker;
228
Derek Tan89e89d42014-07-08 17:00:10 -0700229 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700230 * A request object to use for transmitting data to an ICC.
231 */
232 private static final class IccAPDUArgument {
233 public int channel, cla, command, p1, p2, p3;
234 public String data;
235
236 public IccAPDUArgument(int channel, int cla, int command,
237 int p1, int p2, int p3, String data) {
238 this.channel = channel;
239 this.cla = cla;
240 this.command = command;
241 this.p1 = p1;
242 this.p2 = p2;
243 this.p3 = p3;
244 this.data = data;
245 }
246 }
247
248 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700249 * A request object to use for transmitting data to an ICC.
250 */
251 private static final class ManualNetworkSelectionArgument {
252 public OperatorInfo operatorInfo;
253 public boolean persistSelection;
254
255 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
256 this.operatorInfo = operatorInfo;
257 this.persistSelection = persistSelection;
258 }
259 }
260
261 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
263 * request after sending. The main thread will notify the request when it is complete.
264 */
265 private static final class MainThreadRequest {
266 /** The argument to use for the request */
267 public Object argument;
268 /** The result of the request that is run on the main thread */
269 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800270 // The subscriber id that this request applies to. Defaults to
271 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
272 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273
274 public MainThreadRequest(Object argument) {
275 this.argument = argument;
276 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800277
278 public MainThreadRequest(Object argument, Integer subId) {
279 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800280 if (subId != null) {
281 this.subId = subId;
282 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284 }
285
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800286 private static final class IncomingThirdPartyCallArgs {
287 public final ComponentName component;
288 public final String callId;
289 public final String callerDisplayName;
290
291 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
292 String callerDisplayName) {
293 this.component = component;
294 this.callId = callId;
295 this.callerDisplayName = callerDisplayName;
296 }
297 }
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /**
300 * A handler that processes messages on the main thread in the phone process. Since many
301 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
302 * inbound binder threads to the main thread in the phone process. The Binder thread
303 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
304 * on, which will be notified when the operation completes and will contain the result of the
305 * request.
306 *
307 * <p>If a MainThreadRequest object is provided in the msg.obj field,
308 * note that request.result must be set to something non-null for the calling thread to
309 * unblock.
310 */
311 private final class MainThreadHandler extends Handler {
312 @Override
313 public void handleMessage(Message msg) {
314 MainThreadRequest request;
315 Message onCompleted;
316 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800317 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700318 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319
320 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700321 case CMD_HANDLE_USSD_REQUEST: {
322 request = (MainThreadRequest) msg.obj;
323 final Phone phone = getPhoneFromRequest(request);
324 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
325 String ussdRequest = ussdObject.first;
326 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700327
328 if (!isUssdApiAllowed(request.subId)) {
329 // Carrier does not support use of this API, return failure.
330 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
331 UssdResponse response = new UssdResponse(ussdRequest, null);
332 Bundle returnData = new Bundle();
333 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
334 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
335
336 request.result = true;
337 synchronized (request) {
338 request.notifyAll();
339 }
340 return;
341 }
342
Tyler Gunn52dcf772017-04-26 11:30:31 -0700343 try {
344 request.result = phone != null ?
345 phone.handleUssdRequest(ussdRequest, wrappedCallback)
346 : false;
347 } catch (CallStateException cse) {
348 request.result = false;
349 }
pkanwar32d516d2016-10-14 19:37:38 -0700350 // Wake up the requesting thread
351 synchronized (request) {
352 request.notifyAll();
353 }
354 break;
355 }
356
Yorke Lee716f67e2015-06-17 15:39:16 -0700357 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700359 final Phone phone = getPhoneFromRequest(request);
360 request.result = phone != null ?
361 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
362 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 // Wake up the requesting thread
364 synchronized (request) {
365 request.notifyAll();
366 }
367 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
370 case CMD_HANDLE_NEIGHBORING_CELL:
371 request = (MainThreadRequest) msg.obj;
372 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
373 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700374 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 break;
376
377 case EVENT_NEIGHBORING_CELL_DONE:
378 ar = (AsyncResult) msg.obj;
379 request = (MainThreadRequest) ar.userObj;
380 if (ar.exception == null && ar.result != null) {
381 request.result = ar.result;
382 } else {
383 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800384 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 }
386 // Wake up the requesting thread
387 synchronized (request) {
388 request.notifyAll();
389 }
390 break;
391
392 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700393 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800394 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700395 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 break;
397
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 case CMD_END_CALL:
399 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800400 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700401 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700402 Phone phone = getPhone(end_subId);
403 if (phone == null) {
404 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
405 break;
406 }
407 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
409 // CDMA: If the user presses the Power button we treat it as
410 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700411 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
413 // GSM: End the call as per the Phone state
414 hungUp = PhoneUtils.hangup(mCM);
415 } else {
416 throw new IllegalStateException("Unexpected phone type: " + phoneType);
417 }
418 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
419 request.result = hungUp;
420 // Wake up the requesting thread
421 synchronized (request) {
422 request.notifyAll();
423 }
424 break;
425
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700427 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800429 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 if (uiccCard == null) {
431 loge("iccTransmitApduLogicalChannel: No UICC");
432 request.result = new IccIoResult(0x6F, 0, (byte[])null);
433 synchronized (request) {
434 request.notifyAll();
435 }
436 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
438 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 iccArgument.channel, iccArgument.cla, iccArgument.command,
441 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700443 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 break;
445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 ar = (AsyncResult) msg.obj;
448 request = (MainThreadRequest) ar.userObj;
449 if (ar.exception == null && ar.result != null) {
450 request.result = ar.result;
451 } else {
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
453 if (ar.result == null) {
454 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800455 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800457 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 } else {
459 loge("iccTransmitApduLogicalChannel: Unknown exception");
460 }
461 }
462 synchronized (request) {
463 request.notifyAll();
464 }
465 break;
466
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
468 request = (MainThreadRequest) msg.obj;
469 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800470 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 if (uiccCard == null) {
472 loge("iccTransmitApduBasicChannel: No UICC");
473 request.result = new IccIoResult(0x6F, 0, (byte[])null);
474 synchronized (request) {
475 request.notifyAll();
476 }
477 } else {
478 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
479 request);
480 uiccCard.iccTransmitApduBasicChannel(
481 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
482 iccArgument.p3, iccArgument.data, onCompleted);
483 }
484 break;
485
486 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
487 ar = (AsyncResult) msg.obj;
488 request = (MainThreadRequest) ar.userObj;
489 if (ar.exception == null && ar.result != null) {
490 request.result = ar.result;
491 } else {
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
493 if (ar.result == null) {
494 loge("iccTransmitApduBasicChannel: Empty response");
495 } else if (ar.exception instanceof CommandException) {
496 loge("iccTransmitApduBasicChannel: CommandException: " +
497 ar.exception);
498 } else {
499 loge("iccTransmitApduBasicChannel: Unknown exception");
500 }
501 }
502 synchronized (request) {
503 request.notifyAll();
504 }
505 break;
506
507 case CMD_EXCHANGE_SIM_IO:
508 request = (MainThreadRequest) msg.obj;
509 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800510 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700511 if (uiccCard == null) {
512 loge("iccExchangeSimIO: No UICC");
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 synchronized (request) {
515 request.notifyAll();
516 }
517 } else {
518 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
519 request);
520 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
521 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
522 iccArgument.data, onCompleted);
523 }
524 break;
525
526 case EVENT_EXCHANGE_SIM_IO_DONE:
527 ar = (AsyncResult) msg.obj;
528 request = (MainThreadRequest) ar.userObj;
529 if (ar.exception == null && ar.result != null) {
530 request.result = ar.result;
531 } else {
532 request.result = new IccIoResult(0x6f, 0, (byte[])null);
533 }
534 synchronized (request) {
535 request.notifyAll();
536 }
537 break;
538
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 case CMD_SEND_ENVELOPE:
540 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800541 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 if (uiccCard == null) {
543 loge("sendEnvelopeWithStatus: No UICC");
544 request.result = new IccIoResult(0x6F, 0, (byte[])null);
545 synchronized (request) {
546 request.notifyAll();
547 }
548 } else {
549 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
550 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
551 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800552 break;
553
554 case EVENT_SEND_ENVELOPE_DONE:
555 ar = (AsyncResult) msg.obj;
556 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700557 if (ar.exception == null && ar.result != null) {
558 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
561 if (ar.result == null) {
562 loge("sendEnvelopeWithStatus: Empty response");
563 } else if (ar.exception instanceof CommandException) {
564 loge("sendEnvelopeWithStatus: CommandException: " +
565 ar.exception);
566 } else {
567 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
568 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800569 }
570 synchronized (request) {
571 request.notifyAll();
572 }
573 break;
574
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 case CMD_OPEN_CHANNEL:
576 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800577 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800578 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800581 request.result = new IccOpenLogicalChannelResponse(-1,
582 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 synchronized (request) {
584 request.notifyAll();
585 }
586 } else {
587 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800588 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
589 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 break;
592
593 case EVENT_OPEN_CHANNEL_DONE:
594 ar = (AsyncResult) msg.obj;
595 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 int[] result = (int[]) ar.result;
599 int channelId = result[0];
600 byte[] selectResponse = null;
601 if (result.length > 1) {
602 selectResponse = new byte[result.length - 1];
603 for (int i = 1; i < result.length; ++i) {
604 selectResponse[i - 1] = (byte) result[i];
605 }
606 }
607 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 if (ar.result == null) {
611 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 if (ar.exception != null) {
614 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
615 }
616
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700618 if (ar.exception instanceof CommandException) {
619 CommandException.Error error =
620 ((CommandException) (ar.exception)).getCommandError();
621 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700623 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 }
626 }
627 openChannelResp = new IccOpenLogicalChannelResponse(
628 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700630 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 synchronized (request) {
632 request.notifyAll();
633 }
634 break;
635
636 case CMD_CLOSE_CHANNEL:
637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800638 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 if (uiccCard == null) {
640 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900641 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 synchronized (request) {
643 request.notifyAll();
644 }
645 } else {
646 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
647 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
648 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
651 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800652 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
653 break;
654
655 case CMD_NV_READ_ITEM:
656 request = (MainThreadRequest) msg.obj;
657 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
658 mPhone.nvReadItem((Integer) request.argument, onCompleted);
659 break;
660
661 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800667 request.result = "";
668 if (ar.result == null) {
669 loge("nvReadItem: Empty response");
670 } else if (ar.exception instanceof CommandException) {
671 loge("nvReadItem: CommandException: " +
672 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800674 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 }
676 }
677 synchronized (request) {
678 request.notifyAll();
679 }
680 break;
681
Jake Hambye994d462014-02-03 13:10:13 -0800682 case CMD_NV_WRITE_ITEM:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
685 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
686 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
687 break;
688
689 case EVENT_NV_WRITE_ITEM_DONE:
690 handleNullReturnEvent(msg, "nvWriteItem");
691 break;
692
693 case CMD_NV_WRITE_CDMA_PRL:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
696 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
697 break;
698
699 case EVENT_NV_WRITE_CDMA_PRL_DONE:
700 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
701 break;
702
703 case CMD_NV_RESET_CONFIG:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
706 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
707 break;
708
709 case EVENT_NV_RESET_CONFIG_DONE:
710 handleNullReturnEvent(msg, "nvResetConfig");
711 break;
712
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 case CMD_GET_PREFERRED_NETWORK_TYPE:
714 request = (MainThreadRequest) msg.obj;
715 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700716 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 break;
718
719 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
720 ar = (AsyncResult) msg.obj;
721 request = (MainThreadRequest) ar.userObj;
722 if (ar.exception == null && ar.result != null) {
723 request.result = ar.result; // Integer
724 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800725 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 if (ar.result == null) {
727 loge("getPreferredNetworkType: Empty response");
728 } else if (ar.exception instanceof CommandException) {
729 loge("getPreferredNetworkType: CommandException: " +
730 ar.exception);
731 } else {
732 loge("getPreferredNetworkType: Unknown exception");
733 }
734 }
735 synchronized (request) {
736 request.notifyAll();
737 }
738 break;
739
740 case CMD_SET_PREFERRED_NETWORK_TYPE:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
743 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700744 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800745 break;
746
747 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
748 handleNullReturnEvent(msg, "setPreferredNetworkType");
749 break;
750
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000751 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
752 request = (MainThreadRequest)msg.obj;
753 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
754 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
755 break;
756
757 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
758 ar = (AsyncResult)msg.obj;
759 request = (MainThreadRequest)ar.userObj;
760 request.result = ar;
761 synchronized (request) {
762 request.notifyAll();
763 }
764 break;
765
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800766 case CMD_SET_VOICEMAIL_NUMBER:
767 request = (MainThreadRequest) msg.obj;
768 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
769 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800770 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
771 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 break;
773
774 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
775 handleNullReturnEvent(msg, "setVoicemailNumber");
776 break;
777
Stuart Scott54788802015-03-30 13:18:01 -0700778 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
781 request);
782 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
783 break;
784
785 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
786 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
787 break;
788
Shishir Agrawal302c8692015-06-19 13:49:39 -0700789 case CMD_PERFORM_NETWORK_SCAN:
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
792 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
793 break;
794
795 case EVENT_PERFORM_NETWORK_SCAN_DONE:
796 ar = (AsyncResult) msg.obj;
797 request = (MainThreadRequest) ar.userObj;
798 CellNetworkScanResult cellScanResult;
799 if (ar.exception == null && ar.result != null) {
800 cellScanResult = new CellNetworkScanResult(
801 CellNetworkScanResult.STATUS_SUCCESS,
802 (List<OperatorInfo>) ar.result);
803 } else {
804 if (ar.result == null) {
805 loge("getCellNetworkScanResults: Empty response");
806 }
807 if (ar.exception != null) {
808 loge("getCellNetworkScanResults: Exception: " + ar.exception);
809 }
810 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
811 if (ar.exception instanceof CommandException) {
812 CommandException.Error error =
813 ((CommandException) (ar.exception)).getCommandError();
814 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
815 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
816 } else if (error == CommandException.Error.GENERIC_FAILURE) {
817 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
818 }
819 }
820 cellScanResult = new CellNetworkScanResult(errorCode, null);
821 }
822 request.result = cellScanResult;
823 synchronized (request) {
824 request.notifyAll();
825 }
826 break;
827
828 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
829 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700830 ManualNetworkSelectionArgument selArg =
831 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
833 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700834 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
835 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 break;
837
838 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
839 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
840 break;
841
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700842 case CMD_GET_MODEM_ACTIVITY_INFO:
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700845 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700846 break;
847
848 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
849 ar = (AsyncResult) msg.obj;
850 request = (MainThreadRequest) ar.userObj;
851 if (ar.exception == null && ar.result != null) {
852 request.result = ar.result;
853 } else {
854 if (ar.result == null) {
855 loge("queryModemActivityInfo: Empty response");
856 } else if (ar.exception instanceof CommandException) {
857 loge("queryModemActivityInfo: CommandException: " +
858 ar.exception);
859 } else {
860 loge("queryModemActivityInfo: Unknown exception");
861 }
862 }
Amit Mahajand4766222016-01-28 15:28:28 -0800863 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
864 if (request.result == null) {
865 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
866 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700867 synchronized (request) {
868 request.notifyAll();
869 }
870 break;
871
Meng Wang1a7c35a2016-05-05 20:56:15 -0700872 case CMD_SET_ALLOWED_CARRIERS:
873 request = (MainThreadRequest) msg.obj;
874 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
875 mPhone.setAllowedCarriers(
876 (List<CarrierIdentifier>) request.argument,
877 onCompleted);
878 break;
879
880 case EVENT_SET_ALLOWED_CARRIERS_DONE:
881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result;
885 } else {
886 if (ar.result == null) {
887 loge("setAllowedCarriers: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("setAllowedCarriers: CommandException: " +
890 ar.exception);
891 } else {
892 loge("setAllowedCarriers: Unknown exception");
893 }
894 }
895 // Result cannot be null. Return -1 on error.
896 if (request.result == null) {
897 request.result = new int[]{-1};
898 }
899 synchronized (request) {
900 request.notifyAll();
901 }
902 break;
903
904 case CMD_GET_ALLOWED_CARRIERS:
905 request = (MainThreadRequest) msg.obj;
906 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
907 mPhone.getAllowedCarriers(onCompleted);
908 break;
909
910 case EVENT_GET_ALLOWED_CARRIERS_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result;
915 } else {
916 if (ar.result == null) {
917 loge("getAllowedCarriers: Empty response");
918 } else if (ar.exception instanceof CommandException) {
919 loge("getAllowedCarriers: CommandException: " +
920 ar.exception);
921 } else {
922 loge("getAllowedCarriers: Unknown exception");
923 }
924 }
925 // Result cannot be null. Return empty list of CarrierIdentifier.
926 if (request.result == null) {
927 request.result = new ArrayList<CarrierIdentifier>(0);
928 }
929 synchronized (request) {
930 request.notifyAll();
931 }
932 break;
933
Nathan Haroldb3014052017-01-25 15:57:32 -0800934 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 if (ar.exception == null && ar.result != null) {
938 request.result = ar.result;
939 } else {
940 request.result = new IllegalArgumentException(
941 "Failed to retrieve Forbidden Plmns");
942 if (ar.result == null) {
943 loge("getForbiddenPlmns: Empty response");
944 } else {
945 loge("getForbiddenPlmns: Unknown exception");
946 }
947 }
948 synchronized (request) {
949 request.notifyAll();
950 }
951 break;
952
953 case CMD_GET_FORBIDDEN_PLMNS:
954 request = (MainThreadRequest) msg.obj;
955 uiccCard = getUiccCardFromRequest(request);
956 if (uiccCard == null) {
957 loge("getForbiddenPlmns() UiccCard is null");
958 request.result = new IllegalArgumentException(
959 "getForbiddenPlmns() UiccCard is null");
960 synchronized (request) {
961 request.notifyAll();
962 }
963 break;
964 }
965 Integer appType = (Integer) request.argument;
966 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
967 if (uiccApp == null) {
968 loge("getForbiddenPlmns() no app with specified type -- "
969 + appType);
970 request.result = new IllegalArgumentException("Failed to get UICC App");
971 synchronized (request) {
972 request.notifyAll();
973 }
974 break;
975 } else {
976 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
977 + " specified type -- " + appType);
978 }
979 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
980 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
981 onCompleted);
982 break;
983
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000984 case CMD_SWITCH_SLOTS:
985 request = (MainThreadRequest) msg.obj;
986 int[] physicalSlots = (int[]) request.argument;
987 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
988 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
989 break;
990
991 case EVENT_SWITCH_SLOTS_DONE:
992 ar = (AsyncResult) msg.obj;
993 request = (MainThreadRequest) ar.userObj;
994 request.result = (ar.exception == null);
995 synchronized (request) {
996 request.notifyAll();
997 }
998 break;
999
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001000 default:
1001 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1002 break;
1003 }
1004 }
Jake Hambye994d462014-02-03 13:10:13 -08001005
1006 private void handleNullReturnEvent(Message msg, String command) {
1007 AsyncResult ar = (AsyncResult) msg.obj;
1008 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1009 if (ar.exception == null) {
1010 request.result = true;
1011 } else {
1012 request.result = false;
1013 if (ar.exception instanceof CommandException) {
1014 loge(command + ": CommandException: " + ar.exception);
1015 } else {
1016 loge(command + ": Unknown exception");
1017 }
1018 }
1019 synchronized (request) {
1020 request.notifyAll();
1021 }
1022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001023 }
1024
1025 /**
1026 * Posts the specified command to be executed on the main thread,
1027 * waits for the request to complete, and returns the result.
1028 * @see #sendRequestAsync
1029 */
1030 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001031 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001032 }
1033
1034 /**
1035 * Posts the specified command to be executed on the main thread,
1036 * waits for the request to complete, and returns the result.
1037 * @see #sendRequestAsync
1038 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001039 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001040 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1041 throw new RuntimeException("This method will deadlock if called from the main thread.");
1042 }
1043
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001044 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 Message msg = mMainThreadHandler.obtainMessage(command, request);
1046 msg.sendToTarget();
1047
1048 // Wait for the request to complete
1049 synchronized (request) {
1050 while (request.result == null) {
1051 try {
1052 request.wait();
1053 } catch (InterruptedException e) {
1054 // Do nothing, go back and wait until the request is complete
1055 }
1056 }
1057 }
1058 return request.result;
1059 }
1060
1061 /**
1062 * Asynchronous ("fire and forget") version of sendRequest():
1063 * Posts the specified command to be executed on the main thread, and
1064 * returns immediately.
1065 * @see #sendRequest
1066 */
1067 private void sendRequestAsync(int command) {
1068 mMainThreadHandler.sendEmptyMessage(command);
1069 }
1070
1071 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001072 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1073 * @see {@link #sendRequest(int,Object)}
1074 */
1075 private void sendRequestAsync(int command, Object argument) {
1076 MainThreadRequest request = new MainThreadRequest(argument);
1077 Message msg = mMainThreadHandler.obtainMessage(command, request);
1078 msg.sendToTarget();
1079 }
1080
1081 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001082 * Initialize the singleton PhoneInterfaceManager instance.
1083 * This is only done once, at startup, from PhoneApp.onCreate().
1084 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001085 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001086 synchronized (PhoneInterfaceManager.class) {
1087 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001088 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001089 } else {
1090 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1091 }
1092 return sInstance;
1093 }
1094 }
1095
1096 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001097 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001098 mApp = app;
1099 mPhone = phone;
1100 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001101 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001102 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1103 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001104 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001105 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001106 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001107 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001108
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001109 publish();
1110 }
1111
1112 private void publish() {
1113 if (DBG) log("publish: " + this);
1114
1115 ServiceManager.addService("phone", this);
1116 }
1117
Stuart Scott584921c2015-01-15 17:10:34 -08001118 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001119 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1120 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001121 }
1122
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001123 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1124 Phone phone = getPhoneFromRequest(request);
1125 return phone == null ? null :
1126 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1127 }
1128
Wink Saville36469e72014-06-11 15:17:00 -07001129 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001130 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001131 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001133 //
1134 // Implementation of the ITelephony interface.
1135 //
1136
1137 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001138 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001139 }
1140
Wink Savilleb564aae2014-10-23 10:18:09 -07001141 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 if (DBG) log("dial: " + number);
1143 // No permission check needed here: This is just a wrapper around the
1144 // ACTION_DIAL intent, which is available to any app since it puts up
1145 // the UI before it does anything.
1146
1147 String url = createTelUrl(number);
1148 if (url == null) {
1149 return;
1150 }
1151
1152 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001153 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001154 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1155 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1156 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1157 mApp.startActivity(intent);
1158 }
1159 }
1160
1161 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001162 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001163 }
1164
Wink Savilleb564aae2014-10-23 10:18:09 -07001165 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001166 if (DBG) log("call: " + number);
1167
1168 // This is just a wrapper around the ACTION_CALL intent, but we still
1169 // need to do a permission check since we're calling startActivity()
1170 // from the context of the phone app.
1171 enforceCallPermission();
1172
1173 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1174 != AppOpsManager.MODE_ALLOWED) {
1175 return;
1176 }
1177
1178 String url = createTelUrl(number);
1179 if (url == null) {
1180 return;
1181 }
1182
Wink Saville08874612014-08-31 19:19:58 -07001183 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001184 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001185 if (slist != null) {
1186 for (SubscriptionInfo subInfoRecord : slist) {
1187 if (subInfoRecord.getSubscriptionId() == subId) {
1188 isValid = true;
1189 break;
1190 }
Wink Saville08874612014-08-31 19:19:58 -07001191 }
1192 }
1193 if (isValid == false) {
1194 return;
1195 }
1196
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001198 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1200 mApp.startActivity(intent);
1201 }
1202
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203 /**
1204 * End a call based on call state
1205 * @return true is a call was ended
1206 */
1207 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001208 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001209 }
1210
1211 /**
1212 * End a call based on the call state of the subId
1213 * @return true is a call was ended
1214 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001215 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001216 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1217 != PackageManager.PERMISSION_GRANTED) {
1218 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1219 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1220 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1221 }
Stuart Scott584921c2015-01-15 17:10:34 -08001222 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 }
1224
1225 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001226 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001227 }
1228
Wink Savilleb564aae2014-10-23 10:18:09 -07001229 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 if (DBG) log("answerRingingCall...");
1231 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1232 // but that can probably wait till the big TelephonyManager API overhaul.
1233 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1234 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001235 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 }
1237
1238 /**
1239 * Make the actual telephony calls to implement answerRingingCall().
1240 * This should only be called from the main thread of the Phone app.
1241 * @see #answerRingingCall
1242 *
1243 * TODO: it would be nice to return true if we answered the call, or
1244 * false if there wasn't actually a ringing incoming call, or some
1245 * other error occurred. (In other words, pass back the return value
1246 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1247 * But that would require calling this method via sendRequest() rather
1248 * than sendRequestAsync(), and right now we don't actually *need* that
1249 * return value, so let's just return void for now.
1250 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001251 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001252 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001253 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001254 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1255 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001256 if (hasActiveCall && hasHoldingCall) {
1257 // Both lines are in use!
1258 // TODO: provide a flag to let the caller specify what
1259 // policy to use if both lines are in use. (The current
1260 // behavior is hardwired to "answer incoming, end ongoing",
1261 // which is how the CALL button is specced to behave.)
1262 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1263 return;
1264 } else {
1265 // answerCall() will automatically hold the current active
1266 // call, if there is one.
1267 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1268 return;
1269 }
1270 } else {
1271 // No call was ringing.
1272 return;
1273 }
1274 }
1275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001277 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001279 public void silenceRinger() {
1280 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 }
1282
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001283 @Override
1284 public boolean isOffhook(String callingPackage) {
1285 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
1287
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 @Override
1289 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001291 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001292 return false;
1293 }
1294
Sanket Padawe356d7632015-06-22 14:03:32 -07001295 final Phone phone = getPhone(subId);
1296 if (phone != null) {
1297 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1298 } else {
1299 return false;
1300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 }
1302
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001303 @Override
1304 public boolean isRinging(String callingPackage) {
1305 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001306 }
1307
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001308 @Override
1309 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001311 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001312 return false;
1313 }
1314
Sanket Padawe356d7632015-06-22 14:03:32 -07001315 final Phone phone = getPhone(subId);
1316 if (phone != null) {
1317 return (phone.getState() == PhoneConstants.State.RINGING);
1318 } else {
1319 return false;
1320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321 }
1322
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001323 @Override
1324 public boolean isIdle(String callingPackage) {
1325 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
1327
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001328 @Override
1329 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001331 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001332 return false;
1333 }
1334
Sanket Padawe356d7632015-06-22 14:03:32 -07001335 final Phone phone = getPhone(subId);
1336 if (phone != null) {
1337 return (phone.getState() == PhoneConstants.State.IDLE);
1338 } else {
1339 return false;
1340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341 }
1342
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001344 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001345 }
1346
Wink Savilleb564aae2014-10-23 10:18:09 -07001347 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001348 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001349 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1350 }
1351
1352 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001353 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001354 }
1355
Wink Savilleb564aae2014-10-23 10:18:09 -07001356 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001357 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001358 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1359 }
1360
1361 /** {@hide} */
1362 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001363 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001364 }
1365
Wink Savilleb564aae2014-10-23 10:18:09 -07001366 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001368 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001369 checkSimPin.start();
1370 return checkSimPin.unlockSim(null, pin);
1371 }
1372
Wink Saville9de0f752013-10-22 19:04:03 -07001373 /** {@hide} */
1374 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001380 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 checkSimPuk.start();
1382 return checkSimPuk.unlockSim(puk, pin);
1383 }
1384
1385 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001386 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387 * a synchronous one.
1388 */
1389 private static class UnlockSim extends Thread {
1390
1391 private final IccCard mSimCard;
1392
1393 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001394 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1395 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396
1397 // For replies from SimCard interface
1398 private Handler mHandler;
1399
1400 // For async handler to identify request type
1401 private static final int SUPPLY_PIN_COMPLETE = 100;
1402
1403 public UnlockSim(IccCard simCard) {
1404 mSimCard = simCard;
1405 }
1406
1407 @Override
1408 public void run() {
1409 Looper.prepare();
1410 synchronized (UnlockSim.this) {
1411 mHandler = new Handler() {
1412 @Override
1413 public void handleMessage(Message msg) {
1414 AsyncResult ar = (AsyncResult) msg.obj;
1415 switch (msg.what) {
1416 case SUPPLY_PIN_COMPLETE:
1417 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1418 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001419 mRetryCount = msg.arg1;
1420 if (ar.exception != null) {
1421 if (ar.exception instanceof CommandException &&
1422 ((CommandException)(ar.exception)).getCommandError()
1423 == CommandException.Error.PASSWORD_INCORRECT) {
1424 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1425 } else {
1426 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1427 }
1428 } else {
1429 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 mDone = true;
1432 UnlockSim.this.notifyAll();
1433 }
1434 break;
1435 }
1436 }
1437 };
1438 UnlockSim.this.notifyAll();
1439 }
1440 Looper.loop();
1441 }
1442
1443 /*
1444 * Use PIN or PUK to unlock SIM card
1445 *
1446 * If PUK is null, unlock SIM card with PIN
1447 *
1448 * If PUK is not null, unlock SIM card with PUK and set PIN code
1449 */
Wink Saville9de0f752013-10-22 19:04:03 -07001450 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451
1452 while (mHandler == null) {
1453 try {
1454 wait();
1455 } catch (InterruptedException e) {
1456 Thread.currentThread().interrupt();
1457 }
1458 }
1459 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1460
1461 if (puk == null) {
1462 mSimCard.supplyPin(pin, callback);
1463 } else {
1464 mSimCard.supplyPuk(puk, pin, callback);
1465 }
1466
1467 while (!mDone) {
1468 try {
1469 Log.d(LOG_TAG, "wait for done");
1470 wait();
1471 } catch (InterruptedException e) {
1472 // Restore the interrupted status
1473 Thread.currentThread().interrupt();
1474 }
1475 }
1476 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001477 int[] resultArray = new int[2];
1478 resultArray[0] = mResult;
1479 resultArray[1] = mRetryCount;
1480 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482 }
1483
1484 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001486
1487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 // No permission check needed here: this call is harmless, and it's
1491 // needed for the ServiceState.requestStateUpdate() call (which is
1492 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001493 final Phone phone = getPhone(subId);
1494 if (phone != null) {
1495 phone.updateServiceLocation();
1496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 }
1498
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001499 @Override
1500 public boolean isRadioOn(String callingPackage) {
1501 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001502 }
1503
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001504 @Override
1505 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001507 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001508 return false;
1509 }
1510 return isRadioOnForSubscriber(subId);
1511 }
1512
1513 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001514 final Phone phone = getPhone(subId);
1515 if (phone != null) {
1516 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1517 } else {
1518 return false;
1519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 }
1521
1522 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001523 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001524
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 }
Wink Saville36469e72014-06-11 15:17:00 -07001526
Wink Savilleb564aae2014-10-23 10:18:09 -07001527 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001529 final Phone phone = getPhone(subId);
1530 if (phone != null) {
1531 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1532 }
Wink Saville36469e72014-06-11 15:17:00 -07001533 }
1534
1535 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Wink Savilleb564aae2014-10-23 10:18:09 -07001539 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001540 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001541 final Phone phone = getPhone(subId);
1542 if (phone == null) {
1543 return false;
1544 }
1545 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001546 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001547 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 }
1549 return true;
1550 }
Wink Saville36469e72014-06-11 15:17:00 -07001551
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001552 public boolean needMobileRadioShutdown() {
1553 /*
1554 * If any of the Radios are available, it will need to be
1555 * shutdown. So return true if any Radio is available.
1556 */
1557 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1558 Phone phone = PhoneFactory.getPhone(i);
1559 if (phone != null && phone.isRadioAvailable()) return true;
1560 }
1561 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1562 return false;
1563 }
1564
1565 public void shutdownMobileRadios() {
1566 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1567 logv("Shutting down Phone " + i);
1568 shutdownRadioUsingPhoneId(i);
1569 }
1570 }
1571
1572 private void shutdownRadioUsingPhoneId(int phoneId) {
1573 enforceModifyPermission();
1574 Phone phone = PhoneFactory.getPhone(phoneId);
1575 if (phone != null && phone.isRadioAvailable()) {
1576 phone.shutdownRadio();
1577 }
1578 }
1579
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001581 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001582 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1583 if (defaultPhone != null) {
1584 defaultPhone.setRadioPower(turnOn);
1585 return true;
1586 } else {
1587 loge("There's no default phone.");
1588 return false;
1589 }
Wink Saville36469e72014-06-11 15:17:00 -07001590 }
1591
Wink Savilleb564aae2014-10-23 10:18:09 -07001592 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 final Phone phone = getPhone(subId);
1595 if (phone != null) {
1596 phone.setRadioPower(turnOn);
1597 return true;
1598 } else {
1599 return false;
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
Wink Saville36469e72014-06-11 15:17:00 -07001603 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 public boolean enableDataConnectivity() {
1606 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001607 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 final Phone phone = getPhone(subId);
1609 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001610 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 return true;
1612 } else {
1613 return false;
1614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
1616
Wink Saville36469e72014-06-11 15:17:00 -07001617 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 public boolean disableDataConnectivity() {
1620 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001621 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001622 final Phone phone = getPhone(subId);
1623 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001624 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 return true;
1626 } else {
1627 return false;
1628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
1630
Sanket Padawe356d7632015-06-22 14:03:32 -07001631 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001632 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001633 final Phone phone = getPhone(subId);
1634 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001635 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001636 } else {
1637 return false;
1638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 }
1640
1641 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001642 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001643 }
1644
pkanwarae03a6b2016-11-06 20:37:09 -08001645 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001646 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001647 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1648 return;
1649 }
1650 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1651 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1652 };
1653
Wink Savilleb564aae2014-10-23 10:18:09 -07001654 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001656 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1657 return false;
1658 }
Wink Saville36469e72014-06-11 15:17:00 -07001659 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 }
1661
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001663 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001664 }
1665
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001666 public int getCallStateForSlot(int slotIndex) {
1667 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001668 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001669 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 }
1671
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001674 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001675 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001676 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001678 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681
Sanket Padawe356d7632015-06-22 14:03:32 -07001682 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001684 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 if (phone != null) {
1686 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1687 } else {
1688 return TelephonyManager.DATA_ACTIVITY_NONE;
1689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
1691
1692 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001693 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001694 mPhone.getContext().getSystemService(AppOpsManager.class)
1695 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001696 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001697 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001698 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001701 if (DBG_LOC) log("getCellLocation: is active user");
1702 Bundle data = new Bundle();
1703 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1704 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 return null;
1706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001708 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001709 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1710 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001711 }
1712
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001714 public String getNetworkCountryIsoForPhone(int phoneId) {
1715 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1716 // registered cell info, so return a NULL country instead.
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001719 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1720 // Get default phone in this case.
1721 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1722 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001723 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001724 // Todo: fix this when we can get the actual cellular network info when the device
1725 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001726 if (TelephonyManager.NETWORK_TYPE_IWLAN
1727 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1728 return "";
1729 }
1730 } finally {
1731 Binder.restoreCallingIdentity(identity);
1732 }
Jack Yu5f7092c2018-04-13 14:05:37 -07001733
1734 Phone phone = PhoneFactory.getPhone(phoneId);
1735 if (phone != null) {
1736 ServiceStateTracker sst = phone.getServiceStateTracker();
1737 if (sst != null) {
1738 LocaleTracker lt = sst.getLocaleTracker();
1739 if (lt != null) {
1740 return lt.getCurrentCountry();
1741 }
1742 }
1743 }
1744 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001745 }
1746
1747 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001749 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001750 }
1751
Sanket Padawe356d7632015-06-22 14:03:32 -07001752 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001753 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 mApp.enforceCallingOrSelfPermission(
1755 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001756 final Phone phone = getPhone(subId);
1757 if (phone != null) {
1758 phone.enableLocationUpdates();
1759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 }
1761
1762 @Override
1763 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001764 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001765 }
1766
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001768 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 mApp.enforceCallingOrSelfPermission(
1770 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 final Phone phone = getPhone(subId);
1772 if (phone != null) {
1773 phone.disableLocationUpdates();
1774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 }
1776
1777 @Override
1778 @SuppressWarnings("unchecked")
1779 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001780 mPhone.getContext().getSystemService(AppOpsManager.class)
1781 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001782 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001783 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001784 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
1787 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1788 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1789 return null;
1790 }
Svetoslav64fad262015-04-14 14:35:21 -07001791
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001792 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001794 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001796 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001797 try {
1798 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1799 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1800 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1801 } catch (RuntimeException e) {
1802 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001804 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 }
1806
1807
1808 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001809 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001810 mPhone.getContext().getSystemService(AppOpsManager.class)
1811 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001812 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001813 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001814 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
1816
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001817 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001818 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001819 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1820 for (Phone phone : PhoneFactory.getPhones()) {
1821 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1822 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001824 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 }
1826
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001827 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001829 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001830 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001831 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 }
1833
Shishir Agrawala9f32182016-04-12 12:00:16 -07001834 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001835 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001836 Phone phone = PhoneFactory.getPhone(slotIndex);
1837 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001838 return null;
1839 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001840 int subId = phone.getSubId();
1841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1842 mApp, subId, callingPackage, "getImeiForSlot")) {
1843 return null;
1844 }
1845 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001846 }
1847
1848 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001849 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001850 Phone phone = PhoneFactory.getPhone(slotIndex);
1851 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001852 return null;
1853 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001854 int subId = phone.getSubId();
1855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1856 mApp, subId, callingPackage, "getMeidForSlot")) {
1857 return null;
1858 }
1859 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001860 }
1861
1862 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001863 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001864 Phone phone = PhoneFactory.getPhone(slotIndex);
1865 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001866 return null;
1867 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001868 int subId = phone.getSubId();
1869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1870 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1871 return null;
1872 }
1873 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001874 }
1875
fionaxu43304da2017-11-27 22:51:16 -08001876 @Override
1877 public int getSubscriptionCarrierId(int subId) {
1878 final Phone phone = getPhone(subId);
1879 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1880 }
1881
1882 @Override
1883 public String getSubscriptionCarrierName(int subId) {
1884 final Phone phone = getPhone(subId);
1885 return phone == null ? null : phone.getCarrierName();
1886 }
1887
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 //
1889 // Internal helper methods.
1890 //
1891
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001892 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1894 *
1895 * @throws SecurityException if the caller does not have the required permission
1896 */
1897 private void enforceModifyPermission() {
1898 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1899 }
1900
1901 /**
1902 * Make sure the caller has the CALL_PHONE permission.
1903 *
1904 * @throws SecurityException if the caller does not have the required permission
1905 */
1906 private void enforceCallPermission() {
1907 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1908 }
1909
Stuart Scott8eef64f2015-04-08 15:13:54 -07001910 private void enforceConnectivityInternalPermission() {
1911 mApp.enforceCallingOrSelfPermission(
1912 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1913 "ConnectivityService");
1914 }
1915
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 private String createTelUrl(String number) {
1917 if (TextUtils.isEmpty(number)) {
1918 return null;
1919 }
1920
Jake Hambye994d462014-02-03 13:10:13 -08001921 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923
Ihab Awadf9e92732013-12-05 18:02:52 -08001924 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1926 }
1927
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001928 private static void logv(String msg) {
1929 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1930 }
1931
Ihab Awadf9e92732013-12-05 18:02:52 -08001932 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1934 }
1935
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001936 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001938 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001939 }
1940
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001942 public int getActivePhoneTypeForSlot(int slotIndex) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00001943 final Phone phone = PhoneFactory.getPhone(slotIndex);
1944 if (phone == null) {
1945 return PhoneConstants.PHONE_TYPE_NONE;
1946 } else {
1947 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 }
1950
1951 /**
1952 * Returns the CDMA ERI icon index to display
1953 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001954 @Override
1955 public int getCdmaEriIconIndex(String callingPackage) {
1956 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001960 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001962 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001963 return -1;
1964 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 final Phone phone = getPhone(subId);
1966 if (phone != null) {
1967 return phone.getCdmaEriIconIndex();
1968 } else {
1969 return -1;
1970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 }
1972
1973 /**
1974 * Returns the CDMA ERI icon mode,
1975 * 0 - ON
1976 * 1 - FLASHING
1977 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001978 @Override
1979 public int getCdmaEriIconMode(String callingPackage) {
1980 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001981 }
1982
Sanket Padawe356d7632015-06-22 14:03:32 -07001983 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001984 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001986 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001987 return -1;
1988 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001989 final Phone phone = getPhone(subId);
1990 if (phone != null) {
1991 return phone.getCdmaEriIconMode();
1992 } else {
1993 return -1;
1994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
1996
1997 /**
1998 * Returns the CDMA ERI text,
1999 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002000 @Override
2001 public String getCdmaEriText(String callingPackage) {
2002 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002003 }
2004
Sanket Padawe356d7632015-06-22 14:03:32 -07002005 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002006 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002008 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002009 return null;
2010 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002011 final Phone phone = getPhone(subId);
2012 if (phone != null) {
2013 return phone.getCdmaEriText();
2014 } else {
2015 return null;
2016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
2019 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002020 * Returns the CDMA MDN.
2021 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002022 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002023 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2025 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07002026 final Phone phone = getPhone(subId);
2027 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2028 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002029 } else {
2030 return null;
2031 }
2032 }
2033
2034 /**
2035 * Returns the CDMA MIN.
2036 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002037 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002038 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2040 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002041 final Phone phone = getPhone(subId);
2042 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2043 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002044 } else {
2045 return null;
2046 }
2047 }
2048
2049 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050 * Returns true if CDMA provisioning needs to run.
2051 */
2052 public boolean needsOtaServiceProvisioning() {
2053 return mPhone.needsOtaServiceProvisioning();
2054 }
2055
2056 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002057 * Sets the voice mail number of a given subId.
2058 */
2059 @Override
2060 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002061 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002062 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2063 new Pair<String, String>(alphaTag, number), new Integer(subId));
2064 return success;
2065 }
2066
Ta-wei Yen87c49842016-05-13 21:19:52 -07002067 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002068 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2069 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2070 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2071 if (!TextUtils.equals(callingPackage, systemDialer)) {
2072 throw new SecurityException("caller must be system dialer");
2073 }
2074 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2075 if (phoneAccountHandle == null){
2076 return null;
2077 }
2078 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2079 }
2080
2081 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002082 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002083 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002085 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002086 return null;
2087 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002088 final long identity = Binder.clearCallingIdentity();
2089 try {
2090 return RemoteVvmTaskManager
2091 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2092 } finally {
2093 Binder.restoreCallingIdentity(identity);
2094 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002095 }
2096
2097 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002098 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2099 VisualVoicemailSmsFilterSettings settings) {
2100 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002101 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002102 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2103 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002104 }
2105
2106 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002107 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2108 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002109 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002110 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002111 }
2112
2113 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002114 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2115 String callingPackage, int subId) {
2116 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002117 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002118 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002119 }
2120
2121 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002122 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002123 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002124 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002125 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2126 }
2127
2128 @Override
2129 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2130 String number, int port, String text, PendingIntent sentIntent) {
2131 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002132 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002133 enforceSendSmsPermission();
2134 // Make the calls as the phone process.
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2138 if (port == 0) {
2139 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2140 sentIntent, null, false);
2141 } else {
2142 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2143 smsManager.sendDataMessageWithSelfPermissions(number, null,
2144 (short) port, data, sentIntent, null);
2145 }
2146 } finally {
2147 Binder.restoreCallingIdentity(identity);
2148 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002149 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002150 /**
fionaxu0152e512016-11-14 13:36:14 -08002151 * Sets the voice activation state of a given subId.
2152 */
2153 @Override
2154 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2156 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002157 final Phone phone = getPhone(subId);
2158 if (phone != null) {
2159 phone.setVoiceActivationState(activationState);
2160 } else {
2161 loge("setVoiceActivationState fails with invalid subId: " + subId);
2162 }
2163 }
2164
2165 /**
2166 * Sets the data activation state of a given subId.
2167 */
2168 @Override
2169 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2171 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002172 final Phone phone = getPhone(subId);
2173 if (phone != null) {
2174 phone.setDataActivationState(activationState);
2175 } else {
2176 loge("setVoiceActivationState fails with invalid subId: " + subId);
2177 }
2178 }
2179
2180 /**
2181 * Returns the voice activation state of a given subId.
2182 */
2183 @Override
2184 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002185 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002186 final Phone phone = getPhone(subId);
2187 if (phone != null) {
2188 return phone.getVoiceActivationState();
2189 } else {
2190 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2191 }
2192 }
2193
2194 /**
2195 * Returns the data activation state of a given subId.
2196 */
2197 @Override
2198 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002199 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002200 final Phone phone = getPhone(subId);
2201 if (phone != null) {
2202 return phone.getDataActivationState();
2203 } else {
2204 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2205 }
2206 }
2207
2208 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 * Returns the unread count of voicemails
2210 */
2211 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002212 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002213 }
2214
2215 /**
2216 * Returns the unread count of voicemails for a subId
2217 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002218 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002219 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002220 final Phone phone = getPhone(subId);
2221 if (phone != null) {
2222 return phone.getVoiceMessageCount();
2223 } else {
2224 return 0;
2225 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002226 }
2227
2228 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002229 * returns true, if the device is in a state where both voice and data
2230 * are supported simultaneously. This can change based on location or network condition.
2231 */
2232 @Override
2233 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2234 final Phone phone = getPhone(subId);
2235 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2236 }
2237
2238 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002239 * Send the dialer code if called from the current default dialer or the caller has
2240 * carrier privilege.
2241 * @param inputCode The dialer code to send
2242 */
2243 @Override
2244 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2245 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2246 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2247 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002248 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2249 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002250 }
2251 mPhone.sendDialerSpecialCode(inputCode);
2252 }
2253
2254 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002255 * Returns the data network type.
2256 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 *
2258 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2259 */
2260 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002261 public int getNetworkType() {
2262 final Phone phone = getPhone(getDefaultSubscription());
2263 if (phone != null) {
2264 return phone.getServiceState().getDataNetworkType();
2265 } else {
2266 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2267 }
Wink Saville36469e72014-06-11 15:17:00 -07002268 }
2269
2270 /**
2271 * Returns the network type for a subId
2272 */
2273 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002274 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002276 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002277 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2278 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002279
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002281 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002282 return phone.getServiceState().getDataNetworkType();
2283 } else {
2284 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 }
2287
2288 /**
2289 * Returns the data network type
2290 */
2291 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002292 public int getDataNetworkType(String callingPackage) {
2293 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002294 }
2295
2296 /**
2297 * Returns the data network type for a subId
2298 */
2299 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002300 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002302 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002303 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2304 }
2305
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 final Phone phone = getPhone(subId);
2307 if (phone != null) {
2308 return phone.getServiceState().getDataNetworkType();
2309 } else {
2310 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
2314 /**
Wink Saville36469e72014-06-11 15:17:00 -07002315 * Returns the Voice network type for a subId
2316 */
2317 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002318 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002320 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002321 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2322 }
2323
Sanket Padawe356d7632015-06-22 14:03:32 -07002324 final Phone phone = getPhone(subId);
2325 if (phone != null) {
2326 return phone.getServiceState().getVoiceNetworkType();
2327 } else {
2328 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 }
2331
2332 /**
2333 * @return true if a ICC card is present
2334 */
2335 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002336 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002337 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2338 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002339 }
2340
2341 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002342 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002343 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002344 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002345 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2346 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002347 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002348 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002349 } else {
2350 return false;
2351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 }
2353
2354 /**
2355 * Return if the current radio is LTE on CDMA. This
2356 * is a tri-state return value as for a period of time
2357 * the mode may be unknown.
2358 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002359 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002361 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002363 @Override
2364 public int getLteOnCdmaMode(String callingPackage) {
2365 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002366 }
2367
Sanket Padawe356d7632015-06-22 14:03:32 -07002368 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002369 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002371 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002372 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2373 }
2374
Sanket Padawe356d7632015-06-22 14:03:32 -07002375 final Phone phone = getPhone(subId);
2376 if (phone == null) {
2377 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2378 } else {
2379 return phone.getLteOnCdmaMode();
2380 }
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
2382
2383 public void setPhone(Phone phone) {
2384 mPhone = phone;
2385 }
2386
2387 /**
2388 * {@hide}
2389 * Returns Default subId, 0 in the case of single standby.
2390 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002391 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002392 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002393 }
2394
Shishir Agrawala9f32182016-04-12 12:00:16 -07002395 private int getSlotForDefaultSubscription() {
2396 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2397 }
2398
Wink Savilleb564aae2014-10-23 10:18:09 -07002399 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002400 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002402
2403 /**
2404 * @see android.telephony.TelephonyManager.WifiCallingChoices
2405 */
2406 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002407 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2408 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002409 }
2410
2411 /**
2412 * @see android.telephony.TelephonyManager.WifiCallingChoices
2413 */
2414 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002415 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2416 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2417 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002418 }
2419
Sailesh Nepald1e68152013-12-12 19:08:02 -08002420 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002421 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002422 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002423 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002424
Shishir Agrawal566b7612013-10-28 14:41:00 -07002425 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002426 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2427 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2429 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002430
Derek Tan740e1672017-06-27 14:56:27 -07002431 if (TextUtils.equals(ISDR_AID, aid)) {
2432 // Only allows LPA to open logical channel to ISD-R.
2433 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2434 ComponentInfo bestComponent =
2435 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2436 if (bestComponent == null
2437 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2438 loge("The calling package is not allowed to access ISD-R.");
2439 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2440 }
2441 }
2442
2443 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002444 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002445 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002446 if (DBG) log("iccOpenLogicalChannel: " + response);
2447 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002448 }
2449
2450 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002451 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2453 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002454
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002455 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002456 if (channel < 0) {
2457 return false;
2458 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002459 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002460 if (DBG) log("iccCloseLogicalChannel: " + success);
2461 return success;
2462 }
2463
2464 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002465 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002466 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2468 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002469
2470 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002471 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2472 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002473 " data=" + data);
2474 }
2475
2476 if (channel < 0) {
2477 return "";
2478 }
2479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002480 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002481 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002482 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2483
Shishir Agrawal566b7612013-10-28 14:41:00 -07002484 // Append the returned status code to the end of the response payload.
2485 String s = Integer.toHexString(
2486 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002487 if (response.payload != null) {
2488 s = IccUtils.bytesToHexString(response.payload) + s;
2489 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002490 return s;
2491 }
Jake Hambye994d462014-02-03 13:10:13 -08002492
Evan Charltonc66da362014-05-16 14:06:40 -07002493 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002494 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2495 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2497 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002498
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002499 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2500 && TextUtils.equals(ISDR_AID, data)) {
2501 // Only allows LPA to select ISD-R.
2502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2503 ComponentInfo bestComponent =
2504 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2505 if (bestComponent == null
2506 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2507 loge("The calling package is not allowed to select ISD-R.");
2508 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2509 }
2510 }
2511
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002512 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002513 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2514 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002515 }
2516
2517 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002518 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002519 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2520
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002521 // Append the returned status code to the end of the response payload.
2522 String s = Integer.toHexString(
2523 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002524 if (response.payload != null) {
2525 s = IccUtils.bytesToHexString(response.payload) + s;
2526 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002527 return s;
2528 }
2529
2530 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002531 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002532 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2534 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002535
2536 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002537 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002538 p1 + " " + p2 + " " + p3 + ":" + filePath);
2539 }
2540
2541 IccIoResult response =
2542 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002543 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2544 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002545
2546 if (DBG) {
2547 log("Exchange SIM_IO [R]" + response);
2548 }
2549
2550 byte[] result = null;
2551 int length = 2;
2552 if (response.payload != null) {
2553 length = 2 + response.payload.length;
2554 result = new byte[length];
2555 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2556 } else {
2557 result = new byte[length];
2558 }
2559
2560 result[length - 1] = (byte) response.sw2;
2561 result[length - 2] = (byte) response.sw1;
2562 return result;
2563 }
2564
Nathan Haroldb3014052017-01-25 15:57:32 -08002565 /**
2566 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2567 * on a particular subscription
2568 */
sqianb6e41952018-03-12 14:54:01 -07002569 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2571 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2572 return null;
2573 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002574 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2575 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2576 return null;
2577 }
2578 Object response = sendRequest(
2579 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2580 if (response instanceof String[]) {
2581 return (String[]) response;
2582 }
2583 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2584 return null;
2585 }
2586
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002587 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002588 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2590 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002591
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002592 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002593 if (response.payload == null) {
2594 return "";
2595 }
2596
2597 // Append the returned status code to the end of the response payload.
2598 String s = Integer.toHexString(
2599 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2600 s = IccUtils.bytesToHexString(response.payload) + s;
2601 return s;
2602 }
2603
Jake Hambye994d462014-02-03 13:10:13 -08002604 /**
2605 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2606 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2607 *
2608 * @param itemID the ID of the item to read
2609 * @return the NV item as a String, or null on error.
2610 */
2611 @Override
2612 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2614 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002615 if (DBG) log("nvReadItem: item " + itemID);
2616 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2617 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2618 return value;
2619 }
2620
2621 /**
2622 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2623 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2624 *
2625 * @param itemID the ID of the item to read
2626 * @param itemValue the value to write, as a String
2627 * @return true on success; false on any failure
2628 */
2629 @Override
2630 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2632 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002633 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2634 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2635 new Pair<Integer, String>(itemID, itemValue));
2636 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2637 return success;
2638 }
2639
2640 /**
2641 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2642 * Used for device configuration by some CDMA operators.
2643 *
2644 * @param preferredRoamingList byte array containing the new PRL
2645 * @return true on success; false on any failure
2646 */
2647 @Override
2648 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2650 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002651 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2652 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2653 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2654 return success;
2655 }
2656
2657 /**
2658 * Perform the specified type of NV config reset.
2659 * Used for device configuration by some CDMA operators.
2660 *
2661 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2662 * @return true on success; false on any failure
2663 */
2664 @Override
2665 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2667 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002668 if (DBG) log("nvResetConfig: type " + resetType);
2669 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2670 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2671 return success;
2672 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002673
2674 /**
Wink Saville36469e72014-06-11 15:17:00 -07002675 * {@hide}
2676 * Returns Default sim, 0 in the case of single standby.
2677 */
2678 public int getDefaultSim() {
2679 //TODO Need to get it from Telephony Devcontroller
2680 return 0;
2681 }
2682
Svet Ganovb320e182015-04-16 12:30:10 -07002683 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002685 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002686 return new String[0];
2687 }
2688
2689
ram87fca6f2014-07-18 18:58:44 +05302690 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002691 }
2692
Brad Ebinger51f743a2017-01-23 13:50:20 -08002693 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002694 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2695 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002696 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002697 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002698 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002699 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002700 }
2701
2702 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002703 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2704 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002705 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002706 public void disableIms(int slotId) {
2707 enforceModifyPermission();
2708 PhoneFactory.getImsResolver().disableIms(slotId);
2709 }
2710
2711 /**
2712 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2713 * feature or {@link null} if the service is not available. If the feature is available, the
2714 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2715 */
2716 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002717 IImsServiceFeatureCallback callback) {
2718 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002719 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002720 }
2721
2722 /**
2723 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2724 * feature during emergency calling or {@link null} if the service is not available. If the
2725 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2726 * listener for feature updates.
2727 */
2728 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2729 enforceModifyPermission();
2730 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002731 }
2732
Brad Ebinger5f64b052017-12-14 14:26:15 -08002733 /**
2734 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2735 * specified.
2736 */
2737 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2738 enforceModifyPermission();
2739 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2740 }
2741
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002742 /**
2743 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2744 * specified.
2745 */
2746 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2747 enforceModifyPermission();
2748 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2749 }
2750
Brad Ebinger884c07b2018-02-15 16:17:40 -08002751 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07002752 * Sets the ImsService Package Name that Telephony will bind to.
2753 *
2754 * @param slotId the slot ID that the ImsService should bind for.
2755 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
2756 * ImsService is the device default ImsService.
2757 * @param packageName The package name of the application that contains the ImsService to bind
2758 * to.
2759 * @return true if setting the ImsService to bind to succeeded, false if it did not.
2760 * @hide
2761 */
2762 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002763 int[] subIds = SubscriptionManager.getSubId(slotId);
2764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2765 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2766 "setImsService");
2767
Brad Ebingerdac2f002018-04-03 15:17:52 -07002768 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
2769 isCarrierImsService, packageName);
2770 }
2771
2772 /**
2773 * Return the ImsService configuration.
2774 *
2775 * @param slotId The slot that the ImsService is associated with.
2776 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
2777 * the device default.
2778 * @return the package name of the ImsService configuration.
2779 */
2780 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002781 int[] subIds = SubscriptionManager.getSubId(slotId);
2782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2783 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2784 "getImsService");
2785
Brad Ebingerdac2f002018-04-03 15:17:52 -07002786 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
2787 isCarrierImsService);
2788 }
2789
Wink Saville36469e72014-06-11 15:17:00 -07002790 public void setImsRegistrationState(boolean registered) {
2791 enforceModifyPermission();
2792 mPhone.setImsRegistrationState(registered);
2793 }
2794
2795 /**
Stuart Scott54788802015-03-30 13:18:01 -07002796 * Set the network selection mode to automatic.
2797 *
2798 */
2799 @Override
2800 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2802 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002803 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2804 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2805 }
2806
2807 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002808 * Set the network selection mode to manual with the selected carrier.
2809 */
2810 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002811 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002812 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2814 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002815 OperatorInfo operator = new OperatorInfo(
2816 /* operatorAlphaLong */ "",
2817 /* operatorAlphaShort */ "",
2818 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002819 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002820 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2821 persistSelection);
2822 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002823 }
2824
2825 /**
2826 * Scans for available networks.
2827 */
2828 @Override
2829 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2831 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002832 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2833 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2834 CMD_PERFORM_NETWORK_SCAN, null, subId);
2835 return result;
2836 }
2837
2838 /**
yinxub1bed742017-04-17 11:45:04 -07002839 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002840 *
yinxub1bed742017-04-17 11:45:04 -07002841 * @param subId id of the subscription
2842 * @param request contains the radio access networks with bands/channels to scan
2843 * @param messenger callback messenger for scan results or errors
2844 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002845 * @return the id of the requested scan which can be used to stop the scan.
2846 */
2847 @Override
2848 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2849 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2851 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002852 return mNetworkScanRequestTracker.startNetworkScan(
2853 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002854 }
2855
2856 /**
2857 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002858 *
2859 * @param subId id of the subscription
2860 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002861 */
2862 @Override
2863 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2865 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002866 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002867 }
2868
2869 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002870 * Get the calculated preferred network type.
2871 * Used for debugging incorrect network type.
2872 *
2873 * @return the preferred network type, defined in RILConstants.java.
2874 */
2875 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002876 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002878 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002879 return RILConstants.PREFERRED_NETWORK_MODE;
2880 }
2881
Amit Mahajan43330e02014-11-18 11:54:45 -08002882 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002883 }
2884
2885 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002886 * Get the preferred network type.
2887 * Used for device configuration by some CDMA operators.
2888 *
2889 * @return the preferred network type, defined in RILConstants.java.
2890 */
2891 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002892 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2894 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002895 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002896 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002897 int networkType = (result != null ? result[0] : -1);
2898 if (DBG) log("getPreferredNetworkType: " + networkType);
2899 return networkType;
2900 }
2901
2902 /**
2903 * Set the preferred network type.
2904 * Used for device configuration by some CDMA operators.
2905 *
2906 * @param networkType the preferred network type, defined in RILConstants.java.
2907 * @return true on success; false on any failure.
2908 */
2909 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002910 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2912 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002913 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2914 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002915 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002916 if (success) {
2917 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002918 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002919 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002920 return success;
2921 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002922
2923 /**
Junda Liu475951f2014-11-07 16:45:03 -08002924 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2925 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2926 * tethering.
2927 *
2928 * @return 0: Not required. 1: required. 2: Not set.
2929 * @hide
2930 */
2931 @Override
2932 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002933 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002934 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2935 Settings.Global.TETHER_DUN_REQUIRED, 2);
2936 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2937 // config_tether_apndata.
2938 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2939 dunRequired = 1;
2940 }
2941 return dunRequired;
2942 }
2943
2944 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002945 * Set mobile data enabled
2946 * Used by the user through settings etc to turn on/off mobile data
2947 *
2948 * @param enable {@code true} turn turn data on, else {@code false}
2949 */
2950 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002951 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2953 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002954 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002955 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002956 Phone phone = PhoneFactory.getPhone(phoneId);
2957 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002958 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2959 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002960 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002961 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002962 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002963 }
2964
2965 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002966 * Get the user enabled state of Mobile Data.
2967 *
2968 * TODO: remove and use isUserDataEnabled.
2969 * This can't be removed now because some vendor codes
2970 * calls through ITelephony directly while they should
2971 * use TelephonyManager.
2972 *
2973 * @return true on enabled
2974 */
2975 @Override
2976 public boolean getDataEnabled(int subId) {
2977 return isUserDataEnabled(subId);
2978 }
2979
2980 /**
2981 * Get whether mobile data is enabled per user setting.
2982 *
2983 * There are other factors deciding whether mobile data is actually enabled, but they are
2984 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002985 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002986 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002987 *
2988 * @return {@code true} if data is enabled else {@code false}
2989 */
2990 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002991 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002992 try {
2993 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2994 null);
2995 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2997 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002998 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002999 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08003000 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08003001 Phone phone = PhoneFactory.getPhone(phoneId);
3002 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08003003 boolean retVal = phone.isUserDataEnabled();
3004 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08003005 return retVal;
3006 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08003007 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3008 return false;
3009 }
3010 }
3011
3012 /**
3013 * Get whether mobile data is enabled.
3014 *
3015 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3016 * whether mobile data is actually enabled.
3017 *
3018 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3019 *
3020 * @return {@code true} if data is enabled else {@code false}
3021 */
3022 @Override
3023 public boolean isDataEnabled(int subId) {
3024 try {
3025 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3026 null);
3027 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3029 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003030 }
3031 int phoneId = mSubscriptionController.getPhoneId(subId);
3032 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3033 Phone phone = PhoneFactory.getPhone(phoneId);
3034 if (phone != null) {
3035 boolean retVal = phone.isDataEnabled();
3036 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3037 return retVal;
3038 } else {
3039 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08003040 return false;
3041 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003042 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003043
3044 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003045 public int getCarrierPrivilegeStatus(int subId) {
3046 final Phone phone = getPhone(subId);
3047 if (phone == null) {
3048 loge("getCarrierPrivilegeStatus: Invalid subId");
3049 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3050 }
3051 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003052 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003053 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003054 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3055 }
3056 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003057 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003058 }
Junda Liu29340342014-07-10 15:23:27 -07003059
3060 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003061 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3062 final Phone phone = getPhone(subId);
3063 if (phone == null) {
3064 loge("getCarrierPrivilegeStatus: Invalid subId");
3065 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3066 }
3067 UiccProfile profile =
3068 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3069 if (profile == null) {
3070 loge("getCarrierPrivilegeStatus: No UICC");
3071 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3072 }
3073 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3074 }
3075
3076 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003077 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003078 if (TextUtils.isEmpty(pkgName))
3079 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003080 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003081 if (card == null) {
3082 loge("checkCarrierPrivilegesForPackage: No UICC");
3083 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3084 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003085 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3086 }
3087
3088 @Override
3089 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003090 if (TextUtils.isEmpty(pkgName))
3091 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003092 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3093 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3094 UiccCard card = UiccController.getInstance().getUiccCard(i);
3095 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003096 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003097 continue;
3098 }
3099
3100 result = card.getCarrierPrivilegeStatus(
3101 mPhone.getContext().getPackageManager(), pkgName);
3102 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3103 break;
3104 }
3105 }
3106
3107 return result;
Junda Liu29340342014-07-10 15:23:27 -07003108 }
Derek Tan89e89d42014-07-08 17:00:10 -07003109
3110 @Override
Junda Liue64de782015-04-16 17:19:16 -07003111 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3112 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3113 loge("phoneId " + phoneId + " is not valid.");
3114 return null;
3115 }
3116 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003117 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003118 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003119 return null ;
3120 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003121 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003122 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003123 }
3124
Amith Yamasani6e118872016-02-19 12:53:51 -08003125 @Override
3126 public List<String> getPackagesWithCarrierPrivileges() {
3127 PackageManager pm = mPhone.getContext().getPackageManager();
3128 List<String> privilegedPackages = new ArrayList<>();
3129 List<PackageInfo> packages = null;
3130 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3131 UiccCard card = UiccController.getInstance().getUiccCard(i);
3132 if (card == null) {
3133 // No UICC in that slot.
3134 continue;
3135 }
3136 if (card.hasCarrierPrivilegeRules()) {
3137 if (packages == null) {
3138 // Only check packages in user 0 for now
3139 packages = pm.getInstalledPackagesAsUser(
3140 PackageManager.MATCH_DISABLED_COMPONENTS
3141 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3142 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3143 }
3144 for (int p = packages.size() - 1; p >= 0; p--) {
3145 PackageInfo pkgInfo = packages.get(p);
3146 if (pkgInfo != null && pkgInfo.packageName != null
3147 && card.getCarrierPrivilegeStatus(pkgInfo)
3148 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3149 privilegedPackages.add(pkgInfo.packageName);
3150 }
3151 }
3152 }
3153 }
3154 return privilegedPackages;
3155 }
3156
Wink Savilleb564aae2014-10-23 10:18:09 -07003157 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003158 final Phone phone = getPhone(subId);
3159 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003160 if (card == null) {
3161 loge("getIccId: No UICC");
3162 return null;
3163 }
3164 String iccId = card.getIccId();
3165 if (TextUtils.isEmpty(iccId)) {
3166 loge("getIccId: ICC ID is null or empty.");
3167 return null;
3168 }
3169 return iccId;
3170 }
3171
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003172 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003173 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3174 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003175 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3176 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003177
Jeff Sharkey85190e62014-12-05 09:40:12 -08003178 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003179 final Phone phone = getPhone(subId);
3180 if (phone == null) {
3181 return false;
3182 }
3183 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003184
3185 if (DBG_MERGE) {
3186 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3187 + subscriberId + " to " + number);
3188 }
3189
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003190 if (TextUtils.isEmpty(iccId)) {
3191 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003192 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003193
Jeff Sharkey85190e62014-12-05 09:40:12 -08003194 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3195
3196 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003197 if (alphaTag == null) {
3198 editor.remove(alphaTagPrefKey);
3199 } else {
3200 editor.putString(alphaTagPrefKey, alphaTag);
3201 }
3202
Jeff Sharkey85190e62014-12-05 09:40:12 -08003203 // Record both the line number and IMSI for this ICCID, since we need to
3204 // track all merged IMSIs based on line number
3205 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3206 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003207 if (number == null) {
3208 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003209 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003210 } else {
3211 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003212 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003213 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003214
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003215 editor.commit();
3216 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003217 }
3218
3219 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003220 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003221 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003223 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003224 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003225 return null;
3226 }
Derek Tan97ebb422014-09-05 16:55:38 -07003227
3228 String iccId = getIccId(subId);
3229 if (iccId != null) {
3230 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003231 if (DBG_MERGE) {
3232 log("getLine1NumberForDisplay returning " +
3233 mTelephonySharedPreferences.getString(numberPrefKey, null));
3234 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003235 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003236 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003237 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003238 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003239 }
3240
3241 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003242 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003244 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003245 return null;
3246 }
Derek Tan97ebb422014-09-05 16:55:38 -07003247
3248 String iccId = getIccId(subId);
3249 if (iccId != null) {
3250 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003251 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003252 }
Derek Tan97ebb422014-09-05 16:55:38 -07003253 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003254 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003255
3256 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003257 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003258 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3259 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003261 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3262 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003263 return null;
3264 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003265 final Context context = mPhone.getContext();
3266 final TelephonyManager tele = TelephonyManager.from(context);
3267 final SubscriptionManager sub = SubscriptionManager.from(context);
3268
3269 // Figure out what subscribers are currently active
3270 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003271 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3272 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 final int[] subIds = sub.getActiveSubscriptionIdList();
3276 for (int subId : subIds) {
3277 activeSubscriberIds.add(tele.getSubscriberId(subId));
3278 }
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003281 }
3282
3283 // First pass, find a number override for an active subscriber
3284 String mergeNumber = null;
3285 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3286 for (String key : prefs.keySet()) {
3287 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3288 final String subscriberId = (String) prefs.get(key);
3289 if (activeSubscriberIds.contains(subscriberId)) {
3290 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3291 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3292 mergeNumber = (String) prefs.get(numberKey);
3293 if (DBG_MERGE) {
3294 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3295 + " for active subscriber " + subscriberId);
3296 }
3297 if (!TextUtils.isEmpty(mergeNumber)) {
3298 break;
3299 }
3300 }
3301 }
3302 }
3303
3304 // Shortcut when no active merged subscribers
3305 if (TextUtils.isEmpty(mergeNumber)) {
3306 return null;
3307 }
3308
3309 // Second pass, find all subscribers under that line override
3310 final ArraySet<String> result = new ArraySet<>();
3311 for (String key : prefs.keySet()) {
3312 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3313 final String number = (String) prefs.get(key);
3314 if (mergeNumber.equals(number)) {
3315 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3316 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3317 final String subscriberId = (String) prefs.get(subscriberKey);
3318 if (!TextUtils.isEmpty(subscriberId)) {
3319 result.add(subscriberId);
3320 }
3321 }
3322 }
3323 }
3324
3325 final String[] resultArray = result.toArray(new String[result.size()]);
3326 Arrays.sort(resultArray);
3327 if (DBG_MERGE) {
3328 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3329 }
3330 return resultArray;
3331 }
3332
3333 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003334 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003335 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3336 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003337 final Phone phone = getPhone(subId);
3338 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003339 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003340
3341 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003342 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003343 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3344 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003345 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003346 final Phone phone = getPhone(subId);
3347 if (phone == null) {
3348 return false;
3349 }
3350 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003351 cdmaNonRoamingList);
3352 }
3353
3354 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003355 @Deprecated
3356 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3357 enforceModifyPermission();
3358
3359 int returnValue = 0;
3360 try {
3361 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3362 if(result.exception == null) {
3363 if (result.result != null) {
3364 byte[] responseData = (byte[])(result.result);
3365 if(responseData.length > oemResp.length) {
3366 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3367 responseData.length + "bytes. Buffer Size is " +
3368 oemResp.length + "bytes.");
3369 }
3370 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3371 returnValue = responseData.length;
3372 }
3373 } else {
3374 CommandException ex = (CommandException) result.exception;
3375 returnValue = ex.getCommandError().ordinal();
3376 if(returnValue > 0) returnValue *= -1;
3377 }
3378 } catch (RuntimeException e) {
3379 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3380 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3381 if(returnValue > 0) returnValue *= -1;
3382 }
3383
3384 return returnValue;
3385 }
3386
3387 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003388 public void setRadioCapability(RadioAccessFamily[] rafs) {
3389 try {
3390 ProxyController.getInstance().setRadioCapability(rafs);
3391 } catch (RuntimeException e) {
3392 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3393 }
3394 }
3395
3396 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003397 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003398 Phone phone = PhoneFactory.getPhone(phoneId);
3399 if (phone == null) {
3400 return RadioAccessFamily.RAF_UNKNOWN;
3401 }
3402 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003404 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003405 return RadioAccessFamily.RAF_UNKNOWN;
3406 }
3407
Wink Saville5d475dd2014-10-17 15:00:58 -07003408 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3409 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003410
3411 @Override
3412 public void enableVideoCalling(boolean enable) {
3413 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003414 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003415 }
3416
3417 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003418 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3420 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3421 return false;
3422 }
Svet Ganovb320e182015-04-16 12:30:10 -07003423
Andrew Lee77527ac2014-10-21 16:57:39 -07003424 // Check the user preference and the system-level IMS setting. Even if the user has
3425 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3426 // In the long run, we may instead need to check if there exists a connection service
3427 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003428 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3429 return imsManager.isVtEnabledByPlatform()
3430 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3431 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003432 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003433
Andrew Leea1239f22015-03-02 17:44:07 -08003434 @Override
3435 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003436 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003437 }
3438
3439 @Override
3440 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003441 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003442 }
3443
Andrew Lee9431b832015-03-09 18:46:45 -07003444 @Override
3445 public boolean isTtyModeSupported() {
3446 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3447 TelephonyManager telephonyManager =
3448 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003449 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003450 }
3451
3452 @Override
3453 public boolean isHearingAidCompatibilitySupported() {
3454 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3455 }
3456
Hall Liu98187582018-01-22 19:15:32 -08003457 public boolean isRttSupported() {
3458 boolean isCarrierSupported =
3459 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3460 boolean isDeviceSupported =
3461 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3462 return isCarrierSupported && isDeviceSupported;
3463 }
3464
Hall Liu3ad5f012018-04-06 16:23:39 -07003465 public boolean isRttEnabled() {
3466 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3467 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3468 }
3469
Sanket Padawe7310cc72015-01-14 09:53:20 -08003470 /**
3471 * Returns the unique device ID of phone, for example, the IMEI for
3472 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3473 *
3474 * <p>Requires Permission:
3475 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3476 */
3477 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003478 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003479 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003480 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003481 return null;
3482 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003483 int subId = phone.getSubId();
3484 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3485 mApp, subId, callingPackage, "getDeviceId")) {
3486 return null;
3487 }
3488 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003489 }
3490
Ping Sunc67b7c22016-03-02 19:16:45 +08003491 /**
3492 * {@hide}
3493 * Returns the IMS Registration Status on a particular subid
3494 *
3495 * @param subId
3496 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003497 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003498 Phone phone = getPhone(subId);
3499 if (phone != null) {
3500 return phone.isImsRegistered();
3501 } else {
3502 return false;
3503 }
3504 }
3505
Santos Cordon7a1885b2015-02-03 11:15:19 -08003506 @Override
3507 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3508 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3509 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003510
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003511 /**
3512 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003513 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003514 public boolean isWifiCallingAvailable(int subId) {
3515 Phone phone = getPhone(subId);
3516 if (phone != null) {
3517 return phone.isWifiCallingEnabled();
3518 } else {
3519 return false;
3520 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003521 }
3522
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003523 /**
3524 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003525 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003526 public boolean isVolteAvailable(int subId) {
3527 Phone phone = getPhone(subId);
3528 if (phone != null) {
3529 return phone.isVolteEnabled();
3530 } else {
3531 return false;
3532 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003533 }
Svet Ganovb320e182015-04-16 12:30:10 -07003534
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003535 /**
3536 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003537 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003538 public boolean isVideoTelephonyAvailable(int subId) {
3539 Phone phone = getPhone(subId);
3540 if (phone != null) {
3541 return phone.isVideoEnabled();
3542 } else {
3543 return false;
3544 }
3545 }
3546
3547 /**
3548 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3549 * defined in {@link ImsRegistrationImplBase}.
3550 */
3551 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3552 Phone phone = getPhone(subId);
3553 if (phone != null) {
3554 return phone.getImsRegistrationTech();
3555 } else {
3556 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3557 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003558 }
3559
Stuart Scott8eef64f2015-04-08 15:13:54 -07003560 @Override
3561 public void factoryReset(int subId) {
3562 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003563 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3564 return;
3565 }
3566
Svet Ganovcc087f82015-05-12 20:35:54 -07003567 final long identity = Binder.clearCallingIdentity();
3568 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003569 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3570 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003571 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003572 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003573 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3574 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003575 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003576 }
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003579 }
3580 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003581
3582 @Override
3583 public String getLocaleFromDefaultSim() {
3584 // We query all subscriptions instead of just the active ones, because
3585 // this might be called early on in the provisioning flow when the
3586 // subscriptions potentially aren't active yet.
3587 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3588 if (slist == null || slist.isEmpty()) {
3589 return null;
3590 }
3591
3592 // This function may be called very early, say, from the setup wizard, at
3593 // which point we won't have a default subscription set. If that's the case
3594 // we just choose the first, which will be valid in "most cases".
3595 final int defaultSubId = getDefaultSubscription();
3596 SubscriptionInfo info = null;
3597 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3598 info = slist.get(0);
3599 } else {
3600 for (SubscriptionInfo item : slist) {
3601 if (item.getSubscriptionId() == defaultSubId) {
3602 info = item;
3603 break;
3604 }
3605 }
3606
3607 if (info == null) {
3608 return null;
3609 }
3610 }
3611
3612 // Try and fetch the locale from the carrier properties or from the SIM language
3613 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003614 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003615 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003616 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003617 if (defaultPhone != null) {
3618 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3619 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003620 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003621 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3622 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003623 } else {
3624 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003625 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003626 }
3627 }
3628
Narayan Kamath011676f2015-07-29 12:04:08 +01003629 // The SIM language preferences only store a language (e.g. fr = French), not an
3630 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3631 // the SIM and carrier preferences does not include a country we add the country
3632 // determined from the SIM MCC to provide an exact locale.
3633 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003634 if (mccLocale != null) {
3635 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3636 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003637 }
3638
Tony Hill183b2de2015-06-24 14:53:58 +01003639 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003640 return null;
3641 }
3642
3643 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 return mSubscriptionController.getAllSubInfoList(
3647 mPhone.getContext().getOpPackageName());
3648 } finally {
3649 Binder.restoreCallingIdentity(identity);
3650 }
3651 }
3652
3653 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 return mSubscriptionController.getActiveSubscriptionInfoList(
3657 mPhone.getContext().getOpPackageName());
3658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
3661 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003662
Chenjie Yu1ba97252018-01-11 18:16:20 -08003663 private final ModemActivityInfo mLastModemActivityInfo =
3664 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3665
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003666 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003667 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3668 * representing the state of the modem.
3669 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003670 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3671 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003672 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003673 */
3674 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003675 public void requestModemActivityInfo(ResultReceiver result) {
3676 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003677 ModemActivityInfo ret = null;
3678 synchronized (mLastModemActivityInfo) {
3679 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3680 null);
Siddharth Rayf5d29552018-06-17 15:02:38 -07003681 if (isModemActivityInfoValid(info)) {
Chenjie Yu1ba97252018-01-11 18:16:20 -08003682 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3683 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3684 mergedTxTimeMs[i] =
3685 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3686 }
3687 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3688 mLastModemActivityInfo.setSleepTimeMillis(
3689 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3690 mLastModemActivityInfo.setIdleTimeMillis(
3691 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3692 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3693 mLastModemActivityInfo.setRxTimeMillis(
3694 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3695 mLastModemActivityInfo.setEnergyUsed(
3696 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3697 }
3698 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3699 mLastModemActivityInfo.getSleepTimeMillis(),
3700 mLastModemActivityInfo.getIdleTimeMillis(),
3701 mLastModemActivityInfo.getTxTimeMillis(),
3702 mLastModemActivityInfo.getRxTimeMillis(),
3703 mLastModemActivityInfo.getEnergyUsed());
3704 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003705 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003706 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003707 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003708 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003709
Siddharth Rayf5d29552018-06-17 15:02:38 -07003710 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
3711 // less than total activity duration.
3712 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
3713 if (info == null) {
3714 return false;
3715 }
3716 int activityDurationMs =
3717 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
3718 int totalTxTimeMs = 0;
3719 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
3720 totalTxTimeMs += info.getTxTimeMillis()[i];
3721 }
3722 return (info.isValid()
3723 && (info.getSleepTimeMillis() <= activityDurationMs)
3724 && (info.getIdleTimeMillis() <= activityDurationMs)
3725 && (info.getRxTimeMillis() <= activityDurationMs)
3726 && (totalTxTimeMs <= activityDurationMs));
3727 }
3728
Jack Yu85bd38a2015-11-09 11:34:32 -08003729 /**
3730 * {@hide}
3731 * Returns the service state information on specified subscription.
3732 */
3733 @Override
3734 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3735
Jeff Davidson7e17e312018-02-13 18:17:36 -08003736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003737 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003738 return null;
3739 }
3740
3741 final Phone phone = getPhone(subId);
3742 if (phone == null) {
3743 return null;
3744 }
3745
3746 return phone.getServiceState();
3747 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003748
3749 /**
3750 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3751 *
3752 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3753 * voicemail ringtone.
3754 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3755 * PhoneAccount.
3756 */
3757 @Override
3758 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003759 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003760 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003761 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003762 }
3763
fionaxu7ed723d2017-05-30 18:58:54 -07003764 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003765 }
3766
3767 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003768 * Sets the per-account voicemail ringtone.
3769 *
3770 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3771 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3772 *
3773 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3774 * voicemail ringtone.
3775 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3776 * PhoneAccount.
3777 */
3778 @Override
3779 public void setVoicemailRingtoneUri(String callingPackage,
3780 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3781 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3782 if (!TextUtils.equals(callingPackage,
3783 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3785 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3786 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003787 }
3788 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3789 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003790 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003791 }
fionaxu7ed723d2017-05-30 18:58:54 -07003792 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003793 }
3794
3795 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003796 * Returns whether vibration is set for voicemail notification in Phone settings.
3797 *
3798 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3799 * voicemail vibration setting.
3800 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3801 */
3802 @Override
3803 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003804 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003805 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003806 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003807 }
3808
fionaxu7ed723d2017-05-30 18:58:54 -07003809 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003810 }
3811
Youhan Wange64578a2016-05-02 15:32:42 -07003812 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003813 * Sets the per-account voicemail vibration.
3814 *
3815 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3816 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3817 *
3818 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3819 * voicemail vibration setting.
3820 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3821 * specific PhoneAccount.
3822 */
3823 @Override
3824 public void setVoicemailVibrationEnabled(String callingPackage,
3825 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3826 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3827 if (!TextUtils.equals(callingPackage,
3828 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3830 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3831 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003832 }
3833
3834 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3835 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003836 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003837 }
fionaxu7ed723d2017-05-30 18:58:54 -07003838 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003839 }
3840
3841 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003842 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3843 *
3844 * @throws SecurityException if the caller does not have the required permission
3845 */
3846 private void enforceReadPrivilegedPermission() {
3847 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3848 null);
3849 }
3850
3851 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003852 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3853 * permission.
3854 *
3855 * @throws SecurityException if the caller does not have the required permission
3856 */
3857 private void enforceSendSmsPermission() {
3858 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3859 }
3860
3861 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003862 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003863 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003864 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003865 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003866 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003867 ComponentName componentName =
3868 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3869 if(componentName == null) {
3870 throw new SecurityException("Caller not current active visual voicemail package[null]");
3871 }
3872 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003873 if (!callingPackage.equals(vvmPackage)) {
3874 throw new SecurityException("Caller not current active visual voicemail package[" +
3875 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003876 }
3877 }
3878
3879 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003880 * Return the application ID for the app type.
3881 *
3882 * @param subId the subscription ID that this request applies to.
3883 * @param appType the uicc app type.
3884 * @return Application ID for specificied app type, or null if no uicc.
3885 */
3886 @Override
3887 public String getAidForAppType(int subId, int appType) {
3888 enforceReadPrivilegedPermission();
3889 Phone phone = getPhone(subId);
3890 if (phone == null) {
3891 return null;
3892 }
3893 String aid = null;
3894 try {
3895 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3896 .getApplicationByType(appType).getAid();
3897 } catch (Exception e) {
3898 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3899 }
3900 return aid;
3901 }
3902
Youhan Wang4001d252016-05-11 10:29:41 -07003903 /**
3904 * Return the Electronic Serial Number.
3905 *
3906 * @param subId the subscription ID that this request applies to.
3907 * @return ESN or null if error.
3908 */
3909 @Override
3910 public String getEsn(int subId) {
3911 enforceReadPrivilegedPermission();
3912 Phone phone = getPhone(subId);
3913 if (phone == null) {
3914 return null;
3915 }
3916 String esn = null;
3917 try {
3918 esn = phone.getEsn();
3919 } catch (Exception e) {
3920 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3921 }
3922 return esn;
3923 }
3924
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003925 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003926 * Return the Preferred Roaming List Version.
3927 *
3928 * @param subId the subscription ID that this request applies to.
3929 * @return PRLVersion or null if error.
3930 */
3931 @Override
3932 public String getCdmaPrlVersion(int subId) {
3933 enforceReadPrivilegedPermission();
3934 Phone phone = getPhone(subId);
3935 if (phone == null) {
3936 return null;
3937 }
3938 String cdmaPrlVersion = null;
3939 try {
3940 cdmaPrlVersion = phone.getCdmaPrlVersion();
3941 } catch (Exception e) {
3942 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3943 }
3944 return cdmaPrlVersion;
3945 }
3946
3947 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003948 * Get snapshot of Telephony histograms
3949 * @return List of Telephony histograms
3950 * @hide
3951 */
3952 @Override
3953 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3955 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003956 return RIL.getTelephonyRILTimingHistograms();
3957 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003958
3959 /**
3960 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003961 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003962 * Require system privileges. In the future we may add this to carrier APIs.
3963 *
3964 * @return The number of carriers set successfully, should match length of carriers
3965 */
3966 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003967 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003968 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003969
Meng Wang9b7c4e92017-02-17 11:41:27 -08003970 if (carriers == null) {
3971 throw new NullPointerException("carriers cannot be null");
3972 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003973
3974 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003975 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3976 return retVal[0];
3977 }
3978
3979 /**
3980 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003981 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003982 * Require system privileges. In the future we may add this to carrier APIs.
3983 *
3984 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3985 * means all carriers are allowed.
3986 */
3987 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003988 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003989 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003990 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003991 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3992 }
3993
fionaxu59545b42016-05-25 15:53:37 -07003994 /**
3995 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3996 * @param subId the subscription ID that this action applies to.
3997 * @param enabled control enable or disable metered apns.
3998 * {@hide}
3999 */
4000 @Override
4001 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4002 enforceModifyPermission();
4003 final Phone phone = getPhone(subId);
4004 if (phone == null) {
4005 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4006 return;
4007 }
4008 try {
4009 phone.carrierActionSetMeteredApnsEnabled(enabled);
4010 } catch (Exception e) {
4011 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
4012 }
4013 }
4014
4015 /**
4016 * Action set from carrier signalling broadcast receivers to enable/disable radio
4017 * @param subId the subscription ID that this action applies to.
4018 * @param enabled control enable or disable radio.
4019 * {@hide}
4020 */
4021 @Override
4022 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4023 enforceModifyPermission();
4024 final Phone phone = getPhone(subId);
4025 if (phone == null) {
4026 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4027 return;
4028 }
4029 try {
4030 phone.carrierActionSetRadioEnabled(enabled);
4031 } catch (Exception e) {
4032 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
4033 }
4034 }
4035
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004036 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004037 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4038 * network status based on which carrier apps could apply actions accordingly,
4039 * enable/disable default url handler for example.
4040 *
4041 * @param subId the subscription ID that this action applies to.
4042 * @param report control start/stop reporting the default network status.
4043 * {@hide}
4044 */
4045 @Override
4046 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4047 enforceModifyPermission();
4048 final Phone phone = getPhone(subId);
4049 if (phone == null) {
4050 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4051 return;
4052 }
4053 try {
4054 phone.carrierActionReportDefaultNetworkStatus(report);
4055 } catch (Exception e) {
4056 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
4057 }
4058 }
4059
4060 /**
fionaxud9622282017-07-17 17:51:30 -07004061 * Action set from carrier signalling broadcast receivers to reset all carrier actions
4062 * @param subId the subscription ID that this action applies to.
4063 * {@hide}
4064 */
4065 @Override
4066 public void carrierActionResetAll(int subId) {
4067 enforceModifyPermission();
4068 final Phone phone = getPhone(subId);
4069 if (phone == null) {
4070 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
4071 return;
4072 }
4073 try {
4074 phone.carrierActionResetAll();
4075 } catch (Exception e) {
4076 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
4077 }
4078 }
4079
4080 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004081 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4082 * bug report is being generated.
4083 */
4084 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004085 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004086 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4087 != PackageManager.PERMISSION_GRANTED) {
4088 writer.println("Permission Denial: can't dump Phone from pid="
4089 + Binder.getCallingPid()
4090 + ", uid=" + Binder.getCallingUid()
4091 + "without permission "
4092 + android.Manifest.permission.DUMP);
4093 return;
4094 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004095 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004096 }
Jack Yueb89b242016-06-22 13:27:47 -07004097
Brad Ebingerdac2f002018-04-03 15:17:52 -07004098 @Override
4099 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4100 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4101 throws RemoteException {
4102 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4103 }
4104
Jack Yueb89b242016-06-22 13:27:47 -07004105 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004106 * Get aggregated video call data usage since boot.
4107 *
4108 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4109 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004110 * {@hide}
4111 */
4112 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004113 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004114 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4115 null);
4116
Jack Yu84291ec2017-05-26 16:07:50 -07004117 // NetworkStatsService keeps tracking the active network interface and identity. It
4118 // records the delta with the corresponding network identity. We just return the total video
4119 // call data usage snapshot since boot.
4120 Phone phone = getPhone(subId);
4121 if (phone != null) {
4122 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004123 }
Jack Yu84291ec2017-05-26 16:07:50 -07004124 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004125 }
Jack Yu75ab2952016-07-08 14:29:33 -07004126
4127 /**
4128 * Policy control of data connection. Usually used when data limit is passed.
4129 * @param enabled True if enabling the data, otherwise disabling.
4130 * @param subId Subscription index
4131 * {@hide}
4132 */
4133 @Override
4134 public void setPolicyDataEnabled(boolean enabled, int subId) {
4135 enforceModifyPermission();
4136 Phone phone = getPhone(subId);
4137 if (phone != null) {
4138 phone.setPolicyDataEnabled(enabled);
4139 }
4140 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004141
4142 /**
4143 * Get Client request stats
4144 * @return List of Client Request Stats
4145 * @hide
4146 */
4147 @Override
4148 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004150 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004151 return null;
4152 }
4153
4154 Phone phone = getPhone(subId);
4155 if (phone != null) {
4156 return phone.getClientRequestStats();
4157 }
4158
4159 return null;
4160 }
4161
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004162 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004163 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004164 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004165 }
Jack Yueb4124c2017-02-16 15:32:43 -08004166
4167 /**
Grace Chen70990072017-03-24 17:21:30 -07004168 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004169 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004170 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004171 * @param state State of SIM (power down, power up, pass through)
4172 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4173 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4174 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004175 *
4176 **/
4177 @Override
Grace Chen70990072017-03-24 17:21:30 -07004178 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004179 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004180 Phone phone = PhoneFactory.getPhone(slotIndex);
4181
Jack Yueb4124c2017-02-16 15:32:43 -08004182 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004183 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004184 }
4185 }
Shuo Qiandd210312017-04-12 22:11:33 +00004186
Tyler Gunn65d45c22017-06-05 11:22:26 -07004187 private boolean isUssdApiAllowed(int subId) {
4188 CarrierConfigManager configManager =
4189 (CarrierConfigManager) mPhone.getContext().getSystemService(
4190 Context.CARRIER_CONFIG_SERVICE);
4191 if (configManager == null) {
4192 return false;
4193 }
4194 PersistableBundle pb = configManager.getConfigForSubId(subId);
4195 if (pb == null) {
4196 return false;
4197 }
4198 return pb.getBoolean(
4199 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4200 }
4201
Shuo Qiandd210312017-04-12 22:11:33 +00004202 /**
4203 * Check if phone is in emergency callback mode
4204 * @return true if phone is in emergency callback mode
4205 * @param subId sub id
4206 */
goneil9c5f4872017-12-05 14:07:56 -08004207 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004208 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004209 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004210 final Phone phone = getPhone(subId);
4211 if (phone != null) {
4212 return phone.isInEcm();
4213 } else {
4214 return false;
4215 }
4216 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004217
4218 /**
4219 * Get the current signal strength information for the given subscription.
4220 * Because this information is not updated when the device is in a low power state
4221 * it should not be relied-upon to be current.
4222 * @param subId Subscription index
4223 * @return the most recent cached signal strength info from the modem
4224 */
4225 @Override
4226 public SignalStrength getSignalStrength(int subId) {
4227 Phone p = getPhone(subId);
4228 if (p == null) {
4229 return null;
4230 }
4231
4232 return p.getSignalStrength();
4233 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004234
4235 @Override
4236 public UiccSlotInfo[] getUiccSlotsInfo() {
4237 enforceReadPrivilegedPermission();
4238
4239 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004240 if (slots == null) {
4241 Rlog.i(LOG_TAG, "slots is null.");
4242 return null;
4243 }
4244
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004245 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4246 for (int i = 0; i < slots.length; i++) {
4247 UiccSlot slot = slots[i];
Holly Jiuyu Sun6723f982018-06-04 15:48:38 -07004248 if (slot == null) {
4249 continue;
4250 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004251
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004252 String cardId;
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004253 UiccCard card = slot.getUiccCard();
4254 if (card != null) {
4255 cardId = card.getCardId();
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004256 } else {
4257 cardId = slot.getIccId();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004258 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004259
4260 int cardState = 0;
4261 switch (slot.getCardState()) {
4262 case CARDSTATE_ABSENT:
4263 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4264 break;
4265 case CARDSTATE_PRESENT:
4266 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4267 break;
4268 case CARDSTATE_ERROR:
4269 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4270 break;
4271 case CARDSTATE_RESTRICTED:
4272 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4273 break;
4274 default:
4275 break;
4276
4277 }
4278
Qingxi Li795c5882018-01-31 13:43:27 -08004279 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004280 slot.isActive(),
4281 slot.isEuicc(),
4282 cardId,
4283 cardState,
4284 slot.getPhoneId(),
4285 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004286 }
4287 return infos;
4288 }
4289
4290 @Override
4291 public boolean switchSlots(int[] physicalSlots) {
4292 enforceModifyPermission();
4293 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4294 }
Jack Yu4c988042018-02-27 15:30:01 -08004295
4296 @Override
4297 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4298 enforceModifyPermission();
4299 final Phone phone = getPhone(subId);
4300 if (phone == null) {
4301 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4302 return;
4303 }
4304
4305 phone.setRadioIndicationUpdateMode(filters, mode);
4306 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004307
4308 /**
goneil47ffb6e2018-04-06 15:40:58 -07004309 * A test API to reload the UICC profile.
4310 *
4311 * <p>Requires that the calling app has permission
4312 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4313 * @hide
4314 */
4315 @Override
4316 public void refreshUiccProfile(int subId) {
4317 enforceModifyPermission();
4318
4319 final long identity = Binder.clearCallingIdentity();
4320 try {
4321 Phone phone = getPhone(subId);
4322 if (phone == null) {
4323 return;
4324 }
4325 UiccCard uiccCard = phone.getUiccCard();
4326 if (uiccCard == null) {
4327 return;
4328 }
4329 UiccProfile uiccProfile = uiccCard.getUiccProfile();
4330 if (uiccProfile == null) {
4331 return;
4332 }
4333 uiccProfile.refresh();
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
4337 }
4338
4339 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07004340 * Returns false if the mobile data is disabled by default, otherwise return true.
4341 */
4342 private boolean getDefaultDataEnabled() {
4343 return "true".equalsIgnoreCase(
4344 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4345 }
4346
4347 /**
4348 * Returns true if the data roaming is enabled by default, i.e the system property
4349 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4350 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4351 */
4352 private boolean getDefaultDataRoamingEnabled(int subId) {
4353 final CarrierConfigManager configMgr = (CarrierConfigManager)
4354 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4355 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4356 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4357 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4358 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4359 return isDataRoamingEnabled;
4360 }
4361
4362 /**
4363 * Returns the default network type for the given {@code subId}, if the default network type is
4364 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4365 */
4366 private int getDefaultNetworkType(int subId) {
4367 return Integer.parseInt(
4368 TelephonyManager.getTelephonyProperty(
4369 mSubscriptionController.getPhoneId(subId),
4370 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4371 String.valueOf(Phone.PREFERRED_NT_MODE)));
4372 }
fionaxua13278b2018-03-21 00:08:13 -07004373
4374 @Override
4375 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4376 gid1, String gid2, String plmn, String spn) {
4377 enforceModifyPermission();
4378 final Phone phone = getPhone(subId);
4379 if (phone == null) {
4380 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4381 return;
4382 }
4383 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4384 }
4385
4386 @Override
4387 public int getCarrierIdListVersion(int subId) {
4388 enforceReadPrivilegedPermission();
4389 final Phone phone = getPhone(subId);
4390 if (phone == null) {
4391 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4392 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4393 }
4394 return phone.getCarrierIdListVersion();
4395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004396}