blob: 825acc5faa198e4bfd83039ffc2f51262dd40622 [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
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001152 final long identity = Binder.clearCallingIdentity();
1153 try {
1154 String url = createTelUrl(number);
1155 if (url == null) {
1156 return;
1157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001159 // PENDING: should we just silently fail if phone is offhook or ringing?
1160 PhoneConstants.State state = mCM.getState(subId);
1161 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1162 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1163 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1164 mApp.startActivity(intent);
1165 }
1166 } finally {
1167 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 }
1169 }
1170
1171 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001172 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001173 }
1174
Wink Savilleb564aae2014-10-23 10:18:09 -07001175 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001176 if (DBG) log("call: " + number);
1177
1178 // This is just a wrapper around the ACTION_CALL intent, but we still
1179 // need to do a permission check since we're calling startActivity()
1180 // from the context of the phone app.
1181 enforceCallPermission();
1182
1183 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1184 != AppOpsManager.MODE_ALLOWED) {
1185 return;
1186 }
1187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001188 final long identity = Binder.clearCallingIdentity();
1189 try {
1190 String url = createTelUrl(number);
1191 if (url == null) {
1192 return;
1193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001195 boolean isValid = false;
1196 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1197 if (slist != null) {
1198 for (SubscriptionInfo subInfoRecord : slist) {
1199 if (subInfoRecord.getSubscriptionId() == subId) {
1200 isValid = true;
1201 break;
1202 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001203 }
Wink Saville08874612014-08-31 19:19:58 -07001204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001205 if (!isValid) {
1206 return;
1207 }
Wink Saville08874612014-08-31 19:19:58 -07001208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001209 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1210 intent.putExtra(SUBSCRIPTION_KEY, subId);
1211 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1212 mApp.startActivity(intent);
1213 } finally {
1214 Binder.restoreCallingIdentity(identity);
1215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 }
1217
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 /**
1219 * End a call based on call state
1220 * @return true is a call was ended
1221 */
1222 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001223 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001224 }
1225
1226 /**
1227 * End a call based on the call state of the subId
1228 * @return true is a call was ended
1229 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001230 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001231 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1232 != PackageManager.PERMISSION_GRANTED) {
1233 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1234 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1235 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001237
1238 final long identity = Binder.clearCallingIdentity();
1239 try {
1240 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1241 } finally {
1242 Binder.restoreCallingIdentity(identity);
1243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 }
1245
1246 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001247 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001248 }
1249
Wink Savilleb564aae2014-10-23 10:18:09 -07001250 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 if (DBG) log("answerRingingCall...");
1252 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1253 // but that can probably wait till the big TelephonyManager API overhaul.
1254 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1255 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001256
1257 final long identity = Binder.clearCallingIdentity();
1258 try {
1259 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1260 } finally {
1261 Binder.restoreCallingIdentity(identity);
1262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 }
1264
1265 /**
1266 * Make the actual telephony calls to implement answerRingingCall().
1267 * This should only be called from the main thread of the Phone app.
1268 * @see #answerRingingCall
1269 *
1270 * TODO: it would be nice to return true if we answered the call, or
1271 * false if there wasn't actually a ringing incoming call, or some
1272 * other error occurred. (In other words, pass back the return value
1273 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1274 * But that would require calling this method via sendRequest() rather
1275 * than sendRequestAsync(), and right now we don't actually *need* that
1276 * return value, so let's just return void for now.
1277 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001278 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001279 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001281 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1282 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 if (hasActiveCall && hasHoldingCall) {
1284 // Both lines are in use!
1285 // TODO: provide a flag to let the caller specify what
1286 // policy to use if both lines are in use. (The current
1287 // behavior is hardwired to "answer incoming, end ongoing",
1288 // which is how the CALL button is specced to behave.)
1289 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1290 return;
1291 } else {
1292 // answerCall() will automatically hold the current active
1293 // call, if there is one.
1294 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1295 return;
1296 }
1297 } else {
1298 // No call was ringing.
1299 return;
1300 }
1301 }
1302
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001304 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001306 public void silenceRinger() {
1307 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 }
1309
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001310 @Override
1311 public boolean isOffhook(String callingPackage) {
1312 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001313 }
1314
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001315 @Override
1316 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001318 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001319 return false;
1320 }
1321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001322 final long identity = Binder.clearCallingIdentity();
1323 try {
1324 final Phone phone = getPhone(subId);
1325 if (phone != null) {
1326 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1327 } else {
1328 return false;
1329 }
1330 } finally {
1331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 }
1334
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001335 @Override
1336 public boolean isRinging(String callingPackage) {
1337 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001338 }
1339
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001340 @Override
1341 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001343 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001344 return false;
1345 }
1346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001347 final long identity = Binder.clearCallingIdentity();
1348 try {
1349 final Phone phone = getPhone(subId);
1350 if (phone != null) {
1351 return (phone.getState() == PhoneConstants.State.RINGING);
1352 } else {
1353 return false;
1354 }
1355 } finally {
1356 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 }
1359
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001360 @Override
1361 public boolean isIdle(String callingPackage) {
1362 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001363 }
1364
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001365 @Override
1366 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001368 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001369 return false;
1370 }
1371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001372 final long identity = Binder.clearCallingIdentity();
1373 try {
1374 final Phone phone = getPhone(subId);
1375 if (phone != null) {
1376 return (phone.getState() == PhoneConstants.State.IDLE);
1377 } else {
1378 return false;
1379 }
1380 } finally {
1381 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 }
1384
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001386 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001387 }
1388
Wink Savilleb564aae2014-10-23 10:18:09 -07001389 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001390 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001391 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1392 }
1393
1394 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001395 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001396 }
1397
Wink Savilleb564aae2014-10-23 10:18:09 -07001398 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001400 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1401 }
1402
1403 /** {@hide} */
1404 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001405 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001406 }
1407
Wink Savilleb564aae2014-10-23 10:18:09 -07001408 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001410
1411 final long identity = Binder.clearCallingIdentity();
1412 try {
1413 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1414 checkSimPin.start();
1415 return checkSimPin.unlockSim(null, pin);
1416 } finally {
1417 Binder.restoreCallingIdentity(identity);
1418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 }
1420
Wink Saville9de0f752013-10-22 19:04:03 -07001421 /** {@hide} */
1422 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001423 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
1425
Wink Savilleb564aae2014-10-23 10:18:09 -07001426 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001428
1429 final long identity = Binder.clearCallingIdentity();
1430 try {
1431 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1432 checkSimPuk.start();
1433 return checkSimPuk.unlockSim(puk, pin);
1434 } finally {
1435 Binder.restoreCallingIdentity(identity);
1436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001437 }
1438
1439 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001440 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441 * a synchronous one.
1442 */
1443 private static class UnlockSim extends Thread {
1444
1445 private final IccCard mSimCard;
1446
1447 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001448 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1449 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450
1451 // For replies from SimCard interface
1452 private Handler mHandler;
1453
1454 // For async handler to identify request type
1455 private static final int SUPPLY_PIN_COMPLETE = 100;
1456
1457 public UnlockSim(IccCard simCard) {
1458 mSimCard = simCard;
1459 }
1460
1461 @Override
1462 public void run() {
1463 Looper.prepare();
1464 synchronized (UnlockSim.this) {
1465 mHandler = new Handler() {
1466 @Override
1467 public void handleMessage(Message msg) {
1468 AsyncResult ar = (AsyncResult) msg.obj;
1469 switch (msg.what) {
1470 case SUPPLY_PIN_COMPLETE:
1471 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1472 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001473 mRetryCount = msg.arg1;
1474 if (ar.exception != null) {
1475 if (ar.exception instanceof CommandException &&
1476 ((CommandException)(ar.exception)).getCommandError()
1477 == CommandException.Error.PASSWORD_INCORRECT) {
1478 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1479 } else {
1480 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1481 }
1482 } else {
1483 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485 mDone = true;
1486 UnlockSim.this.notifyAll();
1487 }
1488 break;
1489 }
1490 }
1491 };
1492 UnlockSim.this.notifyAll();
1493 }
1494 Looper.loop();
1495 }
1496
1497 /*
1498 * Use PIN or PUK to unlock SIM card
1499 *
1500 * If PUK is null, unlock SIM card with PIN
1501 *
1502 * If PUK is not null, unlock SIM card with PUK and set PIN code
1503 */
Wink Saville9de0f752013-10-22 19:04:03 -07001504 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505
1506 while (mHandler == null) {
1507 try {
1508 wait();
1509 } catch (InterruptedException e) {
1510 Thread.currentThread().interrupt();
1511 }
1512 }
1513 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1514
1515 if (puk == null) {
1516 mSimCard.supplyPin(pin, callback);
1517 } else {
1518 mSimCard.supplyPuk(puk, pin, callback);
1519 }
1520
1521 while (!mDone) {
1522 try {
1523 Log.d(LOG_TAG, "wait for done");
1524 wait();
1525 } catch (InterruptedException e) {
1526 // Restore the interrupted status
1527 Thread.currentThread().interrupt();
1528 }
1529 }
1530 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001531 int[] resultArray = new int[2];
1532 resultArray[0] = mResult;
1533 resultArray[1] = mRetryCount;
1534 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 }
1536 }
1537
1538 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001540
1541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 // No permission check needed here: this call is harmless, and it's
1545 // needed for the ServiceState.requestStateUpdate() call (which is
1546 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001547 final long identity = Binder.clearCallingIdentity();
1548 try {
1549 final Phone phone = getPhone(subId);
1550 if (phone != null) {
1551 phone.updateServiceLocation();
1552 }
1553 } finally {
1554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001558 @Override
1559 public boolean isRadioOn(String callingPackage) {
1560 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001561 }
1562
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001563 @Override
1564 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001566 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001567 return false;
1568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001569
1570 final long identity = Binder.clearCallingIdentity();
1571 try {
1572 return isRadioOnForSubscriber(subId);
1573 } finally {
1574 Binder.restoreCallingIdentity(identity);
1575 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001576 }
1577
1578 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001579 final long identity = Binder.clearCallingIdentity();
1580 try {
1581 final Phone phone = getPhone(subId);
1582 if (phone != null) {
1583 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1584 } else {
1585 return false;
1586 }
1587 } finally {
1588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 }
1591
1592 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001593 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 }
Wink Saville36469e72014-06-11 15:17:00 -07001595
Wink Savilleb564aae2014-10-23 10:18:09 -07001596 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001598
1599 final long identity = Binder.clearCallingIdentity();
1600 try {
1601 final Phone phone = getPhone(subId);
1602 if (phone != null) {
1603 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1604 }
1605 } finally {
1606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 }
Wink Saville36469e72014-06-11 15:17:00 -07001608 }
1609
1610 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001611 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001612 }
1613
Wink Savilleb564aae2014-10-23 10:18:09 -07001614 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001615 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001616
1617 final long identity = Binder.clearCallingIdentity();
1618 try {
1619 final Phone phone = getPhone(subId);
1620 if (phone == null) {
1621 return false;
1622 }
1623 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1624 toggleRadioOnOffForSubscriber(subId);
1625 }
1626 return true;
1627 } finally {
1628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 }
Wink Saville36469e72014-06-11 15:17:00 -07001631
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001632 public boolean needMobileRadioShutdown() {
1633 /*
1634 * If any of the Radios are available, it will need to be
1635 * shutdown. So return true if any Radio is available.
1636 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1640 Phone phone = PhoneFactory.getPhone(i);
1641 if (phone != null && phone.isRadioAvailable()) return true;
1642 }
1643 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1644 return false;
1645 } finally {
1646 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001647 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001648 }
1649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001650 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001651 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001652 enforceModifyPermission();
1653
1654 final long identity = Binder.clearCallingIdentity();
1655 try {
1656 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1657 logv("Shutting down Phone " + i);
1658 shutdownRadioUsingPhoneId(i);
1659 }
1660 } finally {
1661 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001662 }
1663 }
1664
1665 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001666 Phone phone = PhoneFactory.getPhone(phoneId);
1667 if (phone != null && phone.isRadioAvailable()) {
1668 phone.shutdownRadio();
1669 }
1670 }
1671
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001673 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001674
1675 final long identity = Binder.clearCallingIdentity();
1676 try {
1677 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1678 if (defaultPhone != null) {
1679 defaultPhone.setRadioPower(turnOn);
1680 return true;
1681 } else {
1682 loge("There's no default phone.");
1683 return false;
1684 }
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001687 }
Wink Saville36469e72014-06-11 15:17:00 -07001688 }
1689
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001692
1693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
1697 phone.setRadioPower(turnOn);
1698 return true;
1699 } else {
1700 return false;
1701 }
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
Wink Saville36469e72014-06-11 15:17:00 -07001707 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 public boolean enableDataConnectivity() {
1710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001711
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 int subId = mSubscriptionController.getDefaultDataSubId();
1715 final Phone phone = getPhone(subId);
1716 if (phone != null) {
1717 phone.setUserDataEnabled(true);
1718 return true;
1719 } else {
1720 return false;
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
Wink Saville36469e72014-06-11 15:17:00 -07001727 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 public boolean disableDataConnectivity() {
1730 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001731
1732 final long identity = Binder.clearCallingIdentity();
1733 try {
1734 int subId = mSubscriptionController.getDefaultDataSubId();
1735 final Phone phone = getPhone(subId);
1736 if (phone != null) {
1737 phone.setUserDataEnabled(false);
1738 return true;
1739 } else {
1740 return false;
1741 }
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001748 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 final Phone phone = getPhone(subId);
1752 if (phone != null) {
1753 return phone.isDataAllowed();
1754 } else {
1755 return false;
1756 }
1757 } finally {
1758 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 }
1761
1762 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001763 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001764 }
1765
pkanwarae03a6b2016-11-06 20:37:09 -08001766 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 enforceCallPermission();
1768
1769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1772 return;
1773 }
1774 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1775 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1776 } finally {
1777 Binder.restoreCallingIdentity(identity);
1778 }
pkanwar32d516d2016-10-14 19:37:38 -07001779 };
1780
Wink Savilleb564aae2014-10-23 10:18:09 -07001781 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001783
1784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1787 return false;
1788 }
1789 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001796 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001797 }
1798
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001799 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800 final long identity = Binder.clearCallingIdentity();
1801 try {
1802 Phone phone = PhoneFactory.getPhone(slotIndex);
1803 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1804 PhoneConstantConversions.convertCallState(phone.getState());
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
1807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Sanket Padawe356d7632015-06-22 14:03:32 -07001810 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 final long identity = Binder.clearCallingIdentity();
1813 try {
1814 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1815 if (phone != null) {
1816 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1817 } else {
1818 return PhoneConstantConversions.convertDataState(
1819 PhoneConstants.DataState.DISCONNECTED);
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
Sanket Padawe356d7632015-06-22 14:03:32 -07001826 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001828 final long identity = Binder.clearCallingIdentity();
1829 try {
1830 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1831 if (phone != null) {
1832 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1833 } else {
1834 return TelephonyManager.DATA_ACTIVITY_NONE;
1835 }
1836 } finally {
1837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 }
1840
1841 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001842 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001843 mPhone.getContext().getSystemService(AppOpsManager.class)
1844 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001845 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001846 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001847 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001850 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001851 final long identity = Binder.clearCallingIdentity();
1852 try {
1853 if (DBG_LOC) log("getCellLocation: is active user");
1854 Bundle data = new Bundle();
1855 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1856 if (phone == null) {
1857 return null;
1858 }
1859
1860 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1861 return data;
1862 } finally {
1863 Binder.restoreCallingIdentity(identity);
1864 }
Svetoslav64fad262015-04-14 14:35:21 -07001865 }
1866
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001868 public String getNetworkCountryIsoForPhone(int phoneId) {
1869 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1870 // registered cell info, so return a NULL country instead.
1871 final long identity = Binder.clearCallingIdentity();
1872 try {
1873 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001874 // Todo: fix this when we can get the actual cellular network info when the device
1875 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001876 if (TelephonyManager.NETWORK_TYPE_IWLAN
1877 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1878 return "";
1879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 Phone phone = PhoneFactory.getPhone(phoneId);
1881 if (phone != null) {
1882 ServiceStateTracker sst = phone.getServiceStateTracker();
1883 if (sst != null) {
1884 LocaleTracker lt = sst.getLocaleTracker();
1885 if (lt != null) {
1886 return lt.getCurrentCountry();
1887 }
1888 }
1889 }
1890 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001894 }
1895
1896 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001898 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001902 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 mApp.enforceCallingOrSelfPermission(
1904 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001905
1906 final long identity = Binder.clearCallingIdentity();
1907 try {
1908 final Phone phone = getPhone(subId);
1909 if (phone != null) {
1910 phone.enableLocationUpdates();
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917 @Override
1918 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001919 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001920 }
1921
Sanket Padawe356d7632015-06-22 14:03:32 -07001922 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001923 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 mApp.enforceCallingOrSelfPermission(
1925 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001926
1927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 final Phone phone = getPhone(subId);
1930 if (phone != null) {
1931 phone.disableLocationUpdates();
1932 }
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
1938 @Override
1939 @SuppressWarnings("unchecked")
1940 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001941 mPhone.getContext().getSystemService(AppOpsManager.class)
1942 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001943 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001944 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001945 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
1948 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1949 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1950 return null;
1951 }
Svetoslav64fad262015-04-14 14:35:21 -07001952
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001953 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001955 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001957 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958
1959 final long identity = Binder.clearCallingIdentity();
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001960 try {
1961 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1962 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1963 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1964 } catch (RuntimeException e) {
1965 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 } finally {
1967 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001969 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971
1972
1973 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001974 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001975 mPhone.getContext().getSystemService(AppOpsManager.class)
1976 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001977 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001978 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001979 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 }
1981
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001982 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001983 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001984 final long identity = Binder.clearCallingIdentity();
1985 try {
1986 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1987 for (Phone phone : PhoneFactory.getPhones()) {
1988 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1989 if (info != null) cellInfos.addAll(info);
1990 }
1991 return cellInfos;
1992 } finally {
1993 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995 }
1996
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001997 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001999 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001
2002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 mPhone.setCellInfoListRate(rateInMillis, workSource);
2005 } finally {
2006 Binder.restoreCallingIdentity(identity);
2007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 }
2009
Shishir Agrawala9f32182016-04-12 12:00:16 -07002010 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002011 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002012 Phone phone = PhoneFactory.getPhone(slotIndex);
2013 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002014 return null;
2015 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002016 int subId = phone.getSubId();
2017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2018 mApp, subId, callingPackage, "getImeiForSlot")) {
2019 return null;
2020 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021
2022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 return phone.getImei();
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002028 }
2029
2030 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002031 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002032 Phone phone = PhoneFactory.getPhone(slotIndex);
2033 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002034 return null;
2035 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002036 int subId = phone.getSubId();
2037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2038 mApp, subId, callingPackage, "getMeidForSlot")) {
2039 return null;
2040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 return phone.getMeid();
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
2047 }
Jack Yu2af8d712017-03-15 17:14:14 -07002048 }
2049
2050 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002051 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002052 Phone phone = PhoneFactory.getPhone(slotIndex);
2053 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002054 return null;
2055 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002056 int subId = phone.getSubId();
2057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2058 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2059 return null;
2060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061
2062 final long identity = Binder.clearCallingIdentity();
2063 try {
2064 return phone.getDeviceSvn();
2065 } finally {
2066 Binder.restoreCallingIdentity(identity);
2067 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002068 }
2069
fionaxu43304da2017-11-27 22:51:16 -08002070 @Override
2071 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 final long identity = Binder.clearCallingIdentity();
2073 try {
2074 final Phone phone = getPhone(subId);
2075 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2076 } finally {
2077 Binder.restoreCallingIdentity(identity);
2078 }
fionaxu43304da2017-11-27 22:51:16 -08002079 }
2080
2081 @Override
2082 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002083 final long identity = Binder.clearCallingIdentity();
2084 try {
2085 final Phone phone = getPhone(subId);
2086 return phone == null ? null : phone.getCarrierName();
2087 } finally {
2088 Binder.restoreCallingIdentity(identity);
2089 }
fionaxu43304da2017-11-27 22:51:16 -08002090 }
2091
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 //
2093 // Internal helper methods.
2094 //
2095
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002096 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2098 *
2099 * @throws SecurityException if the caller does not have the required permission
2100 */
2101 private void enforceModifyPermission() {
2102 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2103 }
2104
2105 /**
2106 * Make sure the caller has the CALL_PHONE permission.
2107 *
2108 * @throws SecurityException if the caller does not have the required permission
2109 */
2110 private void enforceCallPermission() {
2111 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2112 }
2113
Stuart Scott8eef64f2015-04-08 15:13:54 -07002114 private void enforceConnectivityInternalPermission() {
2115 mApp.enforceCallingOrSelfPermission(
2116 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2117 "ConnectivityService");
2118 }
2119
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 private String createTelUrl(String number) {
2121 if (TextUtils.isEmpty(number)) {
2122 return null;
2123 }
2124
Jake Hambye994d462014-02-03 13:10:13 -08002125 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 }
2127
Ihab Awadf9e92732013-12-05 18:02:52 -08002128 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2130 }
2131
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002132 private static void logv(String msg) {
2133 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2134 }
2135
Ihab Awadf9e92732013-12-05 18:02:52 -08002136 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2138 }
2139
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002140 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002142 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002143 }
2144
Sanket Padawe356d7632015-06-22 14:03:32 -07002145 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002146 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147 final long identity = Binder.clearCallingIdentity();
2148 try {
2149 final Phone phone = PhoneFactory.getPhone(slotIndex);
2150 if (phone == null) {
2151 return PhoneConstants.PHONE_TYPE_NONE;
2152 } else {
2153 return phone.getPhoneType();
2154 }
2155 } finally {
2156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 }
2159
2160 /**
2161 * Returns the CDMA ERI icon index to display
2162 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002163 @Override
2164 public int getCdmaEriIconIndex(String callingPackage) {
2165 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
2167
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002171 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002172 return -1;
2173 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174
2175 final long identity = Binder.clearCallingIdentity();
2176 try {
2177 final Phone phone = getPhone(subId);
2178 if (phone != null) {
2179 return phone.getCdmaEriIconIndex();
2180 } else {
2181 return -1;
2182 }
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 }
2187
2188 /**
2189 * Returns the CDMA ERI icon mode,
2190 * 0 - ON
2191 * 1 - FLASHING
2192 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002193 @Override
2194 public int getCdmaEriIconMode(String callingPackage) {
2195 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002196 }
2197
Sanket Padawe356d7632015-06-22 14:03:32 -07002198 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002199 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002201 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002202 return -1;
2203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002204
2205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 final Phone phone = getPhone(subId);
2208 if (phone != null) {
2209 return phone.getCdmaEriIconMode();
2210 } else {
2211 return -1;
2212 }
2213 } finally {
2214 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 }
2217
2218 /**
2219 * Returns the CDMA ERI text,
2220 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002221 @Override
2222 public String getCdmaEriText(String callingPackage) {
2223 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002224 }
2225
Sanket Padawe356d7632015-06-22 14:03:32 -07002226 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002227 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002229 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 return null;
2231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232
2233 final long identity = Binder.clearCallingIdentity();
2234 try {
2235 final Phone phone = getPhone(subId);
2236 if (phone != null) {
2237 return phone.getCdmaEriText();
2238 } else {
2239 return null;
2240 }
2241 } finally {
2242 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 }
2245
2246 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002247 * Returns the CDMA MDN.
2248 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002250 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2252 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253
2254 final long identity = Binder.clearCallingIdentity();
2255 try {
2256 final Phone phone = getPhone(subId);
2257 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2258 return phone.getLine1Number();
2259 } else {
2260 return null;
2261 }
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002264 }
2265 }
2266
2267 /**
2268 * Returns the CDMA MIN.
2269 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002271 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2273 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002274
2275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 final Phone phone = getPhone(subId);
2278 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2279 return phone.getCdmaMin();
2280 } else {
2281 return null;
2282 }
2283 } finally {
2284 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002285 }
2286 }
2287
2288 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 * Returns true if CDMA provisioning needs to run.
2290 */
2291 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292 final long identity = Binder.clearCallingIdentity();
2293 try {
2294 return mPhone.needsOtaServiceProvisioning();
2295 } finally {
2296 Binder.restoreCallingIdentity(identity);
2297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
2300 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002301 * Sets the voice mail number of a given subId.
2302 */
2303 @Override
2304 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002305 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306
2307 final long identity = Binder.clearCallingIdentity();
2308 try {
2309 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2310 new Pair<String, String>(alphaTag, number), new Integer(subId));
2311 return success;
2312 } finally {
2313 Binder.restoreCallingIdentity(identity);
2314 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002315 }
2316
Ta-wei Yen87c49842016-05-13 21:19:52 -07002317 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002318 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2320 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2321 if (!TextUtils.equals(callingPackage, systemDialer)) {
2322 throw new SecurityException("caller must be system dialer");
2323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2328 if (phoneAccountHandle == null) {
2329 return null;
2330 }
2331 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002334 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002335 }
2336
2337 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002338 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002339 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002341 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002342 return null;
2343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 return RemoteVvmTaskManager
2348 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
2351 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002352 }
2353
2354 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002355 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2356 VisualVoicemailSmsFilterSettings settings) {
2357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002358
2359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2362 mPhone.getContext(), callingPackage, subId, settings);
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
2365 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002366 }
2367
2368 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002369 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2370 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371
2372 final long identity = Binder.clearCallingIdentity();
2373 try {
2374 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2375 mPhone.getContext(), callingPackage, subId);
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
2378 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002379 }
2380
2381 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002382 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2383 String callingPackage, int subId) {
2384 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002385
2386 final long identity = Binder.clearCallingIdentity();
2387 try {
2388 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2389 mPhone.getContext(), callingPackage, subId);
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
2392 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002393 }
2394
2395 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002396 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002397 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398
2399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2402 mPhone.getContext(), subId);
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
2405 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002406 }
2407
2408 @Override
2409 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2410 String number, int port, String text, PendingIntent sentIntent) {
2411 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002412 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002413 enforceSendSmsPermission();
2414 // Make the calls as the phone process.
2415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2418 if (port == 0) {
2419 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2420 sentIntent, null, false);
2421 } else {
2422 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2423 smsManager.sendDataMessageWithSelfPermissions(number, null,
2424 (short) port, data, sentIntent, null);
2425 }
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002429 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002430 /**
fionaxu0152e512016-11-14 13:36:14 -08002431 * Sets the voice activation state of a given subId.
2432 */
2433 @Override
2434 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2436 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 final Phone phone = getPhone(subId);
2441 if (phone != null) {
2442 phone.setVoiceActivationState(activationState);
2443 } else {
2444 loge("setVoiceActivationState fails with invalid subId: " + subId);
2445 }
2446 } finally {
2447 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002448 }
2449 }
2450
2451 /**
2452 * Sets the data activation state of a given subId.
2453 */
2454 @Override
2455 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2457 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002458
2459 final long identity = Binder.clearCallingIdentity();
2460 try {
2461 final Phone phone = getPhone(subId);
2462 if (phone != null) {
2463 phone.setDataActivationState(activationState);
2464 } else {
2465 loge("setVoiceActivationState fails with invalid subId: " + subId);
2466 }
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002469 }
2470 }
2471
2472 /**
2473 * Returns the voice activation state of a given subId.
2474 */
2475 @Override
2476 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002477 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
fionaxu0152e512016-11-14 13:36:14 -08002479 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 if (phone != null) {
2483 return phone.getVoiceActivationState();
2484 } else {
2485 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2486 }
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002489 }
2490 }
2491
2492 /**
2493 * Returns the data activation state of a given subId.
2494 */
2495 @Override
2496 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002497 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498
fionaxu0152e512016-11-14 13:36:14 -08002499 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 if (phone != null) {
2503 return phone.getDataActivationState();
2504 } else {
2505 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002509 }
2510 }
2511
2512 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 * Returns the unread count of voicemails
2514 */
2515 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002516 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002517 }
2518
2519 /**
2520 * Returns the unread count of voicemails for a subId
2521 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002522 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002523 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 final Phone phone = getPhone(subId);
2527 if (phone != null) {
2528 return phone.getVoiceMessageCount();
2529 } else {
2530 return 0;
2531 }
2532 } finally {
2533 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 }
2536
2537 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002538 * returns true, if the device is in a state where both voice and data
2539 * are supported simultaneously. This can change based on location or network condition.
2540 */
2541 @Override
2542 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543 final long identity = Binder.clearCallingIdentity();
2544 try {
2545 final Phone phone = getPhone(subId);
2546 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
2549 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002550 }
2551
2552 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002553 * Send the dialer code if called from the current default dialer or the caller has
2554 * carrier privilege.
2555 * @param inputCode The dialer code to send
2556 */
2557 @Override
2558 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2560 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2561 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002562 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2563 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 mPhone.sendDialerSpecialCode(inputCode);
2569 } finally {
2570 Binder.restoreCallingIdentity(identity);
2571 }
fionaxu235cc5e2017-03-06 22:25:57 -08002572 }
2573
2574 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002575 * Returns the data network type.
2576 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 *
2578 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2579 */
2580 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002581 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 final Phone phone = getPhone(getDefaultSubscription());
2585 if (phone != null) {
2586 return phone.getServiceState().getDataNetworkType();
2587 } else {
2588 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2589 }
2590 } finally {
2591 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002592 }
Wink Saville36469e72014-06-11 15:17:00 -07002593 }
2594
2595 /**
2596 * Returns the network type for a subId
2597 */
2598 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002599 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002601 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002602 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2603 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(subId);
2608 if (phone != null) {
2609 return phone.getServiceState().getDataNetworkType();
2610 } else {
2611 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2612 }
2613 } finally {
2614 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 }
2617
2618 /**
2619 * Returns the data network type
2620 */
2621 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002622 public int getDataNetworkType(String callingPackage) {
2623 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002624 }
2625
2626 /**
2627 * Returns the data network type for a subId
2628 */
2629 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002632 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002633 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2634 }
2635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 final Phone phone = getPhone(subId);
2639 if (phone != null) {
2640 return phone.getServiceState().getDataNetworkType();
2641 } else {
2642 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2643 }
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648
2649 /**
Wink Saville36469e72014-06-11 15:17:00 -07002650 * Returns the Voice network type for a subId
2651 */
2652 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002653 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002655 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002656 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2657 }
2658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 final Phone phone = getPhone(subId);
2662 if (phone != null) {
2663 return phone.getServiceState().getVoiceNetworkType();
2664 } else {
2665 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2666 }
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
2672 /**
2673 * @return true if a ICC card is present
2674 */
2675 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002676 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002677 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2678 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002679 }
2680
2681 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002682 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002683 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002684 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002685 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 final Phone phone = PhoneFactory.getPhone(slotIndex);
2689 if (phone != null) {
2690 return phone.getIccCard().hasIccCard();
2691 } else {
2692 return false;
2693 }
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
2698
2699 /**
2700 * Return if the current radio is LTE on CDMA. This
2701 * is a tri-state return value as for a period of time
2702 * the mode may be unknown.
2703 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002704 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002706 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002708 @Override
2709 public int getLteOnCdmaMode(String callingPackage) {
2710 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002711 }
2712
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002714 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002716 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002717 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2718 }
2719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 final Phone phone = getPhone(subId);
2723 if (phone == null) {
2724 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2725 } else {
2726 return phone.getLteOnCdmaMode();
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002730 }
Wink Saville36469e72014-06-11 15:17:00 -07002731 }
2732
2733 public void setPhone(Phone phone) {
2734 mPhone = phone;
2735 }
2736
2737 /**
2738 * {@hide}
2739 * Returns Default subId, 0 in the case of single standby.
2740 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002741 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002742 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002743 }
2744
Shishir Agrawala9f32182016-04-12 12:00:16 -07002745 private int getSlotForDefaultSubscription() {
2746 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2747 }
2748
Wink Savilleb564aae2014-10-23 10:18:09 -07002749 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002750 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002752
2753 /**
2754 * @see android.telephony.TelephonyManager.WifiCallingChoices
2755 */
2756 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2760 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2761 getWhenToMakeWifiCallsDefaultPreference());
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
2764 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002765 }
2766
2767 /**
2768 * @see android.telephony.TelephonyManager.WifiCallingChoices
2769 */
2770 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2774 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2775 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
2778 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002779 }
2780
Sailesh Nepald1e68152013-12-12 19:08:02 -08002781 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002782 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002783 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002784 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002785
Shishir Agrawal566b7612013-10-28 14:41:00 -07002786 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002787 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2788 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2790 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 final long identity = Binder.clearCallingIdentity();
2794 try {
2795 if (TextUtils.equals(ISDR_AID, aid)) {
2796 // Only allows LPA to open logical channel to ISD-R.
2797 ComponentInfo bestComponent =
2798 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2799 if (bestComponent == null
2800 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2801 loge("The calling package is not allowed to access ISD-R.");
2802 throw new SecurityException(
2803 "The calling package is not allowed to access ISD-R.");
2804 }
Derek Tan740e1672017-06-27 14:56:27 -07002805 }
Derek Tan740e1672017-06-27 14:56:27 -07002806
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 if (DBG) {
2808 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2809 }
2810 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2811 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2812 if (DBG) log("iccOpenLogicalChannel: " + response);
2813 return response;
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002817 }
2818
2819 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002820 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2822 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2827 if (channel < 0) {
2828 return false;
2829 }
2830 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2831 if (DBG) log("iccCloseLogicalChannel: " + success);
2832 return success;
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002835 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002836 }
2837
2838 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002839 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002840 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2842 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 if (DBG) {
2847 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2848 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2849 + p3 + " data=" + data);
2850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 if (channel < 0) {
2853 return "";
2854 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2857 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2858 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860 // Append the returned status code to the end of the response payload.
2861 String s = Integer.toHexString(
2862 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2863 if (response.payload != null) {
2864 s = IccUtils.bytesToHexString(response.payload) + s;
2865 }
2866 return s;
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002870 }
Jake Hambye994d462014-02-03 13:10:13 -08002871
Evan Charltonc66da362014-05-16 14:06:40 -07002872 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002873 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2874 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2876 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2882 && TextUtils.equals(ISDR_AID, data)) {
2883 // Only allows LPA to select ISD-R.
2884 ComponentInfo bestComponent =
2885 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2886 if (bestComponent == null
2887 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2888 loge("The calling package is not allowed to select ISD-R.");
2889 throw new SecurityException(
2890 "The calling package is not allowed to select ISD-R.");
2891 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002892 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 if (DBG) {
2895 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2896 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2897 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2900 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2901 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 // Append the returned status code to the end of the response payload.
2904 String s = Integer.toHexString(
2905 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2906 if (response.payload != null) {
2907 s = IccUtils.bytesToHexString(response.payload) + s;
2908 }
2909 return s;
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002912 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002913 }
2914
2915 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002916 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002917 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2919 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 if (DBG) {
2924 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2925 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2926 }
2927
2928 IccIoResult response =
2929 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2930 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2931 subId);
2932
2933 if (DBG) {
2934 log("Exchange SIM_IO [R]" + response);
2935 }
2936
2937 byte[] result = null;
2938 int length = 2;
2939 if (response.payload != null) {
2940 length = 2 + response.payload.length;
2941 result = new byte[length];
2942 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2943 } else {
2944 result = new byte[length];
2945 }
2946
2947 result[length - 1] = (byte) response.sw2;
2948 result[length - 2] = (byte) response.sw1;
2949 return result;
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002952 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002953 }
2954
Nathan Haroldb3014052017-01-25 15:57:32 -08002955 /**
2956 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2957 * on a particular subscription
2958 */
sqianb6e41952018-03-12 14:54:01 -07002959 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2961 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2962 return null;
2963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 if (appType != TelephonyManager.APPTYPE_USIM
2968 && appType != TelephonyManager.APPTYPE_SIM) {
2969 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2970 return null;
2971 }
2972 Object response = sendRequest(
2973 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2974 if (response instanceof String[]) {
2975 return (String[]) response;
2976 }
2977 // Response is an Exception of some kind,
2978 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08002979 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 } finally {
2981 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002982 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002983 }
2984
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002985 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002986 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2988 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 final long identity = Binder.clearCallingIdentity();
2991 try {
2992 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2993 if (response.payload == null) {
2994 return "";
2995 }
Evan Charltonc66da362014-05-16 14:06:40 -07002996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 // Append the returned status code to the end of the response payload.
2998 String s = Integer.toHexString(
2999 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3000 s = IccUtils.bytesToHexString(response.payload) + s;
3001 return s;
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
Evan Charltonc66da362014-05-16 14:06:40 -07003005 }
3006
Jake Hambye994d462014-02-03 13:10:13 -08003007 /**
3008 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3009 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3010 *
3011 * @param itemID the ID of the item to read
3012 * @return the NV item as a String, or null on error.
3013 */
3014 @Override
3015 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3017 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 if (DBG) log("nvReadItem: item " + itemID);
3022 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3023 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3024 return value;
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
Jake Hambye994d462014-02-03 13:10:13 -08003028 }
3029
3030 /**
3031 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3032 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3033 *
3034 * @param itemID the ID of the item to read
3035 * @param itemValue the value to write, as a String
3036 * @return true on success; false on any failure
3037 */
3038 @Override
3039 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3041 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3046 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3047 new Pair<Integer, String>(itemID, itemValue));
3048 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3049 return success;
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
Jake Hambye994d462014-02-03 13:10:13 -08003053 }
3054
3055 /**
3056 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3057 * Used for device configuration by some CDMA operators.
3058 *
3059 * @param preferredRoamingList byte array containing the new PRL
3060 * @return true on success; false on any failure
3061 */
3062 @Override
3063 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3065 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3070 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3071 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3072 return success;
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
Jake Hambye994d462014-02-03 13:10:13 -08003076 }
3077
3078 /**
3079 * Perform the specified type of NV config reset.
3080 * Used for device configuration by some CDMA operators.
3081 *
3082 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3083 * @return true on success; false on any failure
3084 */
3085 @Override
3086 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3088 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 if (DBG) log("nvResetConfig: type " + resetType);
3093 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3094 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3095 return success;
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
Jake Hambye994d462014-02-03 13:10:13 -08003099 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003100
Svet Ganovb320e182015-04-16 12:30:10 -07003101 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003103 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003104 return new String[0];
3105 }
3106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 return mPhone.getPcscfAddress(apnType);
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
Wink Saville36469e72014-06-11 15:17:00 -07003113 }
3114
Brad Ebinger51f743a2017-01-23 13:50:20 -08003115 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003116 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3117 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003118 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003119 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121
3122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 PhoneFactory.getImsResolver().enableIms(slotId);
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003128 }
3129
3130 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003131 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3132 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003133 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003134 public void disableIms(int slotId) {
3135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136
3137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 PhoneFactory.getImsResolver().disableIms(slotId);
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003143 }
3144
3145 /**
3146 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3147 * feature or {@link null} if the service is not available. If the feature is available, the
3148 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3149 */
3150 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003151 IImsServiceFeatureCallback callback) {
3152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003160 }
3161
3162 /**
3163 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3164 * feature during emergency calling or {@link null} if the service is not available. If the
3165 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3166 * listener for feature updates.
3167 */
3168 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3169 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003177 }
3178
Brad Ebinger5f64b052017-12-14 14:26:15 -08003179 /**
3180 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3181 * specified.
3182 */
3183 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3184 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003192 }
3193
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003194 /**
3195 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3196 * specified.
3197 */
3198 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3199 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200
3201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003207 }
3208
Brad Ebinger884c07b2018-02-15 16:17:40 -08003209 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003210 * Sets the ImsService Package Name that Telephony will bind to.
3211 *
3212 * @param slotId the slot ID that the ImsService should bind for.
3213 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3214 * ImsService is the device default ImsService.
3215 * @param packageName The package name of the application that contains the ImsService to bind
3216 * to.
3217 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3218 * @hide
3219 */
3220 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003221 int[] subIds = SubscriptionManager.getSubId(slotId);
3222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3223 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3224 "setImsService");
3225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3229 isCarrierImsService, packageName);
3230 } finally {
3231 Binder.restoreCallingIdentity(identity);
3232 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003233 }
3234
3235 /**
3236 * Return the ImsService configuration.
3237 *
3238 * @param slotId The slot that the ImsService is associated with.
3239 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3240 * the device default.
3241 * @return the package name of the ImsService configuration.
3242 */
3243 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003244 int[] subIds = SubscriptionManager.getSubId(slotId);
3245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3246 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3247 "getImsService");
3248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3252 isCarrierImsService);
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003256 }
3257
Wink Saville36469e72014-06-11 15:17:00 -07003258 public void setImsRegistrationState(boolean registered) {
3259 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260
3261 final long identity = Binder.clearCallingIdentity();
3262 try {
3263 mPhone.setImsRegistrationState(registered);
3264 } finally {
3265 Binder.restoreCallingIdentity(identity);
3266 }
Wink Saville36469e72014-06-11 15:17:00 -07003267 }
3268
3269 /**
Stuart Scott54788802015-03-30 13:18:01 -07003270 * Set the network selection mode to automatic.
3271 *
3272 */
3273 @Override
3274 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3276 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3281 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
Stuart Scott54788802015-03-30 13:18:01 -07003285 }
3286
3287 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003288 * Set the network selection mode to manual with the selected carrier.
3289 */
3290 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003291 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003292 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3294 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003299 /* operatorAlphaLong */ "",
3300 /* operatorAlphaShort */ "",
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003301 operatorNumeric);
3302 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3303 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3304 persistSelection);
3305 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3306 } finally {
3307 Binder.restoreCallingIdentity(identity);
3308 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003309 }
3310
3311 /**
3312 * Scans for available networks.
3313 */
3314 @Override
3315 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3317 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318
3319 final long identity = Binder.clearCallingIdentity();
3320 try {
3321 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3322 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3323 CMD_PERFORM_NETWORK_SCAN, null, subId);
3324 return result;
3325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003328 }
3329
3330 /**
yinxub1bed742017-04-17 11:45:04 -07003331 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003332 *
yinxub1bed742017-04-17 11:45:04 -07003333 * @param subId id of the subscription
3334 * @param request contains the radio access networks with bands/channels to scan
3335 * @param messenger callback messenger for scan results or errors
3336 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003337 * @return the id of the requested scan which can be used to stop the scan.
3338 */
3339 @Override
3340 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3341 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3343 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 return mNetworkScanRequestTracker.startNetworkScan(
3348 request, messenger, binder, getPhone(subId));
3349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
yinxu504e1392017-04-12 16:03:22 -07003352 }
3353
3354 /**
3355 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003356 *
3357 * @param subId id of the subscription
3358 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003359 */
3360 @Override
3361 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3363 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364
3365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
yinxu504e1392017-04-12 16:03:22 -07003371 }
3372
3373 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003374 * Get the calculated preferred network type.
3375 * Used for debugging incorrect network type.
3376 *
3377 * @return the preferred network type, defined in RILConstants.java.
3378 */
3379 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003380 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003382 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003383 return RILConstants.PREFERRED_NETWORK_MODE;
3384 }
3385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 // FIXME: need to get SubId from somewhere.
3389 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3390 } finally {
3391 Binder.restoreCallingIdentity(identity);
3392 }
Junda Liu84d15a22014-07-02 11:21:04 -07003393 }
3394
3395 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003396 * Get the preferred network type.
3397 * Used for device configuration by some CDMA operators.
3398 *
3399 * @return the preferred network type, defined in RILConstants.java.
3400 */
3401 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003402 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3404 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 if (DBG) log("getPreferredNetworkType");
3409 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3410 int networkType = (result != null ? result[0] : -1);
3411 if (DBG) log("getPreferredNetworkType: " + networkType);
3412 return networkType;
3413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003416 }
3417
3418 /**
3419 * Set the preferred network type.
3420 * Used for device configuration by some CDMA operators.
3421 *
3422 * @param networkType the preferred network type, defined in RILConstants.java.
3423 * @return true on success; false on any failure.
3424 */
3425 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003426 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3428 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429
3430 final long identity = Binder.clearCallingIdentity();
3431 try {
3432 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3433 Boolean success = (Boolean) sendRequest(
3434 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3435 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3436 if (success) {
3437 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3438 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3439 }
3440 return success;
3441 } finally {
3442 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003443 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003444 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003445
3446 /**
Junda Liu475951f2014-11-07 16:45:03 -08003447 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3448 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3449 * tethering.
3450 *
3451 * @return 0: Not required. 1: required. 2: Not set.
3452 * @hide
3453 */
3454 @Override
3455 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003456 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003457
3458 final long identity = Binder.clearCallingIdentity();
3459 try {
3460 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3461 Settings.Global.TETHER_DUN_REQUIRED, 2);
3462 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3463 // config_tether_apndata.
3464 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3465 dunRequired = 1;
3466 }
3467 return dunRequired;
3468 } finally {
3469 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003470 }
Junda Liu475951f2014-11-07 16:45:03 -08003471 }
3472
3473 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003474 * Set mobile data enabled
3475 * Used by the user through settings etc to turn on/off mobile data
3476 *
3477 * @param enable {@code true} turn turn data on, else {@code false}
3478 */
3479 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003480 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3482 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483
3484 final long identity = Binder.clearCallingIdentity();
3485 try {
3486 int phoneId = mSubscriptionController.getPhoneId(subId);
3487 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3488 Phone phone = PhoneFactory.getPhone(phoneId);
3489 if (phone != null) {
3490 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3491 phone.setUserDataEnabled(enable);
3492 } else {
3493 loge("setUserDataEnabled: no phone for subId=" + subId);
3494 }
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003497 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003498 }
3499
3500 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003501 * Get the user enabled state of Mobile Data.
3502 *
3503 * TODO: remove and use isUserDataEnabled.
3504 * This can't be removed now because some vendor codes
3505 * calls through ITelephony directly while they should
3506 * use TelephonyManager.
3507 *
3508 * @return true on enabled
3509 */
3510 @Override
3511 public boolean getDataEnabled(int subId) {
3512 return isUserDataEnabled(subId);
3513 }
3514
3515 /**
3516 * Get whether mobile data is enabled per user setting.
3517 *
3518 * There are other factors deciding whether mobile data is actually enabled, but they are
3519 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003520 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003521 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003522 *
3523 * @return {@code true} if data is enabled else {@code false}
3524 */
3525 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003526 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003527 try {
3528 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3529 null);
3530 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3532 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 int phoneId = mSubscriptionController.getPhoneId(subId);
3538 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3539 Phone phone = PhoneFactory.getPhone(phoneId);
3540 if (phone != null) {
3541 boolean retVal = phone.isUserDataEnabled();
3542 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3543 return retVal;
3544 } else {
3545 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3546 return false;
3547 }
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003550 }
3551 }
3552
3553 /**
3554 * Get whether mobile data is enabled.
3555 *
3556 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3557 * whether mobile data is actually enabled.
3558 *
3559 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3560 *
3561 * @return {@code true} if data is enabled else {@code false}
3562 */
3563 @Override
3564 public boolean isDataEnabled(int subId) {
3565 try {
3566 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3567 null);
3568 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3570 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 int phoneId = mSubscriptionController.getPhoneId(subId);
3576 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3577 Phone phone = PhoneFactory.getPhone(phoneId);
3578 if (phone != null) {
3579 boolean retVal = phone.isDataEnabled();
3580 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3581 return retVal;
3582 } else {
3583 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3584 return false;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003588 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003589 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003590
3591 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003592 public int getCarrierPrivilegeStatus(int subId) {
3593 final Phone phone = getPhone(subId);
3594 if (phone == null) {
3595 loge("getCarrierPrivilegeStatus: Invalid subId");
3596 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3597 }
3598 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003599 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003600 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003601 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3602 }
3603 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003604 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003605 }
Junda Liu29340342014-07-10 15:23:27 -07003606
3607 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003608 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3609 final Phone phone = getPhone(subId);
3610 if (phone == null) {
3611 loge("getCarrierPrivilegeStatus: Invalid subId");
3612 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3613 }
3614 UiccProfile profile =
3615 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3616 if (profile == null) {
3617 loge("getCarrierPrivilegeStatus: No UICC");
3618 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3619 }
3620 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3621 }
3622
3623 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003624 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003625 if (TextUtils.isEmpty(pkgName))
3626 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003627 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003628 if (card == null) {
3629 loge("checkCarrierPrivilegesForPackage: No UICC");
3630 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3631 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003632 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3633 }
3634
3635 @Override
3636 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003637 if (TextUtils.isEmpty(pkgName))
3638 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003639 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3640 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3641 UiccCard card = UiccController.getInstance().getUiccCard(i);
3642 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003643 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003644 continue;
3645 }
3646
3647 result = card.getCarrierPrivilegeStatus(
3648 mPhone.getContext().getPackageManager(), pkgName);
3649 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3650 break;
3651 }
3652 }
3653
3654 return result;
Junda Liu29340342014-07-10 15:23:27 -07003655 }
Derek Tan89e89d42014-07-08 17:00:10 -07003656
3657 @Override
Junda Liue64de782015-04-16 17:19:16 -07003658 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3659 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3660 loge("phoneId " + phoneId + " is not valid.");
3661 return null;
3662 }
3663 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003664 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003665 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003666 return null ;
3667 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003668 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003669 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003670 }
3671
Amith Yamasani6e118872016-02-19 12:53:51 -08003672 @Override
3673 public List<String> getPackagesWithCarrierPrivileges() {
3674 PackageManager pm = mPhone.getContext().getPackageManager();
3675 List<String> privilegedPackages = new ArrayList<>();
3676 List<PackageInfo> packages = null;
3677 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3678 UiccCard card = UiccController.getInstance().getUiccCard(i);
3679 if (card == null) {
3680 // No UICC in that slot.
3681 continue;
3682 }
3683 if (card.hasCarrierPrivilegeRules()) {
3684 if (packages == null) {
3685 // Only check packages in user 0 for now
3686 packages = pm.getInstalledPackagesAsUser(
3687 PackageManager.MATCH_DISABLED_COMPONENTS
3688 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3689 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3690 }
3691 for (int p = packages.size() - 1; p >= 0; p--) {
3692 PackageInfo pkgInfo = packages.get(p);
3693 if (pkgInfo != null && pkgInfo.packageName != null
3694 && card.getCarrierPrivilegeStatus(pkgInfo)
3695 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3696 privilegedPackages.add(pkgInfo.packageName);
3697 }
3698 }
3699 }
3700 }
3701 return privilegedPackages;
3702 }
3703
Wink Savilleb564aae2014-10-23 10:18:09 -07003704 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003705 final Phone phone = getPhone(subId);
3706 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003707 if (card == null) {
3708 loge("getIccId: No UICC");
3709 return null;
3710 }
3711 String iccId = card.getIccId();
3712 if (TextUtils.isEmpty(iccId)) {
3713 loge("getIccId: ICC ID is null or empty.");
3714 return null;
3715 }
3716 return iccId;
3717 }
3718
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003719 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003720 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3721 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003722 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3723 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 final String iccId = getIccId(subId);
3728 final Phone phone = getPhone(subId);
3729 if (phone == null) {
3730 return false;
3731 }
3732 final String subscriberId = phone.getSubscriberId();
3733
3734 if (DBG_MERGE) {
3735 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3736 + subscriberId + " to " + number);
3737 }
3738
3739 if (TextUtils.isEmpty(iccId)) {
3740 return false;
3741 }
3742
3743 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3744
3745 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3746 if (alphaTag == null) {
3747 editor.remove(alphaTagPrefKey);
3748 } else {
3749 editor.putString(alphaTagPrefKey, alphaTag);
3750 }
3751
3752 // Record both the line number and IMSI for this ICCID, since we need to
3753 // track all merged IMSIs based on line number
3754 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3755 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3756 if (number == null) {
3757 editor.remove(numberPrefKey);
3758 editor.remove(subscriberPrefKey);
3759 } else {
3760 editor.putString(numberPrefKey, number);
3761 editor.putString(subscriberPrefKey, subscriberId);
3762 }
3763
3764 editor.commit();
3765 return true;
3766 } finally {
3767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003768 }
Derek Tan7226c842014-07-02 17:42:23 -07003769 }
3770
3771 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003772 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003773 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003775 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003776 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003777 return null;
3778 }
Derek Tan97ebb422014-09-05 16:55:38 -07003779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780 final long identity = Binder.clearCallingIdentity();
3781 try {
3782 String iccId = getIccId(subId);
3783 if (iccId != null) {
3784 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3785 if (DBG_MERGE) {
3786 log("getLine1NumberForDisplay returning "
3787 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3788 }
3789 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3792 return null;
3793 } finally {
3794 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003795 }
Derek Tan7226c842014-07-02 17:42:23 -07003796 }
3797
3798 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003799 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003801 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003802 return null;
3803 }
Derek Tan97ebb422014-09-05 16:55:38 -07003804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805 final long identity = Binder.clearCallingIdentity();
3806 try {
3807 String iccId = getIccId(subId);
3808 if (iccId != null) {
3809 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3810 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3811 }
3812 return null;
3813 } finally {
3814 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003815 }
Derek Tan7226c842014-07-02 17:42:23 -07003816 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003817
3818 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003819 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003820 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3821 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003823 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3824 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003825 return null;
3826 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003827
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003828 final long identity = Binder.clearCallingIdentity();
3829 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 final Context context = mPhone.getContext();
3831 final TelephonyManager tele = TelephonyManager.from(context);
3832 final SubscriptionManager sub = SubscriptionManager.from(context);
3833
3834 // Figure out what subscribers are currently active
3835 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3836 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3837 // the process, where TelephonyManager was instantiated.
3838 // Otherwise AppOps check will fail.
3839
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003840 final int[] subIds = sub.getActiveSubscriptionIdList();
3841 for (int subId : subIds) {
3842 activeSubscriberIds.add(tele.getSubscriberId(subId));
3843 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844
3845 // First pass, find a number override for an active subscriber
3846 String mergeNumber = null;
3847 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3848 for (String key : prefs.keySet()) {
3849 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3850 final String subscriberId = (String) prefs.get(key);
3851 if (activeSubscriberIds.contains(subscriberId)) {
3852 final String iccId = key.substring(
3853 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3854 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3855 mergeNumber = (String) prefs.get(numberKey);
3856 if (DBG_MERGE) {
3857 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3858 + " for active subscriber " + subscriberId);
3859 }
3860 if (!TextUtils.isEmpty(mergeNumber)) {
3861 break;
3862 }
3863 }
3864 }
3865 }
3866
3867 // Shortcut when no active merged subscribers
3868 if (TextUtils.isEmpty(mergeNumber)) {
3869 return null;
3870 }
3871
3872 // Second pass, find all subscribers under that line override
3873 final ArraySet<String> result = new ArraySet<>();
3874 for (String key : prefs.keySet()) {
3875 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3876 final String number = (String) prefs.get(key);
3877 if (mergeNumber.equals(number)) {
3878 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3879 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3880 final String subscriberId = (String) prefs.get(subscriberKey);
3881 if (!TextUtils.isEmpty(subscriberId)) {
3882 result.add(subscriberId);
3883 }
3884 }
3885 }
3886 }
3887
3888 final String[] resultArray = result.toArray(new String[result.size()]);
3889 Arrays.sort(resultArray);
3890 if (DBG_MERGE) {
3891 Slog.d(LOG_TAG,
3892 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3893 }
3894 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003895 } finally {
3896 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003897 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003898 }
3899
3900 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003901 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003902 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3903 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904
3905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 final Phone phone = getPhone(subId);
3908 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3909 } finally {
3910 Binder.restoreCallingIdentity(identity);
3911 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003912 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003913
3914 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003915 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003916 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3917 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003918 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 final Phone phone = getPhone(subId);
3923 if (phone == null) {
3924 return false;
3925 }
3926 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3927 cdmaNonRoamingList);
3928 } finally {
3929 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003930 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003931 }
3932
3933 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003934 @Deprecated
3935 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3936 enforceModifyPermission();
3937
3938 int returnValue = 0;
3939 try {
3940 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3941 if(result.exception == null) {
3942 if (result.result != null) {
3943 byte[] responseData = (byte[])(result.result);
3944 if(responseData.length > oemResp.length) {
3945 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3946 responseData.length + "bytes. Buffer Size is " +
3947 oemResp.length + "bytes.");
3948 }
3949 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3950 returnValue = responseData.length;
3951 }
3952 } else {
3953 CommandException ex = (CommandException) result.exception;
3954 returnValue = ex.getCommandError().ordinal();
3955 if(returnValue > 0) returnValue *= -1;
3956 }
3957 } catch (RuntimeException e) {
3958 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3959 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3960 if(returnValue > 0) returnValue *= -1;
3961 }
3962
3963 return returnValue;
3964 }
3965
3966 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003967 public void setRadioCapability(RadioAccessFamily[] rafs) {
3968 try {
3969 ProxyController.getInstance().setRadioCapability(rafs);
3970 } catch (RuntimeException e) {
3971 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3972 }
3973 }
3974
3975 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003976 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003977 Phone phone = PhoneFactory.getPhone(phoneId);
3978 if (phone == null) {
3979 return RadioAccessFamily.RAF_UNKNOWN;
3980 }
3981 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003983 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003984 return RadioAccessFamily.RAF_UNKNOWN;
3985 }
3986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 final long identity = Binder.clearCallingIdentity();
3988 try {
3989 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3990 } finally {
3991 Binder.restoreCallingIdentity(identity);
3992 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003993 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003994
3995 @Override
3996 public void enableVideoCalling(boolean enable) {
3997 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998
3999 final long identity = Binder.clearCallingIdentity();
4000 try {
4001 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4002 } finally {
4003 Binder.restoreCallingIdentity(identity);
4004 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004005 }
4006
4007 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004008 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4010 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4011 return false;
4012 }
Svet Ganovb320e182015-04-16 12:30:10 -07004013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 // Check the user preference and the system-level IMS setting. Even if the user has
4017 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4018 // In the long run, we may instead need to check if there exists a connection service
4019 // which can support video calling.
4020 ImsManager imsManager =
4021 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4022 return imsManager.isVtEnabledByPlatform()
4023 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4024 && imsManager.isVtEnabledByUser();
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004028 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004029
Andrew Leea1239f22015-03-02 17:44:07 -08004030 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4033 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4034 return false;
4035 }
4036
4037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 CarrierConfigManager configManager =
4040 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4041 return configManager.getConfigForSubId(mPhone.getSubId())
4042 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4043 } finally {
4044 Binder.restoreCallingIdentity(identity);
4045 }
Andrew Leea1239f22015-03-02 17:44:07 -08004046 }
4047
4048 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 public boolean isWorldPhone(int subId, String callingPackage) {
4050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4051 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4052 return false;
4053 }
4054
4055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 CarrierConfigManager configManager =
4058 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4059 return configManager.getConfigForSubId(mPhone.getSubId())
4060 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
Andrew Leea1239f22015-03-02 17:44:07 -08004064 }
4065
Andrew Lee9431b832015-03-09 18:46:45 -07004066 @Override
4067 public boolean isTtyModeSupported() {
4068 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004069 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004070 }
4071
4072 @Override
4073 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4077 } finally {
4078 Binder.restoreCallingIdentity(identity);
4079 }
Andrew Lee9431b832015-03-09 18:46:45 -07004080 }
4081
Hall Liu98187582018-01-22 19:15:32 -08004082 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4086 mPhone.getSubId()).getBoolean(
4087 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4088 boolean isDeviceSupported =
4089 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4090 return isCarrierSupported && isDeviceSupported;
4091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
Hall Liu98187582018-01-22 19:15:32 -08004094 }
4095
Hall Liu3ad5f012018-04-06 16:23:39 -07004096 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 return isRttSupported() && Settings.Secure.getInt(
4100 mPhone.getContext().getContentResolver(),
4101 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
4104 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004105 }
4106
Sanket Padawe7310cc72015-01-14 09:53:20 -08004107 /**
4108 * Returns the unique device ID of phone, for example, the IMEI for
4109 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4110 *
4111 * <p>Requires Permission:
4112 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4113 */
4114 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004115 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004116 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004117 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004118 return null;
4119 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004120 int subId = phone.getSubId();
4121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4122 mApp, subId, callingPackage, "getDeviceId")) {
4123 return null;
4124 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 return phone.getDeviceId();
4129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004132 }
4133
Ping Sunc67b7c22016-03-02 19:16:45 +08004134 /**
4135 * {@hide}
4136 * Returns the IMS Registration Status on a particular subid
4137 *
4138 * @param subId
4139 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004140 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004141 Phone phone = getPhone(subId);
4142 if (phone != null) {
4143 return phone.isImsRegistered();
4144 } else {
4145 return false;
4146 }
4147 }
4148
Santos Cordon7a1885b2015-02-03 11:15:19 -08004149 @Override
4150 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4154 } finally {
4155 Binder.restoreCallingIdentity(identity);
4156 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004157 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004158
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004159 /**
4160 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004161 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004162 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 final long identity = Binder.clearCallingIdentity();
4164 try {
4165 Phone phone = getPhone(subId);
4166 if (phone != null) {
4167 return phone.isWifiCallingEnabled();
4168 } else {
4169 return false;
4170 }
4171 } finally {
4172 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004173 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004174 }
4175
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004176 /**
4177 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004178 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004179 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 Phone phone = getPhone(subId);
4183 if (phone != null) {
4184 return phone.isVolteEnabled();
4185 } else {
4186 return false;
4187 }
4188 } finally {
4189 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004190 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004191 }
Svet Ganovb320e182015-04-16 12:30:10 -07004192
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004193 /**
4194 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004195 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004196 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 final long identity = Binder.clearCallingIdentity();
4198 try {
4199 Phone phone = getPhone(subId);
4200 if (phone != null) {
4201 return phone.isVideoEnabled();
4202 } else {
4203 return false;
4204 }
4205 } finally {
4206 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004207 }
4208 }
4209
4210 /**
4211 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4212 * defined in {@link ImsRegistrationImplBase}.
4213 */
4214 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 Phone phone = getPhone(subId);
4218 if (phone != null) {
4219 return phone.getImsRegistrationTech();
4220 } else {
4221 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4222 }
4223 } finally {
4224 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004225 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004226 }
4227
Stuart Scott8eef64f2015-04-08 15:13:54 -07004228 @Override
4229 public void factoryReset(int subId) {
4230 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004231 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4232 return;
4233 }
4234
Svet Ganovcc087f82015-05-12 20:35:54 -07004235 final long identity = Binder.clearCallingIdentity();
4236 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004237 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4238 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004239 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004240 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004241 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4242 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004243 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004244 }
4245 } finally {
4246 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004247 }
4248 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004249
4250 @Override
4251 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 // We query all subscriptions instead of just the active ones, because
4255 // this might be called early on in the provisioning flow when the
4256 // subscriptions potentially aren't active yet.
4257 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4258 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004259 return null;
4260 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 // This function may be called very early, say, from the setup wizard, at
4263 // which point we won't have a default subscription set. If that's the case
4264 // we just choose the first, which will be valid in "most cases".
4265 final int defaultSubId = getDefaultSubscription();
4266 SubscriptionInfo info = null;
4267 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4268 info = slist.get(0);
4269 } else {
4270 for (SubscriptionInfo item : slist) {
4271 if (item.getSubscriptionId() == defaultSubId) {
4272 info = item;
4273 break;
4274 }
4275 }
4276
4277 if (info == null) {
4278 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004279 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004280 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282 // Try and fetch the locale from the carrier properties or from the SIM language
4283 // preferences (EF-PL and EF-LI)...
4284 final int mcc = info.getMcc();
4285 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4286 String simLanguage = null;
4287 if (defaultPhone != null) {
4288 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4289 if (localeFromDefaultSim != null) {
4290 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4291 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4292 return localeFromDefaultSim.toLanguageTag();
4293 } else {
4294 simLanguage = localeFromDefaultSim.getLanguage();
4295 }
4296 }
4297 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 // The SIM language preferences only store a language (e.g. fr = French), not an
4300 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4301 // the SIM and carrier preferences does not include a country we add the country
4302 // determined from the SIM MCC to provide an exact locale.
4303 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4304 simLanguage);
4305 if (mccLocale != null) {
4306 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4307 return mccLocale.toLanguageTag();
4308 }
4309
4310 if (DBG) log("No locale found - returning null");
4311 return null;
4312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004315 }
4316
4317 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004318 return mSubscriptionController.getAllSubInfoList(
4319 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004320 }
4321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322 /**
4323 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4324 */
4325 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4326 return mSubscriptionController.getActiveSubscriptionInfoList(
4327 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004328 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004329
Chenjie Yu1ba97252018-01-11 18:16:20 -08004330 private final ModemActivityInfo mLastModemActivityInfo =
4331 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4332
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004333 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004334 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4335 * representing the state of the modem.
4336 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004337 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4338 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004339 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004340 */
4341 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004342 public void requestModemActivityInfo(ResultReceiver result) {
4343 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004344
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 ModemActivityInfo ret = null;
4348 synchronized (mLastModemActivityInfo) {
4349 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4350 CMD_GET_MODEM_ACTIVITY_INFO,
4351 null);
Siddharth Rayb8114062018-06-17 15:02:38 -07004352 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4354 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4355 mergedTxTimeMs[i] =
4356 info.getTxTimeMillis()[i]
4357 + mLastModemActivityInfo.getTxTimeMillis()[i];
4358 }
4359 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4360 mLastModemActivityInfo.setSleepTimeMillis(
4361 info.getSleepTimeMillis()
4362 + mLastModemActivityInfo.getSleepTimeMillis());
4363 mLastModemActivityInfo.setIdleTimeMillis(
4364 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4365 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4366 mLastModemActivityInfo.setRxTimeMillis(
4367 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4368 mLastModemActivityInfo.setEnergyUsed(
4369 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4372 mLastModemActivityInfo.getSleepTimeMillis(),
4373 mLastModemActivityInfo.getIdleTimeMillis(),
4374 mLastModemActivityInfo.getTxTimeMillis(),
4375 mLastModemActivityInfo.getRxTimeMillis(),
4376 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 Bundle bundle = new Bundle();
4379 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4380 result.send(0, bundle);
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004383 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004384 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004385
Siddharth Rayb8114062018-06-17 15:02:38 -07004386 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4387 // less than total activity duration.
4388 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4389 if (info == null) {
4390 return false;
4391 }
4392 int activityDurationMs =
4393 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4394 int totalTxTimeMs = 0;
4395 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4396 totalTxTimeMs += info.getTxTimeMillis()[i];
4397 }
4398 return (info.isValid()
4399 && (info.getSleepTimeMillis() <= activityDurationMs)
4400 && (info.getIdleTimeMillis() <= activityDurationMs)
4401 && (info.getRxTimeMillis() <= activityDurationMs)
4402 && (totalTxTimeMs <= activityDurationMs));
4403 }
4404
Jack Yu85bd38a2015-11-09 11:34:32 -08004405 /**
4406 * {@hide}
4407 * Returns the service state information on specified subscription.
4408 */
4409 @Override
4410 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004412 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004413 return null;
4414 }
4415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004416 final long identity = Binder.clearCallingIdentity();
4417 try {
4418 final Phone phone = getPhone(subId);
4419 if (phone == null) {
4420 return null;
4421 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004423 return phone.getServiceState();
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004427 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004428
4429 /**
4430 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4431 *
4432 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4433 * voicemail ringtone.
4434 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4435 * PhoneAccount.
4436 */
4437 @Override
4438 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004439 final long identity = Binder.clearCallingIdentity();
4440 try {
4441 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4442 if (phone == null) {
4443 phone = mPhone;
4444 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004450 }
4451
4452 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004453 * Sets the per-account voicemail ringtone.
4454 *
4455 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4456 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4457 *
4458 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4459 * voicemail ringtone.
4460 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4461 * PhoneAccount.
4462 */
4463 @Override
4464 public void setVoicemailRingtoneUri(String callingPackage,
4465 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4466 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4467 if (!TextUtils.equals(callingPackage,
4468 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4470 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4471 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473
4474 final long identity = Binder.clearCallingIdentity();
4475 try {
4476 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4477 if (phone == null) {
4478 phone = mPhone;
4479 }
4480 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4481 } finally {
4482 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004483 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004484 }
4485
4486 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004487 * Returns whether vibration is set for voicemail notification in Phone settings.
4488 *
4489 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4490 * voicemail vibration setting.
4491 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4492 */
4493 @Override
4494 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
4497 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4498 if (phone == null) {
4499 phone = mPhone;
4500 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004506 }
4507
Youhan Wange64578a2016-05-02 15:32:42 -07004508 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004509 * Sets the per-account voicemail vibration.
4510 *
4511 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4512 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4513 *
4514 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4515 * voicemail vibration setting.
4516 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4517 * specific PhoneAccount.
4518 */
4519 @Override
4520 public void setVoicemailVibrationEnabled(String callingPackage,
4521 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4522 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4523 if (!TextUtils.equals(callingPackage,
4524 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4526 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4527 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004528 }
4529
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530 final long identity = Binder.clearCallingIdentity();
4531 try {
4532 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4533 if (phone == null) {
4534 phone = mPhone;
4535 }
4536 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4537 } finally {
4538 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004539 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004540 }
4541
4542 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004543 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4544 *
4545 * @throws SecurityException if the caller does not have the required permission
4546 */
4547 private void enforceReadPrivilegedPermission() {
4548 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4549 null);
4550 }
4551
4552 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004553 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4554 * permission.
4555 *
4556 * @throws SecurityException if the caller does not have the required permission
4557 */
4558 private void enforceSendSmsPermission() {
4559 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4560 }
4561
4562 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004563 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004564 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004565 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004566 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004567 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 final long identity = Binder.clearCallingIdentity();
4569 try {
4570 ComponentName componentName =
4571 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4572 if (componentName == null) {
4573 throw new SecurityException(
4574 "Caller not current active visual voicemail package[null]");
4575 }
4576 String vvmPackage = componentName.getPackageName();
4577 if (!callingPackage.equals(vvmPackage)) {
4578 throw new SecurityException("Caller not current active visual voicemail package["
4579 + vvmPackage + "]");
4580 }
4581 } finally {
4582 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004583 }
4584 }
4585
4586 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004587 * Return the application ID for the app type.
4588 *
4589 * @param subId the subscription ID that this request applies to.
4590 * @param appType the uicc app type.
4591 * @return Application ID for specificied app type, or null if no uicc.
4592 */
4593 @Override
4594 public String getAidForAppType(int subId, int appType) {
4595 enforceReadPrivilegedPermission();
4596 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597
4598 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004599 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004600 if (phone == null) {
4601 return null;
4602 }
4603 String aid = null;
4604 try {
4605 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4606 .getApplicationByType(appType).getAid();
4607 } catch (Exception e) {
4608 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4609 }
4610 return aid;
4611 } finally {
4612 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004613 }
Youhan Wange64578a2016-05-02 15:32:42 -07004614 }
4615
Youhan Wang4001d252016-05-11 10:29:41 -07004616 /**
4617 * Return the Electronic Serial Number.
4618 *
4619 * @param subId the subscription ID that this request applies to.
4620 * @return ESN or null if error.
4621 */
4622 @Override
4623 public String getEsn(int subId) {
4624 enforceReadPrivilegedPermission();
4625 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626
4627 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004628 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 if (phone == null) {
4630 return null;
4631 }
4632 String esn = null;
4633 try {
4634 esn = phone.getEsn();
4635 } catch (Exception e) {
4636 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4637 }
4638 return esn;
4639 } finally {
4640 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004641 }
Youhan Wang4001d252016-05-11 10:29:41 -07004642 }
4643
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004644 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004645 * Return the Preferred Roaming List Version.
4646 *
4647 * @param subId the subscription ID that this request applies to.
4648 * @return PRLVersion or null if error.
4649 */
4650 @Override
4651 public String getCdmaPrlVersion(int subId) {
4652 enforceReadPrivilegedPermission();
4653 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654
4655 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004656 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 if (phone == null) {
4658 return null;
4659 }
4660 String cdmaPrlVersion = null;
4661 try {
4662 cdmaPrlVersion = phone.getCdmaPrlVersion();
4663 } catch (Exception e) {
4664 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4665 }
4666 return cdmaPrlVersion;
4667 } finally {
4668 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004669 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004670 }
4671
4672 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004673 * Get snapshot of Telephony histograms
4674 * @return List of Telephony histograms
4675 * @hide
4676 */
4677 @Override
4678 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4680 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681
4682 final long identity = Binder.clearCallingIdentity();
4683 try {
4684 return RIL.getTelephonyRILTimingHistograms();
4685 } finally {
4686 Binder.restoreCallingIdentity(identity);
4687 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004688 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004689
4690 /**
4691 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004692 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004693 * Require system privileges. In the future we may add this to carrier APIs.
4694 *
4695 * @return The number of carriers set successfully, should match length of carriers
4696 */
4697 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004698 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004699 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004700
Meng Wang9b7c4e92017-02-17 11:41:27 -08004701 if (carriers == null) {
4702 throw new NullPointerException("carriers cannot be null");
4703 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4708 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4709 return retVal[0];
4710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004713 }
4714
4715 /**
4716 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004717 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004718 * Require system privileges. In the future we may add this to carrier APIs.
4719 *
4720 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4721 * means all carriers are allowed.
4722 */
4723 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004724 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004725 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726
4727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4730 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004734 }
4735
fionaxu59545b42016-05-25 15:53:37 -07004736 /**
4737 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4738 * @param subId the subscription ID that this action applies to.
4739 * @param enabled control enable or disable metered apns.
4740 * {@hide}
4741 */
4742 @Override
4743 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4744 enforceModifyPermission();
4745 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746
4747 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004748 if (phone == null) {
4749 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4750 return;
4751 }
4752 try {
4753 phone.carrierActionSetMeteredApnsEnabled(enabled);
4754 } catch (Exception e) {
4755 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004756 } finally {
4757 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004758 }
4759 }
4760
4761 /**
4762 * Action set from carrier signalling broadcast receivers to enable/disable radio
4763 * @param subId the subscription ID that this action applies to.
4764 * @param enabled control enable or disable radio.
4765 * {@hide}
4766 */
4767 @Override
4768 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4769 enforceModifyPermission();
4770 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004771
4772 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004773 if (phone == null) {
4774 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4775 return;
4776 }
4777 try {
4778 phone.carrierActionSetRadioEnabled(enabled);
4779 } catch (Exception e) {
4780 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 } finally {
4782 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004783 }
4784 }
4785
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004786 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004787 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4788 * network status based on which carrier apps could apply actions accordingly,
4789 * enable/disable default url handler for example.
4790 *
4791 * @param subId the subscription ID that this action applies to.
4792 * @param report control start/stop reporting the default network status.
4793 * {@hide}
4794 */
4795 @Override
4796 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4797 enforceModifyPermission();
4798 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799
4800 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004801 if (phone == null) {
4802 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4803 return;
4804 }
4805 try {
4806 phone.carrierActionReportDefaultNetworkStatus(report);
4807 } catch (Exception e) {
4808 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 } finally {
4810 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004811 }
4812 }
4813
4814 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004815 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4816 * bug report is being generated.
4817 */
4818 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004819 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004820 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4821 != PackageManager.PERMISSION_GRANTED) {
4822 writer.println("Permission Denial: can't dump Phone from pid="
4823 + Binder.getCallingPid()
4824 + ", uid=" + Binder.getCallingUid()
4825 + "without permission "
4826 + android.Manifest.permission.DUMP);
4827 return;
4828 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004829 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004830 }
Jack Yueb89b242016-06-22 13:27:47 -07004831
Brad Ebingerdac2f002018-04-03 15:17:52 -07004832 @Override
4833 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4834 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4835 throws RemoteException {
4836 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4837 }
4838
Jack Yueb89b242016-06-22 13:27:47 -07004839 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004840 * Get aggregated video call data usage since boot.
4841 *
4842 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4843 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004844 * {@hide}
4845 */
4846 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004847 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004848 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4849 null);
4850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 final long identity = Binder.clearCallingIdentity();
4852 try {
4853 // NetworkStatsService keeps tracking the active network interface and identity. It
4854 // records the delta with the corresponding network identity.
4855 // We just return the total video call data usage snapshot since boot.
4856 Phone phone = getPhone(subId);
4857 if (phone != null) {
4858 return phone.getVtDataUsage(perUidStats);
4859 }
4860 return null;
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004863 }
Jack Yueb89b242016-06-22 13:27:47 -07004864 }
Jack Yu75ab2952016-07-08 14:29:33 -07004865
4866 /**
4867 * Policy control of data connection. Usually used when data limit is passed.
4868 * @param enabled True if enabling the data, otherwise disabling.
4869 * @param subId Subscription index
4870 * {@hide}
4871 */
4872 @Override
4873 public void setPolicyDataEnabled(boolean enabled, int subId) {
4874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875
4876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 Phone phone = getPhone(subId);
4879 if (phone != null) {
4880 phone.setPolicyDataEnabled(enabled);
4881 }
4882 } finally {
4883 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004884 }
4885 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004886
4887 /**
4888 * Get Client request stats
4889 * @return List of Client Request Stats
4890 * @hide
4891 */
4892 @Override
4893 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004895 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004896 return null;
4897 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004898 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 final long identity = Binder.clearCallingIdentity();
4901 try {
4902 if (phone != null) {
4903 return phone.getClientRequestStats();
4904 }
4905
4906 return null;
4907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004910 }
4911
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004912 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004913 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004914 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004915 }
Jack Yueb4124c2017-02-16 15:32:43 -08004916
4917 /**
Grace Chen70990072017-03-24 17:21:30 -07004918 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004919 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004920 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004921 * @param state State of SIM (power down, power up, pass through)
4922 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4923 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4924 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004925 *
4926 **/
4927 @Override
Grace Chen70990072017-03-24 17:21:30 -07004928 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004929 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004930 Phone phone = PhoneFactory.getPhone(slotIndex);
4931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 if (phone != null) {
4935 phone.setSimPowerState(state);
4936 }
4937 } finally {
4938 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004939 }
4940 }
Shuo Qiandd210312017-04-12 22:11:33 +00004941
Tyler Gunn65d45c22017-06-05 11:22:26 -07004942 private boolean isUssdApiAllowed(int subId) {
4943 CarrierConfigManager configManager =
4944 (CarrierConfigManager) mPhone.getContext().getSystemService(
4945 Context.CARRIER_CONFIG_SERVICE);
4946 if (configManager == null) {
4947 return false;
4948 }
4949 PersistableBundle pb = configManager.getConfigForSubId(subId);
4950 if (pb == null) {
4951 return false;
4952 }
4953 return pb.getBoolean(
4954 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4955 }
4956
Shuo Qiandd210312017-04-12 22:11:33 +00004957 /**
4958 * Check if phone is in emergency callback mode
4959 * @return true if phone is in emergency callback mode
4960 * @param subId sub id
4961 */
goneil9c5f4872017-12-05 14:07:56 -08004962 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004963 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004964 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004965 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966
4967 final long identity = Binder.clearCallingIdentity();
4968 try {
4969 if (phone != null) {
4970 return phone.isInEcm();
4971 } else {
4972 return false;
4973 }
4974 } finally {
4975 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004976 }
4977 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004978
4979 /**
4980 * Get the current signal strength information for the given subscription.
4981 * Because this information is not updated when the device is in a low power state
4982 * it should not be relied-upon to be current.
4983 * @param subId Subscription index
4984 * @return the most recent cached signal strength info from the modem
4985 */
4986 @Override
4987 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 Phone p = getPhone(subId);
4991 if (p == null) {
4992 return null;
4993 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 return p.getSignalStrength();
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004999 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005000
5001 @Override
5002 public UiccSlotInfo[] getUiccSlotsInfo() {
5003 enforceReadPrivilegedPermission();
5004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 final long identity = Binder.clearCallingIdentity();
5006 try {
5007 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5008 if (slots == null) {
5009 Rlog.i(LOG_TAG, "slots is null.");
5010 return null;
5011 }
5012
5013 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5014 for (int i = 0; i < slots.length; i++) {
5015 UiccSlot slot = slots[i];
5016 if (slot == null) {
5017 continue;
5018 }
5019
5020 String cardId;
5021 UiccCard card = slot.getUiccCard();
5022 if (card != null) {
5023 cardId = card.getCardId();
5024 } else {
5025 cardId = slot.getIccId();
5026 }
5027
5028 int cardState = 0;
5029 switch (slot.getCardState()) {
5030 case CARDSTATE_ABSENT:
5031 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5032 break;
5033 case CARDSTATE_PRESENT:
5034 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5035 break;
5036 case CARDSTATE_ERROR:
5037 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5038 break;
5039 case CARDSTATE_RESTRICTED:
5040 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5041 break;
5042 default:
5043 break;
5044
5045 }
5046
5047 infos[i] = new UiccSlotInfo(
5048 slot.isActive(),
5049 slot.isEuicc(),
5050 cardId,
5051 cardState,
5052 slot.getPhoneId(),
5053 slot.isExtendedApduSupported());
5054 }
5055 return infos;
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005058 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005059 }
5060
5061 @Override
5062 public boolean switchSlots(int[] physicalSlots) {
5063 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064
5065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5068 } finally {
5069 Binder.restoreCallingIdentity(identity);
5070 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005071 }
Jack Yu4c988042018-02-27 15:30:01 -08005072
5073 @Override
5074 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5075 enforceModifyPermission();
5076 final Phone phone = getPhone(subId);
5077 if (phone == null) {
5078 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5079 return;
5080 }
5081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 phone.setRadioIndicationUpdateMode(filters, mode);
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
Jack Yu4c988042018-02-27 15:30:01 -08005088 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005089
5090 /**
goneil47ffb6e2018-04-06 15:40:58 -07005091 * A test API to reload the UICC profile.
5092 *
5093 * <p>Requires that the calling app has permission
5094 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5095 * @hide
5096 */
5097 @Override
5098 public void refreshUiccProfile(int subId) {
5099 enforceModifyPermission();
5100
5101 final long identity = Binder.clearCallingIdentity();
5102 try {
5103 Phone phone = getPhone(subId);
5104 if (phone == null) {
5105 return;
5106 }
5107 UiccCard uiccCard = phone.getUiccCard();
5108 if (uiccCard == null) {
5109 return;
5110 }
5111 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5112 if (uiccProfile == null) {
5113 return;
5114 }
5115 uiccProfile.refresh();
5116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
5119 }
5120
5121 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005122 * Returns false if the mobile data is disabled by default, otherwise return true.
5123 */
5124 private boolean getDefaultDataEnabled() {
5125 return "true".equalsIgnoreCase(
5126 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5127 }
5128
5129 /**
5130 * Returns true if the data roaming is enabled by default, i.e the system property
5131 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5132 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5133 */
5134 private boolean getDefaultDataRoamingEnabled(int subId) {
5135 final CarrierConfigManager configMgr = (CarrierConfigManager)
5136 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5137 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5138 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5139 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5140 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5141 return isDataRoamingEnabled;
5142 }
5143
5144 /**
5145 * Returns the default network type for the given {@code subId}, if the default network type is
5146 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5147 */
5148 private int getDefaultNetworkType(int subId) {
5149 return Integer.parseInt(
5150 TelephonyManager.getTelephonyProperty(
5151 mSubscriptionController.getPhoneId(subId),
5152 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5153 String.valueOf(Phone.PREFERRED_NT_MODE)));
5154 }
fionaxua13278b2018-03-21 00:08:13 -07005155
5156 @Override
5157 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5158 gid1, String gid2, String plmn, String spn) {
5159 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160
5161 final long identity = Binder.clearCallingIdentity();
5162 try {
5163 final Phone phone = getPhone(subId);
5164 if (phone == null) {
5165 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5166 return;
5167 }
5168 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005171 }
fionaxua13278b2018-03-21 00:08:13 -07005172 }
5173
5174 @Override
5175 public int getCarrierIdListVersion(int subId) {
5176 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177
5178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 final Phone phone = getPhone(subId);
5181 if (phone == null) {
5182 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5183 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5184 }
5185 return phone.getCarrierIdListVersion();
5186 } finally {
5187 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005188 }
fionaxua13278b2018-03-21 00:08:13 -07005189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005190}