blob: bcbf2c3d4eb2b23e5b501820fe2ef8a5b621ace0 [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);
Mengjun Lengb3369682017-10-19 18:39:20 +0800396 request.result = ""; // dummy result for notifying the waiting thread
397 // Wake up the requesting thread
398 synchronized (request) {
399 request.notifyAll();
400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 break;
402
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 case CMD_END_CALL:
404 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800405 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700406 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700407 Phone phone = getPhone(end_subId);
408 if (phone == null) {
409 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
410 break;
411 }
412 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
414 // CDMA: If the user presses the Power button we treat it as
415 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700416 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
418 // GSM: End the call as per the Phone state
419 hungUp = PhoneUtils.hangup(mCM);
420 } else {
421 throw new IllegalStateException("Unexpected phone type: " + phoneType);
422 }
423 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
424 request.result = hungUp;
425 // Wake up the requesting thread
426 synchronized (request) {
427 request.notifyAll();
428 }
429 break;
430
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800434 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700435 if (uiccCard == null) {
436 loge("iccTransmitApduLogicalChannel: No UICC");
437 request.result = new IccIoResult(0x6F, 0, (byte[])null);
438 synchronized (request) {
439 request.notifyAll();
440 }
441 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
443 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700444 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 iccArgument.channel, iccArgument.cla, iccArgument.command,
446 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700448 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 break;
450
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 ar = (AsyncResult) msg.obj;
453 request = (MainThreadRequest) ar.userObj;
454 if (ar.exception == null && ar.result != null) {
455 request.result = ar.result;
456 } else {
457 request.result = new IccIoResult(0x6F, 0, (byte[])null);
458 if (ar.result == null) {
459 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800460 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800462 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 } else {
464 loge("iccTransmitApduLogicalChannel: Unknown exception");
465 }
466 }
467 synchronized (request) {
468 request.notifyAll();
469 }
470 break;
471
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
473 request = (MainThreadRequest) msg.obj;
474 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800475 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 if (uiccCard == null) {
477 loge("iccTransmitApduBasicChannel: No UICC");
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
479 synchronized (request) {
480 request.notifyAll();
481 }
482 } else {
483 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
484 request);
485 uiccCard.iccTransmitApduBasicChannel(
486 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
487 iccArgument.p3, iccArgument.data, onCompleted);
488 }
489 break;
490
491 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
492 ar = (AsyncResult) msg.obj;
493 request = (MainThreadRequest) ar.userObj;
494 if (ar.exception == null && ar.result != null) {
495 request.result = ar.result;
496 } else {
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
498 if (ar.result == null) {
499 loge("iccTransmitApduBasicChannel: Empty response");
500 } else if (ar.exception instanceof CommandException) {
501 loge("iccTransmitApduBasicChannel: CommandException: " +
502 ar.exception);
503 } else {
504 loge("iccTransmitApduBasicChannel: Unknown exception");
505 }
506 }
507 synchronized (request) {
508 request.notifyAll();
509 }
510 break;
511
512 case CMD_EXCHANGE_SIM_IO:
513 request = (MainThreadRequest) msg.obj;
514 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800515 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 if (uiccCard == null) {
517 loge("iccExchangeSimIO: No UICC");
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 synchronized (request) {
520 request.notifyAll();
521 }
522 } else {
523 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
524 request);
525 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
526 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
527 iccArgument.data, onCompleted);
528 }
529 break;
530
531 case EVENT_EXCHANGE_SIM_IO_DONE:
532 ar = (AsyncResult) msg.obj;
533 request = (MainThreadRequest) ar.userObj;
534 if (ar.exception == null && ar.result != null) {
535 request.result = ar.result;
536 } else {
537 request.result = new IccIoResult(0x6f, 0, (byte[])null);
538 }
539 synchronized (request) {
540 request.notifyAll();
541 }
542 break;
543
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 case CMD_SEND_ENVELOPE:
545 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800546 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 if (uiccCard == null) {
548 loge("sendEnvelopeWithStatus: No UICC");
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 synchronized (request) {
551 request.notifyAll();
552 }
553 } else {
554 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
555 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
556 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 break;
558
559 case EVENT_SEND_ENVELOPE_DONE:
560 ar = (AsyncResult) msg.obj;
561 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700562 if (ar.exception == null && ar.result != null) {
563 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
566 if (ar.result == null) {
567 loge("sendEnvelopeWithStatus: Empty response");
568 } else if (ar.exception instanceof CommandException) {
569 loge("sendEnvelopeWithStatus: CommandException: " +
570 ar.exception);
571 } else {
572 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 }
575 synchronized (request) {
576 request.notifyAll();
577 }
578 break;
579
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 case CMD_OPEN_CHANNEL:
581 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800582 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800583 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 if (uiccCard == null) {
585 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800586 request.result = new IccOpenLogicalChannelResponse(-1,
587 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 synchronized (request) {
589 request.notifyAll();
590 }
591 } else {
592 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800593 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
594 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 break;
597
598 case EVENT_OPEN_CHANNEL_DONE:
599 ar = (AsyncResult) msg.obj;
600 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 int[] result = (int[]) ar.result;
604 int channelId = result[0];
605 byte[] selectResponse = null;
606 if (result.length > 1) {
607 selectResponse = new byte[result.length - 1];
608 for (int i = 1; i < result.length; ++i) {
609 selectResponse[i - 1] = (byte) result[i];
610 }
611 }
612 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.result == null) {
616 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 if (ar.exception != null) {
619 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
620 }
621
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700623 if (ar.exception instanceof CommandException) {
624 CommandException.Error error =
625 ((CommandException) (ar.exception)).getCommandError();
626 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700627 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700628 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700629 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 }
631 }
632 openChannelResp = new IccOpenLogicalChannelResponse(
633 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700635 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 synchronized (request) {
637 request.notifyAll();
638 }
639 break;
640
641 case CMD_CLOSE_CHANNEL:
642 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800643 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 if (uiccCard == null) {
645 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900646 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 synchronized (request) {
648 request.notifyAll();
649 }
650 } else {
651 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
652 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 break;
655
656 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800657 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
658 break;
659
660 case CMD_NV_READ_ITEM:
661 request = (MainThreadRequest) msg.obj;
662 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
663 mPhone.nvReadItem((Integer) request.argument, onCompleted);
664 break;
665
666 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 ar = (AsyncResult) msg.obj;
668 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800669 if (ar.exception == null && ar.result != null) {
670 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800672 request.result = "";
673 if (ar.result == null) {
674 loge("nvReadItem: Empty response");
675 } else if (ar.exception instanceof CommandException) {
676 loge("nvReadItem: CommandException: " +
677 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800679 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 }
681 }
682 synchronized (request) {
683 request.notifyAll();
684 }
685 break;
686
Jake Hambye994d462014-02-03 13:10:13 -0800687 case CMD_NV_WRITE_ITEM:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
690 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
691 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
692 break;
693
694 case EVENT_NV_WRITE_ITEM_DONE:
695 handleNullReturnEvent(msg, "nvWriteItem");
696 break;
697
698 case CMD_NV_WRITE_CDMA_PRL:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
701 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
702 break;
703
704 case EVENT_NV_WRITE_CDMA_PRL_DONE:
705 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
706 break;
707
708 case CMD_NV_RESET_CONFIG:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
711 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
712 break;
713
714 case EVENT_NV_RESET_CONFIG_DONE:
715 handleNullReturnEvent(msg, "nvResetConfig");
716 break;
717
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 case CMD_GET_PREFERRED_NETWORK_TYPE:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700721 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 break;
723
724 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
727 if (ar.exception == null && ar.result != null) {
728 request.result = ar.result; // Integer
729 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800730 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 if (ar.result == null) {
732 loge("getPreferredNetworkType: Empty response");
733 } else if (ar.exception instanceof CommandException) {
734 loge("getPreferredNetworkType: CommandException: " +
735 ar.exception);
736 } else {
737 loge("getPreferredNetworkType: Unknown exception");
738 }
739 }
740 synchronized (request) {
741 request.notifyAll();
742 }
743 break;
744
745 case CMD_SET_PREFERRED_NETWORK_TYPE:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
748 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700749 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
753 handleNullReturnEvent(msg, "setPreferredNetworkType");
754 break;
755
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000756 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
757 request = (MainThreadRequest)msg.obj;
758 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
759 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
760 break;
761
762 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
763 ar = (AsyncResult)msg.obj;
764 request = (MainThreadRequest)ar.userObj;
765 request.result = ar;
766 synchronized (request) {
767 request.notifyAll();
768 }
769 break;
770
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800771 case CMD_SET_VOICEMAIL_NUMBER:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
774 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800775 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
776 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800777 break;
778
779 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
780 handleNullReturnEvent(msg, "setVoicemailNumber");
781 break;
782
Stuart Scott54788802015-03-30 13:18:01 -0700783 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
784 request = (MainThreadRequest) msg.obj;
785 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
786 request);
787 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
788 break;
789
790 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
791 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
792 break;
793
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 case CMD_PERFORM_NETWORK_SCAN:
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
797 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
798 break;
799
800 case EVENT_PERFORM_NETWORK_SCAN_DONE:
801 ar = (AsyncResult) msg.obj;
802 request = (MainThreadRequest) ar.userObj;
803 CellNetworkScanResult cellScanResult;
804 if (ar.exception == null && ar.result != null) {
805 cellScanResult = new CellNetworkScanResult(
806 CellNetworkScanResult.STATUS_SUCCESS,
807 (List<OperatorInfo>) ar.result);
808 } else {
809 if (ar.result == null) {
810 loge("getCellNetworkScanResults: Empty response");
811 }
812 if (ar.exception != null) {
813 loge("getCellNetworkScanResults: Exception: " + ar.exception);
814 }
815 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
816 if (ar.exception instanceof CommandException) {
817 CommandException.Error error =
818 ((CommandException) (ar.exception)).getCommandError();
819 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
820 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
821 } else if (error == CommandException.Error.GENERIC_FAILURE) {
822 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
823 }
824 }
825 cellScanResult = new CellNetworkScanResult(errorCode, null);
826 }
827 request.result = cellScanResult;
828 synchronized (request) {
829 request.notifyAll();
830 }
831 break;
832
833 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
834 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700835 ManualNetworkSelectionArgument selArg =
836 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
838 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700839 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
840 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
843 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
844 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
845 break;
846
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700847 case CMD_GET_MODEM_ACTIVITY_INFO:
848 request = (MainThreadRequest) msg.obj;
849 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700850 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700851 break;
852
853 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result;
858 } else {
859 if (ar.result == null) {
860 loge("queryModemActivityInfo: Empty response");
861 } else if (ar.exception instanceof CommandException) {
862 loge("queryModemActivityInfo: CommandException: " +
863 ar.exception);
864 } else {
865 loge("queryModemActivityInfo: Unknown exception");
866 }
867 }
Amit Mahajand4766222016-01-28 15:28:28 -0800868 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
869 if (request.result == null) {
870 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
871 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700872 synchronized (request) {
873 request.notifyAll();
874 }
875 break;
876
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 case CMD_SET_ALLOWED_CARRIERS:
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
880 mPhone.setAllowedCarriers(
881 (List<CarrierIdentifier>) request.argument,
882 onCompleted);
883 break;
884
885 case EVENT_SET_ALLOWED_CARRIERS_DONE:
886 ar = (AsyncResult) msg.obj;
887 request = (MainThreadRequest) ar.userObj;
888 if (ar.exception == null && ar.result != null) {
889 request.result = ar.result;
890 } else {
891 if (ar.result == null) {
892 loge("setAllowedCarriers: Empty response");
893 } else if (ar.exception instanceof CommandException) {
894 loge("setAllowedCarriers: CommandException: " +
895 ar.exception);
896 } else {
897 loge("setAllowedCarriers: Unknown exception");
898 }
899 }
900 // Result cannot be null. Return -1 on error.
901 if (request.result == null) {
902 request.result = new int[]{-1};
903 }
904 synchronized (request) {
905 request.notifyAll();
906 }
907 break;
908
909 case CMD_GET_ALLOWED_CARRIERS:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
912 mPhone.getAllowedCarriers(onCompleted);
913 break;
914
915 case EVENT_GET_ALLOWED_CARRIERS_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null && ar.result != null) {
919 request.result = ar.result;
920 } else {
921 if (ar.result == null) {
922 loge("getAllowedCarriers: Empty response");
923 } else if (ar.exception instanceof CommandException) {
924 loge("getAllowedCarriers: CommandException: " +
925 ar.exception);
926 } else {
927 loge("getAllowedCarriers: Unknown exception");
928 }
929 }
930 // Result cannot be null. Return empty list of CarrierIdentifier.
931 if (request.result == null) {
932 request.result = new ArrayList<CarrierIdentifier>(0);
933 }
934 synchronized (request) {
935 request.notifyAll();
936 }
937 break;
938
Nathan Haroldb3014052017-01-25 15:57:32 -0800939 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
940 ar = (AsyncResult) msg.obj;
941 request = (MainThreadRequest) ar.userObj;
942 if (ar.exception == null && ar.result != null) {
943 request.result = ar.result;
944 } else {
945 request.result = new IllegalArgumentException(
946 "Failed to retrieve Forbidden Plmns");
947 if (ar.result == null) {
948 loge("getForbiddenPlmns: Empty response");
949 } else {
950 loge("getForbiddenPlmns: Unknown exception");
951 }
952 }
953 synchronized (request) {
954 request.notifyAll();
955 }
956 break;
957
958 case CMD_GET_FORBIDDEN_PLMNS:
959 request = (MainThreadRequest) msg.obj;
960 uiccCard = getUiccCardFromRequest(request);
961 if (uiccCard == null) {
962 loge("getForbiddenPlmns() UiccCard is null");
963 request.result = new IllegalArgumentException(
964 "getForbiddenPlmns() UiccCard is null");
965 synchronized (request) {
966 request.notifyAll();
967 }
968 break;
969 }
970 Integer appType = (Integer) request.argument;
971 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
972 if (uiccApp == null) {
973 loge("getForbiddenPlmns() no app with specified type -- "
974 + appType);
975 request.result = new IllegalArgumentException("Failed to get UICC App");
976 synchronized (request) {
977 request.notifyAll();
978 }
979 break;
980 } else {
981 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
982 + " specified type -- " + appType);
983 }
984 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
985 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
986 onCompleted);
987 break;
988
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000989 case CMD_SWITCH_SLOTS:
990 request = (MainThreadRequest) msg.obj;
991 int[] physicalSlots = (int[]) request.argument;
992 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
993 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
994 break;
995
996 case EVENT_SWITCH_SLOTS_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = (ar.exception == null);
1000 synchronized (request) {
1001 request.notifyAll();
1002 }
1003 break;
1004
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001005 default:
1006 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1007 break;
1008 }
1009 }
Jake Hambye994d462014-02-03 13:10:13 -08001010
1011 private void handleNullReturnEvent(Message msg, String command) {
1012 AsyncResult ar = (AsyncResult) msg.obj;
1013 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1014 if (ar.exception == null) {
1015 request.result = true;
1016 } else {
1017 request.result = false;
1018 if (ar.exception instanceof CommandException) {
1019 loge(command + ": CommandException: " + ar.exception);
1020 } else {
1021 loge(command + ": Unknown exception");
1022 }
1023 }
1024 synchronized (request) {
1025 request.notifyAll();
1026 }
1027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001028 }
1029
1030 /**
1031 * Posts the specified command to be executed on the main thread,
1032 * waits for the request to complete, and returns the result.
1033 * @see #sendRequestAsync
1034 */
1035 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001036 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001037 }
1038
1039 /**
1040 * Posts the specified command to be executed on the main thread,
1041 * waits for the request to complete, and returns the result.
1042 * @see #sendRequestAsync
1043 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001044 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1046 throw new RuntimeException("This method will deadlock if called from the main thread.");
1047 }
1048
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001049 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001050 Message msg = mMainThreadHandler.obtainMessage(command, request);
1051 msg.sendToTarget();
1052
1053 // Wait for the request to complete
1054 synchronized (request) {
1055 while (request.result == null) {
1056 try {
1057 request.wait();
1058 } catch (InterruptedException e) {
1059 // Do nothing, go back and wait until the request is complete
1060 }
1061 }
1062 }
1063 return request.result;
1064 }
1065
1066 /**
1067 * Asynchronous ("fire and forget") version of sendRequest():
1068 * Posts the specified command to be executed on the main thread, and
1069 * returns immediately.
1070 * @see #sendRequest
1071 */
1072 private void sendRequestAsync(int command) {
1073 mMainThreadHandler.sendEmptyMessage(command);
1074 }
1075
1076 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001077 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1078 * @see {@link #sendRequest(int,Object)}
1079 */
1080 private void sendRequestAsync(int command, Object argument) {
1081 MainThreadRequest request = new MainThreadRequest(argument);
1082 Message msg = mMainThreadHandler.obtainMessage(command, request);
1083 msg.sendToTarget();
1084 }
1085
1086 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 * Initialize the singleton PhoneInterfaceManager instance.
1088 * This is only done once, at startup, from PhoneApp.onCreate().
1089 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001090 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 synchronized (PhoneInterfaceManager.class) {
1092 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001093 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001094 } else {
1095 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1096 }
1097 return sInstance;
1098 }
1099 }
1100
1101 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001102 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 mApp = app;
1104 mPhone = phone;
1105 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001106 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001107 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1108 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001109 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001110 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001111 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001112 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001113
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 publish();
1115 }
1116
1117 private void publish() {
1118 if (DBG) log("publish: " + this);
1119
1120 ServiceManager.addService("phone", this);
1121 }
1122
Stuart Scott584921c2015-01-15 17:10:34 -08001123 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001124 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1125 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001126 }
1127
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001128 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1129 Phone phone = getPhoneFromRequest(request);
1130 return phone == null ? null :
1131 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1132 }
1133
Wink Saville36469e72014-06-11 15:17:00 -07001134 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001135 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001136 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 //
1139 // Implementation of the ITelephony interface.
1140 //
1141
1142 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001143 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001144 }
1145
Wink Savilleb564aae2014-10-23 10:18:09 -07001146 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001147 if (DBG) log("dial: " + number);
1148 // No permission check needed here: This is just a wrapper around the
1149 // ACTION_DIAL intent, which is available to any app since it puts up
1150 // the UI before it does anything.
1151
1152 String url = createTelUrl(number);
1153 if (url == null) {
1154 return;
1155 }
1156
1157 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001158 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001159 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1160 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1161 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1162 mApp.startActivity(intent);
1163 }
1164 }
1165
1166 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001167 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001168 }
1169
Wink Savilleb564aae2014-10-23 10:18:09 -07001170 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 if (DBG) log("call: " + number);
1172
1173 // This is just a wrapper around the ACTION_CALL intent, but we still
1174 // need to do a permission check since we're calling startActivity()
1175 // from the context of the phone app.
1176 enforceCallPermission();
1177
1178 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1179 != AppOpsManager.MODE_ALLOWED) {
1180 return;
1181 }
1182
1183 String url = createTelUrl(number);
1184 if (url == null) {
1185 return;
1186 }
1187
Wink Saville08874612014-08-31 19:19:58 -07001188 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001189 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001190 if (slist != null) {
1191 for (SubscriptionInfo subInfoRecord : slist) {
1192 if (subInfoRecord.getSubscriptionId() == subId) {
1193 isValid = true;
1194 break;
1195 }
Wink Saville08874612014-08-31 19:19:58 -07001196 }
1197 }
1198 if (isValid == false) {
1199 return;
1200 }
1201
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001203 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1205 mApp.startActivity(intent);
1206 }
1207
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001208 /**
1209 * End a call based on call state
1210 * @return true is a call was ended
1211 */
1212 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001213 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001214 }
1215
1216 /**
1217 * End a call based on the call state of the subId
1218 * @return true is a call was ended
1219 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001220 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001221 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1222 != PackageManager.PERMISSION_GRANTED) {
1223 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1224 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1225 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1226 }
Stuart Scott584921c2015-01-15 17:10:34 -08001227 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 }
1229
1230 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001231 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001232 }
1233
Wink Savilleb564aae2014-10-23 10:18:09 -07001234 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 if (DBG) log("answerRingingCall...");
1236 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1237 // but that can probably wait till the big TelephonyManager API overhaul.
1238 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1239 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001240 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 }
1242
1243 /**
1244 * Make the actual telephony calls to implement answerRingingCall().
1245 * This should only be called from the main thread of the Phone app.
1246 * @see #answerRingingCall
1247 *
1248 * TODO: it would be nice to return true if we answered the call, or
1249 * false if there wasn't actually a ringing incoming call, or some
1250 * other error occurred. (In other words, pass back the return value
1251 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1252 * But that would require calling this method via sendRequest() rather
1253 * than sendRequestAsync(), and right now we don't actually *need* that
1254 * return value, so let's just return void for now.
1255 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001256 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001257 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001259 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1260 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 if (hasActiveCall && hasHoldingCall) {
1262 // Both lines are in use!
1263 // TODO: provide a flag to let the caller specify what
1264 // policy to use if both lines are in use. (The current
1265 // behavior is hardwired to "answer incoming, end ongoing",
1266 // which is how the CALL button is specced to behave.)
1267 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1268 return;
1269 } else {
1270 // answerCall() will automatically hold the current active
1271 // call, if there is one.
1272 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1273 return;
1274 }
1275 } else {
1276 // No call was ringing.
1277 return;
1278 }
1279 }
1280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001282 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001284 public void silenceRinger() {
1285 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 }
1287
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 @Override
1289 public boolean isOffhook(String callingPackage) {
1290 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001291 }
1292
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001293 @Override
1294 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001296 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001297 return false;
1298 }
1299
Sanket Padawe356d7632015-06-22 14:03:32 -07001300 final Phone phone = getPhone(subId);
1301 if (phone != null) {
1302 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1303 } else {
1304 return false;
1305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 }
1307
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001308 @Override
1309 public boolean isRinging(String callingPackage) {
1310 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001311 }
1312
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001313 @Override
1314 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001316 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001317 return false;
1318 }
1319
Sanket Padawe356d7632015-06-22 14:03:32 -07001320 final Phone phone = getPhone(subId);
1321 if (phone != null) {
1322 return (phone.getState() == PhoneConstants.State.RINGING);
1323 } else {
1324 return false;
1325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 }
1327
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001328 @Override
1329 public boolean isIdle(String callingPackage) {
1330 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001331 }
1332
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001333 @Override
1334 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001336 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001337 return false;
1338 }
1339
Sanket Padawe356d7632015-06-22 14:03:32 -07001340 final Phone phone = getPhone(subId);
1341 if (phone != null) {
1342 return (phone.getState() == PhoneConstants.State.IDLE);
1343 } else {
1344 return false;
1345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001346 }
1347
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001349 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001350 }
1351
Wink Savilleb564aae2014-10-23 10:18:09 -07001352 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001353 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001354 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1355 }
1356
1357 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001358 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001359 }
1360
Wink Savilleb564aae2014-10-23 10:18:09 -07001361 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001362 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001363 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1364 }
1365
1366 /** {@hide} */
1367 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001368 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001369 }
1370
Wink Savilleb564aae2014-10-23 10:18:09 -07001371 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001373 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 checkSimPin.start();
1375 return checkSimPin.unlockSim(null, pin);
1376 }
1377
Wink Saville9de0f752013-10-22 19:04:03 -07001378 /** {@hide} */
1379 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001380 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001381 }
1382
Wink Savilleb564aae2014-10-23 10:18:09 -07001383 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001385 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 checkSimPuk.start();
1387 return checkSimPuk.unlockSim(puk, pin);
1388 }
1389
1390 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001391 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 * a synchronous one.
1393 */
1394 private static class UnlockSim extends Thread {
1395
1396 private final IccCard mSimCard;
1397
1398 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001399 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1400 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401
1402 // For replies from SimCard interface
1403 private Handler mHandler;
1404
1405 // For async handler to identify request type
1406 private static final int SUPPLY_PIN_COMPLETE = 100;
1407
1408 public UnlockSim(IccCard simCard) {
1409 mSimCard = simCard;
1410 }
1411
1412 @Override
1413 public void run() {
1414 Looper.prepare();
1415 synchronized (UnlockSim.this) {
1416 mHandler = new Handler() {
1417 @Override
1418 public void handleMessage(Message msg) {
1419 AsyncResult ar = (AsyncResult) msg.obj;
1420 switch (msg.what) {
1421 case SUPPLY_PIN_COMPLETE:
1422 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1423 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001424 mRetryCount = msg.arg1;
1425 if (ar.exception != null) {
1426 if (ar.exception instanceof CommandException &&
1427 ((CommandException)(ar.exception)).getCommandError()
1428 == CommandException.Error.PASSWORD_INCORRECT) {
1429 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1430 } else {
1431 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1432 }
1433 } else {
1434 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001436 mDone = true;
1437 UnlockSim.this.notifyAll();
1438 }
1439 break;
1440 }
1441 }
1442 };
1443 UnlockSim.this.notifyAll();
1444 }
1445 Looper.loop();
1446 }
1447
1448 /*
1449 * Use PIN or PUK to unlock SIM card
1450 *
1451 * If PUK is null, unlock SIM card with PIN
1452 *
1453 * If PUK is not null, unlock SIM card with PUK and set PIN code
1454 */
Wink Saville9de0f752013-10-22 19:04:03 -07001455 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456
1457 while (mHandler == null) {
1458 try {
1459 wait();
1460 } catch (InterruptedException e) {
1461 Thread.currentThread().interrupt();
1462 }
1463 }
1464 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1465
1466 if (puk == null) {
1467 mSimCard.supplyPin(pin, callback);
1468 } else {
1469 mSimCard.supplyPuk(puk, pin, callback);
1470 }
1471
1472 while (!mDone) {
1473 try {
1474 Log.d(LOG_TAG, "wait for done");
1475 wait();
1476 } catch (InterruptedException e) {
1477 // Restore the interrupted status
1478 Thread.currentThread().interrupt();
1479 }
1480 }
1481 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001482 int[] resultArray = new int[2];
1483 resultArray[0] = mResult;
1484 resultArray[1] = mRetryCount;
1485 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 }
1487 }
1488
1489 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001490 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001491
1492 }
1493
Wink Savilleb564aae2014-10-23 10:18:09 -07001494 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 // No permission check needed here: this call is harmless, and it's
1496 // needed for the ServiceState.requestStateUpdate() call (which is
1497 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001498 final Phone phone = getPhone(subId);
1499 if (phone != null) {
1500 phone.updateServiceLocation();
1501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 }
1503
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001504 @Override
1505 public boolean isRadioOn(String callingPackage) {
1506 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001507 }
1508
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001509 @Override
1510 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001511 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001512 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001513 return false;
1514 }
1515 return isRadioOnForSubscriber(subId);
1516 }
1517
1518 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001519 final Phone phone = getPhone(subId);
1520 if (phone != null) {
1521 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1522 } else {
1523 return false;
1524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 }
1526
1527 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001528 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001529
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 }
Wink Saville36469e72014-06-11 15:17:00 -07001531
Wink Savilleb564aae2014-10-23 10:18:09 -07001532 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001534 final Phone phone = getPhone(subId);
1535 if (phone != null) {
1536 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1537 }
Wink Saville36469e72014-06-11 15:17:00 -07001538 }
1539
1540 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001541 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001545 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001546 final Phone phone = getPhone(subId);
1547 if (phone == null) {
1548 return false;
1549 }
1550 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001551 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001552 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 }
1554 return true;
1555 }
Wink Saville36469e72014-06-11 15:17:00 -07001556
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001557 public boolean needMobileRadioShutdown() {
1558 /*
1559 * If any of the Radios are available, it will need to be
1560 * shutdown. So return true if any Radio is available.
1561 */
1562 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1563 Phone phone = PhoneFactory.getPhone(i);
1564 if (phone != null && phone.isRadioAvailable()) return true;
1565 }
1566 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1567 return false;
1568 }
1569
1570 public void shutdownMobileRadios() {
1571 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1572 logv("Shutting down Phone " + i);
1573 shutdownRadioUsingPhoneId(i);
1574 }
1575 }
1576
1577 private void shutdownRadioUsingPhoneId(int phoneId) {
1578 enforceModifyPermission();
1579 Phone phone = PhoneFactory.getPhone(phoneId);
1580 if (phone != null && phone.isRadioAvailable()) {
1581 phone.shutdownRadio();
1582 }
1583 }
1584
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001586 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001587 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1588 if (defaultPhone != null) {
1589 defaultPhone.setRadioPower(turnOn);
1590 return true;
1591 } else {
1592 loge("There's no default phone.");
1593 return false;
1594 }
Wink Saville36469e72014-06-11 15:17:00 -07001595 }
1596
Wink Savilleb564aae2014-10-23 10:18:09 -07001597 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 final Phone phone = getPhone(subId);
1600 if (phone != null) {
1601 phone.setRadioPower(turnOn);
1602 return true;
1603 } else {
1604 return false;
1605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 }
1607
Wink Saville36469e72014-06-11 15:17:00 -07001608 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 public boolean enableDataConnectivity() {
1611 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001612 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001613 final Phone phone = getPhone(subId);
1614 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001615 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 return true;
1617 } else {
1618 return false;
1619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Wink Saville36469e72014-06-11 15:17:00 -07001622 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 public boolean disableDataConnectivity() {
1625 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001626 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001627 final Phone phone = getPhone(subId);
1628 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001629 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 return true;
1631 } else {
1632 return false;
1633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 }
1635
Sanket Padawe356d7632015-06-22 14:03:32 -07001636 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001637 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 final Phone phone = getPhone(subId);
1639 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001640 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001641 } else {
1642 return false;
1643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 }
1645
1646 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001647 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001648 }
1649
pkanwarae03a6b2016-11-06 20:37:09 -08001650 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001651 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001652 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1653 return;
1654 }
1655 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1656 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1657 };
1658
Wink Savilleb564aae2014-10-23 10:18:09 -07001659 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001661 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1662 return false;
1663 }
Wink Saville36469e72014-06-11 15:17:00 -07001664 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 }
1666
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001668 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001669 }
1670
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001671 public int getCallStateForSlot(int slotIndex) {
1672 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001673 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001674 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 }
1676
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001679 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001680 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001681 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001682 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001683 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 }
1686
Sanket Padawe356d7632015-06-22 14:03:32 -07001687 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001689 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001690 if (phone != null) {
1691 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1692 } else {
1693 return TelephonyManager.DATA_ACTIVITY_NONE;
1694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 }
1696
1697 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001698 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001699 mPhone.getContext().getSystemService(AppOpsManager.class)
1700 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001701 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001702 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001703 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001706 if (DBG_LOC) log("getCellLocation: is active user");
1707 Bundle data = new Bundle();
1708 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1709 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 return null;
1711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001713 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001714 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1715 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001716 }
1717
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001719 public String getNetworkCountryIsoForPhone(int phoneId) {
1720 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1721 // registered cell info, so return a NULL country instead.
1722 final long identity = Binder.clearCallingIdentity();
1723 try {
1724 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001725 // Todo: fix this when we can get the actual cellular network info when the device
1726 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001727 if (TelephonyManager.NETWORK_TYPE_IWLAN
1728 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1729 return "";
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
1733 }
Jack Yu5f7092c2018-04-13 14:05:37 -07001734
1735 Phone phone = PhoneFactory.getPhone(phoneId);
1736 if (phone != null) {
1737 ServiceStateTracker sst = phone.getServiceStateTracker();
1738 if (sst != null) {
1739 LocaleTracker lt = sst.getLocaleTracker();
1740 if (lt != null) {
1741 return lt.getCurrentCountry();
1742 }
1743 }
1744 }
1745 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001746 }
1747
1748 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001750 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001751 }
1752
Sanket Padawe356d7632015-06-22 14:03:32 -07001753 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 mApp.enforceCallingOrSelfPermission(
1756 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001757 final Phone phone = getPhone(subId);
1758 if (phone != null) {
1759 phone.enableLocationUpdates();
1760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 }
1762
1763 @Override
1764 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001765 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001769 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 mApp.enforceCallingOrSelfPermission(
1771 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 final Phone phone = getPhone(subId);
1773 if (phone != null) {
1774 phone.disableLocationUpdates();
1775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 }
1777
1778 @Override
1779 @SuppressWarnings("unchecked")
1780 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001781 mPhone.getContext().getSystemService(AppOpsManager.class)
1782 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001783 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001784 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001785 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 }
1787
1788 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1789 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1790 return null;
1791 }
Svetoslav64fad262015-04-14 14:35:21 -07001792
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001793 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001795 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001797 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001798 try {
1799 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1800 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1801 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1802 } catch (RuntimeException e) {
1803 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001805 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 }
1807
1808
1809 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001810 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001811 mPhone.getContext().getSystemService(AppOpsManager.class)
1812 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001813 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001814 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001815 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 }
1817
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001818 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001819 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001820 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1821 for (Phone phone : PhoneFactory.getPhones()) {
1822 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1823 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001825 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 }
1827
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001828 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001830 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001831 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001832 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 }
1834
Shishir Agrawala9f32182016-04-12 12:00:16 -07001835 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001836 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001837 Phone phone = PhoneFactory.getPhone(slotIndex);
1838 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001839 return null;
1840 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001841 int subId = phone.getSubId();
1842 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1843 mApp, subId, callingPackage, "getImeiForSlot")) {
1844 return null;
1845 }
1846 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001847 }
1848
1849 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001850 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001851 Phone phone = PhoneFactory.getPhone(slotIndex);
1852 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001853 return null;
1854 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001855 int subId = phone.getSubId();
1856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1857 mApp, subId, callingPackage, "getMeidForSlot")) {
1858 return null;
1859 }
1860 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001861 }
1862
1863 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001864 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001865 Phone phone = PhoneFactory.getPhone(slotIndex);
1866 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001867 return null;
1868 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001869 int subId = phone.getSubId();
1870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1871 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1872 return null;
1873 }
1874 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001875 }
1876
fionaxu43304da2017-11-27 22:51:16 -08001877 @Override
1878 public int getSubscriptionCarrierId(int subId) {
1879 final Phone phone = getPhone(subId);
1880 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1881 }
1882
1883 @Override
1884 public String getSubscriptionCarrierName(int subId) {
1885 final Phone phone = getPhone(subId);
1886 return phone == null ? null : phone.getCarrierName();
1887 }
1888
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 //
1890 // Internal helper methods.
1891 //
1892
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001893 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1895 *
1896 * @throws SecurityException if the caller does not have the required permission
1897 */
1898 private void enforceModifyPermission() {
1899 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1900 }
1901
1902 /**
1903 * Make sure the caller has the CALL_PHONE permission.
1904 *
1905 * @throws SecurityException if the caller does not have the required permission
1906 */
1907 private void enforceCallPermission() {
1908 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1909 }
1910
Stuart Scott8eef64f2015-04-08 15:13:54 -07001911 private void enforceConnectivityInternalPermission() {
1912 mApp.enforceCallingOrSelfPermission(
1913 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1914 "ConnectivityService");
1915 }
1916
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 private String createTelUrl(String number) {
1918 if (TextUtils.isEmpty(number)) {
1919 return null;
1920 }
1921
Jake Hambye994d462014-02-03 13:10:13 -08001922 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 }
1924
Ihab Awadf9e92732013-12-05 18:02:52 -08001925 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1927 }
1928
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001929 private static void logv(String msg) {
1930 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1931 }
1932
Ihab Awadf9e92732013-12-05 18:02:52 -08001933 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1935 }
1936
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001937 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001939 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001940 }
1941
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001943 public int getActivePhoneTypeForSlot(int slotIndex) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00001944 final Phone phone = PhoneFactory.getPhone(slotIndex);
1945 if (phone == null) {
1946 return PhoneConstants.PHONE_TYPE_NONE;
1947 } else {
1948 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 }
1951
1952 /**
1953 * Returns the CDMA ERI icon index to display
1954 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001955 @Override
1956 public int getCdmaEriIconIndex(String callingPackage) {
1957 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001958 }
1959
Sanket Padawe356d7632015-06-22 14:03:32 -07001960 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001961 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001963 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001964 return -1;
1965 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001966 final Phone phone = getPhone(subId);
1967 if (phone != null) {
1968 return phone.getCdmaEriIconIndex();
1969 } else {
1970 return -1;
1971 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 }
1973
1974 /**
1975 * Returns the CDMA ERI icon mode,
1976 * 0 - ON
1977 * 1 - FLASHING
1978 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001979 @Override
1980 public int getCdmaEriIconMode(String callingPackage) {
1981 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001982 }
1983
Sanket Padawe356d7632015-06-22 14:03:32 -07001984 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001985 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001987 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001988 return -1;
1989 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 final Phone phone = getPhone(subId);
1991 if (phone != null) {
1992 return phone.getCdmaEriIconMode();
1993 } else {
1994 return -1;
1995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
1998 /**
1999 * Returns the CDMA ERI text,
2000 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002001 @Override
2002 public String getCdmaEriText(String callingPackage) {
2003 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002004 }
2005
Sanket Padawe356d7632015-06-22 14:03:32 -07002006 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002007 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002009 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002010 return null;
2011 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002012 final Phone phone = getPhone(subId);
2013 if (phone != null) {
2014 return phone.getCdmaEriText();
2015 } else {
2016 return null;
2017 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 }
2019
2020 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002021 * Returns the CDMA MDN.
2022 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002023 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002024 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2026 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07002027 final Phone phone = getPhone(subId);
2028 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2029 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002030 } else {
2031 return null;
2032 }
2033 }
2034
2035 /**
2036 * Returns the CDMA MIN.
2037 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002038 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002039 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2041 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002042 final Phone phone = getPhone(subId);
2043 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2044 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002045 } else {
2046 return null;
2047 }
2048 }
2049
2050 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 * Returns true if CDMA provisioning needs to run.
2052 */
2053 public boolean needsOtaServiceProvisioning() {
2054 return mPhone.needsOtaServiceProvisioning();
2055 }
2056
2057 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002058 * Sets the voice mail number of a given subId.
2059 */
2060 @Override
2061 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002062 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002063 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2064 new Pair<String, String>(alphaTag, number), new Integer(subId));
2065 return success;
2066 }
2067
Ta-wei Yen87c49842016-05-13 21:19:52 -07002068 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002069 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2070 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2071 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2072 if (!TextUtils.equals(callingPackage, systemDialer)) {
2073 throw new SecurityException("caller must be system dialer");
2074 }
2075 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2076 if (phoneAccountHandle == null){
2077 return null;
2078 }
2079 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2080 }
2081
2082 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002083 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002084 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002086 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002087 return null;
2088 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002089 final long identity = Binder.clearCallingIdentity();
2090 try {
2091 return RemoteVvmTaskManager
2092 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2093 } finally {
2094 Binder.restoreCallingIdentity(identity);
2095 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002096 }
2097
2098 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002099 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2100 VisualVoicemailSmsFilterSettings settings) {
2101 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002102 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002103 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2104 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002105 }
2106
2107 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002108 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2109 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002110 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002111 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002112 }
2113
2114 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002115 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2116 String callingPackage, int subId) {
2117 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002118 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002119 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002120 }
2121
2122 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002123 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002124 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002125 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002126 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2127 }
2128
2129 @Override
2130 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2131 String number, int port, String text, PendingIntent sentIntent) {
2132 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002133 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002134 enforceSendSmsPermission();
2135 // Make the calls as the phone process.
2136 final long identity = Binder.clearCallingIdentity();
2137 try {
2138 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2139 if (port == 0) {
2140 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2141 sentIntent, null, false);
2142 } else {
2143 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2144 smsManager.sendDataMessageWithSelfPermissions(number, null,
2145 (short) port, data, sentIntent, null);
2146 }
2147 } finally {
2148 Binder.restoreCallingIdentity(identity);
2149 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002150 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002151 /**
fionaxu0152e512016-11-14 13:36:14 -08002152 * Sets the voice activation state of a given subId.
2153 */
2154 @Override
2155 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2157 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002158 final Phone phone = getPhone(subId);
2159 if (phone != null) {
2160 phone.setVoiceActivationState(activationState);
2161 } else {
2162 loge("setVoiceActivationState fails with invalid subId: " + subId);
2163 }
2164 }
2165
2166 /**
2167 * Sets the data activation state of a given subId.
2168 */
2169 @Override
2170 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2172 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002173 final Phone phone = getPhone(subId);
2174 if (phone != null) {
2175 phone.setDataActivationState(activationState);
2176 } else {
2177 loge("setVoiceActivationState fails with invalid subId: " + subId);
2178 }
2179 }
2180
2181 /**
2182 * Returns the voice activation state of a given subId.
2183 */
2184 @Override
2185 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002186 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002187 final Phone phone = getPhone(subId);
2188 if (phone != null) {
2189 return phone.getVoiceActivationState();
2190 } else {
2191 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2192 }
2193 }
2194
2195 /**
2196 * Returns the data activation state of a given subId.
2197 */
2198 @Override
2199 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002200 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002201 final Phone phone = getPhone(subId);
2202 if (phone != null) {
2203 return phone.getDataActivationState();
2204 } else {
2205 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2206 }
2207 }
2208
2209 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 * Returns the unread count of voicemails
2211 */
2212 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002213 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002214 }
2215
2216 /**
2217 * Returns the unread count of voicemails for a subId
2218 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002220 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 final Phone phone = getPhone(subId);
2222 if (phone != null) {
2223 return phone.getVoiceMessageCount();
2224 } else {
2225 return 0;
2226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 }
2228
2229 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002230 * returns true, if the device is in a state where both voice and data
2231 * are supported simultaneously. This can change based on location or network condition.
2232 */
2233 @Override
2234 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2235 final Phone phone = getPhone(subId);
2236 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2237 }
2238
2239 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002240 * Send the dialer code if called from the current default dialer or the caller has
2241 * carrier privilege.
2242 * @param inputCode The dialer code to send
2243 */
2244 @Override
2245 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2246 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2247 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2248 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002249 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2250 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002251 }
2252 mPhone.sendDialerSpecialCode(inputCode);
2253 }
2254
2255 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002256 * Returns the data network type.
2257 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 *
2259 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2260 */
2261 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002262 public int getNetworkType() {
2263 final Phone phone = getPhone(getDefaultSubscription());
2264 if (phone != null) {
2265 return phone.getServiceState().getDataNetworkType();
2266 } else {
2267 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2268 }
Wink Saville36469e72014-06-11 15:17:00 -07002269 }
2270
2271 /**
2272 * Returns the network type for a subId
2273 */
2274 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002275 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002277 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002278 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2279 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002280
Sanket Padawe356d7632015-06-22 14:03:32 -07002281 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002282 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 return phone.getServiceState().getDataNetworkType();
2284 } else {
2285 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 }
2288
2289 /**
2290 * Returns the data network type
2291 */
2292 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002293 public int getDataNetworkType(String callingPackage) {
2294 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002295 }
2296
2297 /**
2298 * Returns the data network type for a subId
2299 */
2300 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002303 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002304 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2305 }
2306
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 final Phone phone = getPhone(subId);
2308 if (phone != null) {
2309 return phone.getServiceState().getDataNetworkType();
2310 } else {
2311 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
2315 /**
Wink Saville36469e72014-06-11 15:17:00 -07002316 * Returns the Voice network type for a subId
2317 */
2318 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002319 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002321 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002322 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2323 }
2324
Sanket Padawe356d7632015-06-22 14:03:32 -07002325 final Phone phone = getPhone(subId);
2326 if (phone != null) {
2327 return phone.getServiceState().getVoiceNetworkType();
2328 } else {
2329 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 }
2332
2333 /**
2334 * @return true if a ICC card is present
2335 */
2336 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002337 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002338 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2339 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002340 }
2341
2342 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002343 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002344 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002345 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002346 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2347 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002348 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002349 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002350 } else {
2351 return false;
2352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
2355 /**
2356 * Return if the current radio is LTE on CDMA. This
2357 * is a tri-state return value as for a period of time
2358 * the mode may be unknown.
2359 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002360 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002362 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002364 @Override
2365 public int getLteOnCdmaMode(String callingPackage) {
2366 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002367 }
2368
Sanket Padawe356d7632015-06-22 14:03:32 -07002369 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002370 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002372 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002373 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2374 }
2375
Sanket Padawe356d7632015-06-22 14:03:32 -07002376 final Phone phone = getPhone(subId);
2377 if (phone == null) {
2378 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2379 } else {
2380 return phone.getLteOnCdmaMode();
2381 }
Wink Saville36469e72014-06-11 15:17:00 -07002382 }
2383
2384 public void setPhone(Phone phone) {
2385 mPhone = phone;
2386 }
2387
2388 /**
2389 * {@hide}
2390 * Returns Default subId, 0 in the case of single standby.
2391 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002392 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002393 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002394 }
2395
Shishir Agrawala9f32182016-04-12 12:00:16 -07002396 private int getSlotForDefaultSubscription() {
2397 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2398 }
2399
Wink Savilleb564aae2014-10-23 10:18:09 -07002400 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002401 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002403
2404 /**
2405 * @see android.telephony.TelephonyManager.WifiCallingChoices
2406 */
2407 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002408 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2409 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002410 }
2411
2412 /**
2413 * @see android.telephony.TelephonyManager.WifiCallingChoices
2414 */
2415 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002416 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2417 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2418 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002419 }
2420
Sailesh Nepald1e68152013-12-12 19:08:02 -08002421 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002422 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002423 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002424 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002425
Shishir Agrawal566b7612013-10-28 14:41:00 -07002426 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002427 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2428 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2430 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002431
Derek Tan740e1672017-06-27 14:56:27 -07002432 if (TextUtils.equals(ISDR_AID, aid)) {
2433 // Only allows LPA to open logical channel to ISD-R.
2434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2435 ComponentInfo bestComponent =
2436 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2437 if (bestComponent == null
2438 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2439 loge("The calling package is not allowed to access ISD-R.");
2440 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2441 }
2442 }
2443
2444 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002445 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002446 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002447 if (DBG) log("iccOpenLogicalChannel: " + response);
2448 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002449 }
2450
2451 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002452 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2454 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002455
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002456 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002457 if (channel < 0) {
2458 return false;
2459 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002460 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002461 if (DBG) log("iccCloseLogicalChannel: " + success);
2462 return success;
2463 }
2464
2465 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002466 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002467 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2469 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002470
2471 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002472 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2473 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002474 " data=" + data);
2475 }
2476
2477 if (channel < 0) {
2478 return "";
2479 }
2480
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002481 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002482 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002483 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2484
Shishir Agrawal566b7612013-10-28 14:41:00 -07002485 // Append the returned status code to the end of the response payload.
2486 String s = Integer.toHexString(
2487 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002488 if (response.payload != null) {
2489 s = IccUtils.bytesToHexString(response.payload) + s;
2490 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002491 return s;
2492 }
Jake Hambye994d462014-02-03 13:10:13 -08002493
Evan Charltonc66da362014-05-16 14:06:40 -07002494 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002495 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2496 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2498 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002499
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002500 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2501 && TextUtils.equals(ISDR_AID, data)) {
2502 // Only allows LPA to select ISD-R.
2503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2504 ComponentInfo bestComponent =
2505 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2506 if (bestComponent == null
2507 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2508 loge("The calling package is not allowed to select ISD-R.");
2509 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2510 }
2511 }
2512
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002513 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002514 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2515 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002516 }
2517
2518 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002520 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2521
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002522 // Append the returned status code to the end of the response payload.
2523 String s = Integer.toHexString(
2524 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002525 if (response.payload != null) {
2526 s = IccUtils.bytesToHexString(response.payload) + s;
2527 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002528 return s;
2529 }
2530
2531 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002532 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002533 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2535 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002536
2537 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002538 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002539 p1 + " " + p2 + " " + p3 + ":" + filePath);
2540 }
2541
2542 IccIoResult response =
2543 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002544 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2545 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002546
2547 if (DBG) {
2548 log("Exchange SIM_IO [R]" + response);
2549 }
2550
2551 byte[] result = null;
2552 int length = 2;
2553 if (response.payload != null) {
2554 length = 2 + response.payload.length;
2555 result = new byte[length];
2556 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2557 } else {
2558 result = new byte[length];
2559 }
2560
2561 result[length - 1] = (byte) response.sw2;
2562 result[length - 2] = (byte) response.sw1;
2563 return result;
2564 }
2565
Nathan Haroldb3014052017-01-25 15:57:32 -08002566 /**
2567 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2568 * on a particular subscription
2569 */
sqianb6e41952018-03-12 14:54:01 -07002570 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2572 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2573 return null;
2574 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002575 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2576 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2577 return null;
2578 }
2579 Object response = sendRequest(
2580 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2581 if (response instanceof String[]) {
2582 return (String[]) response;
2583 }
2584 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2585 return null;
2586 }
2587
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002588 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002589 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2591 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002592
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002593 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002594 if (response.payload == null) {
2595 return "";
2596 }
2597
2598 // Append the returned status code to the end of the response payload.
2599 String s = Integer.toHexString(
2600 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2601 s = IccUtils.bytesToHexString(response.payload) + s;
2602 return s;
2603 }
2604
Jake Hambye994d462014-02-03 13:10:13 -08002605 /**
2606 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2607 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2608 *
2609 * @param itemID the ID of the item to read
2610 * @return the NV item as a String, or null on error.
2611 */
2612 @Override
2613 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2615 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002616 if (DBG) log("nvReadItem: item " + itemID);
2617 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2618 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2619 return value;
2620 }
2621
2622 /**
2623 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2624 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2625 *
2626 * @param itemID the ID of the item to read
2627 * @param itemValue the value to write, as a String
2628 * @return true on success; false on any failure
2629 */
2630 @Override
2631 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2633 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002634 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2635 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2636 new Pair<Integer, String>(itemID, itemValue));
2637 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2638 return success;
2639 }
2640
2641 /**
2642 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2643 * Used for device configuration by some CDMA operators.
2644 *
2645 * @param preferredRoamingList byte array containing the new PRL
2646 * @return true on success; false on any failure
2647 */
2648 @Override
2649 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2651 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002652 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2653 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2654 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2655 return success;
2656 }
2657
2658 /**
2659 * Perform the specified type of NV config reset.
2660 * Used for device configuration by some CDMA operators.
2661 *
2662 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2663 * @return true on success; false on any failure
2664 */
2665 @Override
2666 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2668 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002669 if (DBG) log("nvResetConfig: type " + resetType);
2670 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2671 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2672 return success;
2673 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002674
Svet Ganovb320e182015-04-16 12:30:10 -07002675 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002676 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002677 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002678 return new String[0];
2679 }
2680
2681
ram87fca6f2014-07-18 18:58:44 +05302682 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002683 }
2684
Brad Ebinger51f743a2017-01-23 13:50:20 -08002685 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002686 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2687 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002688 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002689 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002690 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002691 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002692 }
2693
2694 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002695 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2696 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002697 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002698 public void disableIms(int slotId) {
2699 enforceModifyPermission();
2700 PhoneFactory.getImsResolver().disableIms(slotId);
2701 }
2702
2703 /**
2704 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2705 * feature or {@link null} if the service is not available. If the feature is available, the
2706 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2707 */
2708 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002709 IImsServiceFeatureCallback callback) {
2710 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002711 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002712 }
2713
2714 /**
2715 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2716 * feature during emergency calling or {@link null} if the service is not available. If the
2717 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2718 * listener for feature updates.
2719 */
2720 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2721 enforceModifyPermission();
2722 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002723 }
2724
Brad Ebinger5f64b052017-12-14 14:26:15 -08002725 /**
2726 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2727 * specified.
2728 */
2729 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2730 enforceModifyPermission();
2731 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2732 }
2733
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002734 /**
2735 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2736 * specified.
2737 */
2738 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2739 enforceModifyPermission();
2740 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2741 }
2742
Brad Ebinger884c07b2018-02-15 16:17:40 -08002743 /**
Brad Ebinger67801702018-03-02 13:43:36 -08002744 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2745 * available, false if the IMS resolver is idle.
2746 */
2747 public boolean isResolvingImsBinding() {
2748 enforceModifyPermission();
2749 return PhoneFactory.getImsResolver().isResolvingBinding();
2750 }
2751
Brad Ebingerdac2f002018-04-03 15:17:52 -07002752 /**
2753 * Sets the ImsService Package Name that Telephony will bind to.
2754 *
2755 * @param slotId the slot ID that the ImsService should bind for.
2756 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
2757 * ImsService is the device default ImsService.
2758 * @param packageName The package name of the application that contains the ImsService to bind
2759 * to.
2760 * @return true if setting the ImsService to bind to succeeded, false if it did not.
2761 * @hide
2762 */
2763 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002764 int[] subIds = SubscriptionManager.getSubId(slotId);
2765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2766 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2767 "setImsService");
2768
Brad Ebingerdac2f002018-04-03 15:17:52 -07002769 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
2770 isCarrierImsService, packageName);
2771 }
2772
2773 /**
2774 * Return the ImsService configuration.
2775 *
2776 * @param slotId The slot that the ImsService is associated with.
2777 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
2778 * the device default.
2779 * @return the package name of the ImsService configuration.
2780 */
2781 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002782 int[] subIds = SubscriptionManager.getSubId(slotId);
2783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2784 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2785 "getImsService");
2786
Brad Ebingerdac2f002018-04-03 15:17:52 -07002787 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
2788 isCarrierImsService);
2789 }
2790
Wink Saville36469e72014-06-11 15:17:00 -07002791 public void setImsRegistrationState(boolean registered) {
2792 enforceModifyPermission();
2793 mPhone.setImsRegistrationState(registered);
2794 }
2795
2796 /**
Stuart Scott54788802015-03-30 13:18:01 -07002797 * Set the network selection mode to automatic.
2798 *
2799 */
2800 @Override
2801 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2803 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002804 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2805 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2806 }
2807
2808 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002809 * Set the network selection mode to manual with the selected carrier.
2810 */
2811 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002812 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002813 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2815 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002816 OperatorInfo operator = new OperatorInfo(
2817 /* operatorAlphaLong */ "",
2818 /* operatorAlphaShort */ "",
2819 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002820 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002821 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2822 persistSelection);
2823 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002824 }
2825
2826 /**
2827 * Scans for available networks.
2828 */
2829 @Override
2830 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2832 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002833 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2834 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2835 CMD_PERFORM_NETWORK_SCAN, null, subId);
2836 return result;
2837 }
2838
2839 /**
yinxub1bed742017-04-17 11:45:04 -07002840 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002841 *
yinxub1bed742017-04-17 11:45:04 -07002842 * @param subId id of the subscription
2843 * @param request contains the radio access networks with bands/channels to scan
2844 * @param messenger callback messenger for scan results or errors
2845 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002846 * @return the id of the requested scan which can be used to stop the scan.
2847 */
2848 @Override
2849 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2850 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2852 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002853 return mNetworkScanRequestTracker.startNetworkScan(
2854 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002855 }
2856
2857 /**
2858 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002859 *
2860 * @param subId id of the subscription
2861 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002862 */
2863 @Override
2864 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2866 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002867 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002868 }
2869
2870 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002871 * Get the calculated preferred network type.
2872 * Used for debugging incorrect network type.
2873 *
2874 * @return the preferred network type, defined in RILConstants.java.
2875 */
2876 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002877 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002878 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002879 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002880 return RILConstants.PREFERRED_NETWORK_MODE;
2881 }
2882
Amit Mahajan43330e02014-11-18 11:54:45 -08002883 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002884 }
2885
2886 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002887 * Get the preferred network type.
2888 * Used for device configuration by some CDMA operators.
2889 *
2890 * @return the preferred network type, defined in RILConstants.java.
2891 */
2892 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002893 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2895 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002896 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002897 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002898 int networkType = (result != null ? result[0] : -1);
2899 if (DBG) log("getPreferredNetworkType: " + networkType);
2900 return networkType;
2901 }
2902
2903 /**
2904 * Set the preferred network type.
2905 * Used for device configuration by some CDMA operators.
2906 *
2907 * @param networkType the preferred network type, defined in RILConstants.java.
2908 * @return true on success; false on any failure.
2909 */
2910 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002911 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2913 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002914 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2915 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002916 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002917 if (success) {
2918 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002919 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002920 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002921 return success;
2922 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002923
2924 /**
Junda Liu475951f2014-11-07 16:45:03 -08002925 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2926 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2927 * tethering.
2928 *
2929 * @return 0: Not required. 1: required. 2: Not set.
2930 * @hide
2931 */
2932 @Override
2933 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002934 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002935 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2936 Settings.Global.TETHER_DUN_REQUIRED, 2);
2937 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2938 // config_tether_apndata.
2939 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2940 dunRequired = 1;
2941 }
2942 return dunRequired;
2943 }
2944
2945 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002946 * Set mobile data enabled
2947 * Used by the user through settings etc to turn on/off mobile data
2948 *
2949 * @param enable {@code true} turn turn data on, else {@code false}
2950 */
2951 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002952 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2954 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002955 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002956 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002957 Phone phone = PhoneFactory.getPhone(phoneId);
2958 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002959 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2960 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002961 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002962 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002963 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002964 }
2965
2966 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002967 * Get the user enabled state of Mobile Data.
2968 *
2969 * TODO: remove and use isUserDataEnabled.
2970 * This can't be removed now because some vendor codes
2971 * calls through ITelephony directly while they should
2972 * use TelephonyManager.
2973 *
2974 * @return true on enabled
2975 */
2976 @Override
2977 public boolean getDataEnabled(int subId) {
2978 return isUserDataEnabled(subId);
2979 }
2980
2981 /**
2982 * Get whether mobile data is enabled per user setting.
2983 *
2984 * There are other factors deciding whether mobile data is actually enabled, but they are
2985 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002986 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002987 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002988 *
2989 * @return {@code true} if data is enabled else {@code false}
2990 */
2991 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002992 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002993 try {
2994 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2995 null);
2996 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2998 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002999 }
Wink Savillee7353bb2014-12-05 14:21:41 -08003000 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08003001 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08003002 Phone phone = PhoneFactory.getPhone(phoneId);
3003 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08003004 boolean retVal = phone.isUserDataEnabled();
3005 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08003006 return retVal;
3007 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08003008 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3009 return false;
3010 }
3011 }
3012
3013 /**
3014 * Get whether mobile data is enabled.
3015 *
3016 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3017 * whether mobile data is actually enabled.
3018 *
3019 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3020 *
3021 * @return {@code true} if data is enabled else {@code false}
3022 */
3023 @Override
3024 public boolean isDataEnabled(int subId) {
3025 try {
3026 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3027 null);
3028 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3030 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003031 }
3032 int phoneId = mSubscriptionController.getPhoneId(subId);
3033 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3034 Phone phone = PhoneFactory.getPhone(phoneId);
3035 if (phone != null) {
3036 boolean retVal = phone.isDataEnabled();
3037 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3038 return retVal;
3039 } else {
3040 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08003041 return false;
3042 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003043 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003044
3045 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003046 public int getCarrierPrivilegeStatus(int subId) {
3047 final Phone phone = getPhone(subId);
3048 if (phone == null) {
3049 loge("getCarrierPrivilegeStatus: Invalid subId");
3050 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3051 }
3052 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003053 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003054 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003055 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3056 }
3057 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003058 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003059 }
Junda Liu29340342014-07-10 15:23:27 -07003060
3061 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003062 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3063 final Phone phone = getPhone(subId);
3064 if (phone == null) {
3065 loge("getCarrierPrivilegeStatus: Invalid subId");
3066 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3067 }
3068 UiccProfile profile =
3069 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3070 if (profile == null) {
3071 loge("getCarrierPrivilegeStatus: No UICC");
3072 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3073 }
3074 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3075 }
3076
3077 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003078 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003079 if (TextUtils.isEmpty(pkgName))
3080 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003081 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003082 if (card == null) {
3083 loge("checkCarrierPrivilegesForPackage: No UICC");
3084 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3085 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003086 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3087 }
3088
3089 @Override
3090 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003091 if (TextUtils.isEmpty(pkgName))
3092 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003093 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3094 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3095 UiccCard card = UiccController.getInstance().getUiccCard(i);
3096 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003097 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003098 continue;
3099 }
3100
3101 result = card.getCarrierPrivilegeStatus(
3102 mPhone.getContext().getPackageManager(), pkgName);
3103 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3104 break;
3105 }
3106 }
3107
3108 return result;
Junda Liu29340342014-07-10 15:23:27 -07003109 }
Derek Tan89e89d42014-07-08 17:00:10 -07003110
3111 @Override
Junda Liue64de782015-04-16 17:19:16 -07003112 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3113 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3114 loge("phoneId " + phoneId + " is not valid.");
3115 return null;
3116 }
3117 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003118 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003119 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003120 return null ;
3121 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003122 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003123 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003124 }
3125
Amith Yamasani6e118872016-02-19 12:53:51 -08003126 @Override
3127 public List<String> getPackagesWithCarrierPrivileges() {
3128 PackageManager pm = mPhone.getContext().getPackageManager();
3129 List<String> privilegedPackages = new ArrayList<>();
3130 List<PackageInfo> packages = null;
3131 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3132 UiccCard card = UiccController.getInstance().getUiccCard(i);
3133 if (card == null) {
3134 // No UICC in that slot.
3135 continue;
3136 }
3137 if (card.hasCarrierPrivilegeRules()) {
3138 if (packages == null) {
3139 // Only check packages in user 0 for now
3140 packages = pm.getInstalledPackagesAsUser(
3141 PackageManager.MATCH_DISABLED_COMPONENTS
3142 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3143 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3144 }
3145 for (int p = packages.size() - 1; p >= 0; p--) {
3146 PackageInfo pkgInfo = packages.get(p);
3147 if (pkgInfo != null && pkgInfo.packageName != null
3148 && card.getCarrierPrivilegeStatus(pkgInfo)
3149 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3150 privilegedPackages.add(pkgInfo.packageName);
3151 }
3152 }
3153 }
3154 }
3155 return privilegedPackages;
3156 }
3157
Wink Savilleb564aae2014-10-23 10:18:09 -07003158 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003159 final Phone phone = getPhone(subId);
3160 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003161 if (card == null) {
3162 loge("getIccId: No UICC");
3163 return null;
3164 }
3165 String iccId = card.getIccId();
3166 if (TextUtils.isEmpty(iccId)) {
3167 loge("getIccId: ICC ID is null or empty.");
3168 return null;
3169 }
3170 return iccId;
3171 }
3172
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003173 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003174 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3175 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003176 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3177 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003178
Jeff Sharkey85190e62014-12-05 09:40:12 -08003179 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003180 final Phone phone = getPhone(subId);
3181 if (phone == null) {
3182 return false;
3183 }
3184 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003185
3186 if (DBG_MERGE) {
3187 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3188 + subscriberId + " to " + number);
3189 }
3190
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003191 if (TextUtils.isEmpty(iccId)) {
3192 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003193 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003194
Jeff Sharkey85190e62014-12-05 09:40:12 -08003195 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3196
3197 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003198 if (alphaTag == null) {
3199 editor.remove(alphaTagPrefKey);
3200 } else {
3201 editor.putString(alphaTagPrefKey, alphaTag);
3202 }
3203
Jeff Sharkey85190e62014-12-05 09:40:12 -08003204 // Record both the line number and IMSI for this ICCID, since we need to
3205 // track all merged IMSIs based on line number
3206 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3207 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003208 if (number == null) {
3209 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003210 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003211 } else {
3212 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003213 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003214 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003215
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003216 editor.commit();
3217 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003218 }
3219
3220 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003221 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003222 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003224 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003225 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003226 return null;
3227 }
Derek Tan97ebb422014-09-05 16:55:38 -07003228
3229 String iccId = getIccId(subId);
3230 if (iccId != null) {
3231 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003232 if (DBG_MERGE) {
3233 log("getLine1NumberForDisplay returning " +
3234 mTelephonySharedPreferences.getString(numberPrefKey, null));
3235 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003236 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003237 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003238 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003239 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003240 }
3241
3242 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003243 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003245 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003246 return null;
3247 }
Derek Tan97ebb422014-09-05 16:55:38 -07003248
3249 String iccId = getIccId(subId);
3250 if (iccId != null) {
3251 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003252 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003253 }
Derek Tan97ebb422014-09-05 16:55:38 -07003254 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003255 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003256
3257 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003258 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003259 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3260 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003262 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3263 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003264 return null;
3265 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003266 final Context context = mPhone.getContext();
3267 final TelephonyManager tele = TelephonyManager.from(context);
3268 final SubscriptionManager sub = SubscriptionManager.from(context);
3269
3270 // Figure out what subscribers are currently active
3271 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003272 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3273 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 final int[] subIds = sub.getActiveSubscriptionIdList();
3277 for (int subId : subIds) {
3278 activeSubscriberIds.add(tele.getSubscriberId(subId));
3279 }
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003282 }
3283
3284 // First pass, find a number override for an active subscriber
3285 String mergeNumber = null;
3286 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3287 for (String key : prefs.keySet()) {
3288 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3289 final String subscriberId = (String) prefs.get(key);
3290 if (activeSubscriberIds.contains(subscriberId)) {
3291 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3292 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3293 mergeNumber = (String) prefs.get(numberKey);
3294 if (DBG_MERGE) {
3295 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3296 + " for active subscriber " + subscriberId);
3297 }
3298 if (!TextUtils.isEmpty(mergeNumber)) {
3299 break;
3300 }
3301 }
3302 }
3303 }
3304
3305 // Shortcut when no active merged subscribers
3306 if (TextUtils.isEmpty(mergeNumber)) {
3307 return null;
3308 }
3309
3310 // Second pass, find all subscribers under that line override
3311 final ArraySet<String> result = new ArraySet<>();
3312 for (String key : prefs.keySet()) {
3313 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3314 final String number = (String) prefs.get(key);
3315 if (mergeNumber.equals(number)) {
3316 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3317 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3318 final String subscriberId = (String) prefs.get(subscriberKey);
3319 if (!TextUtils.isEmpty(subscriberId)) {
3320 result.add(subscriberId);
3321 }
3322 }
3323 }
3324 }
3325
3326 final String[] resultArray = result.toArray(new String[result.size()]);
3327 Arrays.sort(resultArray);
3328 if (DBG_MERGE) {
3329 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3330 }
3331 return resultArray;
3332 }
3333
3334 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003335 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003336 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3337 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003338 final Phone phone = getPhone(subId);
3339 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003340 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003341
3342 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003343 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003344 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3345 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003346 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003347 final Phone phone = getPhone(subId);
3348 if (phone == null) {
3349 return false;
3350 }
3351 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003352 cdmaNonRoamingList);
3353 }
3354
3355 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003356 @Deprecated
3357 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3358 enforceModifyPermission();
3359
3360 int returnValue = 0;
3361 try {
3362 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3363 if(result.exception == null) {
3364 if (result.result != null) {
3365 byte[] responseData = (byte[])(result.result);
3366 if(responseData.length > oemResp.length) {
3367 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3368 responseData.length + "bytes. Buffer Size is " +
3369 oemResp.length + "bytes.");
3370 }
3371 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3372 returnValue = responseData.length;
3373 }
3374 } else {
3375 CommandException ex = (CommandException) result.exception;
3376 returnValue = ex.getCommandError().ordinal();
3377 if(returnValue > 0) returnValue *= -1;
3378 }
3379 } catch (RuntimeException e) {
3380 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3381 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3382 if(returnValue > 0) returnValue *= -1;
3383 }
3384
3385 return returnValue;
3386 }
3387
3388 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003389 public void setRadioCapability(RadioAccessFamily[] rafs) {
3390 try {
3391 ProxyController.getInstance().setRadioCapability(rafs);
3392 } catch (RuntimeException e) {
3393 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3394 }
3395 }
3396
3397 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003398 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003399 Phone phone = PhoneFactory.getPhone(phoneId);
3400 if (phone == null) {
3401 return RadioAccessFamily.RAF_UNKNOWN;
3402 }
3403 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003405 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003406 return RadioAccessFamily.RAF_UNKNOWN;
3407 }
3408
Wink Saville5d475dd2014-10-17 15:00:58 -07003409 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3410 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003411
3412 @Override
3413 public void enableVideoCalling(boolean enable) {
3414 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003415 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003416 }
3417
3418 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003419 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3421 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3422 return false;
3423 }
Svet Ganovb320e182015-04-16 12:30:10 -07003424
Andrew Lee77527ac2014-10-21 16:57:39 -07003425 // Check the user preference and the system-level IMS setting. Even if the user has
3426 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3427 // In the long run, we may instead need to check if there exists a connection service
3428 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003429 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3430 return imsManager.isVtEnabledByPlatform()
3431 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3432 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003433 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003434
Andrew Leea1239f22015-03-02 17:44:07 -08003435 @Override
3436 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003437 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003438 }
3439
3440 @Override
3441 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003442 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003443 }
3444
Andrew Lee9431b832015-03-09 18:46:45 -07003445 @Override
3446 public boolean isTtyModeSupported() {
3447 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3448 TelephonyManager telephonyManager =
3449 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003450 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003451 }
3452
3453 @Override
3454 public boolean isHearingAidCompatibilitySupported() {
3455 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3456 }
3457
Hall Liu98187582018-01-22 19:15:32 -08003458 public boolean isRttSupported() {
3459 boolean isCarrierSupported =
3460 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3461 boolean isDeviceSupported =
3462 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3463 return isCarrierSupported && isDeviceSupported;
3464 }
3465
Hall Liu3ad5f012018-04-06 16:23:39 -07003466 public boolean isRttEnabled() {
3467 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3468 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3469 }
3470
Sanket Padawe7310cc72015-01-14 09:53:20 -08003471 /**
3472 * Returns the unique device ID of phone, for example, the IMEI for
3473 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3474 *
3475 * <p>Requires Permission:
3476 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3477 */
3478 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003479 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003480 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003481 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003482 return null;
3483 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003484 int subId = phone.getSubId();
3485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3486 mApp, subId, callingPackage, "getDeviceId")) {
3487 return null;
3488 }
3489 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003490 }
3491
Ping Sunc67b7c22016-03-02 19:16:45 +08003492 /**
3493 * {@hide}
3494 * Returns the IMS Registration Status on a particular subid
3495 *
3496 * @param subId
3497 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003498 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003499 Phone phone = getPhone(subId);
3500 if (phone != null) {
3501 return phone.isImsRegistered();
3502 } else {
3503 return false;
3504 }
3505 }
3506
Santos Cordon7a1885b2015-02-03 11:15:19 -08003507 @Override
3508 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3509 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3510 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003511
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003512 /**
3513 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003514 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003515 public boolean isWifiCallingAvailable(int subId) {
3516 Phone phone = getPhone(subId);
3517 if (phone != null) {
3518 return phone.isWifiCallingEnabled();
3519 } else {
3520 return false;
3521 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003522 }
3523
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003524 /**
3525 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003526 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003527 public boolean isVolteAvailable(int subId) {
3528 Phone phone = getPhone(subId);
3529 if (phone != null) {
3530 return phone.isVolteEnabled();
3531 } else {
3532 return false;
3533 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003534 }
Svet Ganovb320e182015-04-16 12:30:10 -07003535
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003536 /**
3537 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003538 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003539 public boolean isVideoTelephonyAvailable(int subId) {
3540 Phone phone = getPhone(subId);
3541 if (phone != null) {
3542 return phone.isVideoEnabled();
3543 } else {
3544 return false;
3545 }
3546 }
3547
3548 /**
3549 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3550 * defined in {@link ImsRegistrationImplBase}.
3551 */
3552 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3553 Phone phone = getPhone(subId);
3554 if (phone != null) {
3555 return phone.getImsRegistrationTech();
3556 } else {
3557 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3558 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003559 }
3560
Stuart Scott8eef64f2015-04-08 15:13:54 -07003561 @Override
3562 public void factoryReset(int subId) {
3563 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003564 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3565 return;
3566 }
3567
Svet Ganovcc087f82015-05-12 20:35:54 -07003568 final long identity = Binder.clearCallingIdentity();
3569 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003570 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3571 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003572 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003573 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003574 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3575 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003576 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003577 }
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003580 }
3581 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003582
3583 @Override
3584 public String getLocaleFromDefaultSim() {
3585 // We query all subscriptions instead of just the active ones, because
3586 // this might be called early on in the provisioning flow when the
3587 // subscriptions potentially aren't active yet.
3588 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3589 if (slist == null || slist.isEmpty()) {
3590 return null;
3591 }
3592
3593 // This function may be called very early, say, from the setup wizard, at
3594 // which point we won't have a default subscription set. If that's the case
3595 // we just choose the first, which will be valid in "most cases".
3596 final int defaultSubId = getDefaultSubscription();
3597 SubscriptionInfo info = null;
3598 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3599 info = slist.get(0);
3600 } else {
3601 for (SubscriptionInfo item : slist) {
3602 if (item.getSubscriptionId() == defaultSubId) {
3603 info = item;
3604 break;
3605 }
3606 }
3607
3608 if (info == null) {
3609 return null;
3610 }
3611 }
3612
3613 // Try and fetch the locale from the carrier properties or from the SIM language
3614 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003615 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003616 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003617 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003618 if (defaultPhone != null) {
3619 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3620 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003621 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003622 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3623 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003624 } else {
3625 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003626 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003627 }
3628 }
3629
Narayan Kamath011676f2015-07-29 12:04:08 +01003630 // The SIM language preferences only store a language (e.g. fr = French), not an
3631 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3632 // the SIM and carrier preferences does not include a country we add the country
3633 // determined from the SIM MCC to provide an exact locale.
3634 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003635 if (mccLocale != null) {
3636 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3637 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003638 }
3639
Tony Hill183b2de2015-06-24 14:53:58 +01003640 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003641 return null;
3642 }
3643
3644 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 return mSubscriptionController.getAllSubInfoList(
3648 mPhone.getContext().getOpPackageName());
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
3652 }
3653
3654 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 return mSubscriptionController.getActiveSubscriptionInfoList(
3658 mPhone.getContext().getOpPackageName());
3659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
3662 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003663
Chenjie Yu1ba97252018-01-11 18:16:20 -08003664 private final ModemActivityInfo mLastModemActivityInfo =
3665 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3666
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003667 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003668 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3669 * representing the state of the modem.
3670 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003671 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3672 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003673 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003674 */
3675 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003676 public void requestModemActivityInfo(ResultReceiver result) {
3677 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003678 ModemActivityInfo ret = null;
3679 synchronized (mLastModemActivityInfo) {
3680 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3681 null);
3682 if (info != null) {
3683 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3684 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3685 mergedTxTimeMs[i] =
3686 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3687 }
3688 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3689 mLastModemActivityInfo.setSleepTimeMillis(
3690 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3691 mLastModemActivityInfo.setIdleTimeMillis(
3692 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3693 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3694 mLastModemActivityInfo.setRxTimeMillis(
3695 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3696 mLastModemActivityInfo.setEnergyUsed(
3697 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3698 }
3699 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3700 mLastModemActivityInfo.getSleepTimeMillis(),
3701 mLastModemActivityInfo.getIdleTimeMillis(),
3702 mLastModemActivityInfo.getTxTimeMillis(),
3703 mLastModemActivityInfo.getRxTimeMillis(),
3704 mLastModemActivityInfo.getEnergyUsed());
3705 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003706 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003707 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003708 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003709 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003710
3711 /**
3712 * {@hide}
3713 * Returns the service state information on specified subscription.
3714 */
3715 @Override
3716 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3717
Jeff Davidson7e17e312018-02-13 18:17:36 -08003718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003719 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003720 return null;
3721 }
3722
3723 final Phone phone = getPhone(subId);
3724 if (phone == null) {
3725 return null;
3726 }
3727
3728 return phone.getServiceState();
3729 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003730
3731 /**
3732 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3733 *
3734 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3735 * voicemail ringtone.
3736 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3737 * PhoneAccount.
3738 */
3739 @Override
3740 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003741 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003742 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003743 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003744 }
3745
fionaxu7ed723d2017-05-30 18:58:54 -07003746 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003747 }
3748
3749 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003750 * Sets the per-account voicemail ringtone.
3751 *
3752 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3753 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3754 *
3755 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3756 * voicemail ringtone.
3757 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3758 * PhoneAccount.
3759 */
3760 @Override
3761 public void setVoicemailRingtoneUri(String callingPackage,
3762 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3764 if (!TextUtils.equals(callingPackage,
3765 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3767 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3768 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003769 }
3770 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3771 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003772 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003773 }
fionaxu7ed723d2017-05-30 18:58:54 -07003774 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003775 }
3776
3777 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003778 * Returns whether vibration is set for voicemail notification in Phone settings.
3779 *
3780 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3781 * voicemail vibration setting.
3782 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3783 */
3784 @Override
3785 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003786 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003787 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003788 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003789 }
3790
fionaxu7ed723d2017-05-30 18:58:54 -07003791 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003792 }
3793
Youhan Wange64578a2016-05-02 15:32:42 -07003794 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003795 * Sets the per-account voicemail vibration.
3796 *
3797 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3798 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3799 *
3800 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3801 * voicemail vibration setting.
3802 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3803 * specific PhoneAccount.
3804 */
3805 @Override
3806 public void setVoicemailVibrationEnabled(String callingPackage,
3807 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3809 if (!TextUtils.equals(callingPackage,
3810 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3812 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3813 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003814 }
3815
3816 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3817 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003818 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003819 }
fionaxu7ed723d2017-05-30 18:58:54 -07003820 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003821 }
3822
3823 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003824 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3825 *
3826 * @throws SecurityException if the caller does not have the required permission
3827 */
3828 private void enforceReadPrivilegedPermission() {
3829 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3830 null);
3831 }
3832
3833 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003834 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3835 * permission.
3836 *
3837 * @throws SecurityException if the caller does not have the required permission
3838 */
3839 private void enforceSendSmsPermission() {
3840 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3841 }
3842
3843 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003844 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003845 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003846 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003847 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003848 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003849 ComponentName componentName =
3850 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3851 if(componentName == null) {
3852 throw new SecurityException("Caller not current active visual voicemail package[null]");
3853 }
3854 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003855 if (!callingPackage.equals(vvmPackage)) {
3856 throw new SecurityException("Caller not current active visual voicemail package[" +
3857 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003858 }
3859 }
3860
3861 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003862 * Return the application ID for the app type.
3863 *
3864 * @param subId the subscription ID that this request applies to.
3865 * @param appType the uicc app type.
3866 * @return Application ID for specificied app type, or null if no uicc.
3867 */
3868 @Override
3869 public String getAidForAppType(int subId, int appType) {
3870 enforceReadPrivilegedPermission();
3871 Phone phone = getPhone(subId);
3872 if (phone == null) {
3873 return null;
3874 }
3875 String aid = null;
3876 try {
3877 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3878 .getApplicationByType(appType).getAid();
3879 } catch (Exception e) {
3880 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3881 }
3882 return aid;
3883 }
3884
Youhan Wang4001d252016-05-11 10:29:41 -07003885 /**
3886 * Return the Electronic Serial Number.
3887 *
3888 * @param subId the subscription ID that this request applies to.
3889 * @return ESN or null if error.
3890 */
3891 @Override
3892 public String getEsn(int subId) {
3893 enforceReadPrivilegedPermission();
3894 Phone phone = getPhone(subId);
3895 if (phone == null) {
3896 return null;
3897 }
3898 String esn = null;
3899 try {
3900 esn = phone.getEsn();
3901 } catch (Exception e) {
3902 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3903 }
3904 return esn;
3905 }
3906
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003907 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003908 * Return the Preferred Roaming List Version.
3909 *
3910 * @param subId the subscription ID that this request applies to.
3911 * @return PRLVersion or null if error.
3912 */
3913 @Override
3914 public String getCdmaPrlVersion(int subId) {
3915 enforceReadPrivilegedPermission();
3916 Phone phone = getPhone(subId);
3917 if (phone == null) {
3918 return null;
3919 }
3920 String cdmaPrlVersion = null;
3921 try {
3922 cdmaPrlVersion = phone.getCdmaPrlVersion();
3923 } catch (Exception e) {
3924 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3925 }
3926 return cdmaPrlVersion;
3927 }
3928
3929 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003930 * Get snapshot of Telephony histograms
3931 * @return List of Telephony histograms
3932 * @hide
3933 */
3934 @Override
3935 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3937 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003938 return RIL.getTelephonyRILTimingHistograms();
3939 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003940
3941 /**
3942 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003943 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003944 * Require system privileges. In the future we may add this to carrier APIs.
3945 *
3946 * @return The number of carriers set successfully, should match length of carriers
3947 */
3948 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003949 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003950 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003951
Meng Wang9b7c4e92017-02-17 11:41:27 -08003952 if (carriers == null) {
3953 throw new NullPointerException("carriers cannot be null");
3954 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003955
3956 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003957 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3958 return retVal[0];
3959 }
3960
3961 /**
3962 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003963 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003964 * Require system privileges. In the future we may add this to carrier APIs.
3965 *
3966 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3967 * means all carriers are allowed.
3968 */
3969 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003970 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003971 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003972 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003973 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3974 }
3975
fionaxu59545b42016-05-25 15:53:37 -07003976 /**
3977 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3978 * @param subId the subscription ID that this action applies to.
3979 * @param enabled control enable or disable metered apns.
3980 * {@hide}
3981 */
3982 @Override
3983 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3984 enforceModifyPermission();
3985 final Phone phone = getPhone(subId);
3986 if (phone == null) {
3987 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3988 return;
3989 }
3990 try {
3991 phone.carrierActionSetMeteredApnsEnabled(enabled);
3992 } catch (Exception e) {
3993 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3994 }
3995 }
3996
3997 /**
3998 * Action set from carrier signalling broadcast receivers to enable/disable radio
3999 * @param subId the subscription ID that this action applies to.
4000 * @param enabled control enable or disable radio.
4001 * {@hide}
4002 */
4003 @Override
4004 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4005 enforceModifyPermission();
4006 final Phone phone = getPhone(subId);
4007 if (phone == null) {
4008 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4009 return;
4010 }
4011 try {
4012 phone.carrierActionSetRadioEnabled(enabled);
4013 } catch (Exception e) {
4014 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
4015 }
4016 }
4017
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004018 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004019 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4020 * network status based on which carrier apps could apply actions accordingly,
4021 * enable/disable default url handler for example.
4022 *
4023 * @param subId the subscription ID that this action applies to.
4024 * @param report control start/stop reporting the default network status.
4025 * {@hide}
4026 */
4027 @Override
4028 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4029 enforceModifyPermission();
4030 final Phone phone = getPhone(subId);
4031 if (phone == null) {
4032 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4033 return;
4034 }
4035 try {
4036 phone.carrierActionReportDefaultNetworkStatus(report);
4037 } catch (Exception e) {
4038 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
4039 }
4040 }
4041
4042 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004043 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4044 * bug report is being generated.
4045 */
4046 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004047 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004048 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4049 != PackageManager.PERMISSION_GRANTED) {
4050 writer.println("Permission Denial: can't dump Phone from pid="
4051 + Binder.getCallingPid()
4052 + ", uid=" + Binder.getCallingUid()
4053 + "without permission "
4054 + android.Manifest.permission.DUMP);
4055 return;
4056 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004057 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004058 }
Jack Yueb89b242016-06-22 13:27:47 -07004059
Brad Ebingerdac2f002018-04-03 15:17:52 -07004060 @Override
4061 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4062 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4063 throws RemoteException {
4064 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4065 }
4066
Jack Yueb89b242016-06-22 13:27:47 -07004067 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004068 * Get aggregated video call data usage since boot.
4069 *
4070 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4071 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004072 * {@hide}
4073 */
4074 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004075 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004076 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4077 null);
4078
Jack Yu84291ec2017-05-26 16:07:50 -07004079 // NetworkStatsService keeps tracking the active network interface and identity. It
4080 // records the delta with the corresponding network identity. We just return the total video
4081 // call data usage snapshot since boot.
4082 Phone phone = getPhone(subId);
4083 if (phone != null) {
4084 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004085 }
Jack Yu84291ec2017-05-26 16:07:50 -07004086 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004087 }
Jack Yu75ab2952016-07-08 14:29:33 -07004088
4089 /**
4090 * Policy control of data connection. Usually used when data limit is passed.
4091 * @param enabled True if enabling the data, otherwise disabling.
4092 * @param subId Subscription index
4093 * {@hide}
4094 */
4095 @Override
4096 public void setPolicyDataEnabled(boolean enabled, int subId) {
4097 enforceModifyPermission();
4098 Phone phone = getPhone(subId);
4099 if (phone != null) {
4100 phone.setPolicyDataEnabled(enabled);
4101 }
4102 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004103
4104 /**
4105 * Get Client request stats
4106 * @return List of Client Request Stats
4107 * @hide
4108 */
4109 @Override
4110 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004112 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004113 return null;
4114 }
4115
4116 Phone phone = getPhone(subId);
4117 if (phone != null) {
4118 return phone.getClientRequestStats();
4119 }
4120
4121 return null;
4122 }
4123
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004124 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004125 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004126 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004127 }
Jack Yueb4124c2017-02-16 15:32:43 -08004128
4129 /**
Grace Chen70990072017-03-24 17:21:30 -07004130 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004131 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004132 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004133 * @param state State of SIM (power down, power up, pass through)
4134 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4135 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4136 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004137 *
4138 **/
4139 @Override
Grace Chen70990072017-03-24 17:21:30 -07004140 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004141 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004142 Phone phone = PhoneFactory.getPhone(slotIndex);
4143
Jack Yueb4124c2017-02-16 15:32:43 -08004144 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004145 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004146 }
4147 }
Shuo Qiandd210312017-04-12 22:11:33 +00004148
Tyler Gunn65d45c22017-06-05 11:22:26 -07004149 private boolean isUssdApiAllowed(int subId) {
4150 CarrierConfigManager configManager =
4151 (CarrierConfigManager) mPhone.getContext().getSystemService(
4152 Context.CARRIER_CONFIG_SERVICE);
4153 if (configManager == null) {
4154 return false;
4155 }
4156 PersistableBundle pb = configManager.getConfigForSubId(subId);
4157 if (pb == null) {
4158 return false;
4159 }
4160 return pb.getBoolean(
4161 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4162 }
4163
Shuo Qiandd210312017-04-12 22:11:33 +00004164 /**
4165 * Check if phone is in emergency callback mode
4166 * @return true if phone is in emergency callback mode
4167 * @param subId sub id
4168 */
goneil9c5f4872017-12-05 14:07:56 -08004169 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004170 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004171 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004172 final Phone phone = getPhone(subId);
4173 if (phone != null) {
4174 return phone.isInEcm();
4175 } else {
4176 return false;
4177 }
4178 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004179
4180 /**
4181 * Get the current signal strength information for the given subscription.
4182 * Because this information is not updated when the device is in a low power state
4183 * it should not be relied-upon to be current.
4184 * @param subId Subscription index
4185 * @return the most recent cached signal strength info from the modem
4186 */
4187 @Override
4188 public SignalStrength getSignalStrength(int subId) {
4189 Phone p = getPhone(subId);
4190 if (p == null) {
4191 return null;
4192 }
4193
4194 return p.getSignalStrength();
4195 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004196
4197 @Override
4198 public UiccSlotInfo[] getUiccSlotsInfo() {
4199 enforceReadPrivilegedPermission();
4200
4201 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004202 if (slots == null) {
4203 Rlog.i(LOG_TAG, "slots is null.");
4204 return null;
4205 }
4206
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004207 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4208 for (int i = 0; i < slots.length; i++) {
4209 UiccSlot slot = slots[i];
Holly Jiuyu Sun6723f982018-06-04 15:48:38 -07004210 if (slot == null) {
4211 continue;
4212 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004213
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004214 String cardId;
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004215 UiccCard card = slot.getUiccCard();
4216 if (card != null) {
4217 cardId = card.getCardId();
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004218 } else {
4219 cardId = slot.getIccId();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004220 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004221
4222 int cardState = 0;
4223 switch (slot.getCardState()) {
4224 case CARDSTATE_ABSENT:
4225 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4226 break;
4227 case CARDSTATE_PRESENT:
4228 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4229 break;
4230 case CARDSTATE_ERROR:
4231 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4232 break;
4233 case CARDSTATE_RESTRICTED:
4234 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4235 break;
4236 default:
4237 break;
4238
4239 }
4240
Qingxi Li795c5882018-01-31 13:43:27 -08004241 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004242 slot.isActive(),
4243 slot.isEuicc(),
4244 cardId,
4245 cardState,
4246 slot.getPhoneId(),
4247 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004248 }
4249 return infos;
4250 }
4251
4252 @Override
4253 public boolean switchSlots(int[] physicalSlots) {
4254 enforceModifyPermission();
4255 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4256 }
Jack Yu4c988042018-02-27 15:30:01 -08004257
4258 @Override
4259 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4260 enforceModifyPermission();
4261 final Phone phone = getPhone(subId);
4262 if (phone == null) {
4263 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4264 return;
4265 }
4266
4267 phone.setRadioIndicationUpdateMode(filters, mode);
4268 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004269
4270 /**
goneil47ffb6e2018-04-06 15:40:58 -07004271 * A test API to reload the UICC profile.
4272 *
4273 * <p>Requires that the calling app has permission
4274 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4275 * @hide
4276 */
4277 @Override
4278 public void refreshUiccProfile(int subId) {
4279 enforceModifyPermission();
4280
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 Phone phone = getPhone(subId);
4284 if (phone == null) {
4285 return;
4286 }
4287 UiccCard uiccCard = phone.getUiccCard();
4288 if (uiccCard == null) {
4289 return;
4290 }
4291 UiccProfile uiccProfile = uiccCard.getUiccProfile();
4292 if (uiccProfile == null) {
4293 return;
4294 }
4295 uiccProfile.refresh();
4296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
4299 }
4300
4301 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07004302 * Returns false if the mobile data is disabled by default, otherwise return true.
4303 */
4304 private boolean getDefaultDataEnabled() {
4305 return "true".equalsIgnoreCase(
4306 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4307 }
4308
4309 /**
4310 * Returns true if the data roaming is enabled by default, i.e the system property
4311 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4312 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4313 */
4314 private boolean getDefaultDataRoamingEnabled(int subId) {
4315 final CarrierConfigManager configMgr = (CarrierConfigManager)
4316 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4317 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4318 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4319 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4320 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4321 return isDataRoamingEnabled;
4322 }
4323
4324 /**
4325 * Returns the default network type for the given {@code subId}, if the default network type is
4326 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4327 */
4328 private int getDefaultNetworkType(int subId) {
4329 return Integer.parseInt(
4330 TelephonyManager.getTelephonyProperty(
4331 mSubscriptionController.getPhoneId(subId),
4332 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4333 String.valueOf(Phone.PREFERRED_NT_MODE)));
4334 }
fionaxua13278b2018-03-21 00:08:13 -07004335
4336 @Override
4337 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4338 gid1, String gid2, String plmn, String spn) {
4339 enforceModifyPermission();
4340 final Phone phone = getPhone(subId);
4341 if (phone == null) {
4342 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4343 return;
4344 }
4345 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4346 }
4347
4348 @Override
4349 public int getCarrierIdListVersion(int subId) {
4350 enforceReadPrivilegedPermission();
4351 final Phone phone = getPhone(subId);
4352 if (phone == null) {
4353 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4354 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4355 }
4356 return phone.getCarrierIdListVersion();
4357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004358}