blob: 489c3bd8532338ac7f515ba62fcfc49b19c9b649 [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;
Narayan Kamath1c496c22015-04-16 14:40:19 +010098import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070099import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700100import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800102import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700103import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700104import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700105import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700107import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800108import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800109import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700110import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700111import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700112import com.android.internal.telephony.uicc.IccIoResult;
113import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800114import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700115import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800116import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800118import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000119import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700120import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800121import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700122import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800123import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700124import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700125import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800126
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700127import java.io.FileDescriptor;
128import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800129import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800131import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800132import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100133import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800134import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135
136/**
137 * Implementation of the ITelephony interface.
138 */
Santos Cordon117fee72014-05-16 17:56:12 -0700139public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140 private static final String LOG_TAG = "PhoneInterfaceManager";
141 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
142 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800143 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144
145 // Message codes used with mMainThreadHandler
146 private static final int CMD_HANDLE_PIN_MMI = 1;
147 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
148 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
149 private static final int CMD_ANSWER_RINGING_CALL = 4;
150 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700151 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
152 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153 private static final int CMD_OPEN_CHANNEL = 9;
154 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
155 private static final int CMD_CLOSE_CHANNEL = 11;
156 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800157 private static final int CMD_NV_READ_ITEM = 13;
158 private static final int EVENT_NV_READ_ITEM_DONE = 14;
159 private static final int CMD_NV_WRITE_ITEM = 15;
160 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
161 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
162 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
163 private static final int CMD_NV_RESET_CONFIG = 19;
164 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800165 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
166 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
167 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
168 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800169 private static final int CMD_SEND_ENVELOPE = 25;
170 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qiane12f8752018-04-17 18:39:35 +0000171 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
172 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700173 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
174 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
175 private static final int CMD_EXCHANGE_SIM_IO = 31;
176 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800177 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
178 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700179 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
180 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700181 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
182 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700183 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
184 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
185 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
186 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700187 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
188 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
189 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
190 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700191 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800192 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
193 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000194 private static final int CMD_SWITCH_SLOTS = 50;
195 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800197 // Parameters of select command.
198 private static final int SELECT_COMMAND = 0xA4;
199 private static final int SELECT_P1 = 0x04;
200 private static final int SELECT_P2 = 0;
201 private static final int SELECT_P3 = 0x10;
202
Pengquan Meng85728fb2018-03-12 16:31:21 -0700203 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
204 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
205 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
206
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207 /** The singleton instance. */
208 private static PhoneInterfaceManager sInstance;
209
Wink Saville3ab207e2014-11-20 13:07:20 -0800210 private PhoneGlobals mApp;
211 private Phone mPhone;
212 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700213 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800214 private AppOpsManager mAppOps;
215 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800216 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800217 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218
Derek Tan97ebb422014-09-05 16:55:38 -0700219 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
220 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700222
Derek Tan740e1672017-06-27 14:56:27 -0700223 // The AID of ISD-R.
224 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
225
yinxub1bed742017-04-17 11:45:04 -0700226 private NetworkScanRequestTracker mNetworkScanRequestTracker;
227
Derek Tan89e89d42014-07-08 17:00:10 -0700228 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700229 * A request object to use for transmitting data to an ICC.
230 */
231 private static final class IccAPDUArgument {
232 public int channel, cla, command, p1, p2, p3;
233 public String data;
234
235 public IccAPDUArgument(int channel, int cla, int command,
236 int p1, int p2, int p3, String data) {
237 this.channel = channel;
238 this.cla = cla;
239 this.command = command;
240 this.p1 = p1;
241 this.p2 = p2;
242 this.p3 = p3;
243 this.data = data;
244 }
245 }
246
247 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700248 * A request object to use for transmitting data to an ICC.
249 */
250 private static final class ManualNetworkSelectionArgument {
251 public OperatorInfo operatorInfo;
252 public boolean persistSelection;
253
254 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
255 this.operatorInfo = operatorInfo;
256 this.persistSelection = persistSelection;
257 }
258 }
259
260 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
262 * request after sending. The main thread will notify the request when it is complete.
263 */
264 private static final class MainThreadRequest {
265 /** The argument to use for the request */
266 public Object argument;
267 /** The result of the request that is run on the main thread */
268 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800269 // The subscriber id that this request applies to. Defaults to
270 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
271 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272
273 public MainThreadRequest(Object argument) {
274 this.argument = argument;
275 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800276
277 public MainThreadRequest(Object argument, Integer subId) {
278 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800279 if (subId != null) {
280 this.subId = subId;
281 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283 }
284
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800285 private static final class IncomingThirdPartyCallArgs {
286 public final ComponentName component;
287 public final String callId;
288 public final String callerDisplayName;
289
290 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
291 String callerDisplayName) {
292 this.component = component;
293 this.callId = callId;
294 this.callerDisplayName = callerDisplayName;
295 }
296 }
297
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298 /**
299 * A handler that processes messages on the main thread in the phone process. Since many
300 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
301 * inbound binder threads to the main thread in the phone process. The Binder thread
302 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
303 * on, which will be notified when the operation completes and will contain the result of the
304 * request.
305 *
306 * <p>If a MainThreadRequest object is provided in the msg.obj field,
307 * note that request.result must be set to something non-null for the calling thread to
308 * unblock.
309 */
310 private final class MainThreadHandler extends Handler {
311 @Override
312 public void handleMessage(Message msg) {
313 MainThreadRequest request;
314 Message onCompleted;
315 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800316 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700317 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318
319 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700320 case CMD_HANDLE_USSD_REQUEST: {
321 request = (MainThreadRequest) msg.obj;
322 final Phone phone = getPhoneFromRequest(request);
323 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
324 String ussdRequest = ussdObject.first;
325 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700326
327 if (!isUssdApiAllowed(request.subId)) {
328 // Carrier does not support use of this API, return failure.
329 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
330 UssdResponse response = new UssdResponse(ussdRequest, null);
331 Bundle returnData = new Bundle();
332 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
333 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
334
335 request.result = true;
336 synchronized (request) {
337 request.notifyAll();
338 }
339 return;
340 }
341
Tyler Gunn52dcf772017-04-26 11:30:31 -0700342 try {
343 request.result = phone != null ?
344 phone.handleUssdRequest(ussdRequest, wrappedCallback)
345 : false;
346 } catch (CallStateException cse) {
347 request.result = false;
348 }
pkanwar32d516d2016-10-14 19:37:38 -0700349 // Wake up the requesting thread
350 synchronized (request) {
351 request.notifyAll();
352 }
353 break;
354 }
355
Yorke Lee716f67e2015-06-17 15:39:16 -0700356 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700358 final Phone phone = getPhoneFromRequest(request);
359 request.result = phone != null ?
360 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
361 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 // Wake up the requesting thread
363 synchronized (request) {
364 request.notifyAll();
365 }
366 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368
369 case CMD_HANDLE_NEIGHBORING_CELL:
370 request = (MainThreadRequest) msg.obj;
371 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
372 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700373 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 break;
375
376 case EVENT_NEIGHBORING_CELL_DONE:
377 ar = (AsyncResult) msg.obj;
378 request = (MainThreadRequest) ar.userObj;
379 if (ar.exception == null && ar.result != null) {
380 request.result = ar.result;
381 } else {
382 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800383 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 }
385 // Wake up the requesting thread
386 synchronized (request) {
387 request.notifyAll();
388 }
389 break;
390
391 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700392 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800393 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700394 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 break;
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 case CMD_END_CALL:
398 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800399 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700400 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700401 Phone phone = getPhone(end_subId);
402 if (phone == null) {
403 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
404 break;
405 }
406 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
408 // CDMA: If the user presses the Power button we treat it as
409 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700410 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
412 // GSM: End the call as per the Phone state
413 hungUp = PhoneUtils.hangup(mCM);
414 } else {
415 throw new IllegalStateException("Unexpected phone type: " + phoneType);
416 }
417 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
418 request.result = hungUp;
419 // Wake up the requesting thread
420 synchronized (request) {
421 request.notifyAll();
422 }
423 break;
424
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800428 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 if (uiccCard == null) {
430 loge("iccTransmitApduLogicalChannel: No UICC");
431 request.result = new IccIoResult(0x6F, 0, (byte[])null);
432 synchronized (request) {
433 request.notifyAll();
434 }
435 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
437 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700438 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700439 iccArgument.channel, iccArgument.cla, iccArgument.command,
440 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700441 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700442 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 break;
444
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 ar = (AsyncResult) msg.obj;
447 request = (MainThreadRequest) ar.userObj;
448 if (ar.exception == null && ar.result != null) {
449 request.result = ar.result;
450 } else {
451 request.result = new IccIoResult(0x6F, 0, (byte[])null);
452 if (ar.result == null) {
453 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800454 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800456 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700457 } else {
458 loge("iccTransmitApduLogicalChannel: Unknown exception");
459 }
460 }
461 synchronized (request) {
462 request.notifyAll();
463 }
464 break;
465
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
467 request = (MainThreadRequest) msg.obj;
468 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800469 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 if (uiccCard == null) {
471 loge("iccTransmitApduBasicChannel: No UICC");
472 request.result = new IccIoResult(0x6F, 0, (byte[])null);
473 synchronized (request) {
474 request.notifyAll();
475 }
476 } else {
477 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
478 request);
479 uiccCard.iccTransmitApduBasicChannel(
480 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
481 iccArgument.p3, iccArgument.data, onCompleted);
482 }
483 break;
484
485 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
486 ar = (AsyncResult) msg.obj;
487 request = (MainThreadRequest) ar.userObj;
488 if (ar.exception == null && ar.result != null) {
489 request.result = ar.result;
490 } else {
491 request.result = new IccIoResult(0x6F, 0, (byte[])null);
492 if (ar.result == null) {
493 loge("iccTransmitApduBasicChannel: Empty response");
494 } else if (ar.exception instanceof CommandException) {
495 loge("iccTransmitApduBasicChannel: CommandException: " +
496 ar.exception);
497 } else {
498 loge("iccTransmitApduBasicChannel: Unknown exception");
499 }
500 }
501 synchronized (request) {
502 request.notifyAll();
503 }
504 break;
505
506 case CMD_EXCHANGE_SIM_IO:
507 request = (MainThreadRequest) msg.obj;
508 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800509 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700510 if (uiccCard == null) {
511 loge("iccExchangeSimIO: No UICC");
512 request.result = new IccIoResult(0x6F, 0, (byte[])null);
513 synchronized (request) {
514 request.notifyAll();
515 }
516 } else {
517 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
518 request);
519 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
520 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
521 iccArgument.data, onCompleted);
522 }
523 break;
524
525 case EVENT_EXCHANGE_SIM_IO_DONE:
526 ar = (AsyncResult) msg.obj;
527 request = (MainThreadRequest) ar.userObj;
528 if (ar.exception == null && ar.result != null) {
529 request.result = ar.result;
530 } else {
531 request.result = new IccIoResult(0x6f, 0, (byte[])null);
532 }
533 synchronized (request) {
534 request.notifyAll();
535 }
536 break;
537
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 case CMD_SEND_ENVELOPE:
539 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800540 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 if (uiccCard == null) {
542 loge("sendEnvelopeWithStatus: No UICC");
543 request.result = new IccIoResult(0x6F, 0, (byte[])null);
544 synchronized (request) {
545 request.notifyAll();
546 }
547 } else {
548 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
549 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
550 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800551 break;
552
553 case EVENT_SEND_ENVELOPE_DONE:
554 ar = (AsyncResult) msg.obj;
555 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700556 if (ar.exception == null && ar.result != null) {
557 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
560 if (ar.result == null) {
561 loge("sendEnvelopeWithStatus: Empty response");
562 } else if (ar.exception instanceof CommandException) {
563 loge("sendEnvelopeWithStatus: CommandException: " +
564 ar.exception);
565 } else {
566 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
567 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800568 }
569 synchronized (request) {
570 request.notifyAll();
571 }
572 break;
573
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 case CMD_OPEN_CHANNEL:
575 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800576 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800577 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700578 if (uiccCard == null) {
579 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800580 request.result = new IccOpenLogicalChannelResponse(-1,
581 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 synchronized (request) {
583 request.notifyAll();
584 }
585 } else {
586 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800587 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
588 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
592 case EVENT_OPEN_CHANNEL_DONE:
593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 int[] result = (int[]) ar.result;
598 int channelId = result[0];
599 byte[] selectResponse = null;
600 if (result.length > 1) {
601 selectResponse = new byte[result.length - 1];
602 for (int i = 1; i < result.length; ++i) {
603 selectResponse[i - 1] = (byte) result[i];
604 }
605 }
606 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700607 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 if (ar.result == null) {
610 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 if (ar.exception != null) {
613 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
614 }
615
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700616 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700617 if (ar.exception instanceof CommandException) {
618 CommandException.Error error =
619 ((CommandException) (ar.exception)).getCommandError();
620 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700621 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700622 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 }
625 }
626 openChannelResp = new IccOpenLogicalChannelResponse(
627 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700629 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 synchronized (request) {
631 request.notifyAll();
632 }
633 break;
634
635 case CMD_CLOSE_CHANNEL:
636 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800637 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 if (uiccCard == null) {
639 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900640 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700641 synchronized (request) {
642 request.notifyAll();
643 }
644 } else {
645 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
646 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
647 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 break;
649
650 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800651 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
652 break;
653
654 case CMD_NV_READ_ITEM:
655 request = (MainThreadRequest) msg.obj;
656 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
657 mPhone.nvReadItem((Integer) request.argument, onCompleted);
658 break;
659
660 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800663 if (ar.exception == null && ar.result != null) {
664 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800666 request.result = "";
667 if (ar.result == null) {
668 loge("nvReadItem: Empty response");
669 } else if (ar.exception instanceof CommandException) {
670 loge("nvReadItem: CommandException: " +
671 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
675 }
676 synchronized (request) {
677 request.notifyAll();
678 }
679 break;
680
Jake Hambye994d462014-02-03 13:10:13 -0800681 case CMD_NV_WRITE_ITEM:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
684 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
685 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
686 break;
687
688 case EVENT_NV_WRITE_ITEM_DONE:
689 handleNullReturnEvent(msg, "nvWriteItem");
690 break;
691
692 case CMD_NV_WRITE_CDMA_PRL:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
695 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
696 break;
697
698 case EVENT_NV_WRITE_CDMA_PRL_DONE:
699 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
700 break;
701
702 case CMD_NV_RESET_CONFIG:
703 request = (MainThreadRequest) msg.obj;
704 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
705 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
706 break;
707
708 case EVENT_NV_RESET_CONFIG_DONE:
709 handleNullReturnEvent(msg, "nvResetConfig");
710 break;
711
Jake Hamby7c27be32014-03-03 13:25:59 -0800712 case CMD_GET_PREFERRED_NETWORK_TYPE:
713 request = (MainThreadRequest) msg.obj;
714 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700715 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 break;
717
718 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
719 ar = (AsyncResult) msg.obj;
720 request = (MainThreadRequest) ar.userObj;
721 if (ar.exception == null && ar.result != null) {
722 request.result = ar.result; // Integer
723 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800724 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 if (ar.result == null) {
726 loge("getPreferredNetworkType: Empty response");
727 } else if (ar.exception instanceof CommandException) {
728 loge("getPreferredNetworkType: CommandException: " +
729 ar.exception);
730 } else {
731 loge("getPreferredNetworkType: Unknown exception");
732 }
733 }
734 synchronized (request) {
735 request.notifyAll();
736 }
737 break;
738
739 case CMD_SET_PREFERRED_NETWORK_TYPE:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
742 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700743 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800744 break;
745
746 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
747 handleNullReturnEvent(msg, "setPreferredNetworkType");
748 break;
749
Shuo Qiane12f8752018-04-17 18:39:35 +0000750 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
751 request = (MainThreadRequest)msg.obj;
752 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
753 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
754 break;
755
756 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
757 ar = (AsyncResult)msg.obj;
758 request = (MainThreadRequest)ar.userObj;
759 request.result = ar;
760 synchronized (request) {
761 request.notifyAll();
762 }
763 break;
764
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800765 case CMD_SET_VOICEMAIL_NUMBER:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
768 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800769 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
770 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800771 break;
772
773 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
774 handleNullReturnEvent(msg, "setVoicemailNumber");
775 break;
776
Stuart Scott54788802015-03-30 13:18:01 -0700777 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
780 request);
781 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
782 break;
783
784 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
785 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
786 break;
787
Shishir Agrawal302c8692015-06-19 13:49:39 -0700788 case CMD_PERFORM_NETWORK_SCAN:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
791 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
792 break;
793
794 case EVENT_PERFORM_NETWORK_SCAN_DONE:
795 ar = (AsyncResult) msg.obj;
796 request = (MainThreadRequest) ar.userObj;
797 CellNetworkScanResult cellScanResult;
798 if (ar.exception == null && ar.result != null) {
799 cellScanResult = new CellNetworkScanResult(
800 CellNetworkScanResult.STATUS_SUCCESS,
801 (List<OperatorInfo>) ar.result);
802 } else {
803 if (ar.result == null) {
804 loge("getCellNetworkScanResults: Empty response");
805 }
806 if (ar.exception != null) {
807 loge("getCellNetworkScanResults: Exception: " + ar.exception);
808 }
809 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
810 if (ar.exception instanceof CommandException) {
811 CommandException.Error error =
812 ((CommandException) (ar.exception)).getCommandError();
813 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
814 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
815 } else if (error == CommandException.Error.GENERIC_FAILURE) {
816 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
817 }
818 }
819 cellScanResult = new CellNetworkScanResult(errorCode, null);
820 }
821 request.result = cellScanResult;
822 synchronized (request) {
823 request.notifyAll();
824 }
825 break;
826
827 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
828 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700829 ManualNetworkSelectionArgument selArg =
830 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
832 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700833 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
834 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700835 break;
836
837 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
838 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
839 break;
840
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700841 case CMD_GET_MODEM_ACTIVITY_INFO:
842 request = (MainThreadRequest) msg.obj;
843 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700844 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700845 break;
846
847 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
850 if (ar.exception == null && ar.result != null) {
851 request.result = ar.result;
852 } else {
853 if (ar.result == null) {
854 loge("queryModemActivityInfo: Empty response");
855 } else if (ar.exception instanceof CommandException) {
856 loge("queryModemActivityInfo: CommandException: " +
857 ar.exception);
858 } else {
859 loge("queryModemActivityInfo: Unknown exception");
860 }
861 }
Amit Mahajand4766222016-01-28 15:28:28 -0800862 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
863 if (request.result == null) {
864 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
865 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700866 synchronized (request) {
867 request.notifyAll();
868 }
869 break;
870
Meng Wang1a7c35a2016-05-05 20:56:15 -0700871 case CMD_SET_ALLOWED_CARRIERS:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
874 mPhone.setAllowedCarriers(
875 (List<CarrierIdentifier>) request.argument,
876 onCompleted);
877 break;
878
879 case EVENT_SET_ALLOWED_CARRIERS_DONE:
880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
882 if (ar.exception == null && ar.result != null) {
883 request.result = ar.result;
884 } else {
885 if (ar.result == null) {
886 loge("setAllowedCarriers: Empty response");
887 } else if (ar.exception instanceof CommandException) {
888 loge("setAllowedCarriers: CommandException: " +
889 ar.exception);
890 } else {
891 loge("setAllowedCarriers: Unknown exception");
892 }
893 }
894 // Result cannot be null. Return -1 on error.
895 if (request.result == null) {
896 request.result = new int[]{-1};
897 }
898 synchronized (request) {
899 request.notifyAll();
900 }
901 break;
902
903 case CMD_GET_ALLOWED_CARRIERS:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
906 mPhone.getAllowedCarriers(onCompleted);
907 break;
908
909 case EVENT_GET_ALLOWED_CARRIERS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
915 if (ar.result == null) {
916 loge("getAllowedCarriers: Empty response");
917 } else if (ar.exception instanceof CommandException) {
918 loge("getAllowedCarriers: CommandException: " +
919 ar.exception);
920 } else {
921 loge("getAllowedCarriers: Unknown exception");
922 }
923 }
924 // Result cannot be null. Return empty list of CarrierIdentifier.
925 if (request.result == null) {
926 request.result = new ArrayList<CarrierIdentifier>(0);
927 }
928 synchronized (request) {
929 request.notifyAll();
930 }
931 break;
932
Nathan Haroldb3014052017-01-25 15:57:32 -0800933 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 if (ar.exception == null && ar.result != null) {
937 request.result = ar.result;
938 } else {
939 request.result = new IllegalArgumentException(
940 "Failed to retrieve Forbidden Plmns");
941 if (ar.result == null) {
942 loge("getForbiddenPlmns: Empty response");
943 } else {
944 loge("getForbiddenPlmns: Unknown exception");
945 }
946 }
947 synchronized (request) {
948 request.notifyAll();
949 }
950 break;
951
952 case CMD_GET_FORBIDDEN_PLMNS:
953 request = (MainThreadRequest) msg.obj;
954 uiccCard = getUiccCardFromRequest(request);
955 if (uiccCard == null) {
956 loge("getForbiddenPlmns() UiccCard is null");
957 request.result = new IllegalArgumentException(
958 "getForbiddenPlmns() UiccCard is null");
959 synchronized (request) {
960 request.notifyAll();
961 }
962 break;
963 }
964 Integer appType = (Integer) request.argument;
965 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
966 if (uiccApp == null) {
967 loge("getForbiddenPlmns() no app with specified type -- "
968 + appType);
969 request.result = new IllegalArgumentException("Failed to get UICC App");
970 synchronized (request) {
971 request.notifyAll();
972 }
973 break;
974 } else {
975 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
976 + " specified type -- " + appType);
977 }
978 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
979 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
980 onCompleted);
981 break;
982
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000983 case CMD_SWITCH_SLOTS:
984 request = (MainThreadRequest) msg.obj;
985 int[] physicalSlots = (int[]) request.argument;
986 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
987 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
988 break;
989
990 case EVENT_SWITCH_SLOTS_DONE:
991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
993 request.result = (ar.exception == null);
994 synchronized (request) {
995 request.notifyAll();
996 }
997 break;
998
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700999 default:
1000 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1001 break;
1002 }
1003 }
Jake Hambye994d462014-02-03 13:10:13 -08001004
1005 private void handleNullReturnEvent(Message msg, String command) {
1006 AsyncResult ar = (AsyncResult) msg.obj;
1007 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1008 if (ar.exception == null) {
1009 request.result = true;
1010 } else {
1011 request.result = false;
1012 if (ar.exception instanceof CommandException) {
1013 loge(command + ": CommandException: " + ar.exception);
1014 } else {
1015 loge(command + ": Unknown exception");
1016 }
1017 }
1018 synchronized (request) {
1019 request.notifyAll();
1020 }
1021 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001022 }
1023
1024 /**
1025 * Posts the specified command to be executed on the main thread,
1026 * waits for the request to complete, and returns the result.
1027 * @see #sendRequestAsync
1028 */
1029 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001030 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001031 }
1032
1033 /**
1034 * Posts the specified command to be executed on the main thread,
1035 * waits for the request to complete, and returns the result.
1036 * @see #sendRequestAsync
1037 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001038 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001039 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1040 throw new RuntimeException("This method will deadlock if called from the main thread.");
1041 }
1042
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001043 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001044 Message msg = mMainThreadHandler.obtainMessage(command, request);
1045 msg.sendToTarget();
1046
1047 // Wait for the request to complete
1048 synchronized (request) {
1049 while (request.result == null) {
1050 try {
1051 request.wait();
1052 } catch (InterruptedException e) {
1053 // Do nothing, go back and wait until the request is complete
1054 }
1055 }
1056 }
1057 return request.result;
1058 }
1059
1060 /**
1061 * Asynchronous ("fire and forget") version of sendRequest():
1062 * Posts the specified command to be executed on the main thread, and
1063 * returns immediately.
1064 * @see #sendRequest
1065 */
1066 private void sendRequestAsync(int command) {
1067 mMainThreadHandler.sendEmptyMessage(command);
1068 }
1069
1070 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001071 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1072 * @see {@link #sendRequest(int,Object)}
1073 */
1074 private void sendRequestAsync(int command, Object argument) {
1075 MainThreadRequest request = new MainThreadRequest(argument);
1076 Message msg = mMainThreadHandler.obtainMessage(command, request);
1077 msg.sendToTarget();
1078 }
1079
1080 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001081 * Initialize the singleton PhoneInterfaceManager instance.
1082 * This is only done once, at startup, from PhoneApp.onCreate().
1083 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001084 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 synchronized (PhoneInterfaceManager.class) {
1086 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001087 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001088 } else {
1089 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1090 }
1091 return sInstance;
1092 }
1093 }
1094
1095 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001096 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001097 mApp = app;
1098 mPhone = phone;
1099 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001100 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001101 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1102 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001103 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001104 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001105 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001106 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001107
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001108 publish();
1109 }
1110
1111 private void publish() {
1112 if (DBG) log("publish: " + this);
1113
1114 ServiceManager.addService("phone", this);
1115 }
1116
Stuart Scott584921c2015-01-15 17:10:34 -08001117 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001118 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1119 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001120 }
1121
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001122 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1123 Phone phone = getPhoneFromRequest(request);
1124 return phone == null ? null :
1125 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1126 }
1127
Wink Saville36469e72014-06-11 15:17:00 -07001128 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001129 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001130 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001132 //
1133 // Implementation of the ITelephony interface.
1134 //
1135
1136 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001137 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001138 }
1139
Wink Savilleb564aae2014-10-23 10:18:09 -07001140 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 if (DBG) log("dial: " + number);
1142 // No permission check needed here: This is just a wrapper around the
1143 // ACTION_DIAL intent, which is available to any app since it puts up
1144 // the UI before it does anything.
1145
1146 String url = createTelUrl(number);
1147 if (url == null) {
1148 return;
1149 }
1150
1151 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001152 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001153 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1154 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1155 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1156 mApp.startActivity(intent);
1157 }
1158 }
1159
1160 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001161 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001162 }
1163
Wink Savilleb564aae2014-10-23 10:18:09 -07001164 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 if (DBG) log("call: " + number);
1166
1167 // This is just a wrapper around the ACTION_CALL intent, but we still
1168 // need to do a permission check since we're calling startActivity()
1169 // from the context of the phone app.
1170 enforceCallPermission();
1171
1172 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1173 != AppOpsManager.MODE_ALLOWED) {
1174 return;
1175 }
1176
1177 String url = createTelUrl(number);
1178 if (url == null) {
1179 return;
1180 }
1181
Wink Saville08874612014-08-31 19:19:58 -07001182 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001183 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001184 if (slist != null) {
1185 for (SubscriptionInfo subInfoRecord : slist) {
1186 if (subInfoRecord.getSubscriptionId() == subId) {
1187 isValid = true;
1188 break;
1189 }
Wink Saville08874612014-08-31 19:19:58 -07001190 }
1191 }
1192 if (isValid == false) {
1193 return;
1194 }
1195
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001197 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001198 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1199 mApp.startActivity(intent);
1200 }
1201
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 /**
1203 * End a call based on call state
1204 * @return true is a call was ended
1205 */
1206 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001207 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001208 }
1209
1210 /**
1211 * End a call based on the call state of the subId
1212 * @return true is a call was ended
1213 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001214 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001215 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1216 != PackageManager.PERMISSION_GRANTED) {
1217 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1218 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1219 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1220 }
Stuart Scott584921c2015-01-15 17:10:34 -08001221 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 }
1223
1224 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001225 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001226 }
1227
Wink Savilleb564aae2014-10-23 10:18:09 -07001228 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 if (DBG) log("answerRingingCall...");
1230 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1231 // but that can probably wait till the big TelephonyManager API overhaul.
1232 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1233 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001234 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 }
1236
1237 /**
1238 * Make the actual telephony calls to implement answerRingingCall().
1239 * This should only be called from the main thread of the Phone app.
1240 * @see #answerRingingCall
1241 *
1242 * TODO: it would be nice to return true if we answered the call, or
1243 * false if there wasn't actually a ringing incoming call, or some
1244 * other error occurred. (In other words, pass back the return value
1245 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1246 * But that would require calling this method via sendRequest() rather
1247 * than sendRequestAsync(), and right now we don't actually *need* that
1248 * return value, so let's just return void for now.
1249 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001250 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001251 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001253 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1254 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 if (hasActiveCall && hasHoldingCall) {
1256 // Both lines are in use!
1257 // TODO: provide a flag to let the caller specify what
1258 // policy to use if both lines are in use. (The current
1259 // behavior is hardwired to "answer incoming, end ongoing",
1260 // which is how the CALL button is specced to behave.)
1261 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1262 return;
1263 } else {
1264 // answerCall() will automatically hold the current active
1265 // call, if there is one.
1266 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1267 return;
1268 }
1269 } else {
1270 // No call was ringing.
1271 return;
1272 }
1273 }
1274
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001275 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001276 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001278 public void silenceRinger() {
1279 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 }
1281
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001282 @Override
1283 public boolean isOffhook(String callingPackage) {
1284 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001285 }
1286
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001287 @Override
1288 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001290 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001291 return false;
1292 }
1293
Sanket Padawe356d7632015-06-22 14:03:32 -07001294 final Phone phone = getPhone(subId);
1295 if (phone != null) {
1296 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1297 } else {
1298 return false;
1299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 }
1301
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001302 @Override
1303 public boolean isRinging(String callingPackage) {
1304 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001305 }
1306
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001307 @Override
1308 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001310 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001311 return false;
1312 }
1313
Sanket Padawe356d7632015-06-22 14:03:32 -07001314 final Phone phone = getPhone(subId);
1315 if (phone != null) {
1316 return (phone.getState() == PhoneConstants.State.RINGING);
1317 } else {
1318 return false;
1319 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 }
1321
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001322 @Override
1323 public boolean isIdle(String callingPackage) {
1324 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001325 }
1326
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001327 @Override
1328 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001330 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001331 return false;
1332 }
1333
Sanket Padawe356d7632015-06-22 14:03:32 -07001334 final Phone phone = getPhone(subId);
1335 if (phone != null) {
1336 return (phone.getState() == PhoneConstants.State.IDLE);
1337 } else {
1338 return false;
1339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001340 }
1341
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001343 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001344 }
1345
Wink Savilleb564aae2014-10-23 10:18:09 -07001346 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001347 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001348 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1349 }
1350
1351 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001352 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001353 }
1354
Wink Savilleb564aae2014-10-23 10:18:09 -07001355 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001357 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1358 }
1359
1360 /** {@hide} */
1361 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001362 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001363 }
1364
Wink Savilleb564aae2014-10-23 10:18:09 -07001365 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001367 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 checkSimPin.start();
1369 return checkSimPin.unlockSim(null, pin);
1370 }
1371
Wink Saville9de0f752013-10-22 19:04:03 -07001372 /** {@hide} */
1373 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
1376
Wink Savilleb564aae2014-10-23 10:18:09 -07001377 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001379 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 checkSimPuk.start();
1381 return checkSimPuk.unlockSim(puk, pin);
1382 }
1383
1384 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001385 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 * a synchronous one.
1387 */
1388 private static class UnlockSim extends Thread {
1389
1390 private final IccCard mSimCard;
1391
1392 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001393 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1394 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395
1396 // For replies from SimCard interface
1397 private Handler mHandler;
1398
1399 // For async handler to identify request type
1400 private static final int SUPPLY_PIN_COMPLETE = 100;
1401
1402 public UnlockSim(IccCard simCard) {
1403 mSimCard = simCard;
1404 }
1405
1406 @Override
1407 public void run() {
1408 Looper.prepare();
1409 synchronized (UnlockSim.this) {
1410 mHandler = new Handler() {
1411 @Override
1412 public void handleMessage(Message msg) {
1413 AsyncResult ar = (AsyncResult) msg.obj;
1414 switch (msg.what) {
1415 case SUPPLY_PIN_COMPLETE:
1416 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1417 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001418 mRetryCount = msg.arg1;
1419 if (ar.exception != null) {
1420 if (ar.exception instanceof CommandException &&
1421 ((CommandException)(ar.exception)).getCommandError()
1422 == CommandException.Error.PASSWORD_INCORRECT) {
1423 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1424 } else {
1425 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1426 }
1427 } else {
1428 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 mDone = true;
1431 UnlockSim.this.notifyAll();
1432 }
1433 break;
1434 }
1435 }
1436 };
1437 UnlockSim.this.notifyAll();
1438 }
1439 Looper.loop();
1440 }
1441
1442 /*
1443 * Use PIN or PUK to unlock SIM card
1444 *
1445 * If PUK is null, unlock SIM card with PIN
1446 *
1447 * If PUK is not null, unlock SIM card with PUK and set PIN code
1448 */
Wink Saville9de0f752013-10-22 19:04:03 -07001449 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450
1451 while (mHandler == null) {
1452 try {
1453 wait();
1454 } catch (InterruptedException e) {
1455 Thread.currentThread().interrupt();
1456 }
1457 }
1458 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1459
1460 if (puk == null) {
1461 mSimCard.supplyPin(pin, callback);
1462 } else {
1463 mSimCard.supplyPuk(puk, pin, callback);
1464 }
1465
1466 while (!mDone) {
1467 try {
1468 Log.d(LOG_TAG, "wait for done");
1469 wait();
1470 } catch (InterruptedException e) {
1471 // Restore the interrupted status
1472 Thread.currentThread().interrupt();
1473 }
1474 }
1475 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001476 int[] resultArray = new int[2];
1477 resultArray[0] = mResult;
1478 resultArray[1] = mRetryCount;
1479 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 }
1481 }
1482
1483 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001484 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001485
1486 }
1487
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 // No permission check needed here: this call is harmless, and it's
1490 // needed for the ServiceState.requestStateUpdate() call (which is
1491 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001492 final Phone phone = getPhone(subId);
1493 if (phone != null) {
1494 phone.updateServiceLocation();
1495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 }
1497
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001498 @Override
1499 public boolean isRadioOn(String callingPackage) {
1500 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001501 }
1502
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001503 @Override
1504 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001506 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001507 return false;
1508 }
1509 return isRadioOnForSubscriber(subId);
1510 }
1511
1512 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001513 final Phone phone = getPhone(subId);
1514 if (phone != null) {
1515 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1516 } else {
1517 return false;
1518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001519 }
1520
1521 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001522 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001523
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 }
Wink Saville36469e72014-06-11 15:17:00 -07001525
Wink Savilleb564aae2014-10-23 10:18:09 -07001526 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001528 final Phone phone = getPhone(subId);
1529 if (phone != null) {
1530 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1531 }
Wink Saville36469e72014-06-11 15:17:00 -07001532 }
1533
1534 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001535 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001536 }
1537
Wink Savilleb564aae2014-10-23 10:18:09 -07001538 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001539 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001540 final Phone phone = getPhone(subId);
1541 if (phone == null) {
1542 return false;
1543 }
1544 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001545 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001546 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 }
1548 return true;
1549 }
Wink Saville36469e72014-06-11 15:17:00 -07001550
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001551 public boolean needMobileRadioShutdown() {
1552 /*
1553 * If any of the Radios are available, it will need to be
1554 * shutdown. So return true if any Radio is available.
1555 */
1556 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1557 Phone phone = PhoneFactory.getPhone(i);
1558 if (phone != null && phone.isRadioAvailable()) return true;
1559 }
1560 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1561 return false;
1562 }
1563
1564 public void shutdownMobileRadios() {
1565 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1566 logv("Shutting down Phone " + i);
1567 shutdownRadioUsingPhoneId(i);
1568 }
1569 }
1570
1571 private void shutdownRadioUsingPhoneId(int phoneId) {
1572 enforceModifyPermission();
1573 Phone phone = PhoneFactory.getPhone(phoneId);
1574 if (phone != null && phone.isRadioAvailable()) {
1575 phone.shutdownRadio();
1576 }
1577 }
1578
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001580 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001581 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1582 if (defaultPhone != null) {
1583 defaultPhone.setRadioPower(turnOn);
1584 return true;
1585 } else {
1586 loge("There's no default phone.");
1587 return false;
1588 }
Wink Saville36469e72014-06-11 15:17:00 -07001589 }
1590
Wink Savilleb564aae2014-10-23 10:18:09 -07001591 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 final Phone phone = getPhone(subId);
1594 if (phone != null) {
1595 phone.setRadioPower(turnOn);
1596 return true;
1597 } else {
1598 return false;
1599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
1601
Wink Saville36469e72014-06-11 15:17:00 -07001602 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001603 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 public boolean enableDataConnectivity() {
1605 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001606 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 final Phone phone = getPhone(subId);
1608 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001609 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 return true;
1611 } else {
1612 return false;
1613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 }
1615
Wink Saville36469e72014-06-11 15:17:00 -07001616 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 public boolean disableDataConnectivity() {
1619 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001620 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001621 final Phone phone = getPhone(subId);
1622 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001623 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001624 return true;
1625 } else {
1626 return false;
1627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 }
1629
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001631 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001632 final Phone phone = getPhone(subId);
1633 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001634 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001635 } else {
1636 return false;
1637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 }
1639
1640 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001641 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001642 }
1643
pkanwarae03a6b2016-11-06 20:37:09 -08001644 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001645 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001646 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1647 return;
1648 }
1649 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1650 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1651 };
1652
Wink Savilleb564aae2014-10-23 10:18:09 -07001653 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001655 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1656 return false;
1657 }
Wink Saville36469e72014-06-11 15:17:00 -07001658 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
1660
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001662 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001663 }
1664
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001665 public int getCallStateForSlot(int slotIndex) {
1666 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001667 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001668 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 }
1670
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001673 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001674 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001675 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001676 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001677 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 }
1680
Sanket Padawe356d7632015-06-22 14:03:32 -07001681 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001683 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 if (phone != null) {
1685 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1686 } else {
1687 return TelephonyManager.DATA_ACTIVITY_NONE;
1688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 }
1690
1691 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001692 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001693 mPhone.getContext().getSystemService(AppOpsManager.class)
1694 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001695 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001696 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001697 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 }
1699
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001700 if (DBG_LOC) log("getCellLocation: is active user");
1701 Bundle data = new Bundle();
1702 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1703 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 return null;
1705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001707 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001708 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1709 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001710 }
1711
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001713 public String getNetworkCountryIsoForPhone(int phoneId) {
1714 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1715 // registered cell info, so return a NULL country instead.
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1719 if (TelephonyManager.NETWORK_TYPE_IWLAN
1720 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1721 return "";
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
1725 }
1726 return TelephonyManager.getTelephonyProperty(
1727 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1728 }
1729
1730 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001732 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001733 }
1734
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001736 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 mApp.enforceCallingOrSelfPermission(
1738 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001739 final Phone phone = getPhone(subId);
1740 if (phone != null) {
1741 phone.enableLocationUpdates();
1742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
1744
1745 @Override
1746 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001747 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001748 }
1749
Sanket Padawe356d7632015-06-22 14:03:32 -07001750 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001751 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 mApp.enforceCallingOrSelfPermission(
1753 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001754 final Phone phone = getPhone(subId);
1755 if (phone != null) {
1756 phone.disableLocationUpdates();
1757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759
1760 @Override
1761 @SuppressWarnings("unchecked")
1762 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001763 mPhone.getContext().getSystemService(AppOpsManager.class)
1764 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001765 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001766 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001767 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
1770 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1771 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1772 return null;
1773 }
Svetoslav64fad262015-04-14 14:35:21 -07001774
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001775 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001777 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001779 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001780 try {
1781 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1782 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1783 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1784 } catch (RuntimeException e) {
1785 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001787 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
1789
1790
1791 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001792 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001793 mPhone.getContext().getSystemService(AppOpsManager.class)
1794 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001795 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001796 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001797 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 }
1799
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001800 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001801 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001802 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1803 for (Phone phone : PhoneFactory.getPhones()) {
1804 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1805 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001807 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001810 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001812 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001813 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001814 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
1816
Shishir Agrawala9f32182016-04-12 12:00:16 -07001817 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001818 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001819 Phone phone = PhoneFactory.getPhone(slotIndex);
1820 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001821 return null;
1822 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001823 int subId = phone.getSubId();
1824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1825 mApp, subId, callingPackage, "getImeiForSlot")) {
1826 return null;
1827 }
1828 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001829 }
1830
1831 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001832 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001833 Phone phone = PhoneFactory.getPhone(slotIndex);
1834 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001835 return null;
1836 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001837 int subId = phone.getSubId();
1838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1839 mApp, subId, callingPackage, "getMeidForSlot")) {
1840 return null;
1841 }
1842 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001843 }
1844
1845 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001846 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001847 Phone phone = PhoneFactory.getPhone(slotIndex);
1848 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001849 return null;
1850 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001851 int subId = phone.getSubId();
1852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1853 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1854 return null;
1855 }
1856 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001857 }
1858
fionaxu43304da2017-11-27 22:51:16 -08001859 @Override
1860 public int getSubscriptionCarrierId(int subId) {
1861 final Phone phone = getPhone(subId);
1862 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1863 }
1864
1865 @Override
1866 public String getSubscriptionCarrierName(int subId) {
1867 final Phone phone = getPhone(subId);
1868 return phone == null ? null : phone.getCarrierName();
1869 }
1870
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 //
1872 // Internal helper methods.
1873 //
1874
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001875 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1877 *
1878 * @throws SecurityException if the caller does not have the required permission
1879 */
1880 private void enforceModifyPermission() {
1881 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1882 }
1883
1884 /**
1885 * Make sure the caller has the CALL_PHONE permission.
1886 *
1887 * @throws SecurityException if the caller does not have the required permission
1888 */
1889 private void enforceCallPermission() {
1890 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1891 }
1892
Stuart Scott8eef64f2015-04-08 15:13:54 -07001893 private void enforceConnectivityInternalPermission() {
1894 mApp.enforceCallingOrSelfPermission(
1895 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1896 "ConnectivityService");
1897 }
1898
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 private String createTelUrl(String number) {
1900 if (TextUtils.isEmpty(number)) {
1901 return null;
1902 }
1903
Jake Hambye994d462014-02-03 13:10:13 -08001904 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
Ihab Awadf9e92732013-12-05 18:02:52 -08001907 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1909 }
1910
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001911 private static void logv(String msg) {
1912 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1913 }
1914
Ihab Awadf9e92732013-12-05 18:02:52 -08001915 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1917 }
1918
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001919 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001921 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001922 }
1923
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001925 public int getActivePhoneTypeForSlot(int slotIndex) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00001926 final Phone phone = PhoneFactory.getPhone(slotIndex);
1927 if (phone == null) {
1928 return PhoneConstants.PHONE_TYPE_NONE;
1929 } else {
1930 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932 }
1933
1934 /**
1935 * Returns the CDMA ERI icon index to display
1936 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001937 @Override
1938 public int getCdmaEriIconIndex(String callingPackage) {
1939 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001940 }
1941
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001943 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001945 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001946 return -1;
1947 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 final Phone phone = getPhone(subId);
1949 if (phone != null) {
1950 return phone.getCdmaEriIconIndex();
1951 } else {
1952 return -1;
1953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
1955
1956 /**
1957 * Returns the CDMA ERI icon mode,
1958 * 0 - ON
1959 * 1 - FLASHING
1960 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001961 @Override
1962 public int getCdmaEriIconMode(String callingPackage) {
1963 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001964 }
1965
Sanket Padawe356d7632015-06-22 14:03:32 -07001966 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001967 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001968 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001969 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001970 return -1;
1971 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001972 final Phone phone = getPhone(subId);
1973 if (phone != null) {
1974 return phone.getCdmaEriIconMode();
1975 } else {
1976 return -1;
1977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979
1980 /**
1981 * Returns the CDMA ERI text,
1982 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001983 @Override
1984 public String getCdmaEriText(String callingPackage) {
1985 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001986 }
1987
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001989 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001991 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001992 return null;
1993 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 final Phone phone = getPhone(subId);
1995 if (phone != null) {
1996 return phone.getCdmaEriText();
1997 } else {
1998 return null;
1999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
2001
2002 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002003 * Returns the CDMA MDN.
2004 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002005 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002006 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2008 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 final Phone phone = getPhone(subId);
2010 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2011 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002012 } else {
2013 return null;
2014 }
2015 }
2016
2017 /**
2018 * Returns the CDMA MIN.
2019 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002020 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002021 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2023 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002024 final Phone phone = getPhone(subId);
2025 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2026 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002027 } else {
2028 return null;
2029 }
2030 }
2031
2032 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 * Returns true if CDMA provisioning needs to run.
2034 */
2035 public boolean needsOtaServiceProvisioning() {
2036 return mPhone.needsOtaServiceProvisioning();
2037 }
2038
2039 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002040 * Sets the voice mail number of a given subId.
2041 */
2042 @Override
2043 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002044 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002045 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2046 new Pair<String, String>(alphaTag, number), new Integer(subId));
2047 return success;
2048 }
2049
Ta-wei Yen87c49842016-05-13 21:19:52 -07002050 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002051 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2052 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2053 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2054 if (!TextUtils.equals(callingPackage, systemDialer)) {
2055 throw new SecurityException("caller must be system dialer");
2056 }
2057 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2058 if (phoneAccountHandle == null){
2059 return null;
2060 }
2061 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2062 }
2063
2064 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002065 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002066 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002068 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002069 return null;
2070 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002071 final long identity = Binder.clearCallingIdentity();
2072 try {
2073 return RemoteVvmTaskManager
2074 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2075 } finally {
2076 Binder.restoreCallingIdentity(identity);
2077 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002078 }
2079
2080 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002081 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2082 VisualVoicemailSmsFilterSettings settings) {
2083 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002084 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002085 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2086 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002087 }
2088
2089 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002090 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2091 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002092 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002093 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002094 }
2095
2096 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002097 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2098 String callingPackage, int subId) {
2099 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002100 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002101 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002102 }
2103
2104 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002105 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002106 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002107 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002108 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2109 }
2110
2111 @Override
2112 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2113 String number, int port, String text, PendingIntent sentIntent) {
2114 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002115 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002116 enforceSendSmsPermission();
2117 // Make the calls as the phone process.
2118 final long identity = Binder.clearCallingIdentity();
2119 try {
2120 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2121 if (port == 0) {
2122 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2123 sentIntent, null, false);
2124 } else {
2125 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2126 smsManager.sendDataMessageWithSelfPermissions(number, null,
2127 (short) port, data, sentIntent, null);
2128 }
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
2131 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002132 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002133 /**
fionaxu0152e512016-11-14 13:36:14 -08002134 * Sets the voice activation state of a given subId.
2135 */
2136 @Override
2137 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2139 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002140 final Phone phone = getPhone(subId);
2141 if (phone != null) {
2142 phone.setVoiceActivationState(activationState);
2143 } else {
2144 loge("setVoiceActivationState fails with invalid subId: " + subId);
2145 }
2146 }
2147
2148 /**
2149 * Sets the data activation state of a given subId.
2150 */
2151 @Override
2152 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2154 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002155 final Phone phone = getPhone(subId);
2156 if (phone != null) {
2157 phone.setDataActivationState(activationState);
2158 } else {
2159 loge("setVoiceActivationState fails with invalid subId: " + subId);
2160 }
2161 }
2162
2163 /**
2164 * Returns the voice activation state of a given subId.
2165 */
2166 @Override
2167 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002168 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002169 final Phone phone = getPhone(subId);
2170 if (phone != null) {
2171 return phone.getVoiceActivationState();
2172 } else {
2173 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2174 }
2175 }
2176
2177 /**
2178 * Returns the data activation state of a given subId.
2179 */
2180 @Override
2181 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002182 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002183 final Phone phone = getPhone(subId);
2184 if (phone != null) {
2185 return phone.getDataActivationState();
2186 } else {
2187 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2188 }
2189 }
2190
2191 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 * Returns the unread count of voicemails
2193 */
2194 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002195 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002196 }
2197
2198 /**
2199 * Returns the unread count of voicemails for a subId
2200 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002201 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002202 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002203 final Phone phone = getPhone(subId);
2204 if (phone != null) {
2205 return phone.getVoiceMessageCount();
2206 } else {
2207 return 0;
2208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 }
2210
2211 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002212 * returns true, if the device is in a state where both voice and data
2213 * are supported simultaneously. This can change based on location or network condition.
2214 */
2215 @Override
2216 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2217 final Phone phone = getPhone(subId);
2218 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2219 }
2220
2221 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002222 * Send the dialer code if called from the current default dialer or the caller has
2223 * carrier privilege.
2224 * @param inputCode The dialer code to send
2225 */
2226 @Override
2227 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2228 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2229 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2230 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002231 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2232 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002233 }
2234 mPhone.sendDialerSpecialCode(inputCode);
2235 }
2236
2237 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002238 * Returns the data network type.
2239 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 *
2241 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2242 */
2243 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002244 public int getNetworkType() {
2245 final Phone phone = getPhone(getDefaultSubscription());
2246 if (phone != null) {
2247 return phone.getServiceState().getDataNetworkType();
2248 } else {
2249 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2250 }
Wink Saville36469e72014-06-11 15:17:00 -07002251 }
2252
2253 /**
2254 * Returns the network type for a subId
2255 */
2256 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002257 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002259 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002260 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2261 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002262
Sanket Padawe356d7632015-06-22 14:03:32 -07002263 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002264 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 return phone.getServiceState().getDataNetworkType();
2266 } else {
2267 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2268 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 }
2270
2271 /**
2272 * Returns the data network type
2273 */
2274 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002275 public int getDataNetworkType(String callingPackage) {
2276 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002277 }
2278
2279 /**
2280 * Returns the data network type for a subId
2281 */
2282 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002283 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002285 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002286 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2287 }
2288
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 final Phone phone = getPhone(subId);
2290 if (phone != null) {
2291 return phone.getServiceState().getDataNetworkType();
2292 } else {
2293 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
2297 /**
Wink Saville36469e72014-06-11 15:17:00 -07002298 * Returns the Voice network type for a subId
2299 */
2300 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002301 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002303 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002304 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2305 }
2306
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 final Phone phone = getPhone(subId);
2308 if (phone != null) {
2309 return phone.getServiceState().getVoiceNetworkType();
2310 } else {
2311 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
2315 /**
2316 * @return true if a ICC card is present
2317 */
2318 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002319 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002320 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2321 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002322 }
2323
2324 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002325 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002326 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002327 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002328 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2329 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002330 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002332 } else {
2333 return false;
2334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 }
2336
2337 /**
2338 * Return if the current radio is LTE on CDMA. This
2339 * is a tri-state return value as for a period of time
2340 * the mode may be unknown.
2341 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002342 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002344 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002346 @Override
2347 public int getLteOnCdmaMode(String callingPackage) {
2348 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002349 }
2350
Sanket Padawe356d7632015-06-22 14:03:32 -07002351 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002352 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002353 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002354 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002355 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2356 }
2357
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 final Phone phone = getPhone(subId);
2359 if (phone == null) {
2360 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2361 } else {
2362 return phone.getLteOnCdmaMode();
2363 }
Wink Saville36469e72014-06-11 15:17:00 -07002364 }
2365
2366 public void setPhone(Phone phone) {
2367 mPhone = phone;
2368 }
2369
2370 /**
2371 * {@hide}
2372 * Returns Default subId, 0 in the case of single standby.
2373 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002374 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002375 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002376 }
2377
Shishir Agrawala9f32182016-04-12 12:00:16 -07002378 private int getSlotForDefaultSubscription() {
2379 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2380 }
2381
Wink Savilleb564aae2014-10-23 10:18:09 -07002382 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002383 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002385
2386 /**
2387 * @see android.telephony.TelephonyManager.WifiCallingChoices
2388 */
2389 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002390 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2391 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002392 }
2393
2394 /**
2395 * @see android.telephony.TelephonyManager.WifiCallingChoices
2396 */
2397 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002398 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2399 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2400 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002401 }
2402
Sailesh Nepald1e68152013-12-12 19:08:02 -08002403 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002404 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002405 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002406 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002407
Shishir Agrawal566b7612013-10-28 14:41:00 -07002408 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002409 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2410 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2412 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002413
Derek Tan740e1672017-06-27 14:56:27 -07002414 if (TextUtils.equals(ISDR_AID, aid)) {
2415 // Only allows LPA to open logical channel to ISD-R.
2416 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2417 ComponentInfo bestComponent =
2418 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2419 if (bestComponent == null
2420 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2421 loge("The calling package is not allowed to access ISD-R.");
2422 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2423 }
2424 }
2425
2426 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002427 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002428 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002429 if (DBG) log("iccOpenLogicalChannel: " + response);
2430 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002431 }
2432
2433 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002434 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2436 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002437
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002438 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002439 if (channel < 0) {
2440 return false;
2441 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002442 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002443 if (DBG) log("iccCloseLogicalChannel: " + success);
2444 return success;
2445 }
2446
2447 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002448 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002449 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2451 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002452
2453 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002454 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2455 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002456 " data=" + data);
2457 }
2458
2459 if (channel < 0) {
2460 return "";
2461 }
2462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002463 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002464 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002465 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2466
Shishir Agrawal566b7612013-10-28 14:41:00 -07002467 // Append the returned status code to the end of the response payload.
2468 String s = Integer.toHexString(
2469 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002470 if (response.payload != null) {
2471 s = IccUtils.bytesToHexString(response.payload) + s;
2472 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002473 return s;
2474 }
Jake Hambye994d462014-02-03 13:10:13 -08002475
Evan Charltonc66da362014-05-16 14:06:40 -07002476 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002477 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2478 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2480 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002481
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002482 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2483 && TextUtils.equals(ISDR_AID, data)) {
2484 // Only allows LPA to select ISD-R.
2485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2486 ComponentInfo bestComponent =
2487 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2488 if (bestComponent == null
2489 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2490 loge("The calling package is not allowed to select ISD-R.");
2491 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2492 }
2493 }
2494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002495 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002496 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2497 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002498 }
2499
2500 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002501 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002502 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2503
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002504 // Append the returned status code to the end of the response payload.
2505 String s = Integer.toHexString(
2506 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002507 if (response.payload != null) {
2508 s = IccUtils.bytesToHexString(response.payload) + s;
2509 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002510 return s;
2511 }
2512
2513 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002514 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002515 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2517 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002518
2519 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002520 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002521 p1 + " " + p2 + " " + p3 + ":" + filePath);
2522 }
2523
2524 IccIoResult response =
2525 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002526 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2527 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002528
2529 if (DBG) {
2530 log("Exchange SIM_IO [R]" + response);
2531 }
2532
2533 byte[] result = null;
2534 int length = 2;
2535 if (response.payload != null) {
2536 length = 2 + response.payload.length;
2537 result = new byte[length];
2538 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2539 } else {
2540 result = new byte[length];
2541 }
2542
2543 result[length - 1] = (byte) response.sw2;
2544 result[length - 2] = (byte) response.sw1;
2545 return result;
2546 }
2547
Nathan Haroldb3014052017-01-25 15:57:32 -08002548 /**
2549 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2550 * on a particular subscription
2551 */
sqianb6e41952018-03-12 14:54:01 -07002552 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2553 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2554 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2555 return null;
2556 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002557 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2558 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2559 return null;
2560 }
2561 Object response = sendRequest(
2562 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2563 if (response instanceof String[]) {
2564 return (String[]) response;
2565 }
2566 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2567 return null;
2568 }
2569
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002570 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002571 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2573 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002574
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002575 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002576 if (response.payload == null) {
2577 return "";
2578 }
2579
2580 // Append the returned status code to the end of the response payload.
2581 String s = Integer.toHexString(
2582 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2583 s = IccUtils.bytesToHexString(response.payload) + s;
2584 return s;
2585 }
2586
Jake Hambye994d462014-02-03 13:10:13 -08002587 /**
2588 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2589 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2590 *
2591 * @param itemID the ID of the item to read
2592 * @return the NV item as a String, or null on error.
2593 */
2594 @Override
2595 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2597 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002598 if (DBG) log("nvReadItem: item " + itemID);
2599 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2600 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2601 return value;
2602 }
2603
2604 /**
2605 * Write 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 * @param itemValue the value to write, as a String
2610 * @return true on success; false on any failure
2611 */
2612 @Override
2613 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2615 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002616 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2617 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2618 new Pair<Integer, String>(itemID, itemValue));
2619 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2620 return success;
2621 }
2622
2623 /**
2624 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2625 * Used for device configuration by some CDMA operators.
2626 *
2627 * @param preferredRoamingList byte array containing the new PRL
2628 * @return true on success; false on any failure
2629 */
2630 @Override
2631 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2633 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002634 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2635 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2636 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2637 return success;
2638 }
2639
2640 /**
2641 * Perform the specified type of NV config reset.
2642 * Used for device configuration by some CDMA operators.
2643 *
2644 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2645 * @return true on success; false on any failure
2646 */
2647 @Override
2648 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2650 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002651 if (DBG) log("nvResetConfig: type " + resetType);
2652 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2653 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2654 return success;
2655 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002656
2657 /**
Wink Saville36469e72014-06-11 15:17:00 -07002658 * {@hide}
2659 * Returns Default sim, 0 in the case of single standby.
2660 */
2661 public int getDefaultSim() {
2662 //TODO Need to get it from Telephony Devcontroller
2663 return 0;
2664 }
2665
Svet Ganovb320e182015-04-16 12:30:10 -07002666 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002668 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002669 return new String[0];
2670 }
2671
2672
ram87fca6f2014-07-18 18:58:44 +05302673 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002674 }
2675
Brad Ebinger51f743a2017-01-23 13:50:20 -08002676 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002677 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2678 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002679 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002680 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002681 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002682 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002683 }
2684
2685 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002686 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2687 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002688 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002689 public void disableIms(int slotId) {
2690 enforceModifyPermission();
2691 PhoneFactory.getImsResolver().disableIms(slotId);
2692 }
2693
2694 /**
2695 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2696 * feature or {@link null} if the service is not available. If the feature is available, the
2697 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2698 */
2699 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002700 IImsServiceFeatureCallback callback) {
2701 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002702 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002703 }
2704
2705 /**
2706 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2707 * feature during emergency calling or {@link null} if the service is not available. If the
2708 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2709 * listener for feature updates.
2710 */
2711 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2712 enforceModifyPermission();
2713 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002714 }
2715
Brad Ebinger5f64b052017-12-14 14:26:15 -08002716 /**
2717 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2718 * specified.
2719 */
2720 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2721 enforceModifyPermission();
2722 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2723 }
2724
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002725 /**
2726 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2727 * specified.
2728 */
2729 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2730 enforceModifyPermission();
2731 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2732 }
2733
Brad Ebinger884c07b2018-02-15 16:17:40 -08002734 /**
Brad Ebinger304415d2018-03-02 13:43:36 -08002735 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2736 * available, false if the IMS resolver is idle.
2737 */
2738 public boolean isResolvingImsBinding() {
2739 enforceModifyPermission();
2740 return PhoneFactory.getImsResolver().isResolvingBinding();
2741 }
2742
Brad Ebingerdac2f002018-04-03 15:17:52 -07002743 /**
2744 * Sets the ImsService Package Name that Telephony will bind to.
2745 *
2746 * @param slotId the slot ID that the ImsService should bind for.
2747 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
2748 * ImsService is the device default ImsService.
2749 * @param packageName The package name of the application that contains the ImsService to bind
2750 * to.
2751 * @return true if setting the ImsService to bind to succeeded, false if it did not.
2752 * @hide
2753 */
2754 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002755 int[] subIds = SubscriptionManager.getSubId(slotId);
2756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2757 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2758 "setImsService");
2759
Brad Ebingerdac2f002018-04-03 15:17:52 -07002760 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
2761 isCarrierImsService, packageName);
2762 }
2763
2764 /**
2765 * Return the ImsService configuration.
2766 *
2767 * @param slotId The slot that the ImsService is associated with.
2768 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
2769 * the device default.
2770 * @return the package name of the ImsService configuration.
2771 */
2772 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002773 int[] subIds = SubscriptionManager.getSubId(slotId);
2774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2775 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2776 "getImsService");
2777
Brad Ebingerdac2f002018-04-03 15:17:52 -07002778 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
2779 isCarrierImsService);
2780 }
2781
Wink Saville36469e72014-06-11 15:17:00 -07002782 public void setImsRegistrationState(boolean registered) {
2783 enforceModifyPermission();
2784 mPhone.setImsRegistrationState(registered);
2785 }
2786
2787 /**
Stuart Scott54788802015-03-30 13:18:01 -07002788 * Set the network selection mode to automatic.
2789 *
2790 */
2791 @Override
2792 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2794 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002795 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2796 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2797 }
2798
2799 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002800 * Set the network selection mode to manual with the selected carrier.
2801 */
2802 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002803 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002804 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2806 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002807 OperatorInfo operator = new OperatorInfo(
2808 /* operatorAlphaLong */ "",
2809 /* operatorAlphaShort */ "",
2810 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002811 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002812 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2813 persistSelection);
2814 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002815 }
2816
2817 /**
2818 * Scans for available networks.
2819 */
2820 @Override
2821 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2823 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002824 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2825 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2826 CMD_PERFORM_NETWORK_SCAN, null, subId);
2827 return result;
2828 }
2829
2830 /**
yinxub1bed742017-04-17 11:45:04 -07002831 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002832 *
yinxub1bed742017-04-17 11:45:04 -07002833 * @param subId id of the subscription
2834 * @param request contains the radio access networks with bands/channels to scan
2835 * @param messenger callback messenger for scan results or errors
2836 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002837 * @return the id of the requested scan which can be used to stop the scan.
2838 */
2839 @Override
2840 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2841 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2843 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002844 return mNetworkScanRequestTracker.startNetworkScan(
2845 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002846 }
2847
2848 /**
2849 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002850 *
2851 * @param subId id of the subscription
2852 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002853 */
2854 @Override
2855 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2857 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002858 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002859 }
2860
2861 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002862 * Get the calculated preferred network type.
2863 * Used for debugging incorrect network type.
2864 *
2865 * @return the preferred network type, defined in RILConstants.java.
2866 */
2867 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002868 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002870 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002871 return RILConstants.PREFERRED_NETWORK_MODE;
2872 }
2873
Amit Mahajan43330e02014-11-18 11:54:45 -08002874 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002875 }
2876
2877 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002878 * Get the preferred network type.
2879 * Used for device configuration by some CDMA operators.
2880 *
2881 * @return the preferred network type, defined in RILConstants.java.
2882 */
2883 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002884 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2886 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002887 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002888 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002889 int networkType = (result != null ? result[0] : -1);
2890 if (DBG) log("getPreferredNetworkType: " + networkType);
2891 return networkType;
2892 }
2893
2894 /**
2895 * Set the preferred network type.
2896 * Used for device configuration by some CDMA operators.
2897 *
2898 * @param networkType the preferred network type, defined in RILConstants.java.
2899 * @return true on success; false on any failure.
2900 */
2901 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002902 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2904 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002905 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2906 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002907 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002908 if (success) {
2909 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002910 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002911 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002912 return success;
2913 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002914
2915 /**
Junda Liu475951f2014-11-07 16:45:03 -08002916 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2917 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2918 * tethering.
2919 *
2920 * @return 0: Not required. 1: required. 2: Not set.
2921 * @hide
2922 */
2923 @Override
2924 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002925 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002926 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2927 Settings.Global.TETHER_DUN_REQUIRED, 2);
2928 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2929 // config_tether_apndata.
2930 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2931 dunRequired = 1;
2932 }
2933 return dunRequired;
2934 }
2935
2936 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002937 * Set mobile data enabled
2938 * Used by the user through settings etc to turn on/off mobile data
2939 *
2940 * @param enable {@code true} turn turn data on, else {@code false}
2941 */
2942 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002943 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2945 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002946 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002947 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002948 Phone phone = PhoneFactory.getPhone(phoneId);
2949 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002950 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2951 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002952 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002953 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002954 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002955 }
2956
2957 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002958 * Get the user enabled state of Mobile Data.
2959 *
2960 * TODO: remove and use isUserDataEnabled.
2961 * This can't be removed now because some vendor codes
2962 * calls through ITelephony directly while they should
2963 * use TelephonyManager.
2964 *
2965 * @return true on enabled
2966 */
2967 @Override
2968 public boolean getDataEnabled(int subId) {
2969 return isUserDataEnabled(subId);
2970 }
2971
2972 /**
2973 * Get whether mobile data is enabled per user setting.
2974 *
2975 * There are other factors deciding whether mobile data is actually enabled, but they are
2976 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002977 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002978 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002979 *
2980 * @return {@code true} if data is enabled else {@code false}
2981 */
2982 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002983 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002984 try {
2985 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2986 null);
2987 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2989 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002990 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002991 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002992 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002993 Phone phone = PhoneFactory.getPhone(phoneId);
2994 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002995 boolean retVal = phone.isUserDataEnabled();
2996 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002997 return retVal;
2998 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002999 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3000 return false;
3001 }
3002 }
3003
3004 /**
3005 * Get whether mobile data is enabled.
3006 *
3007 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3008 * whether mobile data is actually enabled.
3009 *
3010 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3011 *
3012 * @return {@code true} if data is enabled else {@code false}
3013 */
3014 @Override
3015 public boolean isDataEnabled(int subId) {
3016 try {
3017 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3018 null);
3019 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3021 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003022 }
3023 int phoneId = mSubscriptionController.getPhoneId(subId);
3024 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3025 Phone phone = PhoneFactory.getPhone(phoneId);
3026 if (phone != null) {
3027 boolean retVal = phone.isDataEnabled();
3028 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3029 return retVal;
3030 } else {
3031 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08003032 return false;
3033 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003034 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003035
3036 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003037 public int getCarrierPrivilegeStatus(int subId) {
3038 final Phone phone = getPhone(subId);
3039 if (phone == null) {
3040 loge("getCarrierPrivilegeStatus: Invalid subId");
3041 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3042 }
3043 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003044 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003045 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003046 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3047 }
3048 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003049 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003050 }
Junda Liu29340342014-07-10 15:23:27 -07003051
3052 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003053 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3054 final Phone phone = getPhone(subId);
3055 if (phone == null) {
3056 loge("getCarrierPrivilegeStatus: Invalid subId");
3057 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3058 }
3059 UiccProfile profile =
3060 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3061 if (profile == null) {
3062 loge("getCarrierPrivilegeStatus: No UICC");
3063 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3064 }
3065 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3066 }
3067
3068 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003069 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003070 if (TextUtils.isEmpty(pkgName))
3071 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003072 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003073 if (card == null) {
3074 loge("checkCarrierPrivilegesForPackage: No UICC");
3075 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3076 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003077 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3078 }
3079
3080 @Override
3081 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003082 if (TextUtils.isEmpty(pkgName))
3083 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003084 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3085 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3086 UiccCard card = UiccController.getInstance().getUiccCard(i);
3087 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003088 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003089 continue;
3090 }
3091
3092 result = card.getCarrierPrivilegeStatus(
3093 mPhone.getContext().getPackageManager(), pkgName);
3094 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3095 break;
3096 }
3097 }
3098
3099 return result;
Junda Liu29340342014-07-10 15:23:27 -07003100 }
Derek Tan89e89d42014-07-08 17:00:10 -07003101
3102 @Override
Junda Liue64de782015-04-16 17:19:16 -07003103 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3104 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3105 loge("phoneId " + phoneId + " is not valid.");
3106 return null;
3107 }
3108 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003109 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003110 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003111 return null ;
3112 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003113 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003114 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003115 }
3116
Amith Yamasani6e118872016-02-19 12:53:51 -08003117 @Override
3118 public List<String> getPackagesWithCarrierPrivileges() {
3119 PackageManager pm = mPhone.getContext().getPackageManager();
3120 List<String> privilegedPackages = new ArrayList<>();
3121 List<PackageInfo> packages = null;
3122 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3123 UiccCard card = UiccController.getInstance().getUiccCard(i);
3124 if (card == null) {
3125 // No UICC in that slot.
3126 continue;
3127 }
3128 if (card.hasCarrierPrivilegeRules()) {
3129 if (packages == null) {
3130 // Only check packages in user 0 for now
3131 packages = pm.getInstalledPackagesAsUser(
3132 PackageManager.MATCH_DISABLED_COMPONENTS
3133 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3134 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3135 }
3136 for (int p = packages.size() - 1; p >= 0; p--) {
3137 PackageInfo pkgInfo = packages.get(p);
3138 if (pkgInfo != null && pkgInfo.packageName != null
3139 && card.getCarrierPrivilegeStatus(pkgInfo)
3140 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3141 privilegedPackages.add(pkgInfo.packageName);
3142 }
3143 }
3144 }
3145 }
3146 return privilegedPackages;
3147 }
3148
Wink Savilleb564aae2014-10-23 10:18:09 -07003149 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003150 final Phone phone = getPhone(subId);
3151 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003152 if (card == null) {
3153 loge("getIccId: No UICC");
3154 return null;
3155 }
3156 String iccId = card.getIccId();
3157 if (TextUtils.isEmpty(iccId)) {
3158 loge("getIccId: ICC ID is null or empty.");
3159 return null;
3160 }
3161 return iccId;
3162 }
3163
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003164 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003165 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3166 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003167 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3168 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003169
Jeff Sharkey85190e62014-12-05 09:40:12 -08003170 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003171 final Phone phone = getPhone(subId);
3172 if (phone == null) {
3173 return false;
3174 }
3175 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003176
3177 if (DBG_MERGE) {
3178 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3179 + subscriberId + " to " + number);
3180 }
3181
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003182 if (TextUtils.isEmpty(iccId)) {
3183 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003184 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003185
Jeff Sharkey85190e62014-12-05 09:40:12 -08003186 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3187
3188 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003189 if (alphaTag == null) {
3190 editor.remove(alphaTagPrefKey);
3191 } else {
3192 editor.putString(alphaTagPrefKey, alphaTag);
3193 }
3194
Jeff Sharkey85190e62014-12-05 09:40:12 -08003195 // Record both the line number and IMSI for this ICCID, since we need to
3196 // track all merged IMSIs based on line number
3197 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3198 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003199 if (number == null) {
3200 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003201 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003202 } else {
3203 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003204 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003205 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003206
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003207 editor.commit();
3208 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003209 }
3210
3211 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003212 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003213 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003215 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003216 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003217 return null;
3218 }
Derek Tan97ebb422014-09-05 16:55:38 -07003219
3220 String iccId = getIccId(subId);
3221 if (iccId != null) {
3222 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003223 if (DBG_MERGE) {
3224 log("getLine1NumberForDisplay returning " +
3225 mTelephonySharedPreferences.getString(numberPrefKey, null));
3226 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003227 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003228 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003229 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003230 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003231 }
3232
3233 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003234 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003236 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003237 return null;
3238 }
Derek Tan97ebb422014-09-05 16:55:38 -07003239
3240 String iccId = getIccId(subId);
3241 if (iccId != null) {
3242 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003243 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003244 }
Derek Tan97ebb422014-09-05 16:55:38 -07003245 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003246 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003247
3248 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003249 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003250 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3251 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003252 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003253 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3254 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003255 return null;
3256 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003257 final Context context = mPhone.getContext();
3258 final TelephonyManager tele = TelephonyManager.from(context);
3259 final SubscriptionManager sub = SubscriptionManager.from(context);
3260
3261 // Figure out what subscribers are currently active
3262 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003263 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3264 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3265 final long identity = Binder.clearCallingIdentity();
3266 try {
3267 final int[] subIds = sub.getActiveSubscriptionIdList();
3268 for (int subId : subIds) {
3269 activeSubscriberIds.add(tele.getSubscriberId(subId));
3270 }
3271 } finally {
3272 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003273 }
3274
3275 // First pass, find a number override for an active subscriber
3276 String mergeNumber = null;
3277 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3278 for (String key : prefs.keySet()) {
3279 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3280 final String subscriberId = (String) prefs.get(key);
3281 if (activeSubscriberIds.contains(subscriberId)) {
3282 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3283 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3284 mergeNumber = (String) prefs.get(numberKey);
3285 if (DBG_MERGE) {
3286 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3287 + " for active subscriber " + subscriberId);
3288 }
3289 if (!TextUtils.isEmpty(mergeNumber)) {
3290 break;
3291 }
3292 }
3293 }
3294 }
3295
3296 // Shortcut when no active merged subscribers
3297 if (TextUtils.isEmpty(mergeNumber)) {
3298 return null;
3299 }
3300
3301 // Second pass, find all subscribers under that line override
3302 final ArraySet<String> result = new ArraySet<>();
3303 for (String key : prefs.keySet()) {
3304 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3305 final String number = (String) prefs.get(key);
3306 if (mergeNumber.equals(number)) {
3307 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3308 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3309 final String subscriberId = (String) prefs.get(subscriberKey);
3310 if (!TextUtils.isEmpty(subscriberId)) {
3311 result.add(subscriberId);
3312 }
3313 }
3314 }
3315 }
3316
3317 final String[] resultArray = result.toArray(new String[result.size()]);
3318 Arrays.sort(resultArray);
3319 if (DBG_MERGE) {
3320 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3321 }
3322 return resultArray;
3323 }
3324
3325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003326 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003327 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3328 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003329 final Phone phone = getPhone(subId);
3330 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003331 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003332
3333 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003334 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003335 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3336 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003337 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003338 final Phone phone = getPhone(subId);
3339 if (phone == null) {
3340 return false;
3341 }
3342 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003343 cdmaNonRoamingList);
3344 }
3345
3346 @Override
Shuo Qiane12f8752018-04-17 18:39:35 +00003347 @Deprecated
3348 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3349 enforceModifyPermission();
3350
3351 int returnValue = 0;
3352 try {
3353 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3354 if(result.exception == null) {
3355 if (result.result != null) {
3356 byte[] responseData = (byte[])(result.result);
3357 if(responseData.length > oemResp.length) {
3358 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3359 responseData.length + "bytes. Buffer Size is " +
3360 oemResp.length + "bytes.");
3361 }
3362 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3363 returnValue = responseData.length;
3364 }
3365 } else {
3366 CommandException ex = (CommandException) result.exception;
3367 returnValue = ex.getCommandError().ordinal();
3368 if(returnValue > 0) returnValue *= -1;
3369 }
3370 } catch (RuntimeException e) {
3371 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3372 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3373 if(returnValue > 0) returnValue *= -1;
3374 }
3375
3376 return returnValue;
3377 }
3378
3379 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003380 public void setRadioCapability(RadioAccessFamily[] rafs) {
3381 try {
3382 ProxyController.getInstance().setRadioCapability(rafs);
3383 } catch (RuntimeException e) {
3384 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3385 }
3386 }
3387
3388 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003389 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003390 Phone phone = PhoneFactory.getPhone(phoneId);
3391 if (phone == null) {
3392 return RadioAccessFamily.RAF_UNKNOWN;
3393 }
3394 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003396 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003397 return RadioAccessFamily.RAF_UNKNOWN;
3398 }
3399
Wink Saville5d475dd2014-10-17 15:00:58 -07003400 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3401 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003402
3403 @Override
3404 public void enableVideoCalling(boolean enable) {
3405 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003406 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003407 }
3408
3409 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003410 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3412 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3413 return false;
3414 }
Svet Ganovb320e182015-04-16 12:30:10 -07003415
Andrew Lee77527ac2014-10-21 16:57:39 -07003416 // Check the user preference and the system-level IMS setting. Even if the user has
3417 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3418 // In the long run, we may instead need to check if there exists a connection service
3419 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003420 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3421 return imsManager.isVtEnabledByPlatform()
3422 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3423 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003424 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003425
Andrew Leea1239f22015-03-02 17:44:07 -08003426 @Override
3427 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003428 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003429 }
3430
3431 @Override
3432 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003433 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003434 }
3435
Andrew Lee9431b832015-03-09 18:46:45 -07003436 @Override
3437 public boolean isTtyModeSupported() {
3438 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3439 TelephonyManager telephonyManager =
3440 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003441 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003442 }
3443
3444 @Override
3445 public boolean isHearingAidCompatibilitySupported() {
3446 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3447 }
3448
Hall Liu98187582018-01-22 19:15:32 -08003449 public boolean isRttSupported() {
3450 boolean isCarrierSupported =
3451 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3452 boolean isDeviceSupported =
3453 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3454 return isCarrierSupported && isDeviceSupported;
3455 }
3456
Hall Liu3ad5f012018-04-06 16:23:39 -07003457 public boolean isRttEnabled() {
3458 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3459 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3460 }
3461
Sanket Padawe7310cc72015-01-14 09:53:20 -08003462 /**
3463 * Returns the unique device ID of phone, for example, the IMEI for
3464 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3465 *
3466 * <p>Requires Permission:
3467 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3468 */
3469 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003470 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003471 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003472 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003473 return null;
3474 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003475 int subId = phone.getSubId();
3476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3477 mApp, subId, callingPackage, "getDeviceId")) {
3478 return null;
3479 }
3480 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003481 }
3482
Ping Sunc67b7c22016-03-02 19:16:45 +08003483 /**
3484 * {@hide}
3485 * Returns the IMS Registration Status on a particular subid
3486 *
3487 * @param subId
3488 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003489 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003490 Phone phone = getPhone(subId);
3491 if (phone != null) {
3492 return phone.isImsRegistered();
3493 } else {
3494 return false;
3495 }
3496 }
3497
Santos Cordon7a1885b2015-02-03 11:15:19 -08003498 @Override
3499 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3500 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3501 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003502
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003503 /**
3504 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003505 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003506 public boolean isWifiCallingAvailable(int subId) {
3507 Phone phone = getPhone(subId);
3508 if (phone != null) {
3509 return phone.isWifiCallingEnabled();
3510 } else {
3511 return false;
3512 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003513 }
3514
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003515 /**
3516 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003517 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003518 public boolean isVolteAvailable(int subId) {
3519 Phone phone = getPhone(subId);
3520 if (phone != null) {
3521 return phone.isVolteEnabled();
3522 } else {
3523 return false;
3524 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003525 }
Svet Ganovb320e182015-04-16 12:30:10 -07003526
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003527 /**
3528 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003529 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003530 public boolean isVideoTelephonyAvailable(int subId) {
3531 Phone phone = getPhone(subId);
3532 if (phone != null) {
3533 return phone.isVideoEnabled();
3534 } else {
3535 return false;
3536 }
3537 }
3538
3539 /**
3540 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3541 * defined in {@link ImsRegistrationImplBase}.
3542 */
3543 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3544 Phone phone = getPhone(subId);
3545 if (phone != null) {
3546 return phone.getImsRegistrationTech();
3547 } else {
3548 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3549 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003550 }
3551
Stuart Scott8eef64f2015-04-08 15:13:54 -07003552 @Override
3553 public void factoryReset(int subId) {
3554 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003555 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3556 return;
3557 }
3558
Svet Ganovcc087f82015-05-12 20:35:54 -07003559 final long identity = Binder.clearCallingIdentity();
3560 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003561 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3562 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003563 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003564 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003565 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3566 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003567 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003568 }
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003571 }
3572 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003573
3574 @Override
3575 public String getLocaleFromDefaultSim() {
3576 // We query all subscriptions instead of just the active ones, because
3577 // this might be called early on in the provisioning flow when the
3578 // subscriptions potentially aren't active yet.
3579 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3580 if (slist == null || slist.isEmpty()) {
3581 return null;
3582 }
3583
3584 // This function may be called very early, say, from the setup wizard, at
3585 // which point we won't have a default subscription set. If that's the case
3586 // we just choose the first, which will be valid in "most cases".
3587 final int defaultSubId = getDefaultSubscription();
3588 SubscriptionInfo info = null;
3589 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3590 info = slist.get(0);
3591 } else {
3592 for (SubscriptionInfo item : slist) {
3593 if (item.getSubscriptionId() == defaultSubId) {
3594 info = item;
3595 break;
3596 }
3597 }
3598
3599 if (info == null) {
3600 return null;
3601 }
3602 }
3603
3604 // Try and fetch the locale from the carrier properties or from the SIM language
3605 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003606 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003607 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003608 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003609 if (defaultPhone != null) {
3610 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3611 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003612 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003613 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3614 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003615 } else {
3616 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003617 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003618 }
3619 }
3620
Narayan Kamath011676f2015-07-29 12:04:08 +01003621 // The SIM language preferences only store a language (e.g. fr = French), not an
3622 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3623 // the SIM and carrier preferences does not include a country we add the country
3624 // determined from the SIM MCC to provide an exact locale.
3625 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003626 if (mccLocale != null) {
3627 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3628 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003629 }
3630
Tony Hill183b2de2015-06-24 14:53:58 +01003631 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003632 return null;
3633 }
3634
3635 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 return mSubscriptionController.getAllSubInfoList(
3639 mPhone.getContext().getOpPackageName());
3640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
3643 }
3644
3645 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 return mSubscriptionController.getActiveSubscriptionInfoList(
3649 mPhone.getContext().getOpPackageName());
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
3653 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003654
Chenjie Yu1ba97252018-01-11 18:16:20 -08003655 private final ModemActivityInfo mLastModemActivityInfo =
3656 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3657
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003658 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003659 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3660 * representing the state of the modem.
3661 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003662 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3663 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003664 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003665 */
3666 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003667 public void requestModemActivityInfo(ResultReceiver result) {
3668 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003669 ModemActivityInfo ret = null;
3670 synchronized (mLastModemActivityInfo) {
3671 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3672 null);
3673 if (info != null) {
3674 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3675 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3676 mergedTxTimeMs[i] =
3677 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3678 }
3679 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3680 mLastModemActivityInfo.setSleepTimeMillis(
3681 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3682 mLastModemActivityInfo.setIdleTimeMillis(
3683 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3684 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3685 mLastModemActivityInfo.setRxTimeMillis(
3686 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3687 mLastModemActivityInfo.setEnergyUsed(
3688 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3689 }
3690 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3691 mLastModemActivityInfo.getSleepTimeMillis(),
3692 mLastModemActivityInfo.getIdleTimeMillis(),
3693 mLastModemActivityInfo.getTxTimeMillis(),
3694 mLastModemActivityInfo.getRxTimeMillis(),
3695 mLastModemActivityInfo.getEnergyUsed());
3696 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003697 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003698 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003699 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003700 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003701
3702 /**
3703 * {@hide}
3704 * Returns the service state information on specified subscription.
3705 */
3706 @Override
3707 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3708
Jeff Davidson7e17e312018-02-13 18:17:36 -08003709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003710 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003711 return null;
3712 }
3713
3714 final Phone phone = getPhone(subId);
3715 if (phone == null) {
3716 return null;
3717 }
3718
3719 return phone.getServiceState();
3720 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003721
3722 /**
3723 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3724 *
3725 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3726 * voicemail ringtone.
3727 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3728 * PhoneAccount.
3729 */
3730 @Override
3731 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003732 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003733 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003734 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003735 }
3736
fionaxu7ed723d2017-05-30 18:58:54 -07003737 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003738 }
3739
3740 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003741 * Sets the per-account voicemail ringtone.
3742 *
3743 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3744 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3745 *
3746 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3747 * voicemail ringtone.
3748 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3749 * PhoneAccount.
3750 */
3751 @Override
3752 public void setVoicemailRingtoneUri(String callingPackage,
3753 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3755 if (!TextUtils.equals(callingPackage,
3756 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3758 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3759 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003760 }
3761 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3762 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003763 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003764 }
fionaxu7ed723d2017-05-30 18:58:54 -07003765 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003766 }
3767
3768 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003769 * Returns whether vibration is set for voicemail notification in Phone settings.
3770 *
3771 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3772 * voicemail vibration setting.
3773 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3774 */
3775 @Override
3776 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003777 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003778 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003779 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003780 }
3781
fionaxu7ed723d2017-05-30 18:58:54 -07003782 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003783 }
3784
Youhan Wange64578a2016-05-02 15:32:42 -07003785 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003786 * Sets the per-account voicemail vibration.
3787 *
3788 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3789 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3790 *
3791 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3792 * voicemail vibration setting.
3793 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3794 * specific PhoneAccount.
3795 */
3796 @Override
3797 public void setVoicemailVibrationEnabled(String callingPackage,
3798 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3799 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3800 if (!TextUtils.equals(callingPackage,
3801 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3803 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3804 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003805 }
3806
3807 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3808 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003809 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003810 }
fionaxu7ed723d2017-05-30 18:58:54 -07003811 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003812 }
3813
3814 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003815 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3816 *
3817 * @throws SecurityException if the caller does not have the required permission
3818 */
3819 private void enforceReadPrivilegedPermission() {
3820 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3821 null);
3822 }
3823
3824 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003825 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3826 * permission.
3827 *
3828 * @throws SecurityException if the caller does not have the required permission
3829 */
3830 private void enforceSendSmsPermission() {
3831 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3832 }
3833
3834 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003835 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003836 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003837 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003838 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003839 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003840 ComponentName componentName =
3841 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3842 if(componentName == null) {
3843 throw new SecurityException("Caller not current active visual voicemail package[null]");
3844 }
3845 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003846 if (!callingPackage.equals(vvmPackage)) {
3847 throw new SecurityException("Caller not current active visual voicemail package[" +
3848 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003849 }
3850 }
3851
3852 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003853 * Return the application ID for the app type.
3854 *
3855 * @param subId the subscription ID that this request applies to.
3856 * @param appType the uicc app type.
3857 * @return Application ID for specificied app type, or null if no uicc.
3858 */
3859 @Override
3860 public String getAidForAppType(int subId, int appType) {
3861 enforceReadPrivilegedPermission();
3862 Phone phone = getPhone(subId);
3863 if (phone == null) {
3864 return null;
3865 }
3866 String aid = null;
3867 try {
3868 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3869 .getApplicationByType(appType).getAid();
3870 } catch (Exception e) {
3871 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3872 }
3873 return aid;
3874 }
3875
Youhan Wang4001d252016-05-11 10:29:41 -07003876 /**
3877 * Return the Electronic Serial Number.
3878 *
3879 * @param subId the subscription ID that this request applies to.
3880 * @return ESN or null if error.
3881 */
3882 @Override
3883 public String getEsn(int subId) {
3884 enforceReadPrivilegedPermission();
3885 Phone phone = getPhone(subId);
3886 if (phone == null) {
3887 return null;
3888 }
3889 String esn = null;
3890 try {
3891 esn = phone.getEsn();
3892 } catch (Exception e) {
3893 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3894 }
3895 return esn;
3896 }
3897
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003898 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003899 * Return the Preferred Roaming List Version.
3900 *
3901 * @param subId the subscription ID that this request applies to.
3902 * @return PRLVersion or null if error.
3903 */
3904 @Override
3905 public String getCdmaPrlVersion(int subId) {
3906 enforceReadPrivilegedPermission();
3907 Phone phone = getPhone(subId);
3908 if (phone == null) {
3909 return null;
3910 }
3911 String cdmaPrlVersion = null;
3912 try {
3913 cdmaPrlVersion = phone.getCdmaPrlVersion();
3914 } catch (Exception e) {
3915 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3916 }
3917 return cdmaPrlVersion;
3918 }
3919
3920 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003921 * Get snapshot of Telephony histograms
3922 * @return List of Telephony histograms
3923 * @hide
3924 */
3925 @Override
3926 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3928 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003929 return RIL.getTelephonyRILTimingHistograms();
3930 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003931
3932 /**
3933 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003934 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003935 * Require system privileges. In the future we may add this to carrier APIs.
3936 *
3937 * @return The number of carriers set successfully, should match length of carriers
3938 */
3939 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003940 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003941 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003942
Meng Wang9b7c4e92017-02-17 11:41:27 -08003943 if (carriers == null) {
3944 throw new NullPointerException("carriers cannot be null");
3945 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003946
3947 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003948 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3949 return retVal[0];
3950 }
3951
3952 /**
3953 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003954 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003955 * Require system privileges. In the future we may add this to carrier APIs.
3956 *
3957 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3958 * means all carriers are allowed.
3959 */
3960 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003961 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003962 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003963 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003964 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3965 }
3966
fionaxu59545b42016-05-25 15:53:37 -07003967 /**
3968 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3969 * @param subId the subscription ID that this action applies to.
3970 * @param enabled control enable or disable metered apns.
3971 * {@hide}
3972 */
3973 @Override
3974 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3975 enforceModifyPermission();
3976 final Phone phone = getPhone(subId);
3977 if (phone == null) {
3978 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3979 return;
3980 }
3981 try {
3982 phone.carrierActionSetMeteredApnsEnabled(enabled);
3983 } catch (Exception e) {
3984 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3985 }
3986 }
3987
3988 /**
3989 * Action set from carrier signalling broadcast receivers to enable/disable radio
3990 * @param subId the subscription ID that this action applies to.
3991 * @param enabled control enable or disable radio.
3992 * {@hide}
3993 */
3994 @Override
3995 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3996 enforceModifyPermission();
3997 final Phone phone = getPhone(subId);
3998 if (phone == null) {
3999 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4000 return;
4001 }
4002 try {
4003 phone.carrierActionSetRadioEnabled(enabled);
4004 } catch (Exception e) {
4005 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
4006 }
4007 }
4008
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004009 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004010 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4011 * network status based on which carrier apps could apply actions accordingly,
4012 * enable/disable default url handler for example.
4013 *
4014 * @param subId the subscription ID that this action applies to.
4015 * @param report control start/stop reporting the default network status.
4016 * {@hide}
4017 */
4018 @Override
4019 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4020 enforceModifyPermission();
4021 final Phone phone = getPhone(subId);
4022 if (phone == null) {
4023 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4024 return;
4025 }
4026 try {
4027 phone.carrierActionReportDefaultNetworkStatus(report);
4028 } catch (Exception e) {
4029 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
4030 }
4031 }
4032
4033 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004034 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4035 * bug report is being generated.
4036 */
4037 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004038 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004039 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4040 != PackageManager.PERMISSION_GRANTED) {
4041 writer.println("Permission Denial: can't dump Phone from pid="
4042 + Binder.getCallingPid()
4043 + ", uid=" + Binder.getCallingUid()
4044 + "without permission "
4045 + android.Manifest.permission.DUMP);
4046 return;
4047 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004048 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004049 }
Jack Yueb89b242016-06-22 13:27:47 -07004050
Brad Ebingerdac2f002018-04-03 15:17:52 -07004051 @Override
4052 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4053 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4054 throws RemoteException {
4055 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4056 }
4057
Jack Yueb89b242016-06-22 13:27:47 -07004058 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004059 * Get aggregated video call data usage since boot.
4060 *
4061 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4062 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004063 * {@hide}
4064 */
4065 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004066 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004067 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4068 null);
4069
Jack Yu84291ec2017-05-26 16:07:50 -07004070 // NetworkStatsService keeps tracking the active network interface and identity. It
4071 // records the delta with the corresponding network identity. We just return the total video
4072 // call data usage snapshot since boot.
4073 Phone phone = getPhone(subId);
4074 if (phone != null) {
4075 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004076 }
Jack Yu84291ec2017-05-26 16:07:50 -07004077 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004078 }
Jack Yu75ab2952016-07-08 14:29:33 -07004079
4080 /**
4081 * Policy control of data connection. Usually used when data limit is passed.
4082 * @param enabled True if enabling the data, otherwise disabling.
4083 * @param subId Subscription index
4084 * {@hide}
4085 */
4086 @Override
4087 public void setPolicyDataEnabled(boolean enabled, int subId) {
4088 enforceModifyPermission();
4089 Phone phone = getPhone(subId);
4090 if (phone != null) {
4091 phone.setPolicyDataEnabled(enabled);
4092 }
4093 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004094
4095 /**
4096 * Get Client request stats
4097 * @return List of Client Request Stats
4098 * @hide
4099 */
4100 @Override
4101 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004103 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004104 return null;
4105 }
4106
4107 Phone phone = getPhone(subId);
4108 if (phone != null) {
4109 return phone.getClientRequestStats();
4110 }
4111
4112 return null;
4113 }
4114
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004115 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004116 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004117 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004118 }
Jack Yueb4124c2017-02-16 15:32:43 -08004119
4120 /**
Grace Chen70990072017-03-24 17:21:30 -07004121 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004122 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004123 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004124 * @param state State of SIM (power down, power up, pass through)
4125 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4126 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4127 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004128 *
4129 **/
4130 @Override
Grace Chen70990072017-03-24 17:21:30 -07004131 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004132 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004133 Phone phone = PhoneFactory.getPhone(slotIndex);
4134
Jack Yueb4124c2017-02-16 15:32:43 -08004135 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004136 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004137 }
4138 }
Shuo Qiandd210312017-04-12 22:11:33 +00004139
Tyler Gunn65d45c22017-06-05 11:22:26 -07004140 private boolean isUssdApiAllowed(int subId) {
4141 CarrierConfigManager configManager =
4142 (CarrierConfigManager) mPhone.getContext().getSystemService(
4143 Context.CARRIER_CONFIG_SERVICE);
4144 if (configManager == null) {
4145 return false;
4146 }
4147 PersistableBundle pb = configManager.getConfigForSubId(subId);
4148 if (pb == null) {
4149 return false;
4150 }
4151 return pb.getBoolean(
4152 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4153 }
4154
Shuo Qiandd210312017-04-12 22:11:33 +00004155 /**
4156 * Check if phone is in emergency callback mode
4157 * @return true if phone is in emergency callback mode
4158 * @param subId sub id
4159 */
goneil9c5f4872017-12-05 14:07:56 -08004160 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004161 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004162 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004163 final Phone phone = getPhone(subId);
4164 if (phone != null) {
4165 return phone.isInEcm();
4166 } else {
4167 return false;
4168 }
4169 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004170
4171 /**
4172 * Get the current signal strength information for the given subscription.
4173 * Because this information is not updated when the device is in a low power state
4174 * it should not be relied-upon to be current.
4175 * @param subId Subscription index
4176 * @return the most recent cached signal strength info from the modem
4177 */
4178 @Override
4179 public SignalStrength getSignalStrength(int subId) {
4180 Phone p = getPhone(subId);
4181 if (p == null) {
4182 return null;
4183 }
4184
4185 return p.getSignalStrength();
4186 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004187
4188 @Override
4189 public UiccSlotInfo[] getUiccSlotsInfo() {
4190 enforceReadPrivilegedPermission();
4191
4192 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004193 if (slots == null) {
4194 Rlog.i(LOG_TAG, "slots is null.");
4195 return null;
4196 }
4197
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004198 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4199 for (int i = 0; i < slots.length; i++) {
4200 UiccSlot slot = slots[i];
4201
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004202 String cardId;
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004203 UiccCard card = slot.getUiccCard();
4204 if (card != null) {
4205 cardId = card.getCardId();
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004206 } else {
4207 cardId = slot.getIccId();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004208 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004209
4210 int cardState = 0;
4211 switch (slot.getCardState()) {
4212 case CARDSTATE_ABSENT:
4213 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4214 break;
4215 case CARDSTATE_PRESENT:
4216 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4217 break;
4218 case CARDSTATE_ERROR:
4219 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4220 break;
4221 case CARDSTATE_RESTRICTED:
4222 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4223 break;
4224 default:
4225 break;
4226
4227 }
4228
Qingxi Li795c5882018-01-31 13:43:27 -08004229 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004230 slot.isActive(),
4231 slot.isEuicc(),
4232 cardId,
4233 cardState,
4234 slot.getPhoneId(),
4235 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004236 }
4237 return infos;
4238 }
4239
4240 @Override
4241 public boolean switchSlots(int[] physicalSlots) {
4242 enforceModifyPermission();
4243 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4244 }
Jack Yu4c988042018-02-27 15:30:01 -08004245
4246 @Override
4247 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4248 enforceModifyPermission();
4249 final Phone phone = getPhone(subId);
4250 if (phone == null) {
4251 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4252 return;
4253 }
4254
4255 phone.setRadioIndicationUpdateMode(filters, mode);
4256 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004257
4258 /**
4259 * Returns false if the mobile data is disabled by default, otherwise return true.
4260 */
4261 private boolean getDefaultDataEnabled() {
4262 return "true".equalsIgnoreCase(
4263 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4264 }
4265
4266 /**
4267 * Returns true if the data roaming is enabled by default, i.e the system property
4268 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4269 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4270 */
4271 private boolean getDefaultDataRoamingEnabled(int subId) {
4272 final CarrierConfigManager configMgr = (CarrierConfigManager)
4273 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4274 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4275 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4276 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4277 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4278 return isDataRoamingEnabled;
4279 }
4280
4281 /**
4282 * Returns the default network type for the given {@code subId}, if the default network type is
4283 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4284 */
4285 private int getDefaultNetworkType(int subId) {
4286 return Integer.parseInt(
4287 TelephonyManager.getTelephonyProperty(
4288 mSubscriptionController.getPhoneId(subId),
4289 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4290 String.valueOf(Phone.PREFERRED_NT_MODE)));
4291 }
fionaxua13278b2018-03-21 00:08:13 -07004292
4293 @Override
4294 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4295 gid1, String gid2, String plmn, String spn) {
4296 enforceModifyPermission();
4297 final Phone phone = getPhone(subId);
4298 if (phone == null) {
4299 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4300 return;
4301 }
4302 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4303 }
4304
4305 @Override
4306 public int getCarrierIdListVersion(int subId) {
4307 enforceReadPrivilegedPermission();
4308 final Phone phone = getPhone(subId);
4309 if (phone == null) {
4310 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4311 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4312 }
4313 return phone.getCarrierIdListVersion();
4314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004315}