blob: ae3ec4eabf454c52805099969a5cdd24f2fbfc42 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070045import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070046import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070048import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070049import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070050import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080051import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070052import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080053import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080054import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070055import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070056import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070059import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080060import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070061import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080062import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070063import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070064import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070065import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080067import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070068import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080069import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080070import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070071import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000073import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070074import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070075import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080076import android.telephony.ims.aidl.IImsConfig;
77import android.telephony.ims.aidl.IImsMmTelFeature;
78import android.telephony.ims.aidl.IImsRcsFeature;
79import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080080import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080082import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080083import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080086import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080087
Andrew Lee312e8172014-10-23 17:01:36 -070088import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080089import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070091import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070092import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070093import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070094import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080097import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -070098import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +010099import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700100import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700101import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800103import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700105import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700106import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700107import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700108import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700109import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800110import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800111import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700112import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700113import com.android.internal.telephony.uicc.IccIoResult;
114import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800115import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700116import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800117import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800119import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000120import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700121import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800122import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700123import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800124import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700125import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700126import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800127
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700128import java.io.FileDescriptor;
129import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800133import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100134import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800135import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136
137/**
138 * Implementation of the ITelephony interface.
139 */
Santos Cordon117fee72014-05-16 17:56:12 -0700140public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141 private static final String LOG_TAG = "PhoneInterfaceManager";
142 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
143 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800144 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145
146 // Message codes used with mMainThreadHandler
147 private static final int CMD_HANDLE_PIN_MMI = 1;
148 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
149 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
150 private static final int CMD_ANSWER_RINGING_CALL = 4;
151 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700152 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
153 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154 private static final int CMD_OPEN_CHANNEL = 9;
155 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
156 private static final int CMD_CLOSE_CHANNEL = 11;
157 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800158 private static final int CMD_NV_READ_ITEM = 13;
159 private static final int EVENT_NV_READ_ITEM_DONE = 14;
160 private static final int CMD_NV_WRITE_ITEM = 15;
161 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
162 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
163 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
164 private static final int CMD_NV_RESET_CONFIG = 19;
165 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800166 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
167 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
168 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
169 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800170 private static final int CMD_SEND_ENVELOPE = 25;
171 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000172 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
173 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700174 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
175 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
176 private static final int CMD_EXCHANGE_SIM_IO = 31;
177 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800178 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
179 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700180 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
181 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700182 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
183 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700184 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
185 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
186 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
187 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700188 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
189 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
190 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
191 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700192 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800193 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
194 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000195 private static final int CMD_SWITCH_SLOTS = 50;
196 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800198 // Parameters of select command.
199 private static final int SELECT_COMMAND = 0xA4;
200 private static final int SELECT_P1 = 0x04;
201 private static final int SELECT_P2 = 0;
202 private static final int SELECT_P3 = 0x10;
203
Pengquan Meng85728fb2018-03-12 16:31:21 -0700204 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
205 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
206 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
207
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 /** The singleton instance. */
209 private static PhoneInterfaceManager sInstance;
210
Wink Saville3ab207e2014-11-20 13:07:20 -0800211 private PhoneGlobals mApp;
212 private Phone mPhone;
213 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700214 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800215 private AppOpsManager mAppOps;
216 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800217 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800218 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219
Derek Tan97ebb422014-09-05 16:55:38 -0700220 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
221 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700223
Derek Tan740e1672017-06-27 14:56:27 -0700224 // The AID of ISD-R.
225 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
226
yinxub1bed742017-04-17 11:45:04 -0700227 private NetworkScanRequestTracker mNetworkScanRequestTracker;
228
Derek Tan89e89d42014-07-08 17:00:10 -0700229 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700230 * A request object to use for transmitting data to an ICC.
231 */
232 private static final class IccAPDUArgument {
233 public int channel, cla, command, p1, p2, p3;
234 public String data;
235
236 public IccAPDUArgument(int channel, int cla, int command,
237 int p1, int p2, int p3, String data) {
238 this.channel = channel;
239 this.cla = cla;
240 this.command = command;
241 this.p1 = p1;
242 this.p2 = p2;
243 this.p3 = p3;
244 this.data = data;
245 }
246 }
247
248 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700249 * A request object to use for transmitting data to an ICC.
250 */
251 private static final class ManualNetworkSelectionArgument {
252 public OperatorInfo operatorInfo;
253 public boolean persistSelection;
254
255 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
256 this.operatorInfo = operatorInfo;
257 this.persistSelection = persistSelection;
258 }
259 }
260
261 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
263 * request after sending. The main thread will notify the request when it is complete.
264 */
265 private static final class MainThreadRequest {
266 /** The argument to use for the request */
267 public Object argument;
268 /** The result of the request that is run on the main thread */
269 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800270 // The subscriber id that this request applies to. Defaults to
271 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
272 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273
274 public MainThreadRequest(Object argument) {
275 this.argument = argument;
276 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800277
278 public MainThreadRequest(Object argument, Integer subId) {
279 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800280 if (subId != null) {
281 this.subId = subId;
282 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284 }
285
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800286 private static final class IncomingThirdPartyCallArgs {
287 public final ComponentName component;
288 public final String callId;
289 public final String callerDisplayName;
290
291 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
292 String callerDisplayName) {
293 this.component = component;
294 this.callId = callId;
295 this.callerDisplayName = callerDisplayName;
296 }
297 }
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /**
300 * A handler that processes messages on the main thread in the phone process. Since many
301 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
302 * inbound binder threads to the main thread in the phone process. The Binder thread
303 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
304 * on, which will be notified when the operation completes and will contain the result of the
305 * request.
306 *
307 * <p>If a MainThreadRequest object is provided in the msg.obj field,
308 * note that request.result must be set to something non-null for the calling thread to
309 * unblock.
310 */
311 private final class MainThreadHandler extends Handler {
312 @Override
313 public void handleMessage(Message msg) {
314 MainThreadRequest request;
315 Message onCompleted;
316 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800317 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700318 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319
320 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700321 case CMD_HANDLE_USSD_REQUEST: {
322 request = (MainThreadRequest) msg.obj;
323 final Phone phone = getPhoneFromRequest(request);
324 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
325 String ussdRequest = ussdObject.first;
326 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700327
328 if (!isUssdApiAllowed(request.subId)) {
329 // Carrier does not support use of this API, return failure.
330 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
331 UssdResponse response = new UssdResponse(ussdRequest, null);
332 Bundle returnData = new Bundle();
333 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
334 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
335
336 request.result = true;
337 synchronized (request) {
338 request.notifyAll();
339 }
340 return;
341 }
342
Tyler Gunn52dcf772017-04-26 11:30:31 -0700343 try {
344 request.result = phone != null ?
345 phone.handleUssdRequest(ussdRequest, wrappedCallback)
346 : false;
347 } catch (CallStateException cse) {
348 request.result = false;
349 }
pkanwar32d516d2016-10-14 19:37:38 -0700350 // Wake up the requesting thread
351 synchronized (request) {
352 request.notifyAll();
353 }
354 break;
355 }
356
Yorke Lee716f67e2015-06-17 15:39:16 -0700357 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700359 final Phone phone = getPhoneFromRequest(request);
360 request.result = phone != null ?
361 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
362 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 // Wake up the requesting thread
364 synchronized (request) {
365 request.notifyAll();
366 }
367 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
370 case CMD_HANDLE_NEIGHBORING_CELL:
371 request = (MainThreadRequest) msg.obj;
372 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
373 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700374 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 break;
376
377 case EVENT_NEIGHBORING_CELL_DONE:
378 ar = (AsyncResult) msg.obj;
379 request = (MainThreadRequest) ar.userObj;
380 if (ar.exception == null && ar.result != null) {
381 request.result = ar.result;
382 } else {
383 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800384 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 }
386 // Wake up the requesting thread
387 synchronized (request) {
388 request.notifyAll();
389 }
390 break;
391
392 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700393 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800394 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700395 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 break;
397
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 case CMD_END_CALL:
399 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800400 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700401 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700402 Phone phone = getPhone(end_subId);
403 if (phone == null) {
404 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
405 break;
406 }
407 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
409 // CDMA: If the user presses the Power button we treat it as
410 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700411 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
413 // GSM: End the call as per the Phone state
414 hungUp = PhoneUtils.hangup(mCM);
415 } else {
416 throw new IllegalStateException("Unexpected phone type: " + phoneType);
417 }
418 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
419 request.result = hungUp;
420 // Wake up the requesting thread
421 synchronized (request) {
422 request.notifyAll();
423 }
424 break;
425
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700427 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800429 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 if (uiccCard == null) {
431 loge("iccTransmitApduLogicalChannel: No UICC");
432 request.result = new IccIoResult(0x6F, 0, (byte[])null);
433 synchronized (request) {
434 request.notifyAll();
435 }
436 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
438 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 iccArgument.channel, iccArgument.cla, iccArgument.command,
441 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700443 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 break;
445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 ar = (AsyncResult) msg.obj;
448 request = (MainThreadRequest) ar.userObj;
449 if (ar.exception == null && ar.result != null) {
450 request.result = ar.result;
451 } else {
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
453 if (ar.result == null) {
454 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800455 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800457 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 } else {
459 loge("iccTransmitApduLogicalChannel: Unknown exception");
460 }
461 }
462 synchronized (request) {
463 request.notifyAll();
464 }
465 break;
466
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
468 request = (MainThreadRequest) msg.obj;
469 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800470 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 if (uiccCard == null) {
472 loge("iccTransmitApduBasicChannel: No UICC");
473 request.result = new IccIoResult(0x6F, 0, (byte[])null);
474 synchronized (request) {
475 request.notifyAll();
476 }
477 } else {
478 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
479 request);
480 uiccCard.iccTransmitApduBasicChannel(
481 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
482 iccArgument.p3, iccArgument.data, onCompleted);
483 }
484 break;
485
486 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
487 ar = (AsyncResult) msg.obj;
488 request = (MainThreadRequest) ar.userObj;
489 if (ar.exception == null && ar.result != null) {
490 request.result = ar.result;
491 } else {
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
493 if (ar.result == null) {
494 loge("iccTransmitApduBasicChannel: Empty response");
495 } else if (ar.exception instanceof CommandException) {
496 loge("iccTransmitApduBasicChannel: CommandException: " +
497 ar.exception);
498 } else {
499 loge("iccTransmitApduBasicChannel: Unknown exception");
500 }
501 }
502 synchronized (request) {
503 request.notifyAll();
504 }
505 break;
506
507 case CMD_EXCHANGE_SIM_IO:
508 request = (MainThreadRequest) msg.obj;
509 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800510 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700511 if (uiccCard == null) {
512 loge("iccExchangeSimIO: No UICC");
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 synchronized (request) {
515 request.notifyAll();
516 }
517 } else {
518 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
519 request);
520 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
521 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
522 iccArgument.data, onCompleted);
523 }
524 break;
525
526 case EVENT_EXCHANGE_SIM_IO_DONE:
527 ar = (AsyncResult) msg.obj;
528 request = (MainThreadRequest) ar.userObj;
529 if (ar.exception == null && ar.result != null) {
530 request.result = ar.result;
531 } else {
532 request.result = new IccIoResult(0x6f, 0, (byte[])null);
533 }
534 synchronized (request) {
535 request.notifyAll();
536 }
537 break;
538
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 case CMD_SEND_ENVELOPE:
540 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800541 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 if (uiccCard == null) {
543 loge("sendEnvelopeWithStatus: No UICC");
544 request.result = new IccIoResult(0x6F, 0, (byte[])null);
545 synchronized (request) {
546 request.notifyAll();
547 }
548 } else {
549 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
550 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
551 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800552 break;
553
554 case EVENT_SEND_ENVELOPE_DONE:
555 ar = (AsyncResult) msg.obj;
556 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700557 if (ar.exception == null && ar.result != null) {
558 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
561 if (ar.result == null) {
562 loge("sendEnvelopeWithStatus: Empty response");
563 } else if (ar.exception instanceof CommandException) {
564 loge("sendEnvelopeWithStatus: CommandException: " +
565 ar.exception);
566 } else {
567 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
568 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800569 }
570 synchronized (request) {
571 request.notifyAll();
572 }
573 break;
574
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 case CMD_OPEN_CHANNEL:
576 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800577 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800578 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800581 request.result = new IccOpenLogicalChannelResponse(-1,
582 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 synchronized (request) {
584 request.notifyAll();
585 }
586 } else {
587 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800588 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
589 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 break;
592
593 case EVENT_OPEN_CHANNEL_DONE:
594 ar = (AsyncResult) msg.obj;
595 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 int[] result = (int[]) ar.result;
599 int channelId = result[0];
600 byte[] selectResponse = null;
601 if (result.length > 1) {
602 selectResponse = new byte[result.length - 1];
603 for (int i = 1; i < result.length; ++i) {
604 selectResponse[i - 1] = (byte) result[i];
605 }
606 }
607 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 if (ar.result == null) {
611 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 if (ar.exception != null) {
614 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
615 }
616
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700618 if (ar.exception instanceof CommandException) {
619 CommandException.Error error =
620 ((CommandException) (ar.exception)).getCommandError();
621 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700623 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 }
626 }
627 openChannelResp = new IccOpenLogicalChannelResponse(
628 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700630 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 synchronized (request) {
632 request.notifyAll();
633 }
634 break;
635
636 case CMD_CLOSE_CHANNEL:
637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800638 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 if (uiccCard == null) {
640 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900641 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 synchronized (request) {
643 request.notifyAll();
644 }
645 } else {
646 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
647 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
648 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
651 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800652 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
653 break;
654
655 case CMD_NV_READ_ITEM:
656 request = (MainThreadRequest) msg.obj;
657 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
658 mPhone.nvReadItem((Integer) request.argument, onCompleted);
659 break;
660
661 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800667 request.result = "";
668 if (ar.result == null) {
669 loge("nvReadItem: Empty response");
670 } else if (ar.exception instanceof CommandException) {
671 loge("nvReadItem: CommandException: " +
672 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800674 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 }
676 }
677 synchronized (request) {
678 request.notifyAll();
679 }
680 break;
681
Jake Hambye994d462014-02-03 13:10:13 -0800682 case CMD_NV_WRITE_ITEM:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
685 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
686 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
687 break;
688
689 case EVENT_NV_WRITE_ITEM_DONE:
690 handleNullReturnEvent(msg, "nvWriteItem");
691 break;
692
693 case CMD_NV_WRITE_CDMA_PRL:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
696 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
697 break;
698
699 case EVENT_NV_WRITE_CDMA_PRL_DONE:
700 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
701 break;
702
703 case CMD_NV_RESET_CONFIG:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
706 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
707 break;
708
709 case EVENT_NV_RESET_CONFIG_DONE:
710 handleNullReturnEvent(msg, "nvResetConfig");
711 break;
712
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 case CMD_GET_PREFERRED_NETWORK_TYPE:
714 request = (MainThreadRequest) msg.obj;
715 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700716 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 break;
718
719 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
720 ar = (AsyncResult) msg.obj;
721 request = (MainThreadRequest) ar.userObj;
722 if (ar.exception == null && ar.result != null) {
723 request.result = ar.result; // Integer
724 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800725 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 if (ar.result == null) {
727 loge("getPreferredNetworkType: Empty response");
728 } else if (ar.exception instanceof CommandException) {
729 loge("getPreferredNetworkType: CommandException: " +
730 ar.exception);
731 } else {
732 loge("getPreferredNetworkType: Unknown exception");
733 }
734 }
735 synchronized (request) {
736 request.notifyAll();
737 }
738 break;
739
740 case CMD_SET_PREFERRED_NETWORK_TYPE:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
743 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700744 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800745 break;
746
747 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
748 handleNullReturnEvent(msg, "setPreferredNetworkType");
749 break;
750
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000751 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
752 request = (MainThreadRequest)msg.obj;
753 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
754 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
755 break;
756
757 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
758 ar = (AsyncResult)msg.obj;
759 request = (MainThreadRequest)ar.userObj;
760 request.result = ar;
761 synchronized (request) {
762 request.notifyAll();
763 }
764 break;
765
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800766 case CMD_SET_VOICEMAIL_NUMBER:
767 request = (MainThreadRequest) msg.obj;
768 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
769 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800770 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
771 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 break;
773
774 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
775 handleNullReturnEvent(msg, "setVoicemailNumber");
776 break;
777
Stuart Scott54788802015-03-30 13:18:01 -0700778 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
781 request);
782 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
783 break;
784
785 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
786 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
787 break;
788
Shishir Agrawal302c8692015-06-19 13:49:39 -0700789 case CMD_PERFORM_NETWORK_SCAN:
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
792 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
793 break;
794
795 case EVENT_PERFORM_NETWORK_SCAN_DONE:
796 ar = (AsyncResult) msg.obj;
797 request = (MainThreadRequest) ar.userObj;
798 CellNetworkScanResult cellScanResult;
799 if (ar.exception == null && ar.result != null) {
800 cellScanResult = new CellNetworkScanResult(
801 CellNetworkScanResult.STATUS_SUCCESS,
802 (List<OperatorInfo>) ar.result);
803 } else {
804 if (ar.result == null) {
805 loge("getCellNetworkScanResults: Empty response");
806 }
807 if (ar.exception != null) {
808 loge("getCellNetworkScanResults: Exception: " + ar.exception);
809 }
810 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
811 if (ar.exception instanceof CommandException) {
812 CommandException.Error error =
813 ((CommandException) (ar.exception)).getCommandError();
814 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
815 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
816 } else if (error == CommandException.Error.GENERIC_FAILURE) {
817 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
818 }
819 }
820 cellScanResult = new CellNetworkScanResult(errorCode, null);
821 }
822 request.result = cellScanResult;
823 synchronized (request) {
824 request.notifyAll();
825 }
826 break;
827
828 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
829 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700830 ManualNetworkSelectionArgument selArg =
831 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
833 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700834 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
835 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 break;
837
838 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
839 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
840 break;
841
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700842 case CMD_GET_MODEM_ACTIVITY_INFO:
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700845 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700846 break;
847
848 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
849 ar = (AsyncResult) msg.obj;
850 request = (MainThreadRequest) ar.userObj;
851 if (ar.exception == null && ar.result != null) {
852 request.result = ar.result;
853 } else {
854 if (ar.result == null) {
855 loge("queryModemActivityInfo: Empty response");
856 } else if (ar.exception instanceof CommandException) {
857 loge("queryModemActivityInfo: CommandException: " +
858 ar.exception);
859 } else {
860 loge("queryModemActivityInfo: Unknown exception");
861 }
862 }
Amit Mahajand4766222016-01-28 15:28:28 -0800863 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
864 if (request.result == null) {
865 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
866 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700867 synchronized (request) {
868 request.notifyAll();
869 }
870 break;
871
Meng Wang1a7c35a2016-05-05 20:56:15 -0700872 case CMD_SET_ALLOWED_CARRIERS:
873 request = (MainThreadRequest) msg.obj;
874 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
875 mPhone.setAllowedCarriers(
876 (List<CarrierIdentifier>) request.argument,
877 onCompleted);
878 break;
879
880 case EVENT_SET_ALLOWED_CARRIERS_DONE:
881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result;
885 } else {
886 if (ar.result == null) {
887 loge("setAllowedCarriers: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("setAllowedCarriers: CommandException: " +
890 ar.exception);
891 } else {
892 loge("setAllowedCarriers: Unknown exception");
893 }
894 }
895 // Result cannot be null. Return -1 on error.
896 if (request.result == null) {
897 request.result = new int[]{-1};
898 }
899 synchronized (request) {
900 request.notifyAll();
901 }
902 break;
903
904 case CMD_GET_ALLOWED_CARRIERS:
905 request = (MainThreadRequest) msg.obj;
906 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
907 mPhone.getAllowedCarriers(onCompleted);
908 break;
909
910 case EVENT_GET_ALLOWED_CARRIERS_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result;
915 } else {
916 if (ar.result == null) {
917 loge("getAllowedCarriers: Empty response");
918 } else if (ar.exception instanceof CommandException) {
919 loge("getAllowedCarriers: CommandException: " +
920 ar.exception);
921 } else {
922 loge("getAllowedCarriers: Unknown exception");
923 }
924 }
925 // Result cannot be null. Return empty list of CarrierIdentifier.
926 if (request.result == null) {
927 request.result = new ArrayList<CarrierIdentifier>(0);
928 }
929 synchronized (request) {
930 request.notifyAll();
931 }
932 break;
933
Nathan Haroldb3014052017-01-25 15:57:32 -0800934 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 if (ar.exception == null && ar.result != null) {
938 request.result = ar.result;
939 } else {
940 request.result = new IllegalArgumentException(
941 "Failed to retrieve Forbidden Plmns");
942 if (ar.result == null) {
943 loge("getForbiddenPlmns: Empty response");
944 } else {
945 loge("getForbiddenPlmns: Unknown exception");
946 }
947 }
948 synchronized (request) {
949 request.notifyAll();
950 }
951 break;
952
953 case CMD_GET_FORBIDDEN_PLMNS:
954 request = (MainThreadRequest) msg.obj;
955 uiccCard = getUiccCardFromRequest(request);
956 if (uiccCard == null) {
957 loge("getForbiddenPlmns() UiccCard is null");
958 request.result = new IllegalArgumentException(
959 "getForbiddenPlmns() UiccCard is null");
960 synchronized (request) {
961 request.notifyAll();
962 }
963 break;
964 }
965 Integer appType = (Integer) request.argument;
966 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
967 if (uiccApp == null) {
968 loge("getForbiddenPlmns() no app with specified type -- "
969 + appType);
970 request.result = new IllegalArgumentException("Failed to get UICC App");
971 synchronized (request) {
972 request.notifyAll();
973 }
974 break;
975 } else {
976 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
977 + " specified type -- " + appType);
978 }
979 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
980 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
981 onCompleted);
982 break;
983
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000984 case CMD_SWITCH_SLOTS:
985 request = (MainThreadRequest) msg.obj;
986 int[] physicalSlots = (int[]) request.argument;
987 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
988 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
989 break;
990
991 case EVENT_SWITCH_SLOTS_DONE:
992 ar = (AsyncResult) msg.obj;
993 request = (MainThreadRequest) ar.userObj;
994 request.result = (ar.exception == null);
995 synchronized (request) {
996 request.notifyAll();
997 }
998 break;
999
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001000 default:
1001 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1002 break;
1003 }
1004 }
Jake Hambye994d462014-02-03 13:10:13 -08001005
1006 private void handleNullReturnEvent(Message msg, String command) {
1007 AsyncResult ar = (AsyncResult) msg.obj;
1008 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1009 if (ar.exception == null) {
1010 request.result = true;
1011 } else {
1012 request.result = false;
1013 if (ar.exception instanceof CommandException) {
1014 loge(command + ": CommandException: " + ar.exception);
1015 } else {
1016 loge(command + ": Unknown exception");
1017 }
1018 }
1019 synchronized (request) {
1020 request.notifyAll();
1021 }
1022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001023 }
1024
1025 /**
1026 * Posts the specified command to be executed on the main thread,
1027 * waits for the request to complete, and returns the result.
1028 * @see #sendRequestAsync
1029 */
1030 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001031 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001032 }
1033
1034 /**
1035 * Posts the specified command to be executed on the main thread,
1036 * waits for the request to complete, and returns the result.
1037 * @see #sendRequestAsync
1038 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001039 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001040 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1041 throw new RuntimeException("This method will deadlock if called from the main thread.");
1042 }
1043
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001044 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 Message msg = mMainThreadHandler.obtainMessage(command, request);
1046 msg.sendToTarget();
1047
1048 // Wait for the request to complete
1049 synchronized (request) {
1050 while (request.result == null) {
1051 try {
1052 request.wait();
1053 } catch (InterruptedException e) {
1054 // Do nothing, go back and wait until the request is complete
1055 }
1056 }
1057 }
1058 return request.result;
1059 }
1060
1061 /**
1062 * Asynchronous ("fire and forget") version of sendRequest():
1063 * Posts the specified command to be executed on the main thread, and
1064 * returns immediately.
1065 * @see #sendRequest
1066 */
1067 private void sendRequestAsync(int command) {
1068 mMainThreadHandler.sendEmptyMessage(command);
1069 }
1070
1071 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001072 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1073 * @see {@link #sendRequest(int,Object)}
1074 */
1075 private void sendRequestAsync(int command, Object argument) {
1076 MainThreadRequest request = new MainThreadRequest(argument);
1077 Message msg = mMainThreadHandler.obtainMessage(command, request);
1078 msg.sendToTarget();
1079 }
1080
1081 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001082 * Initialize the singleton PhoneInterfaceManager instance.
1083 * This is only done once, at startup, from PhoneApp.onCreate().
1084 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001085 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001086 synchronized (PhoneInterfaceManager.class) {
1087 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001088 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001089 } else {
1090 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1091 }
1092 return sInstance;
1093 }
1094 }
1095
1096 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001097 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001098 mApp = app;
1099 mPhone = phone;
1100 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001101 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001102 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1103 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001104 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001105 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001106 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001107 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001108
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001109 publish();
1110 }
1111
1112 private void publish() {
1113 if (DBG) log("publish: " + this);
1114
1115 ServiceManager.addService("phone", this);
1116 }
1117
Stuart Scott584921c2015-01-15 17:10:34 -08001118 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001119 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1120 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001121 }
1122
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001123 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1124 Phone phone = getPhoneFromRequest(request);
1125 return phone == null ? null :
1126 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1127 }
1128
Wink Saville36469e72014-06-11 15:17:00 -07001129 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001130 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001131 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001133 //
1134 // Implementation of the ITelephony interface.
1135 //
1136
1137 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001138 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001139 }
1140
Wink Savilleb564aae2014-10-23 10:18:09 -07001141 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 if (DBG) log("dial: " + number);
1143 // No permission check needed here: This is just a wrapper around the
1144 // ACTION_DIAL intent, which is available to any app since it puts up
1145 // the UI before it does anything.
1146
1147 String url = createTelUrl(number);
1148 if (url == null) {
1149 return;
1150 }
1151
1152 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001153 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001154 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1155 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1156 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1157 mApp.startActivity(intent);
1158 }
1159 }
1160
1161 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001162 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001163 }
1164
Wink Savilleb564aae2014-10-23 10:18:09 -07001165 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001166 if (DBG) log("call: " + number);
1167
1168 // This is just a wrapper around the ACTION_CALL intent, but we still
1169 // need to do a permission check since we're calling startActivity()
1170 // from the context of the phone app.
1171 enforceCallPermission();
1172
1173 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1174 != AppOpsManager.MODE_ALLOWED) {
1175 return;
1176 }
1177
1178 String url = createTelUrl(number);
1179 if (url == null) {
1180 return;
1181 }
1182
Wink Saville08874612014-08-31 19:19:58 -07001183 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001184 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001185 if (slist != null) {
1186 for (SubscriptionInfo subInfoRecord : slist) {
1187 if (subInfoRecord.getSubscriptionId() == subId) {
1188 isValid = true;
1189 break;
1190 }
Wink Saville08874612014-08-31 19:19:58 -07001191 }
1192 }
1193 if (isValid == false) {
1194 return;
1195 }
1196
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001198 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1200 mApp.startActivity(intent);
1201 }
1202
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203 /**
1204 * End a call based on call state
1205 * @return true is a call was ended
1206 */
1207 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001208 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001209 }
1210
1211 /**
1212 * End a call based on the call state of the subId
1213 * @return true is a call was ended
1214 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001215 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001216 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1217 != PackageManager.PERMISSION_GRANTED) {
1218 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1219 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1220 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1221 }
Stuart Scott584921c2015-01-15 17:10:34 -08001222 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 }
1224
1225 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001226 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001227 }
1228
Wink Savilleb564aae2014-10-23 10:18:09 -07001229 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 if (DBG) log("answerRingingCall...");
1231 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1232 // but that can probably wait till the big TelephonyManager API overhaul.
1233 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1234 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001235 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 }
1237
1238 /**
1239 * Make the actual telephony calls to implement answerRingingCall().
1240 * This should only be called from the main thread of the Phone app.
1241 * @see #answerRingingCall
1242 *
1243 * TODO: it would be nice to return true if we answered the call, or
1244 * false if there wasn't actually a ringing incoming call, or some
1245 * other error occurred. (In other words, pass back the return value
1246 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1247 * But that would require calling this method via sendRequest() rather
1248 * than sendRequestAsync(), and right now we don't actually *need* that
1249 * return value, so let's just return void for now.
1250 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001251 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001252 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001253 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001254 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1255 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001256 if (hasActiveCall && hasHoldingCall) {
1257 // Both lines are in use!
1258 // TODO: provide a flag to let the caller specify what
1259 // policy to use if both lines are in use. (The current
1260 // behavior is hardwired to "answer incoming, end ongoing",
1261 // which is how the CALL button is specced to behave.)
1262 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1263 return;
1264 } else {
1265 // answerCall() will automatically hold the current active
1266 // call, if there is one.
1267 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1268 return;
1269 }
1270 } else {
1271 // No call was ringing.
1272 return;
1273 }
1274 }
1275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001277 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001279 public void silenceRinger() {
1280 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 }
1282
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001283 @Override
1284 public boolean isOffhook(String callingPackage) {
1285 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
1287
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 @Override
1289 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001291 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001292 return false;
1293 }
1294
Sanket Padawe356d7632015-06-22 14:03:32 -07001295 final Phone phone = getPhone(subId);
1296 if (phone != null) {
1297 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1298 } else {
1299 return false;
1300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 }
1302
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001303 @Override
1304 public boolean isRinging(String callingPackage) {
1305 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001306 }
1307
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001308 @Override
1309 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001311 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001312 return false;
1313 }
1314
Sanket Padawe356d7632015-06-22 14:03:32 -07001315 final Phone phone = getPhone(subId);
1316 if (phone != null) {
1317 return (phone.getState() == PhoneConstants.State.RINGING);
1318 } else {
1319 return false;
1320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321 }
1322
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001323 @Override
1324 public boolean isIdle(String callingPackage) {
1325 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
1327
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001328 @Override
1329 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001331 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001332 return false;
1333 }
1334
Sanket Padawe356d7632015-06-22 14:03:32 -07001335 final Phone phone = getPhone(subId);
1336 if (phone != null) {
1337 return (phone.getState() == PhoneConstants.State.IDLE);
1338 } else {
1339 return false;
1340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341 }
1342
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001344 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001345 }
1346
Wink Savilleb564aae2014-10-23 10:18:09 -07001347 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001348 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001349 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1350 }
1351
1352 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001353 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001354 }
1355
Wink Savilleb564aae2014-10-23 10:18:09 -07001356 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001357 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001358 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1359 }
1360
1361 /** {@hide} */
1362 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001363 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001364 }
1365
Wink Savilleb564aae2014-10-23 10:18:09 -07001366 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001368 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001369 checkSimPin.start();
1370 return checkSimPin.unlockSim(null, pin);
1371 }
1372
Wink Saville9de0f752013-10-22 19:04:03 -07001373 /** {@hide} */
1374 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001380 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 checkSimPuk.start();
1382 return checkSimPuk.unlockSim(puk, pin);
1383 }
1384
1385 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001386 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387 * a synchronous one.
1388 */
1389 private static class UnlockSim extends Thread {
1390
1391 private final IccCard mSimCard;
1392
1393 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001394 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1395 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396
1397 // For replies from SimCard interface
1398 private Handler mHandler;
1399
1400 // For async handler to identify request type
1401 private static final int SUPPLY_PIN_COMPLETE = 100;
1402
1403 public UnlockSim(IccCard simCard) {
1404 mSimCard = simCard;
1405 }
1406
1407 @Override
1408 public void run() {
1409 Looper.prepare();
1410 synchronized (UnlockSim.this) {
1411 mHandler = new Handler() {
1412 @Override
1413 public void handleMessage(Message msg) {
1414 AsyncResult ar = (AsyncResult) msg.obj;
1415 switch (msg.what) {
1416 case SUPPLY_PIN_COMPLETE:
1417 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1418 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001419 mRetryCount = msg.arg1;
1420 if (ar.exception != null) {
1421 if (ar.exception instanceof CommandException &&
1422 ((CommandException)(ar.exception)).getCommandError()
1423 == CommandException.Error.PASSWORD_INCORRECT) {
1424 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1425 } else {
1426 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1427 }
1428 } else {
1429 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 mDone = true;
1432 UnlockSim.this.notifyAll();
1433 }
1434 break;
1435 }
1436 }
1437 };
1438 UnlockSim.this.notifyAll();
1439 }
1440 Looper.loop();
1441 }
1442
1443 /*
1444 * Use PIN or PUK to unlock SIM card
1445 *
1446 * If PUK is null, unlock SIM card with PIN
1447 *
1448 * If PUK is not null, unlock SIM card with PUK and set PIN code
1449 */
Wink Saville9de0f752013-10-22 19:04:03 -07001450 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451
1452 while (mHandler == null) {
1453 try {
1454 wait();
1455 } catch (InterruptedException e) {
1456 Thread.currentThread().interrupt();
1457 }
1458 }
1459 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1460
1461 if (puk == null) {
1462 mSimCard.supplyPin(pin, callback);
1463 } else {
1464 mSimCard.supplyPuk(puk, pin, callback);
1465 }
1466
1467 while (!mDone) {
1468 try {
1469 Log.d(LOG_TAG, "wait for done");
1470 wait();
1471 } catch (InterruptedException e) {
1472 // Restore the interrupted status
1473 Thread.currentThread().interrupt();
1474 }
1475 }
1476 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001477 int[] resultArray = new int[2];
1478 resultArray[0] = mResult;
1479 resultArray[1] = mRetryCount;
1480 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482 }
1483
1484 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001486
1487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 // No permission check needed here: this call is harmless, and it's
1491 // needed for the ServiceState.requestStateUpdate() call (which is
1492 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001493 final Phone phone = getPhone(subId);
1494 if (phone != null) {
1495 phone.updateServiceLocation();
1496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 }
1498
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001499 @Override
1500 public boolean isRadioOn(String callingPackage) {
1501 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001502 }
1503
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001504 @Override
1505 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001507 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001508 return false;
1509 }
1510 return isRadioOnForSubscriber(subId);
1511 }
1512
1513 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001514 final Phone phone = getPhone(subId);
1515 if (phone != null) {
1516 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1517 } else {
1518 return false;
1519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 }
1521
1522 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001523 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001524
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 }
Wink Saville36469e72014-06-11 15:17:00 -07001526
Wink Savilleb564aae2014-10-23 10:18:09 -07001527 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001529 final Phone phone = getPhone(subId);
1530 if (phone != null) {
1531 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1532 }
Wink Saville36469e72014-06-11 15:17:00 -07001533 }
1534
1535 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Wink Savilleb564aae2014-10-23 10:18:09 -07001539 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001540 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001541 final Phone phone = getPhone(subId);
1542 if (phone == null) {
1543 return false;
1544 }
1545 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001546 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001547 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 }
1549 return true;
1550 }
Wink Saville36469e72014-06-11 15:17:00 -07001551
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001552 public boolean needMobileRadioShutdown() {
1553 /*
1554 * If any of the Radios are available, it will need to be
1555 * shutdown. So return true if any Radio is available.
1556 */
1557 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1558 Phone phone = PhoneFactory.getPhone(i);
1559 if (phone != null && phone.isRadioAvailable()) return true;
1560 }
1561 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1562 return false;
1563 }
1564
1565 public void shutdownMobileRadios() {
1566 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1567 logv("Shutting down Phone " + i);
1568 shutdownRadioUsingPhoneId(i);
1569 }
1570 }
1571
1572 private void shutdownRadioUsingPhoneId(int phoneId) {
1573 enforceModifyPermission();
1574 Phone phone = PhoneFactory.getPhone(phoneId);
1575 if (phone != null && phone.isRadioAvailable()) {
1576 phone.shutdownRadio();
1577 }
1578 }
1579
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001581 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001582 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1583 if (defaultPhone != null) {
1584 defaultPhone.setRadioPower(turnOn);
1585 return true;
1586 } else {
1587 loge("There's no default phone.");
1588 return false;
1589 }
Wink Saville36469e72014-06-11 15:17:00 -07001590 }
1591
Wink Savilleb564aae2014-10-23 10:18:09 -07001592 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 final Phone phone = getPhone(subId);
1595 if (phone != null) {
1596 phone.setRadioPower(turnOn);
1597 return true;
1598 } else {
1599 return false;
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
Wink Saville36469e72014-06-11 15:17:00 -07001603 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 public boolean enableDataConnectivity() {
1606 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001607 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 final Phone phone = getPhone(subId);
1609 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001610 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 return true;
1612 } else {
1613 return false;
1614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
1616
Wink Saville36469e72014-06-11 15:17:00 -07001617 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 public boolean disableDataConnectivity() {
1620 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001621 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001622 final Phone phone = getPhone(subId);
1623 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001624 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 return true;
1626 } else {
1627 return false;
1628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
1630
Sanket Padawe356d7632015-06-22 14:03:32 -07001631 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001632 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001633 final Phone phone = getPhone(subId);
1634 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001635 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001636 } else {
1637 return false;
1638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 }
1640
1641 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001642 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001643 }
1644
pkanwarae03a6b2016-11-06 20:37:09 -08001645 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001646 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001647 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1648 return;
1649 }
1650 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1651 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1652 };
1653
Wink Savilleb564aae2014-10-23 10:18:09 -07001654 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001656 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1657 return false;
1658 }
Wink Saville36469e72014-06-11 15:17:00 -07001659 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 }
1661
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001663 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001664 }
1665
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001666 public int getCallStateForSlot(int slotIndex) {
1667 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001668 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001669 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 }
1671
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001674 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001675 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001676 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001678 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681
Sanket Padawe356d7632015-06-22 14:03:32 -07001682 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001684 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 if (phone != null) {
1686 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1687 } else {
1688 return TelephonyManager.DATA_ACTIVITY_NONE;
1689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
1691
1692 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001693 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001694 mPhone.getContext().getSystemService(AppOpsManager.class)
1695 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001696 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001697 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001698 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001701 if (DBG_LOC) log("getCellLocation: is active user");
1702 Bundle data = new Bundle();
1703 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1704 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 return null;
1706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001708 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001709 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1710 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001711 }
1712
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001714 public String getNetworkCountryIsoForPhone(int phoneId) {
1715 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1716 // registered cell info, so return a NULL country instead.
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001720 // Todo: fix this when we can get the actual cellular network info when the device
1721 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001722 if (TelephonyManager.NETWORK_TYPE_IWLAN
1723 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1724 return "";
1725 }
1726 } finally {
1727 Binder.restoreCallingIdentity(identity);
1728 }
Jack Yu5f7092c2018-04-13 14:05:37 -07001729
1730 Phone phone = PhoneFactory.getPhone(phoneId);
1731 if (phone != null) {
1732 ServiceStateTracker sst = phone.getServiceStateTracker();
1733 if (sst != null) {
1734 LocaleTracker lt = sst.getLocaleTracker();
1735 if (lt != null) {
1736 return lt.getCurrentCountry();
1737 }
1738 }
1739 }
1740 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001741 }
1742
1743 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001745 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001746 }
1747
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001749 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 mApp.enforceCallingOrSelfPermission(
1751 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001752 final Phone phone = getPhone(subId);
1753 if (phone != null) {
1754 phone.enableLocationUpdates();
1755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
1757
1758 @Override
1759 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001760 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001761 }
1762
Sanket Padawe356d7632015-06-22 14:03:32 -07001763 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001764 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 mApp.enforceCallingOrSelfPermission(
1766 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 final Phone phone = getPhone(subId);
1768 if (phone != null) {
1769 phone.disableLocationUpdates();
1770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
1773 @Override
1774 @SuppressWarnings("unchecked")
1775 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001776 mPhone.getContext().getSystemService(AppOpsManager.class)
1777 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001778 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001779 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001780 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 }
1782
1783 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1784 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1785 return null;
1786 }
Svetoslav64fad262015-04-14 14:35:21 -07001787
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001788 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001790 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001792 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001793 try {
1794 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1795 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1796 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1797 } catch (RuntimeException e) {
1798 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001800 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 }
1802
1803
1804 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001805 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001806 mPhone.getContext().getSystemService(AppOpsManager.class)
1807 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001808 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001809 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001810 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
1812
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001813 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001814 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001815 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1816 for (Phone phone : PhoneFactory.getPhones()) {
1817 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1818 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001820 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 }
1822
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001823 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001825 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001826 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001827 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
Shishir Agrawala9f32182016-04-12 12:00:16 -07001830 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001831 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001832 Phone phone = PhoneFactory.getPhone(slotIndex);
1833 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001834 return null;
1835 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001836 int subId = phone.getSubId();
1837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1838 mApp, subId, callingPackage, "getImeiForSlot")) {
1839 return null;
1840 }
1841 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001842 }
1843
1844 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001845 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001846 Phone phone = PhoneFactory.getPhone(slotIndex);
1847 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001848 return null;
1849 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001850 int subId = phone.getSubId();
1851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1852 mApp, subId, callingPackage, "getMeidForSlot")) {
1853 return null;
1854 }
1855 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001856 }
1857
1858 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001859 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001860 Phone phone = PhoneFactory.getPhone(slotIndex);
1861 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001862 return null;
1863 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001864 int subId = phone.getSubId();
1865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1866 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1867 return null;
1868 }
1869 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001870 }
1871
fionaxu43304da2017-11-27 22:51:16 -08001872 @Override
1873 public int getSubscriptionCarrierId(int subId) {
1874 final Phone phone = getPhone(subId);
1875 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1876 }
1877
1878 @Override
1879 public String getSubscriptionCarrierName(int subId) {
1880 final Phone phone = getPhone(subId);
1881 return phone == null ? null : phone.getCarrierName();
1882 }
1883
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 //
1885 // Internal helper methods.
1886 //
1887
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001888 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1890 *
1891 * @throws SecurityException if the caller does not have the required permission
1892 */
1893 private void enforceModifyPermission() {
1894 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1895 }
1896
1897 /**
1898 * Make sure the caller has the CALL_PHONE permission.
1899 *
1900 * @throws SecurityException if the caller does not have the required permission
1901 */
1902 private void enforceCallPermission() {
1903 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1904 }
1905
Stuart Scott8eef64f2015-04-08 15:13:54 -07001906 private void enforceConnectivityInternalPermission() {
1907 mApp.enforceCallingOrSelfPermission(
1908 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1909 "ConnectivityService");
1910 }
1911
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 private String createTelUrl(String number) {
1913 if (TextUtils.isEmpty(number)) {
1914 return null;
1915 }
1916
Jake Hambye994d462014-02-03 13:10:13 -08001917 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 }
1919
Ihab Awadf9e92732013-12-05 18:02:52 -08001920 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1922 }
1923
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001924 private static void logv(String msg) {
1925 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1926 }
1927
Ihab Awadf9e92732013-12-05 18:02:52 -08001928 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1930 }
1931
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001932 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001934 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001935 }
1936
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001938 public int getActivePhoneTypeForSlot(int slotIndex) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00001939 final Phone phone = PhoneFactory.getPhone(slotIndex);
1940 if (phone == null) {
1941 return PhoneConstants.PHONE_TYPE_NONE;
1942 } else {
1943 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
1946
1947 /**
1948 * Returns the CDMA ERI icon index to display
1949 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 @Override
1951 public int getCdmaEriIconIndex(String callingPackage) {
1952 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001956 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001958 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001959 return -1;
1960 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 final Phone phone = getPhone(subId);
1962 if (phone != null) {
1963 return phone.getCdmaEriIconIndex();
1964 } else {
1965 return -1;
1966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 }
1968
1969 /**
1970 * Returns the CDMA ERI icon mode,
1971 * 0 - ON
1972 * 1 - FLASHING
1973 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001974 @Override
1975 public int getCdmaEriIconMode(String callingPackage) {
1976 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001977 }
1978
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001980 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001982 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001983 return -1;
1984 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001985 final Phone phone = getPhone(subId);
1986 if (phone != null) {
1987 return phone.getCdmaEriIconMode();
1988 } else {
1989 return -1;
1990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 }
1992
1993 /**
1994 * Returns the CDMA ERI text,
1995 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001996 @Override
1997 public String getCdmaEriText(String callingPackage) {
1998 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001999 }
2000
Sanket Padawe356d7632015-06-22 14:03:32 -07002001 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002002 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002004 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002005 return null;
2006 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002007 final Phone phone = getPhone(subId);
2008 if (phone != null) {
2009 return phone.getCdmaEriText();
2010 } else {
2011 return null;
2012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
2014
2015 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002016 * Returns the CDMA MDN.
2017 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002018 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002019 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2021 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07002022 final Phone phone = getPhone(subId);
2023 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2024 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002025 } else {
2026 return null;
2027 }
2028 }
2029
2030 /**
2031 * Returns the CDMA MIN.
2032 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002033 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002034 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2036 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002037 final Phone phone = getPhone(subId);
2038 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2039 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002040 } else {
2041 return null;
2042 }
2043 }
2044
2045 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 * Returns true if CDMA provisioning needs to run.
2047 */
2048 public boolean needsOtaServiceProvisioning() {
2049 return mPhone.needsOtaServiceProvisioning();
2050 }
2051
2052 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002053 * Sets the voice mail number of a given subId.
2054 */
2055 @Override
2056 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002057 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002058 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2059 new Pair<String, String>(alphaTag, number), new Integer(subId));
2060 return success;
2061 }
2062
Ta-wei Yen87c49842016-05-13 21:19:52 -07002063 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002064 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2066 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2067 if (!TextUtils.equals(callingPackage, systemDialer)) {
2068 throw new SecurityException("caller must be system dialer");
2069 }
2070 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2071 if (phoneAccountHandle == null){
2072 return null;
2073 }
2074 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2075 }
2076
2077 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002078 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002079 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002081 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002082 return null;
2083 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002084 final long identity = Binder.clearCallingIdentity();
2085 try {
2086 return RemoteVvmTaskManager
2087 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
2090 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002091 }
2092
2093 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002094 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2095 VisualVoicemailSmsFilterSettings settings) {
2096 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002097 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002098 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2099 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002100 }
2101
2102 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002103 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2104 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002105 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002106 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002107 }
2108
2109 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002110 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2111 String callingPackage, int subId) {
2112 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002113 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002114 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002115 }
2116
2117 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002118 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002119 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002120 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002121 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2122 }
2123
2124 @Override
2125 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2126 String number, int port, String text, PendingIntent sentIntent) {
2127 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002128 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002129 enforceSendSmsPermission();
2130 // Make the calls as the phone process.
2131 final long identity = Binder.clearCallingIdentity();
2132 try {
2133 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2134 if (port == 0) {
2135 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2136 sentIntent, null, false);
2137 } else {
2138 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2139 smsManager.sendDataMessageWithSelfPermissions(number, null,
2140 (short) port, data, sentIntent, null);
2141 }
2142 } finally {
2143 Binder.restoreCallingIdentity(identity);
2144 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002145 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002146 /**
fionaxu0152e512016-11-14 13:36:14 -08002147 * Sets the voice activation state of a given subId.
2148 */
2149 @Override
2150 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2152 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002153 final Phone phone = getPhone(subId);
2154 if (phone != null) {
2155 phone.setVoiceActivationState(activationState);
2156 } else {
2157 loge("setVoiceActivationState fails with invalid subId: " + subId);
2158 }
2159 }
2160
2161 /**
2162 * Sets the data activation state of a given subId.
2163 */
2164 @Override
2165 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2167 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002168 final Phone phone = getPhone(subId);
2169 if (phone != null) {
2170 phone.setDataActivationState(activationState);
2171 } else {
2172 loge("setVoiceActivationState fails with invalid subId: " + subId);
2173 }
2174 }
2175
2176 /**
2177 * Returns the voice activation state of a given subId.
2178 */
2179 @Override
2180 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002181 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002182 final Phone phone = getPhone(subId);
2183 if (phone != null) {
2184 return phone.getVoiceActivationState();
2185 } else {
2186 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2187 }
2188 }
2189
2190 /**
2191 * Returns the data activation state of a given subId.
2192 */
2193 @Override
2194 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002195 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002196 final Phone phone = getPhone(subId);
2197 if (phone != null) {
2198 return phone.getDataActivationState();
2199 } else {
2200 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2201 }
2202 }
2203
2204 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 * Returns the unread count of voicemails
2206 */
2207 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002208 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002209 }
2210
2211 /**
2212 * Returns the unread count of voicemails for a subId
2213 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002215 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 final Phone phone = getPhone(subId);
2217 if (phone != null) {
2218 return phone.getVoiceMessageCount();
2219 } else {
2220 return 0;
2221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 }
2223
2224 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002225 * returns true, if the device is in a state where both voice and data
2226 * are supported simultaneously. This can change based on location or network condition.
2227 */
2228 @Override
2229 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2230 final Phone phone = getPhone(subId);
2231 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2232 }
2233
2234 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002235 * Send the dialer code if called from the current default dialer or the caller has
2236 * carrier privilege.
2237 * @param inputCode The dialer code to send
2238 */
2239 @Override
2240 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2241 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2242 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2243 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002244 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2245 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002246 }
2247 mPhone.sendDialerSpecialCode(inputCode);
2248 }
2249
2250 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002251 * Returns the data network type.
2252 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 *
2254 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2255 */
2256 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002257 public int getNetworkType() {
2258 final Phone phone = getPhone(getDefaultSubscription());
2259 if (phone != null) {
2260 return phone.getServiceState().getDataNetworkType();
2261 } else {
2262 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2263 }
Wink Saville36469e72014-06-11 15:17:00 -07002264 }
2265
2266 /**
2267 * Returns the network type for a subId
2268 */
2269 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002270 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002272 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002273 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2274 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002275
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002277 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002278 return phone.getServiceState().getDataNetworkType();
2279 } else {
2280 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
2284 /**
2285 * Returns the data network type
2286 */
2287 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002288 public int getDataNetworkType(String callingPackage) {
2289 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002290 }
2291
2292 /**
2293 * Returns the data network type for a subId
2294 */
2295 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002296 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002297 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002298 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002299 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2300 }
2301
Sanket Padawe356d7632015-06-22 14:03:32 -07002302 final Phone phone = getPhone(subId);
2303 if (phone != null) {
2304 return phone.getServiceState().getDataNetworkType();
2305 } else {
2306 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
2310 /**
Wink Saville36469e72014-06-11 15:17:00 -07002311 * Returns the Voice network type for a subId
2312 */
2313 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002314 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002316 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002317 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2318 }
2319
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 final Phone phone = getPhone(subId);
2321 if (phone != null) {
2322 return phone.getServiceState().getVoiceNetworkType();
2323 } else {
2324 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 }
2327
2328 /**
2329 * @return true if a ICC card is present
2330 */
2331 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002332 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002333 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2334 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
2337 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002338 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002339 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002341 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2342 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002343 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002344 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002345 } else {
2346 return false;
2347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 }
2349
2350 /**
2351 * Return if the current radio is LTE on CDMA. This
2352 * is a tri-state return value as for a period of time
2353 * the mode may be unknown.
2354 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002355 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002357 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002359 @Override
2360 public int getLteOnCdmaMode(String callingPackage) {
2361 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002362 }
2363
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002365 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002367 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002368 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2369 }
2370
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 final Phone phone = getPhone(subId);
2372 if (phone == null) {
2373 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2374 } else {
2375 return phone.getLteOnCdmaMode();
2376 }
Wink Saville36469e72014-06-11 15:17:00 -07002377 }
2378
2379 public void setPhone(Phone phone) {
2380 mPhone = phone;
2381 }
2382
2383 /**
2384 * {@hide}
2385 * Returns Default subId, 0 in the case of single standby.
2386 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002387 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002388 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002389 }
2390
Shishir Agrawala9f32182016-04-12 12:00:16 -07002391 private int getSlotForDefaultSubscription() {
2392 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2393 }
2394
Wink Savilleb564aae2014-10-23 10:18:09 -07002395 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002396 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002398
2399 /**
2400 * @see android.telephony.TelephonyManager.WifiCallingChoices
2401 */
2402 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002403 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2404 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002405 }
2406
2407 /**
2408 * @see android.telephony.TelephonyManager.WifiCallingChoices
2409 */
2410 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002411 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2412 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2413 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002414 }
2415
Sailesh Nepald1e68152013-12-12 19:08:02 -08002416 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002417 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002418 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002419 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002420
Shishir Agrawal566b7612013-10-28 14:41:00 -07002421 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002422 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2423 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2425 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002426
Derek Tan740e1672017-06-27 14:56:27 -07002427 if (TextUtils.equals(ISDR_AID, aid)) {
2428 // Only allows LPA to open logical channel to ISD-R.
2429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2430 ComponentInfo bestComponent =
2431 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2432 if (bestComponent == null
2433 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2434 loge("The calling package is not allowed to access ISD-R.");
2435 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2436 }
2437 }
2438
2439 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002440 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002441 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002442 if (DBG) log("iccOpenLogicalChannel: " + response);
2443 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002444 }
2445
2446 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002447 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2449 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002450
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002451 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002452 if (channel < 0) {
2453 return false;
2454 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002455 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002456 if (DBG) log("iccCloseLogicalChannel: " + success);
2457 return success;
2458 }
2459
2460 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002461 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002462 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2464 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002465
2466 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002467 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2468 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002469 " data=" + data);
2470 }
2471
2472 if (channel < 0) {
2473 return "";
2474 }
2475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002476 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002478 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2479
Shishir Agrawal566b7612013-10-28 14:41:00 -07002480 // Append the returned status code to the end of the response payload.
2481 String s = Integer.toHexString(
2482 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002483 if (response.payload != null) {
2484 s = IccUtils.bytesToHexString(response.payload) + s;
2485 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002486 return s;
2487 }
Jake Hambye994d462014-02-03 13:10:13 -08002488
Evan Charltonc66da362014-05-16 14:06:40 -07002489 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002490 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2491 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2493 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002494
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002495 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2496 && TextUtils.equals(ISDR_AID, data)) {
2497 // Only allows LPA to select ISD-R.
2498 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2499 ComponentInfo bestComponent =
2500 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2501 if (bestComponent == null
2502 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2503 loge("The calling package is not allowed to select ISD-R.");
2504 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2505 }
2506 }
2507
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002508 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002509 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2510 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002511 }
2512
2513 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002514 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002515 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2516
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002517 // Append the returned status code to the end of the response payload.
2518 String s = Integer.toHexString(
2519 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002520 if (response.payload != null) {
2521 s = IccUtils.bytesToHexString(response.payload) + s;
2522 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002523 return s;
2524 }
2525
2526 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002527 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002528 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2530 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002531
2532 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002533 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002534 p1 + " " + p2 + " " + p3 + ":" + filePath);
2535 }
2536
2537 IccIoResult response =
2538 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002539 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2540 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002541
2542 if (DBG) {
2543 log("Exchange SIM_IO [R]" + response);
2544 }
2545
2546 byte[] result = null;
2547 int length = 2;
2548 if (response.payload != null) {
2549 length = 2 + response.payload.length;
2550 result = new byte[length];
2551 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2552 } else {
2553 result = new byte[length];
2554 }
2555
2556 result[length - 1] = (byte) response.sw2;
2557 result[length - 2] = (byte) response.sw1;
2558 return result;
2559 }
2560
Nathan Haroldb3014052017-01-25 15:57:32 -08002561 /**
2562 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2563 * on a particular subscription
2564 */
sqianb6e41952018-03-12 14:54:01 -07002565 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2567 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2568 return null;
2569 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002570 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2571 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2572 return null;
2573 }
2574 Object response = sendRequest(
2575 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2576 if (response instanceof String[]) {
2577 return (String[]) response;
2578 }
2579 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2580 return null;
2581 }
2582
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002583 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002584 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2586 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002587
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002588 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002589 if (response.payload == null) {
2590 return "";
2591 }
2592
2593 // Append the returned status code to the end of the response payload.
2594 String s = Integer.toHexString(
2595 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2596 s = IccUtils.bytesToHexString(response.payload) + s;
2597 return s;
2598 }
2599
Jake Hambye994d462014-02-03 13:10:13 -08002600 /**
2601 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2602 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2603 *
2604 * @param itemID the ID of the item to read
2605 * @return the NV item as a String, or null on error.
2606 */
2607 @Override
2608 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2610 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002611 if (DBG) log("nvReadItem: item " + itemID);
2612 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2613 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2614 return value;
2615 }
2616
2617 /**
2618 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2619 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2620 *
2621 * @param itemID the ID of the item to read
2622 * @param itemValue the value to write, as a String
2623 * @return true on success; false on any failure
2624 */
2625 @Override
2626 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2628 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002629 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2630 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2631 new Pair<Integer, String>(itemID, itemValue));
2632 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2633 return success;
2634 }
2635
2636 /**
2637 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2638 * Used for device configuration by some CDMA operators.
2639 *
2640 * @param preferredRoamingList byte array containing the new PRL
2641 * @return true on success; false on any failure
2642 */
2643 @Override
2644 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2646 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002647 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2648 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2649 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2650 return success;
2651 }
2652
2653 /**
2654 * Perform the specified type of NV config reset.
2655 * Used for device configuration by some CDMA operators.
2656 *
2657 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2658 * @return true on success; false on any failure
2659 */
2660 @Override
2661 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2663 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002664 if (DBG) log("nvResetConfig: type " + resetType);
2665 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2666 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2667 return success;
2668 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002669
2670 /**
Wink Saville36469e72014-06-11 15:17:00 -07002671 * {@hide}
2672 * Returns Default sim, 0 in the case of single standby.
2673 */
2674 public int getDefaultSim() {
2675 //TODO Need to get it from Telephony Devcontroller
2676 return 0;
2677 }
2678
Svet Ganovb320e182015-04-16 12:30:10 -07002679 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002680 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002681 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002682 return new String[0];
2683 }
2684
2685
ram87fca6f2014-07-18 18:58:44 +05302686 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002687 }
2688
Brad Ebinger51f743a2017-01-23 13:50:20 -08002689 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002690 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2691 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002692 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002693 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002694 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002695 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002696 }
2697
2698 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002699 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2700 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002701 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002702 public void disableIms(int slotId) {
2703 enforceModifyPermission();
2704 PhoneFactory.getImsResolver().disableIms(slotId);
2705 }
2706
2707 /**
2708 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2709 * feature or {@link null} if the service is not available. If the feature is available, the
2710 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2711 */
2712 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002713 IImsServiceFeatureCallback callback) {
2714 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002715 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002716 }
2717
2718 /**
2719 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2720 * feature during emergency calling or {@link null} if the service is not available. If the
2721 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2722 * listener for feature updates.
2723 */
2724 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2725 enforceModifyPermission();
2726 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002727 }
2728
Brad Ebinger5f64b052017-12-14 14:26:15 -08002729 /**
2730 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2731 * specified.
2732 */
2733 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2734 enforceModifyPermission();
2735 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2736 }
2737
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002738 /**
2739 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2740 * specified.
2741 */
2742 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2743 enforceModifyPermission();
2744 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2745 }
2746
Brad Ebinger884c07b2018-02-15 16:17:40 -08002747 /**
Brad Ebinger304415d2018-03-02 13:43:36 -08002748 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2749 * available, false if the IMS resolver is idle.
2750 */
2751 public boolean isResolvingImsBinding() {
2752 enforceModifyPermission();
2753 return PhoneFactory.getImsResolver().isResolvingBinding();
2754 }
2755
Brad Ebingerdac2f002018-04-03 15:17:52 -07002756 /**
2757 * Sets the ImsService Package Name that Telephony will bind to.
2758 *
2759 * @param slotId the slot ID that the ImsService should bind for.
2760 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
2761 * ImsService is the device default ImsService.
2762 * @param packageName The package name of the application that contains the ImsService to bind
2763 * to.
2764 * @return true if setting the ImsService to bind to succeeded, false if it did not.
2765 * @hide
2766 */
2767 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002768 int[] subIds = SubscriptionManager.getSubId(slotId);
2769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2770 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2771 "setImsService");
2772
Brad Ebingerdac2f002018-04-03 15:17:52 -07002773 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
2774 isCarrierImsService, packageName);
2775 }
2776
2777 /**
2778 * Return the ImsService configuration.
2779 *
2780 * @param slotId The slot that the ImsService is associated with.
2781 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
2782 * the device default.
2783 * @return the package name of the ImsService configuration.
2784 */
2785 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002786 int[] subIds = SubscriptionManager.getSubId(slotId);
2787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2788 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2789 "getImsService");
2790
Brad Ebingerdac2f002018-04-03 15:17:52 -07002791 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
2792 isCarrierImsService);
2793 }
2794
Wink Saville36469e72014-06-11 15:17:00 -07002795 public void setImsRegistrationState(boolean registered) {
2796 enforceModifyPermission();
2797 mPhone.setImsRegistrationState(registered);
2798 }
2799
2800 /**
Stuart Scott54788802015-03-30 13:18:01 -07002801 * Set the network selection mode to automatic.
2802 *
2803 */
2804 @Override
2805 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2807 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002808 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2809 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2810 }
2811
2812 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002813 * Set the network selection mode to manual with the selected carrier.
2814 */
2815 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002816 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002817 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2819 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002820 OperatorInfo operator = new OperatorInfo(
2821 /* operatorAlphaLong */ "",
2822 /* operatorAlphaShort */ "",
2823 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002824 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002825 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2826 persistSelection);
2827 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002828 }
2829
2830 /**
2831 * Scans for available networks.
2832 */
2833 @Override
2834 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2836 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002837 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2838 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2839 CMD_PERFORM_NETWORK_SCAN, null, subId);
2840 return result;
2841 }
2842
2843 /**
yinxub1bed742017-04-17 11:45:04 -07002844 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002845 *
yinxub1bed742017-04-17 11:45:04 -07002846 * @param subId id of the subscription
2847 * @param request contains the radio access networks with bands/channels to scan
2848 * @param messenger callback messenger for scan results or errors
2849 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002850 * @return the id of the requested scan which can be used to stop the scan.
2851 */
2852 @Override
2853 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2854 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2856 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002857 return mNetworkScanRequestTracker.startNetworkScan(
2858 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002859 }
2860
2861 /**
2862 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002863 *
2864 * @param subId id of the subscription
2865 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002866 */
2867 @Override
2868 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2870 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002871 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002872 }
2873
2874 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002875 * Get the calculated preferred network type.
2876 * Used for debugging incorrect network type.
2877 *
2878 * @return the preferred network type, defined in RILConstants.java.
2879 */
2880 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002881 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002882 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002883 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002884 return RILConstants.PREFERRED_NETWORK_MODE;
2885 }
2886
Amit Mahajan43330e02014-11-18 11:54:45 -08002887 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002888 }
2889
2890 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002891 * Get the preferred network type.
2892 * Used for device configuration by some CDMA operators.
2893 *
2894 * @return the preferred network type, defined in RILConstants.java.
2895 */
2896 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002897 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2899 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002900 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002901 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002902 int networkType = (result != null ? result[0] : -1);
2903 if (DBG) log("getPreferredNetworkType: " + networkType);
2904 return networkType;
2905 }
2906
2907 /**
2908 * Set the preferred network type.
2909 * Used for device configuration by some CDMA operators.
2910 *
2911 * @param networkType the preferred network type, defined in RILConstants.java.
2912 * @return true on success; false on any failure.
2913 */
2914 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002915 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2917 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002918 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2919 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002920 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002921 if (success) {
2922 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002923 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002924 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002925 return success;
2926 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002927
2928 /**
Junda Liu475951f2014-11-07 16:45:03 -08002929 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2930 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2931 * tethering.
2932 *
2933 * @return 0: Not required. 1: required. 2: Not set.
2934 * @hide
2935 */
2936 @Override
2937 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002938 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002939 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2940 Settings.Global.TETHER_DUN_REQUIRED, 2);
2941 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2942 // config_tether_apndata.
2943 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2944 dunRequired = 1;
2945 }
2946 return dunRequired;
2947 }
2948
2949 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002950 * Set mobile data enabled
2951 * Used by the user through settings etc to turn on/off mobile data
2952 *
2953 * @param enable {@code true} turn turn data on, else {@code false}
2954 */
2955 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002956 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2958 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002959 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002960 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002961 Phone phone = PhoneFactory.getPhone(phoneId);
2962 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002963 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2964 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002965 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002966 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002967 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002968 }
2969
2970 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002971 * Get the user enabled state of Mobile Data.
2972 *
2973 * TODO: remove and use isUserDataEnabled.
2974 * This can't be removed now because some vendor codes
2975 * calls through ITelephony directly while they should
2976 * use TelephonyManager.
2977 *
2978 * @return true on enabled
2979 */
2980 @Override
2981 public boolean getDataEnabled(int subId) {
2982 return isUserDataEnabled(subId);
2983 }
2984
2985 /**
2986 * Get whether mobile data is enabled per user setting.
2987 *
2988 * There are other factors deciding whether mobile data is actually enabled, but they are
2989 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002990 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002991 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002992 *
2993 * @return {@code true} if data is enabled else {@code false}
2994 */
2995 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002996 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002997 try {
2998 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2999 null);
3000 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3002 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003003 }
Wink Savillee7353bb2014-12-05 14:21:41 -08003004 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08003005 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08003006 Phone phone = PhoneFactory.getPhone(phoneId);
3007 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08003008 boolean retVal = phone.isUserDataEnabled();
3009 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08003010 return retVal;
3011 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08003012 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3013 return false;
3014 }
3015 }
3016
3017 /**
3018 * Get whether mobile data is enabled.
3019 *
3020 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3021 * whether mobile data is actually enabled.
3022 *
3023 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3024 *
3025 * @return {@code true} if data is enabled else {@code false}
3026 */
3027 @Override
3028 public boolean isDataEnabled(int subId) {
3029 try {
3030 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3031 null);
3032 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3034 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003035 }
3036 int phoneId = mSubscriptionController.getPhoneId(subId);
3037 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3038 Phone phone = PhoneFactory.getPhone(phoneId);
3039 if (phone != null) {
3040 boolean retVal = phone.isDataEnabled();
3041 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3042 return retVal;
3043 } else {
3044 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08003045 return false;
3046 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003047 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003048
3049 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003050 public int getCarrierPrivilegeStatus(int subId) {
3051 final Phone phone = getPhone(subId);
3052 if (phone == null) {
3053 loge("getCarrierPrivilegeStatus: Invalid subId");
3054 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3055 }
3056 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003057 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003058 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003059 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3060 }
3061 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003062 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003063 }
Junda Liu29340342014-07-10 15:23:27 -07003064
3065 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003066 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3067 final Phone phone = getPhone(subId);
3068 if (phone == null) {
3069 loge("getCarrierPrivilegeStatus: Invalid subId");
3070 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3071 }
3072 UiccProfile profile =
3073 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3074 if (profile == null) {
3075 loge("getCarrierPrivilegeStatus: No UICC");
3076 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3077 }
3078 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3079 }
3080
3081 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003082 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003083 if (TextUtils.isEmpty(pkgName))
3084 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003085 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003086 if (card == null) {
3087 loge("checkCarrierPrivilegesForPackage: No UICC");
3088 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3089 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003090 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3091 }
3092
3093 @Override
3094 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003095 if (TextUtils.isEmpty(pkgName))
3096 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003097 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3098 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3099 UiccCard card = UiccController.getInstance().getUiccCard(i);
3100 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003101 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003102 continue;
3103 }
3104
3105 result = card.getCarrierPrivilegeStatus(
3106 mPhone.getContext().getPackageManager(), pkgName);
3107 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3108 break;
3109 }
3110 }
3111
3112 return result;
Junda Liu29340342014-07-10 15:23:27 -07003113 }
Derek Tan89e89d42014-07-08 17:00:10 -07003114
3115 @Override
Junda Liue64de782015-04-16 17:19:16 -07003116 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3117 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3118 loge("phoneId " + phoneId + " is not valid.");
3119 return null;
3120 }
3121 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003122 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003123 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003124 return null ;
3125 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003126 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003127 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003128 }
3129
Amith Yamasani6e118872016-02-19 12:53:51 -08003130 @Override
3131 public List<String> getPackagesWithCarrierPrivileges() {
3132 PackageManager pm = mPhone.getContext().getPackageManager();
3133 List<String> privilegedPackages = new ArrayList<>();
3134 List<PackageInfo> packages = null;
3135 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3136 UiccCard card = UiccController.getInstance().getUiccCard(i);
3137 if (card == null) {
3138 // No UICC in that slot.
3139 continue;
3140 }
3141 if (card.hasCarrierPrivilegeRules()) {
3142 if (packages == null) {
3143 // Only check packages in user 0 for now
3144 packages = pm.getInstalledPackagesAsUser(
3145 PackageManager.MATCH_DISABLED_COMPONENTS
3146 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3147 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3148 }
3149 for (int p = packages.size() - 1; p >= 0; p--) {
3150 PackageInfo pkgInfo = packages.get(p);
3151 if (pkgInfo != null && pkgInfo.packageName != null
3152 && card.getCarrierPrivilegeStatus(pkgInfo)
3153 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3154 privilegedPackages.add(pkgInfo.packageName);
3155 }
3156 }
3157 }
3158 }
3159 return privilegedPackages;
3160 }
3161
Wink Savilleb564aae2014-10-23 10:18:09 -07003162 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003163 final Phone phone = getPhone(subId);
3164 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003165 if (card == null) {
3166 loge("getIccId: No UICC");
3167 return null;
3168 }
3169 String iccId = card.getIccId();
3170 if (TextUtils.isEmpty(iccId)) {
3171 loge("getIccId: ICC ID is null or empty.");
3172 return null;
3173 }
3174 return iccId;
3175 }
3176
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003177 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003178 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3179 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003180 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3181 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003182
Jeff Sharkey85190e62014-12-05 09:40:12 -08003183 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003184 final Phone phone = getPhone(subId);
3185 if (phone == null) {
3186 return false;
3187 }
3188 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003189
3190 if (DBG_MERGE) {
3191 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3192 + subscriberId + " to " + number);
3193 }
3194
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003195 if (TextUtils.isEmpty(iccId)) {
3196 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003197 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003198
Jeff Sharkey85190e62014-12-05 09:40:12 -08003199 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3200
3201 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003202 if (alphaTag == null) {
3203 editor.remove(alphaTagPrefKey);
3204 } else {
3205 editor.putString(alphaTagPrefKey, alphaTag);
3206 }
3207
Jeff Sharkey85190e62014-12-05 09:40:12 -08003208 // Record both the line number and IMSI for this ICCID, since we need to
3209 // track all merged IMSIs based on line number
3210 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3211 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003212 if (number == null) {
3213 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003214 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003215 } else {
3216 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003217 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003218 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003219
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003220 editor.commit();
3221 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003222 }
3223
3224 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003225 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003226 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003227 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003228 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003229 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003230 return null;
3231 }
Derek Tan97ebb422014-09-05 16:55:38 -07003232
3233 String iccId = getIccId(subId);
3234 if (iccId != null) {
3235 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003236 if (DBG_MERGE) {
3237 log("getLine1NumberForDisplay returning " +
3238 mTelephonySharedPreferences.getString(numberPrefKey, null));
3239 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003240 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003241 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003242 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003243 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003244 }
3245
3246 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003247 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003249 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003250 return null;
3251 }
Derek Tan97ebb422014-09-05 16:55:38 -07003252
3253 String iccId = getIccId(subId);
3254 if (iccId != null) {
3255 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003256 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003257 }
Derek Tan97ebb422014-09-05 16:55:38 -07003258 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003259 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003260
3261 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003262 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003263 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3264 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003266 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3267 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003268 return null;
3269 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003270 final Context context = mPhone.getContext();
3271 final TelephonyManager tele = TelephonyManager.from(context);
3272 final SubscriptionManager sub = SubscriptionManager.from(context);
3273
3274 // Figure out what subscribers are currently active
3275 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003276 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3277 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 final int[] subIds = sub.getActiveSubscriptionIdList();
3281 for (int subId : subIds) {
3282 activeSubscriberIds.add(tele.getSubscriberId(subId));
3283 }
3284 } finally {
3285 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003286 }
3287
3288 // First pass, find a number override for an active subscriber
3289 String mergeNumber = null;
3290 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3291 for (String key : prefs.keySet()) {
3292 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3293 final String subscriberId = (String) prefs.get(key);
3294 if (activeSubscriberIds.contains(subscriberId)) {
3295 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3296 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3297 mergeNumber = (String) prefs.get(numberKey);
3298 if (DBG_MERGE) {
3299 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3300 + " for active subscriber " + subscriberId);
3301 }
3302 if (!TextUtils.isEmpty(mergeNumber)) {
3303 break;
3304 }
3305 }
3306 }
3307 }
3308
3309 // Shortcut when no active merged subscribers
3310 if (TextUtils.isEmpty(mergeNumber)) {
3311 return null;
3312 }
3313
3314 // Second pass, find all subscribers under that line override
3315 final ArraySet<String> result = new ArraySet<>();
3316 for (String key : prefs.keySet()) {
3317 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3318 final String number = (String) prefs.get(key);
3319 if (mergeNumber.equals(number)) {
3320 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3321 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3322 final String subscriberId = (String) prefs.get(subscriberKey);
3323 if (!TextUtils.isEmpty(subscriberId)) {
3324 result.add(subscriberId);
3325 }
3326 }
3327 }
3328 }
3329
3330 final String[] resultArray = result.toArray(new String[result.size()]);
3331 Arrays.sort(resultArray);
3332 if (DBG_MERGE) {
3333 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3334 }
3335 return resultArray;
3336 }
3337
3338 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003339 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003340 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3341 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003342 final Phone phone = getPhone(subId);
3343 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003344 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003345
3346 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003347 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003348 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3349 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003350 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003351 final Phone phone = getPhone(subId);
3352 if (phone == null) {
3353 return false;
3354 }
3355 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003356 cdmaNonRoamingList);
3357 }
3358
3359 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003360 @Deprecated
3361 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3362 enforceModifyPermission();
3363
3364 int returnValue = 0;
3365 try {
3366 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3367 if(result.exception == null) {
3368 if (result.result != null) {
3369 byte[] responseData = (byte[])(result.result);
3370 if(responseData.length > oemResp.length) {
3371 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3372 responseData.length + "bytes. Buffer Size is " +
3373 oemResp.length + "bytes.");
3374 }
3375 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3376 returnValue = responseData.length;
3377 }
3378 } else {
3379 CommandException ex = (CommandException) result.exception;
3380 returnValue = ex.getCommandError().ordinal();
3381 if(returnValue > 0) returnValue *= -1;
3382 }
3383 } catch (RuntimeException e) {
3384 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3385 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3386 if(returnValue > 0) returnValue *= -1;
3387 }
3388
3389 return returnValue;
3390 }
3391
3392 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003393 public void setRadioCapability(RadioAccessFamily[] rafs) {
3394 try {
3395 ProxyController.getInstance().setRadioCapability(rafs);
3396 } catch (RuntimeException e) {
3397 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3398 }
3399 }
3400
3401 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003402 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003403 Phone phone = PhoneFactory.getPhone(phoneId);
3404 if (phone == null) {
3405 return RadioAccessFamily.RAF_UNKNOWN;
3406 }
3407 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003408 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003409 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003410 return RadioAccessFamily.RAF_UNKNOWN;
3411 }
3412
Wink Saville5d475dd2014-10-17 15:00:58 -07003413 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3414 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003415
3416 @Override
3417 public void enableVideoCalling(boolean enable) {
3418 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003419 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003420 }
3421
3422 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003423 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003424 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3425 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3426 return false;
3427 }
Svet Ganovb320e182015-04-16 12:30:10 -07003428
Andrew Lee77527ac2014-10-21 16:57:39 -07003429 // Check the user preference and the system-level IMS setting. Even if the user has
3430 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3431 // In the long run, we may instead need to check if there exists a connection service
3432 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003433 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3434 return imsManager.isVtEnabledByPlatform()
3435 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3436 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003437 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003438
Andrew Leea1239f22015-03-02 17:44:07 -08003439 @Override
3440 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003441 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003442 }
3443
3444 @Override
3445 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003446 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003447 }
3448
Andrew Lee9431b832015-03-09 18:46:45 -07003449 @Override
3450 public boolean isTtyModeSupported() {
3451 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3452 TelephonyManager telephonyManager =
3453 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003454 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003455 }
3456
3457 @Override
3458 public boolean isHearingAidCompatibilitySupported() {
3459 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3460 }
3461
Hall Liu98187582018-01-22 19:15:32 -08003462 public boolean isRttSupported() {
3463 boolean isCarrierSupported =
3464 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3465 boolean isDeviceSupported =
3466 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3467 return isCarrierSupported && isDeviceSupported;
3468 }
3469
Hall Liu3ad5f012018-04-06 16:23:39 -07003470 public boolean isRttEnabled() {
3471 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3472 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3473 }
3474
Sanket Padawe7310cc72015-01-14 09:53:20 -08003475 /**
3476 * Returns the unique device ID of phone, for example, the IMEI for
3477 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3478 *
3479 * <p>Requires Permission:
3480 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3481 */
3482 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003483 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003484 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003485 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003486 return null;
3487 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003488 int subId = phone.getSubId();
3489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3490 mApp, subId, callingPackage, "getDeviceId")) {
3491 return null;
3492 }
3493 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003494 }
3495
Ping Sunc67b7c22016-03-02 19:16:45 +08003496 /**
3497 * {@hide}
3498 * Returns the IMS Registration Status on a particular subid
3499 *
3500 * @param subId
3501 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003502 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003503 Phone phone = getPhone(subId);
3504 if (phone != null) {
3505 return phone.isImsRegistered();
3506 } else {
3507 return false;
3508 }
3509 }
3510
Santos Cordon7a1885b2015-02-03 11:15:19 -08003511 @Override
3512 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3513 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3514 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003515
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003516 /**
3517 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003518 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003519 public boolean isWifiCallingAvailable(int subId) {
3520 Phone phone = getPhone(subId);
3521 if (phone != null) {
3522 return phone.isWifiCallingEnabled();
3523 } else {
3524 return false;
3525 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003526 }
3527
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003528 /**
3529 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003530 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003531 public boolean isVolteAvailable(int subId) {
3532 Phone phone = getPhone(subId);
3533 if (phone != null) {
3534 return phone.isVolteEnabled();
3535 } else {
3536 return false;
3537 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003538 }
Svet Ganovb320e182015-04-16 12:30:10 -07003539
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003540 /**
3541 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003542 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003543 public boolean isVideoTelephonyAvailable(int subId) {
3544 Phone phone = getPhone(subId);
3545 if (phone != null) {
3546 return phone.isVideoEnabled();
3547 } else {
3548 return false;
3549 }
3550 }
3551
3552 /**
3553 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3554 * defined in {@link ImsRegistrationImplBase}.
3555 */
3556 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3557 Phone phone = getPhone(subId);
3558 if (phone != null) {
3559 return phone.getImsRegistrationTech();
3560 } else {
3561 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3562 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003563 }
3564
Stuart Scott8eef64f2015-04-08 15:13:54 -07003565 @Override
3566 public void factoryReset(int subId) {
3567 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003568 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3569 return;
3570 }
3571
Svet Ganovcc087f82015-05-12 20:35:54 -07003572 final long identity = Binder.clearCallingIdentity();
3573 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003574 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3575 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003576 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003577 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003578 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3579 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003580 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003581 }
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003584 }
3585 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003586
3587 @Override
3588 public String getLocaleFromDefaultSim() {
3589 // We query all subscriptions instead of just the active ones, because
3590 // this might be called early on in the provisioning flow when the
3591 // subscriptions potentially aren't active yet.
3592 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3593 if (slist == null || slist.isEmpty()) {
3594 return null;
3595 }
3596
3597 // This function may be called very early, say, from the setup wizard, at
3598 // which point we won't have a default subscription set. If that's the case
3599 // we just choose the first, which will be valid in "most cases".
3600 final int defaultSubId = getDefaultSubscription();
3601 SubscriptionInfo info = null;
3602 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3603 info = slist.get(0);
3604 } else {
3605 for (SubscriptionInfo item : slist) {
3606 if (item.getSubscriptionId() == defaultSubId) {
3607 info = item;
3608 break;
3609 }
3610 }
3611
3612 if (info == null) {
3613 return null;
3614 }
3615 }
3616
3617 // Try and fetch the locale from the carrier properties or from the SIM language
3618 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003619 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003620 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003621 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003622 if (defaultPhone != null) {
3623 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3624 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003625 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003626 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3627 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003628 } else {
3629 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003630 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003631 }
3632 }
3633
Narayan Kamath011676f2015-07-29 12:04:08 +01003634 // The SIM language preferences only store a language (e.g. fr = French), not an
3635 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3636 // the SIM and carrier preferences does not include a country we add the country
3637 // determined from the SIM MCC to provide an exact locale.
3638 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003639 if (mccLocale != null) {
3640 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3641 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003642 }
3643
Tony Hill183b2de2015-06-24 14:53:58 +01003644 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003645 return null;
3646 }
3647
3648 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 return mSubscriptionController.getAllSubInfoList(
3652 mPhone.getContext().getOpPackageName());
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
3656 }
3657
3658 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 return mSubscriptionController.getActiveSubscriptionInfoList(
3662 mPhone.getContext().getOpPackageName());
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
3666 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003667
Chenjie Yu1ba97252018-01-11 18:16:20 -08003668 private final ModemActivityInfo mLastModemActivityInfo =
3669 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3670
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003671 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003672 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3673 * representing the state of the modem.
3674 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003675 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3676 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003677 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003678 */
3679 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003680 public void requestModemActivityInfo(ResultReceiver result) {
3681 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003682 ModemActivityInfo ret = null;
3683 synchronized (mLastModemActivityInfo) {
3684 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3685 null);
3686 if (info != null) {
3687 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3688 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3689 mergedTxTimeMs[i] =
3690 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3691 }
3692 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3693 mLastModemActivityInfo.setSleepTimeMillis(
3694 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3695 mLastModemActivityInfo.setIdleTimeMillis(
3696 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3697 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3698 mLastModemActivityInfo.setRxTimeMillis(
3699 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3700 mLastModemActivityInfo.setEnergyUsed(
3701 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3702 }
3703 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3704 mLastModemActivityInfo.getSleepTimeMillis(),
3705 mLastModemActivityInfo.getIdleTimeMillis(),
3706 mLastModemActivityInfo.getTxTimeMillis(),
3707 mLastModemActivityInfo.getRxTimeMillis(),
3708 mLastModemActivityInfo.getEnergyUsed());
3709 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003710 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003711 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003712 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003713 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003714
3715 /**
3716 * {@hide}
3717 * Returns the service state information on specified subscription.
3718 */
3719 @Override
3720 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3721
Jeff Davidson7e17e312018-02-13 18:17:36 -08003722 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003723 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003724 return null;
3725 }
3726
3727 final Phone phone = getPhone(subId);
3728 if (phone == null) {
3729 return null;
3730 }
3731
3732 return phone.getServiceState();
3733 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003734
3735 /**
3736 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3737 *
3738 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3739 * voicemail ringtone.
3740 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3741 * PhoneAccount.
3742 */
3743 @Override
3744 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003745 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003746 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003747 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003748 }
3749
fionaxu7ed723d2017-05-30 18:58:54 -07003750 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003751 }
3752
3753 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003754 * Sets the per-account voicemail ringtone.
3755 *
3756 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3757 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3758 *
3759 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3760 * voicemail ringtone.
3761 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3762 * PhoneAccount.
3763 */
3764 @Override
3765 public void setVoicemailRingtoneUri(String callingPackage,
3766 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3767 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3768 if (!TextUtils.equals(callingPackage,
3769 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3771 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3772 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003773 }
3774 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3775 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003776 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003777 }
fionaxu7ed723d2017-05-30 18:58:54 -07003778 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003779 }
3780
3781 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003782 * Returns whether vibration is set for voicemail notification in Phone settings.
3783 *
3784 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3785 * voicemail vibration setting.
3786 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3787 */
3788 @Override
3789 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003790 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003791 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003792 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003793 }
3794
fionaxu7ed723d2017-05-30 18:58:54 -07003795 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003796 }
3797
Youhan Wange64578a2016-05-02 15:32:42 -07003798 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003799 * Sets the per-account voicemail vibration.
3800 *
3801 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3802 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3803 *
3804 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3805 * voicemail vibration setting.
3806 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3807 * specific PhoneAccount.
3808 */
3809 @Override
3810 public void setVoicemailVibrationEnabled(String callingPackage,
3811 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3812 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3813 if (!TextUtils.equals(callingPackage,
3814 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3816 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3817 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003818 }
3819
3820 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3821 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003822 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003823 }
fionaxu7ed723d2017-05-30 18:58:54 -07003824 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003825 }
3826
3827 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003828 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3829 *
3830 * @throws SecurityException if the caller does not have the required permission
3831 */
3832 private void enforceReadPrivilegedPermission() {
3833 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3834 null);
3835 }
3836
3837 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003838 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3839 * permission.
3840 *
3841 * @throws SecurityException if the caller does not have the required permission
3842 */
3843 private void enforceSendSmsPermission() {
3844 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3845 }
3846
3847 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003848 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003849 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003850 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003851 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003852 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003853 ComponentName componentName =
3854 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3855 if(componentName == null) {
3856 throw new SecurityException("Caller not current active visual voicemail package[null]");
3857 }
3858 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003859 if (!callingPackage.equals(vvmPackage)) {
3860 throw new SecurityException("Caller not current active visual voicemail package[" +
3861 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003862 }
3863 }
3864
3865 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003866 * Return the application ID for the app type.
3867 *
3868 * @param subId the subscription ID that this request applies to.
3869 * @param appType the uicc app type.
3870 * @return Application ID for specificied app type, or null if no uicc.
3871 */
3872 @Override
3873 public String getAidForAppType(int subId, int appType) {
3874 enforceReadPrivilegedPermission();
3875 Phone phone = getPhone(subId);
3876 if (phone == null) {
3877 return null;
3878 }
3879 String aid = null;
3880 try {
3881 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3882 .getApplicationByType(appType).getAid();
3883 } catch (Exception e) {
3884 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3885 }
3886 return aid;
3887 }
3888
Youhan Wang4001d252016-05-11 10:29:41 -07003889 /**
3890 * Return the Electronic Serial Number.
3891 *
3892 * @param subId the subscription ID that this request applies to.
3893 * @return ESN or null if error.
3894 */
3895 @Override
3896 public String getEsn(int subId) {
3897 enforceReadPrivilegedPermission();
3898 Phone phone = getPhone(subId);
3899 if (phone == null) {
3900 return null;
3901 }
3902 String esn = null;
3903 try {
3904 esn = phone.getEsn();
3905 } catch (Exception e) {
3906 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3907 }
3908 return esn;
3909 }
3910
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003911 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003912 * Return the Preferred Roaming List Version.
3913 *
3914 * @param subId the subscription ID that this request applies to.
3915 * @return PRLVersion or null if error.
3916 */
3917 @Override
3918 public String getCdmaPrlVersion(int subId) {
3919 enforceReadPrivilegedPermission();
3920 Phone phone = getPhone(subId);
3921 if (phone == null) {
3922 return null;
3923 }
3924 String cdmaPrlVersion = null;
3925 try {
3926 cdmaPrlVersion = phone.getCdmaPrlVersion();
3927 } catch (Exception e) {
3928 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3929 }
3930 return cdmaPrlVersion;
3931 }
3932
3933 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003934 * Get snapshot of Telephony histograms
3935 * @return List of Telephony histograms
3936 * @hide
3937 */
3938 @Override
3939 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3941 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003942 return RIL.getTelephonyRILTimingHistograms();
3943 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003944
3945 /**
3946 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003947 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003948 * Require system privileges. In the future we may add this to carrier APIs.
3949 *
3950 * @return The number of carriers set successfully, should match length of carriers
3951 */
3952 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003953 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003954 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003955
Meng Wang9b7c4e92017-02-17 11:41:27 -08003956 if (carriers == null) {
3957 throw new NullPointerException("carriers cannot be null");
3958 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003959
3960 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003961 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3962 return retVal[0];
3963 }
3964
3965 /**
3966 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003967 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003968 * Require system privileges. In the future we may add this to carrier APIs.
3969 *
3970 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3971 * means all carriers are allowed.
3972 */
3973 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003974 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003975 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003976 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003977 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3978 }
3979
fionaxu59545b42016-05-25 15:53:37 -07003980 /**
3981 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3982 * @param subId the subscription ID that this action applies to.
3983 * @param enabled control enable or disable metered apns.
3984 * {@hide}
3985 */
3986 @Override
3987 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3988 enforceModifyPermission();
3989 final Phone phone = getPhone(subId);
3990 if (phone == null) {
3991 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3992 return;
3993 }
3994 try {
3995 phone.carrierActionSetMeteredApnsEnabled(enabled);
3996 } catch (Exception e) {
3997 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3998 }
3999 }
4000
4001 /**
4002 * Action set from carrier signalling broadcast receivers to enable/disable radio
4003 * @param subId the subscription ID that this action applies to.
4004 * @param enabled control enable or disable radio.
4005 * {@hide}
4006 */
4007 @Override
4008 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4009 enforceModifyPermission();
4010 final Phone phone = getPhone(subId);
4011 if (phone == null) {
4012 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4013 return;
4014 }
4015 try {
4016 phone.carrierActionSetRadioEnabled(enabled);
4017 } catch (Exception e) {
4018 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
4019 }
4020 }
4021
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004022 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004023 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4024 * network status based on which carrier apps could apply actions accordingly,
4025 * enable/disable default url handler for example.
4026 *
4027 * @param subId the subscription ID that this action applies to.
4028 * @param report control start/stop reporting the default network status.
4029 * {@hide}
4030 */
4031 @Override
4032 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4033 enforceModifyPermission();
4034 final Phone phone = getPhone(subId);
4035 if (phone == null) {
4036 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4037 return;
4038 }
4039 try {
4040 phone.carrierActionReportDefaultNetworkStatus(report);
4041 } catch (Exception e) {
4042 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
4043 }
4044 }
4045
4046 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004047 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4048 * bug report is being generated.
4049 */
4050 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004051 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004052 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4053 != PackageManager.PERMISSION_GRANTED) {
4054 writer.println("Permission Denial: can't dump Phone from pid="
4055 + Binder.getCallingPid()
4056 + ", uid=" + Binder.getCallingUid()
4057 + "without permission "
4058 + android.Manifest.permission.DUMP);
4059 return;
4060 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004061 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004062 }
Jack Yueb89b242016-06-22 13:27:47 -07004063
Brad Ebingerdac2f002018-04-03 15:17:52 -07004064 @Override
4065 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4066 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4067 throws RemoteException {
4068 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4069 }
4070
Jack Yueb89b242016-06-22 13:27:47 -07004071 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004072 * Get aggregated video call data usage since boot.
4073 *
4074 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4075 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004076 * {@hide}
4077 */
4078 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004079 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004080 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4081 null);
4082
Jack Yu84291ec2017-05-26 16:07:50 -07004083 // NetworkStatsService keeps tracking the active network interface and identity. It
4084 // records the delta with the corresponding network identity. We just return the total video
4085 // call data usage snapshot since boot.
4086 Phone phone = getPhone(subId);
4087 if (phone != null) {
4088 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004089 }
Jack Yu84291ec2017-05-26 16:07:50 -07004090 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004091 }
Jack Yu75ab2952016-07-08 14:29:33 -07004092
4093 /**
4094 * Policy control of data connection. Usually used when data limit is passed.
4095 * @param enabled True if enabling the data, otherwise disabling.
4096 * @param subId Subscription index
4097 * {@hide}
4098 */
4099 @Override
4100 public void setPolicyDataEnabled(boolean enabled, int subId) {
4101 enforceModifyPermission();
4102 Phone phone = getPhone(subId);
4103 if (phone != null) {
4104 phone.setPolicyDataEnabled(enabled);
4105 }
4106 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004107
4108 /**
4109 * Get Client request stats
4110 * @return List of Client Request Stats
4111 * @hide
4112 */
4113 @Override
4114 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004116 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004117 return null;
4118 }
4119
4120 Phone phone = getPhone(subId);
4121 if (phone != null) {
4122 return phone.getClientRequestStats();
4123 }
4124
4125 return null;
4126 }
4127
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004128 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004129 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004130 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004131 }
Jack Yueb4124c2017-02-16 15:32:43 -08004132
4133 /**
Grace Chen70990072017-03-24 17:21:30 -07004134 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004135 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004136 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004137 * @param state State of SIM (power down, power up, pass through)
4138 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4139 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4140 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004141 *
4142 **/
4143 @Override
Grace Chen70990072017-03-24 17:21:30 -07004144 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004145 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004146 Phone phone = PhoneFactory.getPhone(slotIndex);
4147
Jack Yueb4124c2017-02-16 15:32:43 -08004148 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004149 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004150 }
4151 }
Shuo Qiandd210312017-04-12 22:11:33 +00004152
Tyler Gunn65d45c22017-06-05 11:22:26 -07004153 private boolean isUssdApiAllowed(int subId) {
4154 CarrierConfigManager configManager =
4155 (CarrierConfigManager) mPhone.getContext().getSystemService(
4156 Context.CARRIER_CONFIG_SERVICE);
4157 if (configManager == null) {
4158 return false;
4159 }
4160 PersistableBundle pb = configManager.getConfigForSubId(subId);
4161 if (pb == null) {
4162 return false;
4163 }
4164 return pb.getBoolean(
4165 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4166 }
4167
Shuo Qiandd210312017-04-12 22:11:33 +00004168 /**
4169 * Check if phone is in emergency callback mode
4170 * @return true if phone is in emergency callback mode
4171 * @param subId sub id
4172 */
goneil9c5f4872017-12-05 14:07:56 -08004173 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004174 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004175 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004176 final Phone phone = getPhone(subId);
4177 if (phone != null) {
4178 return phone.isInEcm();
4179 } else {
4180 return false;
4181 }
4182 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004183
4184 /**
4185 * Get the current signal strength information for the given subscription.
4186 * Because this information is not updated when the device is in a low power state
4187 * it should not be relied-upon to be current.
4188 * @param subId Subscription index
4189 * @return the most recent cached signal strength info from the modem
4190 */
4191 @Override
4192 public SignalStrength getSignalStrength(int subId) {
4193 Phone p = getPhone(subId);
4194 if (p == null) {
4195 return null;
4196 }
4197
4198 return p.getSignalStrength();
4199 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004200
4201 @Override
4202 public UiccSlotInfo[] getUiccSlotsInfo() {
4203 enforceReadPrivilegedPermission();
4204
4205 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004206 if (slots == null) {
4207 Rlog.i(LOG_TAG, "slots is null.");
4208 return null;
4209 }
4210
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004211 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4212 for (int i = 0; i < slots.length; i++) {
4213 UiccSlot slot = slots[i];
Holly Jiuyu Sun6723f982018-06-04 15:48:38 -07004214 if (slot == null) {
4215 continue;
4216 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004217
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004218 String cardId;
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004219 UiccCard card = slot.getUiccCard();
4220 if (card != null) {
4221 cardId = card.getCardId();
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004222 } else {
4223 cardId = slot.getIccId();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004224 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004225
4226 int cardState = 0;
4227 switch (slot.getCardState()) {
4228 case CARDSTATE_ABSENT:
4229 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4230 break;
4231 case CARDSTATE_PRESENT:
4232 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4233 break;
4234 case CARDSTATE_ERROR:
4235 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4236 break;
4237 case CARDSTATE_RESTRICTED:
4238 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4239 break;
4240 default:
4241 break;
4242
4243 }
4244
Qingxi Li795c5882018-01-31 13:43:27 -08004245 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004246 slot.isActive(),
4247 slot.isEuicc(),
4248 cardId,
4249 cardState,
4250 slot.getPhoneId(),
4251 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004252 }
4253 return infos;
4254 }
4255
4256 @Override
4257 public boolean switchSlots(int[] physicalSlots) {
4258 enforceModifyPermission();
4259 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4260 }
Jack Yu4c988042018-02-27 15:30:01 -08004261
4262 @Override
4263 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4264 enforceModifyPermission();
4265 final Phone phone = getPhone(subId);
4266 if (phone == null) {
4267 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4268 return;
4269 }
4270
4271 phone.setRadioIndicationUpdateMode(filters, mode);
4272 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004273
4274 /**
goneil47ffb6e2018-04-06 15:40:58 -07004275 * A test API to reload the UICC profile.
4276 *
4277 * <p>Requires that the calling app has permission
4278 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4279 * @hide
4280 */
4281 @Override
4282 public void refreshUiccProfile(int subId) {
4283 enforceModifyPermission();
4284
4285 final long identity = Binder.clearCallingIdentity();
4286 try {
4287 Phone phone = getPhone(subId);
4288 if (phone == null) {
4289 return;
4290 }
4291 UiccCard uiccCard = phone.getUiccCard();
4292 if (uiccCard == null) {
4293 return;
4294 }
4295 UiccProfile uiccProfile = uiccCard.getUiccProfile();
4296 if (uiccProfile == null) {
4297 return;
4298 }
4299 uiccProfile.refresh();
4300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
4303 }
4304
4305 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07004306 * Returns false if the mobile data is disabled by default, otherwise return true.
4307 */
4308 private boolean getDefaultDataEnabled() {
4309 return "true".equalsIgnoreCase(
4310 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4311 }
4312
4313 /**
4314 * Returns true if the data roaming is enabled by default, i.e the system property
4315 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4316 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4317 */
4318 private boolean getDefaultDataRoamingEnabled(int subId) {
4319 final CarrierConfigManager configMgr = (CarrierConfigManager)
4320 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4321 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4322 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4323 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4324 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4325 return isDataRoamingEnabled;
4326 }
4327
4328 /**
4329 * Returns the default network type for the given {@code subId}, if the default network type is
4330 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4331 */
4332 private int getDefaultNetworkType(int subId) {
4333 return Integer.parseInt(
4334 TelephonyManager.getTelephonyProperty(
4335 mSubscriptionController.getPhoneId(subId),
4336 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4337 String.valueOf(Phone.PREFERRED_NT_MODE)));
4338 }
fionaxua13278b2018-03-21 00:08:13 -07004339
4340 @Override
4341 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4342 gid1, String gid2, String plmn, String spn) {
4343 enforceModifyPermission();
4344 final Phone phone = getPhone(subId);
4345 if (phone == null) {
4346 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4347 return;
4348 }
4349 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4350 }
4351
4352 @Override
4353 public int getCarrierIdListVersion(int subId) {
4354 enforceReadPrivilegedPermission();
4355 final Phone phone = getPhone(subId);
4356 if (phone == null) {
4357 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4358 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4359 }
4360 return phone.getCarrierIdListVersion();
4361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004362}