blob: b7d062fd2e9a79a5833531b139e5e24e6c5f0d06 [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
David Kelly5e06a7f2018-03-12 14:10:59 +0000229 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
230 private static final int MANUFACTURER_CODE_LENGTH = 8;
231
Derek Tan89e89d42014-07-08 17:00:10 -0700232 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700233 * A request object to use for transmitting data to an ICC.
234 */
235 private static final class IccAPDUArgument {
236 public int channel, cla, command, p1, p2, p3;
237 public String data;
238
239 public IccAPDUArgument(int channel, int cla, int command,
240 int p1, int p2, int p3, String data) {
241 this.channel = channel;
242 this.cla = cla;
243 this.command = command;
244 this.p1 = p1;
245 this.p2 = p2;
246 this.p3 = p3;
247 this.data = data;
248 }
249 }
250
251 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700252 * A request object to use for transmitting data to an ICC.
253 */
254 private static final class ManualNetworkSelectionArgument {
255 public OperatorInfo operatorInfo;
256 public boolean persistSelection;
257
258 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
259 this.operatorInfo = operatorInfo;
260 this.persistSelection = persistSelection;
261 }
262 }
263
264 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
266 * request after sending. The main thread will notify the request when it is complete.
267 */
268 private static final class MainThreadRequest {
269 /** The argument to use for the request */
270 public Object argument;
271 /** The result of the request that is run on the main thread */
272 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800273 // The subscriber id that this request applies to. Defaults to
274 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
275 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276
277 public MainThreadRequest(Object argument) {
278 this.argument = argument;
279 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800280
281 public MainThreadRequest(Object argument, Integer subId) {
282 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800283 if (subId != null) {
284 this.subId = subId;
285 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287 }
288
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800289 private static final class IncomingThirdPartyCallArgs {
290 public final ComponentName component;
291 public final String callId;
292 public final String callerDisplayName;
293
294 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
295 String callerDisplayName) {
296 this.component = component;
297 this.callId = callId;
298 this.callerDisplayName = callerDisplayName;
299 }
300 }
301
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 /**
303 * A handler that processes messages on the main thread in the phone process. Since many
304 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
305 * inbound binder threads to the main thread in the phone process. The Binder thread
306 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
307 * on, which will be notified when the operation completes and will contain the result of the
308 * request.
309 *
310 * <p>If a MainThreadRequest object is provided in the msg.obj field,
311 * note that request.result must be set to something non-null for the calling thread to
312 * unblock.
313 */
314 private final class MainThreadHandler extends Handler {
315 @Override
316 public void handleMessage(Message msg) {
317 MainThreadRequest request;
318 Message onCompleted;
319 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800320 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700321 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322
323 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700324 case CMD_HANDLE_USSD_REQUEST: {
325 request = (MainThreadRequest) msg.obj;
326 final Phone phone = getPhoneFromRequest(request);
327 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
328 String ussdRequest = ussdObject.first;
329 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700330
331 if (!isUssdApiAllowed(request.subId)) {
332 // Carrier does not support use of this API, return failure.
333 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
334 UssdResponse response = new UssdResponse(ussdRequest, null);
335 Bundle returnData = new Bundle();
336 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
337 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
338
339 request.result = true;
340 synchronized (request) {
341 request.notifyAll();
342 }
343 return;
344 }
345
Tyler Gunn52dcf772017-04-26 11:30:31 -0700346 try {
347 request.result = phone != null ?
348 phone.handleUssdRequest(ussdRequest, wrappedCallback)
349 : false;
350 } catch (CallStateException cse) {
351 request.result = false;
352 }
pkanwar32d516d2016-10-14 19:37:38 -0700353 // Wake up the requesting thread
354 synchronized (request) {
355 request.notifyAll();
356 }
357 break;
358 }
359
Yorke Lee716f67e2015-06-17 15:39:16 -0700360 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700362 final Phone phone = getPhoneFromRequest(request);
363 request.result = phone != null ?
364 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
365 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 // Wake up the requesting thread
367 synchronized (request) {
368 request.notifyAll();
369 }
370 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
373 case CMD_HANDLE_NEIGHBORING_CELL:
374 request = (MainThreadRequest) msg.obj;
375 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
376 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700377 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 break;
379
380 case EVENT_NEIGHBORING_CELL_DONE:
381 ar = (AsyncResult) msg.obj;
382 request = (MainThreadRequest) ar.userObj;
383 if (ar.exception == null && ar.result != null) {
384 request.result = ar.result;
385 } else {
386 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800387 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 }
389 // Wake up the requesting thread
390 synchronized (request) {
391 request.notifyAll();
392 }
393 break;
394
395 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700396 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800397 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700398 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800399 request.result = ""; // dummy result for notifying the waiting thread
400 // Wake up the requesting thread
401 synchronized (request) {
402 request.notifyAll();
403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 break;
405
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 case CMD_END_CALL:
407 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800408 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700409 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700410 Phone phone = getPhone(end_subId);
411 if (phone == null) {
412 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
413 break;
414 }
415 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
417 // CDMA: If the user presses the Power button we treat it as
418 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700419 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
421 // GSM: End the call as per the Phone state
422 hungUp = PhoneUtils.hangup(mCM);
423 } else {
424 throw new IllegalStateException("Unexpected phone type: " + phoneType);
425 }
426 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
427 request.result = hungUp;
428 // Wake up the requesting thread
429 synchronized (request) {
430 request.notifyAll();
431 }
432 break;
433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800437 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700438 if (uiccCard == null) {
439 loge("iccTransmitApduLogicalChannel: No UICC");
440 request.result = new IccIoResult(0x6F, 0, (byte[])null);
441 synchronized (request) {
442 request.notifyAll();
443 }
444 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
446 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700447 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 iccArgument.channel, iccArgument.cla, iccArgument.command,
449 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700451 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 break;
453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 ar = (AsyncResult) msg.obj;
456 request = (MainThreadRequest) ar.userObj;
457 if (ar.exception == null && ar.result != null) {
458 request.result = ar.result;
459 } else {
460 request.result = new IccIoResult(0x6F, 0, (byte[])null);
461 if (ar.result == null) {
462 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800463 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800465 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 } else {
467 loge("iccTransmitApduLogicalChannel: Unknown exception");
468 }
469 }
470 synchronized (request) {
471 request.notifyAll();
472 }
473 break;
474
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
476 request = (MainThreadRequest) msg.obj;
477 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800478 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 if (uiccCard == null) {
480 loge("iccTransmitApduBasicChannel: No UICC");
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
482 synchronized (request) {
483 request.notifyAll();
484 }
485 } else {
486 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
487 request);
488 uiccCard.iccTransmitApduBasicChannel(
489 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
490 iccArgument.p3, iccArgument.data, onCompleted);
491 }
492 break;
493
494 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
495 ar = (AsyncResult) msg.obj;
496 request = (MainThreadRequest) ar.userObj;
497 if (ar.exception == null && ar.result != null) {
498 request.result = ar.result;
499 } else {
500 request.result = new IccIoResult(0x6F, 0, (byte[])null);
501 if (ar.result == null) {
502 loge("iccTransmitApduBasicChannel: Empty response");
503 } else if (ar.exception instanceof CommandException) {
504 loge("iccTransmitApduBasicChannel: CommandException: " +
505 ar.exception);
506 } else {
507 loge("iccTransmitApduBasicChannel: Unknown exception");
508 }
509 }
510 synchronized (request) {
511 request.notifyAll();
512 }
513 break;
514
515 case CMD_EXCHANGE_SIM_IO:
516 request = (MainThreadRequest) msg.obj;
517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 if (uiccCard == null) {
520 loge("iccExchangeSimIO: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
522 synchronized (request) {
523 request.notifyAll();
524 }
525 } else {
526 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
527 request);
528 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
529 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
530 iccArgument.data, onCompleted);
531 }
532 break;
533
534 case EVENT_EXCHANGE_SIM_IO_DONE:
535 ar = (AsyncResult) msg.obj;
536 request = (MainThreadRequest) ar.userObj;
537 if (ar.exception == null && ar.result != null) {
538 request.result = ar.result;
539 } else {
540 request.result = new IccIoResult(0x6f, 0, (byte[])null);
541 }
542 synchronized (request) {
543 request.notifyAll();
544 }
545 break;
546
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 case CMD_SEND_ENVELOPE:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("sendEnvelopeWithStatus: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
553 synchronized (request) {
554 request.notifyAll();
555 }
556 } else {
557 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
558 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
559 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 break;
561
562 case EVENT_SEND_ENVELOPE_DONE:
563 ar = (AsyncResult) msg.obj;
564 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700565 if (ar.exception == null && ar.result != null) {
566 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800567 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
569 if (ar.result == null) {
570 loge("sendEnvelopeWithStatus: Empty response");
571 } else if (ar.exception instanceof CommandException) {
572 loge("sendEnvelopeWithStatus: CommandException: " +
573 ar.exception);
574 } else {
575 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
576 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 }
578 synchronized (request) {
579 request.notifyAll();
580 }
581 break;
582
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 case CMD_OPEN_CHANNEL:
584 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800585 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800586 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 if (uiccCard == null) {
588 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800589 request.result = new IccOpenLogicalChannelResponse(-1,
590 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 synchronized (request) {
592 request.notifyAll();
593 }
594 } else {
595 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800596 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
597 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 break;
600
601 case EVENT_OPEN_CHANNEL_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 int[] result = (int[]) ar.result;
607 int channelId = result[0];
608 byte[] selectResponse = null;
609 if (result.length > 1) {
610 selectResponse = new byte[result.length - 1];
611 for (int i = 1; i < result.length; ++i) {
612 selectResponse[i - 1] = (byte) result[i];
613 }
614 }
615 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700616 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 if (ar.result == null) {
619 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 if (ar.exception != null) {
622 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
623 }
624
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700626 if (ar.exception instanceof CommandException) {
627 CommandException.Error error =
628 ((CommandException) (ar.exception)).getCommandError();
629 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700630 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700631 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700632 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 }
634 }
635 openChannelResp = new IccOpenLogicalChannelResponse(
636 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700638 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 synchronized (request) {
640 request.notifyAll();
641 }
642 break;
643
644 case CMD_CLOSE_CHANNEL:
645 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800646 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 if (uiccCard == null) {
648 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900649 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 synchronized (request) {
651 request.notifyAll();
652 }
653 } else {
654 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
655 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
656 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 break;
658
659 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800660 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
661 break;
662
663 case CMD_NV_READ_ITEM:
664 request = (MainThreadRequest) msg.obj;
665 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
666 mPhone.nvReadItem((Integer) request.argument, onCompleted);
667 break;
668
669 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 ar = (AsyncResult) msg.obj;
671 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800672 if (ar.exception == null && ar.result != null) {
673 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800675 request.result = "";
676 if (ar.result == null) {
677 loge("nvReadItem: Empty response");
678 } else if (ar.exception instanceof CommandException) {
679 loge("nvReadItem: CommandException: " +
680 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800682 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 }
684 }
685 synchronized (request) {
686 request.notifyAll();
687 }
688 break;
689
Jake Hambye994d462014-02-03 13:10:13 -0800690 case CMD_NV_WRITE_ITEM:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
693 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
694 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
695 break;
696
697 case EVENT_NV_WRITE_ITEM_DONE:
698 handleNullReturnEvent(msg, "nvWriteItem");
699 break;
700
701 case CMD_NV_WRITE_CDMA_PRL:
702 request = (MainThreadRequest) msg.obj;
703 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
704 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
705 break;
706
707 case EVENT_NV_WRITE_CDMA_PRL_DONE:
708 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
709 break;
710
711 case CMD_NV_RESET_CONFIG:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
714 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
715 break;
716
717 case EVENT_NV_RESET_CONFIG_DONE:
718 handleNullReturnEvent(msg, "nvResetConfig");
719 break;
720
Jake Hamby7c27be32014-03-03 13:25:59 -0800721 case CMD_GET_PREFERRED_NETWORK_TYPE:
722 request = (MainThreadRequest) msg.obj;
723 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700724 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 break;
726
727 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
728 ar = (AsyncResult) msg.obj;
729 request = (MainThreadRequest) ar.userObj;
730 if (ar.exception == null && ar.result != null) {
731 request.result = ar.result; // Integer
732 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800733 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 if (ar.result == null) {
735 loge("getPreferredNetworkType: Empty response");
736 } else if (ar.exception instanceof CommandException) {
737 loge("getPreferredNetworkType: CommandException: " +
738 ar.exception);
739 } else {
740 loge("getPreferredNetworkType: Unknown exception");
741 }
742 }
743 synchronized (request) {
744 request.notifyAll();
745 }
746 break;
747
748 case CMD_SET_PREFERRED_NETWORK_TYPE:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
751 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700752 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 break;
754
755 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
756 handleNullReturnEvent(msg, "setPreferredNetworkType");
757 break;
758
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
760 request = (MainThreadRequest)msg.obj;
761 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
762 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
763 break;
764
765 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
766 ar = (AsyncResult)msg.obj;
767 request = (MainThreadRequest)ar.userObj;
768 request.result = ar;
769 synchronized (request) {
770 request.notifyAll();
771 }
772 break;
773
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800774 case CMD_SET_VOICEMAIL_NUMBER:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
777 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800778 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
779 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800780 break;
781
782 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
783 handleNullReturnEvent(msg, "setVoicemailNumber");
784 break;
785
Stuart Scott54788802015-03-30 13:18:01 -0700786 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
789 request);
790 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
791 break;
792
793 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
794 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
795 break;
796
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 case CMD_PERFORM_NETWORK_SCAN:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
800 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
801 break;
802
803 case EVENT_PERFORM_NETWORK_SCAN_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 CellNetworkScanResult cellScanResult;
807 if (ar.exception == null && ar.result != null) {
808 cellScanResult = new CellNetworkScanResult(
809 CellNetworkScanResult.STATUS_SUCCESS,
810 (List<OperatorInfo>) ar.result);
811 } else {
812 if (ar.result == null) {
813 loge("getCellNetworkScanResults: Empty response");
814 }
815 if (ar.exception != null) {
816 loge("getCellNetworkScanResults: Exception: " + ar.exception);
817 }
818 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
819 if (ar.exception instanceof CommandException) {
820 CommandException.Error error =
821 ((CommandException) (ar.exception)).getCommandError();
822 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
824 } else if (error == CommandException.Error.GENERIC_FAILURE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
826 }
827 }
828 cellScanResult = new CellNetworkScanResult(errorCode, null);
829 }
830 request.result = cellScanResult;
831 synchronized (request) {
832 request.notifyAll();
833 }
834 break;
835
836 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
837 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 ManualNetworkSelectionArgument selArg =
839 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
841 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700842 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
843 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
846 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
847 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
848 break;
849
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700850 case CMD_GET_MODEM_ACTIVITY_INFO:
851 request = (MainThreadRequest) msg.obj;
852 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700853 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700854 break;
855
856 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
857 ar = (AsyncResult) msg.obj;
858 request = (MainThreadRequest) ar.userObj;
859 if (ar.exception == null && ar.result != null) {
860 request.result = ar.result;
861 } else {
862 if (ar.result == null) {
863 loge("queryModemActivityInfo: Empty response");
864 } else if (ar.exception instanceof CommandException) {
865 loge("queryModemActivityInfo: CommandException: " +
866 ar.exception);
867 } else {
868 loge("queryModemActivityInfo: Unknown exception");
869 }
870 }
Amit Mahajand4766222016-01-28 15:28:28 -0800871 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
872 if (request.result == null) {
873 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
874 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700875 synchronized (request) {
876 request.notifyAll();
877 }
878 break;
879
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 case CMD_SET_ALLOWED_CARRIERS:
881 request = (MainThreadRequest) msg.obj;
882 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
883 mPhone.setAllowedCarriers(
884 (List<CarrierIdentifier>) request.argument,
885 onCompleted);
886 break;
887
888 case EVENT_SET_ALLOWED_CARRIERS_DONE:
889 ar = (AsyncResult) msg.obj;
890 request = (MainThreadRequest) ar.userObj;
891 if (ar.exception == null && ar.result != null) {
892 request.result = ar.result;
893 } else {
894 if (ar.result == null) {
895 loge("setAllowedCarriers: Empty response");
896 } else if (ar.exception instanceof CommandException) {
897 loge("setAllowedCarriers: CommandException: " +
898 ar.exception);
899 } else {
900 loge("setAllowedCarriers: Unknown exception");
901 }
902 }
903 // Result cannot be null. Return -1 on error.
904 if (request.result == null) {
905 request.result = new int[]{-1};
906 }
907 synchronized (request) {
908 request.notifyAll();
909 }
910 break;
911
912 case CMD_GET_ALLOWED_CARRIERS:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
915 mPhone.getAllowedCarriers(onCompleted);
916 break;
917
918 case EVENT_GET_ALLOWED_CARRIERS_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 if (ar.exception == null && ar.result != null) {
922 request.result = ar.result;
923 } else {
924 if (ar.result == null) {
925 loge("getAllowedCarriers: Empty response");
926 } else if (ar.exception instanceof CommandException) {
927 loge("getAllowedCarriers: CommandException: " +
928 ar.exception);
929 } else {
930 loge("getAllowedCarriers: Unknown exception");
931 }
932 }
933 // Result cannot be null. Return empty list of CarrierIdentifier.
934 if (request.result == null) {
935 request.result = new ArrayList<CarrierIdentifier>(0);
936 }
937 synchronized (request) {
938 request.notifyAll();
939 }
940 break;
941
Nathan Haroldb3014052017-01-25 15:57:32 -0800942 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 request.result = new IllegalArgumentException(
949 "Failed to retrieve Forbidden Plmns");
950 if (ar.result == null) {
951 loge("getForbiddenPlmns: Empty response");
952 } else {
953 loge("getForbiddenPlmns: Unknown exception");
954 }
955 }
956 synchronized (request) {
957 request.notifyAll();
958 }
959 break;
960
961 case CMD_GET_FORBIDDEN_PLMNS:
962 request = (MainThreadRequest) msg.obj;
963 uiccCard = getUiccCardFromRequest(request);
964 if (uiccCard == null) {
965 loge("getForbiddenPlmns() UiccCard is null");
966 request.result = new IllegalArgumentException(
967 "getForbiddenPlmns() UiccCard is null");
968 synchronized (request) {
969 request.notifyAll();
970 }
971 break;
972 }
973 Integer appType = (Integer) request.argument;
974 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
975 if (uiccApp == null) {
976 loge("getForbiddenPlmns() no app with specified type -- "
977 + appType);
978 request.result = new IllegalArgumentException("Failed to get UICC App");
979 synchronized (request) {
980 request.notifyAll();
981 }
982 break;
983 } else {
984 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
985 + " specified type -- " + appType);
986 }
987 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
988 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
989 onCompleted);
990 break;
991
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000992 case CMD_SWITCH_SLOTS:
993 request = (MainThreadRequest) msg.obj;
994 int[] physicalSlots = (int[]) request.argument;
995 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
996 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
997 break;
998
999 case EVENT_SWITCH_SLOTS_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 request.result = (ar.exception == null);
1003 synchronized (request) {
1004 request.notifyAll();
1005 }
1006 break;
1007
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001008 default:
1009 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1010 break;
1011 }
1012 }
Jake Hambye994d462014-02-03 13:10:13 -08001013
1014 private void handleNullReturnEvent(Message msg, String command) {
1015 AsyncResult ar = (AsyncResult) msg.obj;
1016 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1017 if (ar.exception == null) {
1018 request.result = true;
1019 } else {
1020 request.result = false;
1021 if (ar.exception instanceof CommandException) {
1022 loge(command + ": CommandException: " + ar.exception);
1023 } else {
1024 loge(command + ": Unknown exception");
1025 }
1026 }
1027 synchronized (request) {
1028 request.notifyAll();
1029 }
1030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001031 }
1032
1033 /**
1034 * Posts the specified command to be executed on the main thread,
1035 * waits for the request to complete, and returns the result.
1036 * @see #sendRequestAsync
1037 */
1038 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001039 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001040 }
1041
1042 /**
1043 * Posts the specified command to be executed on the main thread,
1044 * waits for the request to complete, and returns the result.
1045 * @see #sendRequestAsync
1046 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001047 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001048 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1049 throw new RuntimeException("This method will deadlock if called from the main thread.");
1050 }
1051
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001052 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001053 Message msg = mMainThreadHandler.obtainMessage(command, request);
1054 msg.sendToTarget();
1055
1056 // Wait for the request to complete
1057 synchronized (request) {
1058 while (request.result == null) {
1059 try {
1060 request.wait();
1061 } catch (InterruptedException e) {
1062 // Do nothing, go back and wait until the request is complete
1063 }
1064 }
1065 }
1066 return request.result;
1067 }
1068
1069 /**
1070 * Asynchronous ("fire and forget") version of sendRequest():
1071 * Posts the specified command to be executed on the main thread, and
1072 * returns immediately.
1073 * @see #sendRequest
1074 */
1075 private void sendRequestAsync(int command) {
1076 mMainThreadHandler.sendEmptyMessage(command);
1077 }
1078
1079 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001080 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1081 * @see {@link #sendRequest(int,Object)}
1082 */
1083 private void sendRequestAsync(int command, Object argument) {
1084 MainThreadRequest request = new MainThreadRequest(argument);
1085 Message msg = mMainThreadHandler.obtainMessage(command, request);
1086 msg.sendToTarget();
1087 }
1088
1089 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 * Initialize the singleton PhoneInterfaceManager instance.
1091 * This is only done once, at startup, from PhoneApp.onCreate().
1092 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001093 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001094 synchronized (PhoneInterfaceManager.class) {
1095 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001096 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001097 } else {
1098 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1099 }
1100 return sInstance;
1101 }
1102 }
1103
1104 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001105 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001106 mApp = app;
1107 mPhone = phone;
1108 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001109 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1111 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001112 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001113 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001114 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001115 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001116
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001117 publish();
1118 }
1119
1120 private void publish() {
1121 if (DBG) log("publish: " + this);
1122
1123 ServiceManager.addService("phone", this);
1124 }
1125
Stuart Scott584921c2015-01-15 17:10:34 -08001126 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001127 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1128 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001129 }
1130
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001131 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1132 Phone phone = getPhoneFromRequest(request);
1133 return phone == null ? null :
1134 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1135 }
1136
Wink Saville36469e72014-06-11 15:17:00 -07001137 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001138 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001139 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 //
1142 // Implementation of the ITelephony interface.
1143 //
1144
1145 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001146 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001147 }
1148
Wink Savilleb564aae2014-10-23 10:18:09 -07001149 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 if (DBG) log("dial: " + number);
1151 // No permission check needed here: This is just a wrapper around the
1152 // ACTION_DIAL intent, which is available to any app since it puts up
1153 // the UI before it does anything.
1154
Malcolm Chend965c8b2018-02-28 15:00:40 -08001155 final long identity = Binder.clearCallingIdentity();
1156 try {
1157 String url = createTelUrl(number);
1158 if (url == null) {
1159 return;
1160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001161
Malcolm Chend965c8b2018-02-28 15:00:40 -08001162 // PENDING: should we just silently fail if phone is offhook or ringing?
1163 PhoneConstants.State state = mCM.getState(subId);
1164 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1165 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1166 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1167 mApp.startActivity(intent);
1168 }
1169 } finally {
1170 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 }
1172 }
1173
1174 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001175 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001176 }
1177
Wink Savilleb564aae2014-10-23 10:18:09 -07001178 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001179 if (DBG) log("call: " + number);
1180
1181 // This is just a wrapper around the ACTION_CALL intent, but we still
1182 // need to do a permission check since we're calling startActivity()
1183 // from the context of the phone app.
1184 enforceCallPermission();
1185
1186 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1187 != AppOpsManager.MODE_ALLOWED) {
1188 return;
1189 }
1190
Malcolm Chend965c8b2018-02-28 15:00:40 -08001191 final long identity = Binder.clearCallingIdentity();
1192 try {
1193 String url = createTelUrl(number);
1194 if (url == null) {
1195 return;
1196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197
Malcolm Chend965c8b2018-02-28 15:00:40 -08001198 boolean isValid = false;
1199 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1200 if (slist != null) {
1201 for (SubscriptionInfo subInfoRecord : slist) {
1202 if (subInfoRecord.getSubscriptionId() == subId) {
1203 isValid = true;
1204 break;
1205 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001206 }
Wink Saville08874612014-08-31 19:19:58 -07001207 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001208 if (!isValid) {
1209 return;
1210 }
Wink Saville08874612014-08-31 19:19:58 -07001211
Malcolm Chend965c8b2018-02-28 15:00:40 -08001212 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1213 intent.putExtra(SUBSCRIPTION_KEY, subId);
1214 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1215 mApp.startActivity(intent);
1216 } finally {
1217 Binder.restoreCallingIdentity(identity);
1218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 }
1220
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 /**
1222 * End a call based on call state
1223 * @return true is a call was ended
1224 */
1225 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001226 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001227 }
1228
1229 /**
1230 * End a call based on the call state of the subId
1231 * @return true is a call was ended
1232 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001233 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001234 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1235 != PackageManager.PERMISSION_GRANTED) {
1236 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1237 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1238 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1239 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001240
1241 final long identity = Binder.clearCallingIdentity();
1242 try {
1243 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1244 } finally {
1245 Binder.restoreCallingIdentity(identity);
1246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 }
1248
1249 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001250 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001251 }
1252
Wink Savilleb564aae2014-10-23 10:18:09 -07001253 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 if (DBG) log("answerRingingCall...");
1255 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1256 // but that can probably wait till the big TelephonyManager API overhaul.
1257 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1258 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001259
1260 final long identity = Binder.clearCallingIdentity();
1261 try {
1262 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1263 } finally {
1264 Binder.restoreCallingIdentity(identity);
1265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 }
1267
1268 /**
1269 * Make the actual telephony calls to implement answerRingingCall().
1270 * This should only be called from the main thread of the Phone app.
1271 * @see #answerRingingCall
1272 *
1273 * TODO: it would be nice to return true if we answered the call, or
1274 * false if there wasn't actually a ringing incoming call, or some
1275 * other error occurred. (In other words, pass back the return value
1276 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1277 * But that would require calling this method via sendRequest() rather
1278 * than sendRequestAsync(), and right now we don't actually *need* that
1279 * return value, so let's just return void for now.
1280 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001281 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001282 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001284 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1285 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 if (hasActiveCall && hasHoldingCall) {
1287 // Both lines are in use!
1288 // TODO: provide a flag to let the caller specify what
1289 // policy to use if both lines are in use. (The current
1290 // behavior is hardwired to "answer incoming, end ongoing",
1291 // which is how the CALL button is specced to behave.)
1292 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1293 return;
1294 } else {
1295 // answerCall() will automatically hold the current active
1296 // call, if there is one.
1297 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1298 return;
1299 }
1300 } else {
1301 // No call was ringing.
1302 return;
1303 }
1304 }
1305
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001307 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001309 public void silenceRinger() {
1310 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 }
1312
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001313 @Override
1314 public boolean isOffhook(String callingPackage) {
1315 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001316 }
1317
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001318 @Override
1319 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001321 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001322 return false;
1323 }
1324
Malcolm Chend965c8b2018-02-28 15:00:40 -08001325 final long identity = Binder.clearCallingIdentity();
1326 try {
1327 final Phone phone = getPhone(subId);
1328 if (phone != null) {
1329 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1330 } else {
1331 return false;
1332 }
1333 } finally {
1334 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 }
1337
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001338 @Override
1339 public boolean isRinging(String callingPackage) {
1340 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001341 }
1342
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001343 @Override
1344 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001346 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001347 return false;
1348 }
1349
Malcolm Chend965c8b2018-02-28 15:00:40 -08001350 final long identity = Binder.clearCallingIdentity();
1351 try {
1352 final Phone phone = getPhone(subId);
1353 if (phone != null) {
1354 return (phone.getState() == PhoneConstants.State.RINGING);
1355 } else {
1356 return false;
1357 }
1358 } finally {
1359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 }
1362
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001363 @Override
1364 public boolean isIdle(String callingPackage) {
1365 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001366 }
1367
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001368 @Override
1369 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001371 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001372 return false;
1373 }
1374
Malcolm Chend965c8b2018-02-28 15:00:40 -08001375 final long identity = Binder.clearCallingIdentity();
1376 try {
1377 final Phone phone = getPhone(subId);
1378 if (phone != null) {
1379 return (phone.getState() == PhoneConstants.State.IDLE);
1380 } else {
1381 return false;
1382 }
1383 } finally {
1384 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 }
1387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001389 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001390 }
1391
Wink Savilleb564aae2014-10-23 10:18:09 -07001392 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001393 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001394 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1395 }
1396
1397 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001399 }
1400
Wink Savilleb564aae2014-10-23 10:18:09 -07001401 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001402 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001403 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1404 }
1405
1406 /** {@hide} */
1407 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001408 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001409 }
1410
Wink Savilleb564aae2014-10-23 10:18:09 -07001411 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001413
1414 final long identity = Binder.clearCallingIdentity();
1415 try {
1416 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1417 checkSimPin.start();
1418 return checkSimPin.unlockSim(null, pin);
1419 } finally {
1420 Binder.restoreCallingIdentity(identity);
1421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001422 }
1423
Wink Saville9de0f752013-10-22 19:04:03 -07001424 /** {@hide} */
1425 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001426 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001427 }
1428
Wink Savilleb564aae2014-10-23 10:18:09 -07001429 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001431
1432 final long identity = Binder.clearCallingIdentity();
1433 try {
1434 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1435 checkSimPuk.start();
1436 return checkSimPuk.unlockSim(puk, pin);
1437 } finally {
1438 Binder.restoreCallingIdentity(identity);
1439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 }
1441
1442 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001443 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001444 * a synchronous one.
1445 */
1446 private static class UnlockSim extends Thread {
1447
1448 private final IccCard mSimCard;
1449
1450 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001451 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1452 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453
1454 // For replies from SimCard interface
1455 private Handler mHandler;
1456
1457 // For async handler to identify request type
1458 private static final int SUPPLY_PIN_COMPLETE = 100;
1459
1460 public UnlockSim(IccCard simCard) {
1461 mSimCard = simCard;
1462 }
1463
1464 @Override
1465 public void run() {
1466 Looper.prepare();
1467 synchronized (UnlockSim.this) {
1468 mHandler = new Handler() {
1469 @Override
1470 public void handleMessage(Message msg) {
1471 AsyncResult ar = (AsyncResult) msg.obj;
1472 switch (msg.what) {
1473 case SUPPLY_PIN_COMPLETE:
1474 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1475 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001476 mRetryCount = msg.arg1;
1477 if (ar.exception != null) {
1478 if (ar.exception instanceof CommandException &&
1479 ((CommandException)(ar.exception)).getCommandError()
1480 == CommandException.Error.PASSWORD_INCORRECT) {
1481 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1482 } else {
1483 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1484 }
1485 } else {
1486 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 mDone = true;
1489 UnlockSim.this.notifyAll();
1490 }
1491 break;
1492 }
1493 }
1494 };
1495 UnlockSim.this.notifyAll();
1496 }
1497 Looper.loop();
1498 }
1499
1500 /*
1501 * Use PIN or PUK to unlock SIM card
1502 *
1503 * If PUK is null, unlock SIM card with PIN
1504 *
1505 * If PUK is not null, unlock SIM card with PUK and set PIN code
1506 */
Wink Saville9de0f752013-10-22 19:04:03 -07001507 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508
1509 while (mHandler == null) {
1510 try {
1511 wait();
1512 } catch (InterruptedException e) {
1513 Thread.currentThread().interrupt();
1514 }
1515 }
1516 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1517
1518 if (puk == null) {
1519 mSimCard.supplyPin(pin, callback);
1520 } else {
1521 mSimCard.supplyPuk(puk, pin, callback);
1522 }
1523
1524 while (!mDone) {
1525 try {
1526 Log.d(LOG_TAG, "wait for done");
1527 wait();
1528 } catch (InterruptedException e) {
1529 // Restore the interrupted status
1530 Thread.currentThread().interrupt();
1531 }
1532 }
1533 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001534 int[] resultArray = new int[2];
1535 resultArray[0] = mResult;
1536 resultArray[1] = mRetryCount;
1537 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001538 }
1539 }
1540
1541 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001543
1544 }
1545
Wink Savilleb564aae2014-10-23 10:18:09 -07001546 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 // No permission check needed here: this call is harmless, and it's
1548 // needed for the ServiceState.requestStateUpdate() call (which is
1549 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001550 final long identity = Binder.clearCallingIdentity();
1551 try {
1552 final Phone phone = getPhone(subId);
1553 if (phone != null) {
1554 phone.updateServiceLocation();
1555 }
1556 } finally {
1557 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 }
1560
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001561 @Override
1562 public boolean isRadioOn(String callingPackage) {
1563 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001564 }
1565
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001566 @Override
1567 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001569 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001570 return false;
1571 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001572
1573 final long identity = Binder.clearCallingIdentity();
1574 try {
1575 return isRadioOnForSubscriber(subId);
1576 } finally {
1577 Binder.restoreCallingIdentity(identity);
1578 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001579 }
1580
1581 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001582 final long identity = Binder.clearCallingIdentity();
1583 try {
1584 final Phone phone = getPhone(subId);
1585 if (phone != null) {
1586 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1587 } else {
1588 return false;
1589 }
1590 } finally {
1591 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 }
1594
1595 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001596 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 }
Wink Saville36469e72014-06-11 15:17:00 -07001598
Wink Savilleb564aae2014-10-23 10:18:09 -07001599 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001601
1602 final long identity = Binder.clearCallingIdentity();
1603 try {
1604 final Phone phone = getPhone(subId);
1605 if (phone != null) {
1606 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1607 }
1608 } finally {
1609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 }
Wink Saville36469e72014-06-11 15:17:00 -07001611 }
1612
1613 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001614 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001615 }
1616
Wink Savilleb564aae2014-10-23 10:18:09 -07001617 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001618 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001619
1620 final long identity = Binder.clearCallingIdentity();
1621 try {
1622 final Phone phone = getPhone(subId);
1623 if (phone == null) {
1624 return false;
1625 }
1626 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1627 toggleRadioOnOffForSubscriber(subId);
1628 }
1629 return true;
1630 } finally {
1631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 }
Wink Saville36469e72014-06-11 15:17:00 -07001634
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001635 public boolean needMobileRadioShutdown() {
1636 /*
1637 * If any of the Radios are available, it will need to be
1638 * shutdown. So return true if any Radio is available.
1639 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001640 final long identity = Binder.clearCallingIdentity();
1641 try {
1642 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1643 Phone phone = PhoneFactory.getPhone(i);
1644 if (phone != null && phone.isRadioAvailable()) return true;
1645 }
1646 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1647 return false;
1648 } finally {
1649 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001650 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001651 }
1652
Malcolm Chend965c8b2018-02-28 15:00:40 -08001653 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001654 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001655 enforceModifyPermission();
1656
1657 final long identity = Binder.clearCallingIdentity();
1658 try {
1659 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1660 logv("Shutting down Phone " + i);
1661 shutdownRadioUsingPhoneId(i);
1662 }
1663 } finally {
1664 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001665 }
1666 }
1667
1668 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001669 Phone phone = PhoneFactory.getPhone(phoneId);
1670 if (phone != null && phone.isRadioAvailable()) {
1671 phone.shutdownRadio();
1672 }
1673 }
1674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001676 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001677
1678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1681 if (defaultPhone != null) {
1682 defaultPhone.setRadioPower(turnOn);
1683 return true;
1684 } else {
1685 loge("There's no default phone.");
1686 return false;
1687 }
1688 } finally {
1689 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001690 }
Wink Saville36469e72014-06-11 15:17:00 -07001691 }
1692
Wink Savilleb564aae2014-10-23 10:18:09 -07001693 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001695
1696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 final Phone phone = getPhone(subId);
1699 if (phone != null) {
1700 phone.setRadioPower(turnOn);
1701 return true;
1702 } else {
1703 return false;
1704 }
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 }
1709
Wink Saville36469e72014-06-11 15:17:00 -07001710 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001711 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 public boolean enableDataConnectivity() {
1713 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001714
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 int subId = mSubscriptionController.getDefaultDataSubId();
1718 final Phone phone = getPhone(subId);
1719 if (phone != null) {
1720 phone.setUserDataEnabled(true);
1721 return true;
1722 } else {
1723 return false;
1724 }
1725 } finally {
1726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 }
1729
Wink Saville36469e72014-06-11 15:17:00 -07001730 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001731 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 public boolean disableDataConnectivity() {
1733 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001734
1735 final long identity = Binder.clearCallingIdentity();
1736 try {
1737 int subId = mSubscriptionController.getDefaultDataSubId();
1738 final Phone phone = getPhone(subId);
1739 if (phone != null) {
1740 phone.setUserDataEnabled(false);
1741 return true;
1742 } else {
1743 return false;
1744 }
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
1749
Sanket Padawe356d7632015-06-22 14:03:32 -07001750 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001751 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001752 final long identity = Binder.clearCallingIdentity();
1753 try {
1754 final Phone phone = getPhone(subId);
1755 if (phone != null) {
1756 return phone.isDataAllowed();
1757 } else {
1758 return false;
1759 }
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
1764
1765 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001766 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
1768
pkanwarae03a6b2016-11-06 20:37:09 -08001769 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001770 enforceCallPermission();
1771
1772 final long identity = Binder.clearCallingIdentity();
1773 try {
1774 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1775 return;
1776 }
1777 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1778 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1779 } finally {
1780 Binder.restoreCallingIdentity(identity);
1781 }
pkanwar32d516d2016-10-14 19:37:38 -07001782 };
1783
Wink Savilleb564aae2014-10-23 10:18:09 -07001784 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001786
1787 final long identity = Binder.clearCallingIdentity();
1788 try {
1789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1790 return false;
1791 }
1792 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1793 } finally {
1794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 }
1797
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001799 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001800 }
1801
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001802 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 Phone phone = PhoneFactory.getPhone(slotIndex);
1806 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1807 PhoneConstantConversions.convertCallState(phone.getState());
1808 } finally {
1809 Binder.restoreCallingIdentity(identity);
1810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
1812
Sanket Padawe356d7632015-06-22 14:03:32 -07001813 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1818 if (phone != null) {
1819 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1820 } else {
1821 return PhoneConstantConversions.convertDataState(
1822 PhoneConstants.DataState.DISCONNECTED);
1823 }
1824 } finally {
1825 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 }
1828
Sanket Padawe356d7632015-06-22 14:03:32 -07001829 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001831 final long identity = Binder.clearCallingIdentity();
1832 try {
1833 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1834 if (phone != null) {
1835 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1836 } else {
1837 return TelephonyManager.DATA_ACTIVITY_NONE;
1838 }
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 }
1843
1844 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001845 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001846 mPhone.getContext().getSystemService(AppOpsManager.class)
1847 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001848 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001849 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001850 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 }
1852
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001853 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001854 final long identity = Binder.clearCallingIdentity();
1855 try {
1856 if (DBG_LOC) log("getCellLocation: is active user");
1857 Bundle data = new Bundle();
1858 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1859 if (phone == null) {
1860 return null;
1861 }
1862
1863 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1864 return data;
1865 } finally {
1866 Binder.restoreCallingIdentity(identity);
1867 }
Svetoslav64fad262015-04-14 14:35:21 -07001868 }
1869
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001871 public String getNetworkCountryIsoForPhone(int phoneId) {
1872 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1873 // registered cell info, so return a NULL country instead.
1874 final long identity = Binder.clearCallingIdentity();
1875 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001876 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1877 // Get default phone in this case.
1878 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1879 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001880 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001881 // Todo: fix this when we can get the actual cellular network info when the device
1882 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001883 if (TelephonyManager.NETWORK_TYPE_IWLAN
1884 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1885 return "";
1886 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001887 Phone phone = PhoneFactory.getPhone(phoneId);
1888 if (phone != null) {
1889 ServiceStateTracker sst = phone.getServiceStateTracker();
1890 if (sst != null) {
1891 LocaleTracker lt = sst.getLocaleTracker();
1892 if (lt != null) {
1893 return lt.getCurrentCountry();
1894 }
1895 }
1896 }
1897 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001898 } finally {
1899 Binder.restoreCallingIdentity(identity);
1900 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001901 }
1902
1903 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001905 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001906 }
1907
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001909 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 mApp.enforceCallingOrSelfPermission(
1911 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001912
1913 final long identity = Binder.clearCallingIdentity();
1914 try {
1915 final Phone phone = getPhone(subId);
1916 if (phone != null) {
1917 phone.enableLocationUpdates();
1918 }
1919 } finally {
1920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923
1924 @Override
1925 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001926 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001927 }
1928
Sanket Padawe356d7632015-06-22 14:03:32 -07001929 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001930 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 mApp.enforceCallingOrSelfPermission(
1932 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001933
1934 final long identity = Binder.clearCallingIdentity();
1935 try {
1936 final Phone phone = getPhone(subId);
1937 if (phone != null) {
1938 phone.disableLocationUpdates();
1939 }
1940 } finally {
1941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
1945 @Override
1946 @SuppressWarnings("unchecked")
1947 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001948 mPhone.getContext().getSystemService(AppOpsManager.class)
1949 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001950 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001951 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001952 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
1955 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1956 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1957 return null;
1958 }
Svetoslav64fad262015-04-14 14:35:21 -07001959
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001960 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001962 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001964 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001965
1966 final long identity = Binder.clearCallingIdentity();
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001967 try {
1968 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1969 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1970 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1971 } catch (RuntimeException e) {
1972 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001973 } finally {
1974 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001976 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
1979
1980 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001981 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001982 mPhone.getContext().getSystemService(AppOpsManager.class)
1983 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001984 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001985 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001986 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
1988
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001989 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001990 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001991 final long identity = Binder.clearCallingIdentity();
1992 try {
1993 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1994 for (Phone phone : PhoneFactory.getPhones()) {
1995 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1996 if (info != null) cellInfos.addAll(info);
1997 }
1998 return cellInfos;
1999 } finally {
2000 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 }
2002 }
2003
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002004 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002006 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002007 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002008
2009 final long identity = Binder.clearCallingIdentity();
2010 try {
2011 mPhone.setCellInfoListRate(rateInMillis, workSource);
2012 } finally {
2013 Binder.restoreCallingIdentity(identity);
2014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 }
2016
Shishir Agrawala9f32182016-04-12 12:00:16 -07002017 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002018 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002019 Phone phone = PhoneFactory.getPhone(slotIndex);
2020 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002021 return null;
2022 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002023 int subId = phone.getSubId();
2024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2025 mApp, subId, callingPackage, "getImeiForSlot")) {
2026 return null;
2027 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002028
2029 final long identity = Binder.clearCallingIdentity();
2030 try {
2031 return phone.getImei();
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
2034 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002035 }
2036
2037 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002038 public String getTypeAllocationCodeForSlot(int slotIndex) {
2039 Phone phone = PhoneFactory.getPhone(slotIndex);
2040 String tac = null;
2041 if (phone != null) {
2042 String imei = phone.getImei();
2043 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2044 }
2045 return tac;
2046 }
2047
2048 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002049 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002050 Phone phone = PhoneFactory.getPhone(slotIndex);
2051 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002052 return null;
2053 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002054 int subId = phone.getSubId();
2055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2056 mApp, subId, callingPackage, "getMeidForSlot")) {
2057 return null;
2058 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002059
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
2062 return phone.getMeid();
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
2065 }
Jack Yu2af8d712017-03-15 17:14:14 -07002066 }
2067
2068 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002069 public String getManufacturerCodeForSlot(int slotIndex) {
2070 Phone phone = PhoneFactory.getPhone(slotIndex);
2071 String manufacturerCode = null;
2072 if (phone != null) {
2073 String meid = phone.getMeid();
2074 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2075 }
2076 return manufacturerCode;
2077 }
2078
2079 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002080 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002081 Phone phone = PhoneFactory.getPhone(slotIndex);
2082 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002083 return null;
2084 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002085 int subId = phone.getSubId();
2086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2087 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2088 return null;
2089 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002090
2091 final long identity = Binder.clearCallingIdentity();
2092 try {
2093 return phone.getDeviceSvn();
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
2096 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002097 }
2098
fionaxu43304da2017-11-27 22:51:16 -08002099 @Override
2100 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002101 final long identity = Binder.clearCallingIdentity();
2102 try {
2103 final Phone phone = getPhone(subId);
2104 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
2107 }
fionaxu43304da2017-11-27 22:51:16 -08002108 }
2109
2110 @Override
2111 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 final Phone phone = getPhone(subId);
2115 return phone == null ? null : phone.getCarrierName();
2116 } finally {
2117 Binder.restoreCallingIdentity(identity);
2118 }
fionaxu43304da2017-11-27 22:51:16 -08002119 }
2120
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 //
2122 // Internal helper methods.
2123 //
2124
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002125 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2127 *
2128 * @throws SecurityException if the caller does not have the required permission
2129 */
2130 private void enforceModifyPermission() {
2131 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2132 }
2133
2134 /**
2135 * Make sure the caller has the CALL_PHONE permission.
2136 *
2137 * @throws SecurityException if the caller does not have the required permission
2138 */
2139 private void enforceCallPermission() {
2140 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2141 }
2142
Stuart Scott8eef64f2015-04-08 15:13:54 -07002143 private void enforceConnectivityInternalPermission() {
2144 mApp.enforceCallingOrSelfPermission(
2145 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2146 "ConnectivityService");
2147 }
2148
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 private String createTelUrl(String number) {
2150 if (TextUtils.isEmpty(number)) {
2151 return null;
2152 }
2153
Jake Hambye994d462014-02-03 13:10:13 -08002154 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 }
2156
Ihab Awadf9e92732013-12-05 18:02:52 -08002157 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2159 }
2160
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002161 private static void logv(String msg) {
2162 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2163 }
2164
Ihab Awadf9e92732013-12-05 18:02:52 -08002165 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2167 }
2168
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002171 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002172 }
2173
Sanket Padawe356d7632015-06-22 14:03:32 -07002174 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002175 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 final Phone phone = PhoneFactory.getPhone(slotIndex);
2179 if (phone == null) {
2180 return PhoneConstants.PHONE_TYPE_NONE;
2181 } else {
2182 return phone.getPhoneType();
2183 }
2184 } finally {
2185 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002186 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 }
2188
2189 /**
2190 * Returns the CDMA ERI icon index to display
2191 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002192 @Override
2193 public int getCdmaEriIconIndex(String callingPackage) {
2194 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002195 }
2196
Sanket Padawe356d7632015-06-22 14:03:32 -07002197 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002198 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002199 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002200 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002201 return -1;
2202 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002203
2204 final long identity = Binder.clearCallingIdentity();
2205 try {
2206 final Phone phone = getPhone(subId);
2207 if (phone != null) {
2208 return phone.getCdmaEriIconIndex();
2209 } else {
2210 return -1;
2211 }
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
2217 /**
2218 * Returns the CDMA ERI icon mode,
2219 * 0 - ON
2220 * 1 - FLASHING
2221 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002222 @Override
2223 public int getCdmaEriIconMode(String callingPackage) {
2224 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002225 }
2226
Sanket Padawe356d7632015-06-22 14:03:32 -07002227 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002228 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002230 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002231 return -1;
2232 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002233
2234 final long identity = Binder.clearCallingIdentity();
2235 try {
2236 final Phone phone = getPhone(subId);
2237 if (phone != null) {
2238 return phone.getCdmaEriIconMode();
2239 } else {
2240 return -1;
2241 }
2242 } finally {
2243 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
2247 /**
2248 * Returns the CDMA ERI text,
2249 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002250 @Override
2251 public String getCdmaEriText(String callingPackage) {
2252 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002253 }
2254
Sanket Padawe356d7632015-06-22 14:03:32 -07002255 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002256 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002257 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002258 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 return null;
2260 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002261
2262 final long identity = Binder.clearCallingIdentity();
2263 try {
2264 final Phone phone = getPhone(subId);
2265 if (phone != null) {
2266 return phone.getCdmaEriText();
2267 } else {
2268 return null;
2269 }
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
2275 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002276 * Returns the CDMA MDN.
2277 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002278 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002279 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2281 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002282
2283 final long identity = Binder.clearCallingIdentity();
2284 try {
2285 final Phone phone = getPhone(subId);
2286 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2287 return phone.getLine1Number();
2288 } else {
2289 return null;
2290 }
2291 } finally {
2292 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002293 }
2294 }
2295
2296 /**
2297 * Returns the CDMA MIN.
2298 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002299 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002300 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2302 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002303
2304 final long identity = Binder.clearCallingIdentity();
2305 try {
2306 final Phone phone = getPhone(subId);
2307 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2308 return phone.getCdmaMin();
2309 } else {
2310 return null;
2311 }
2312 } finally {
2313 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002314 }
2315 }
2316
2317 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 * Returns true if CDMA provisioning needs to run.
2319 */
2320 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002321 final long identity = Binder.clearCallingIdentity();
2322 try {
2323 return mPhone.needsOtaServiceProvisioning();
2324 } finally {
2325 Binder.restoreCallingIdentity(identity);
2326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 }
2328
2329 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002330 * Sets the voice mail number of a given subId.
2331 */
2332 @Override
2333 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002334 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002335
2336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2339 new Pair<String, String>(alphaTag, number), new Integer(subId));
2340 return success;
2341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002344 }
2345
Ta-wei Yen87c49842016-05-13 21:19:52 -07002346 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002347 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2348 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2349 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2350 if (!TextUtils.equals(callingPackage, systemDialer)) {
2351 throw new SecurityException("caller must be system dialer");
2352 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002353
2354 final long identity = Binder.clearCallingIdentity();
2355 try {
2356 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2357 if (phoneAccountHandle == null) {
2358 return null;
2359 }
2360 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002363 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002364 }
2365
2366 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002367 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002370 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002371 return null;
2372 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002373
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002374 final long identity = Binder.clearCallingIdentity();
2375 try {
2376 return RemoteVvmTaskManager
2377 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
2380 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002381 }
2382
2383 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002384 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2385 VisualVoicemailSmsFilterSettings settings) {
2386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2391 mPhone.getContext(), callingPackage, subId, settings);
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
2394 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002395 }
2396
2397 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002398 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2399 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002400
2401 final long identity = Binder.clearCallingIdentity();
2402 try {
2403 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2404 mPhone.getContext(), callingPackage, subId);
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
2407 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002408 }
2409
2410 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002411 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2412 String callingPackage, int subId) {
2413 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002414
2415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2418 mPhone.getContext(), callingPackage, subId);
2419 } finally {
2420 Binder.restoreCallingIdentity(identity);
2421 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002422 }
2423
2424 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002425 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002426 enforceReadPrivilegedPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002427
2428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2431 mPhone.getContext(), subId);
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
2434 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002435 }
2436
2437 @Override
2438 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2439 String number, int port, String text, PendingIntent sentIntent) {
2440 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002441 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002442 enforceSendSmsPermission();
2443 // Make the calls as the phone process.
2444 final long identity = Binder.clearCallingIdentity();
2445 try {
2446 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2447 if (port == 0) {
2448 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2449 sentIntent, null, false);
2450 } else {
2451 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2452 smsManager.sendDataMessageWithSelfPermissions(number, null,
2453 (short) port, data, sentIntent, null);
2454 }
2455 } finally {
2456 Binder.restoreCallingIdentity(identity);
2457 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002458 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002459 /**
fionaxu0152e512016-11-14 13:36:14 -08002460 * Sets the voice activation state of a given subId.
2461 */
2462 @Override
2463 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2465 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002466
2467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 final Phone phone = getPhone(subId);
2470 if (phone != null) {
2471 phone.setVoiceActivationState(activationState);
2472 } else {
2473 loge("setVoiceActivationState fails with invalid subId: " + subId);
2474 }
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002477 }
2478 }
2479
2480 /**
2481 * Sets the data activation state of a given subId.
2482 */
2483 @Override
2484 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2486 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 final Phone phone = getPhone(subId);
2491 if (phone != null) {
2492 phone.setDataActivationState(activationState);
2493 } else {
2494 loge("setVoiceActivationState fails with invalid subId: " + subId);
2495 }
2496 } finally {
2497 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002498 }
2499 }
2500
2501 /**
2502 * Returns the voice activation state of a given subId.
2503 */
2504 @Override
2505 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002506 enforceReadPrivilegedPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002507
fionaxu0152e512016-11-14 13:36:14 -08002508 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 if (phone != null) {
2512 return phone.getVoiceActivationState();
2513 } else {
2514 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002518 }
2519 }
2520
2521 /**
2522 * Returns the data activation state of a given subId.
2523 */
2524 @Override
2525 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002526 enforceReadPrivilegedPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002527
fionaxu0152e512016-11-14 13:36:14 -08002528 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002529 final long identity = Binder.clearCallingIdentity();
2530 try {
2531 if (phone != null) {
2532 return phone.getDataActivationState();
2533 } else {
2534 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2535 }
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002538 }
2539 }
2540
2541 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 * Returns the unread count of voicemails
2543 */
2544 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002545 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002546 }
2547
2548 /**
2549 * Returns the unread count of voicemails for a subId
2550 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002551 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002552 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 return phone.getVoiceMessageCount();
2558 } else {
2559 return 0;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
2566 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002567 * returns true, if the device is in a state where both voice and data
2568 * are supported simultaneously. This can change based on location or network condition.
2569 */
2570 @Override
2571 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 final Phone phone = getPhone(subId);
2575 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2576 } finally {
2577 Binder.restoreCallingIdentity(identity);
2578 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002579 }
2580
2581 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002582 * Send the dialer code if called from the current default dialer or the caller has
2583 * carrier privilege.
2584 * @param inputCode The dialer code to send
2585 */
2586 @Override
2587 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2589 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2590 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002591 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2592 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002593 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 mPhone.sendDialerSpecialCode(inputCode);
2598 } finally {
2599 Binder.restoreCallingIdentity(identity);
2600 }
fionaxu235cc5e2017-03-06 22:25:57 -08002601 }
2602
2603 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002604 * Returns the data network type.
2605 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 *
2607 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2608 */
2609 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002610 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002611 final long identity = Binder.clearCallingIdentity();
2612 try {
2613 final Phone phone = getPhone(getDefaultSubscription());
2614 if (phone != null) {
2615 return phone.getServiceState().getDataNetworkType();
2616 } else {
2617 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002621 }
Wink Saville36469e72014-06-11 15:17:00 -07002622 }
2623
2624 /**
2625 * Returns the network type for a subId
2626 */
2627 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002630 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002631 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2632 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002633
Malcolm Chend965c8b2018-02-28 15:00:40 -08002634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 final Phone phone = getPhone(subId);
2637 if (phone != null) {
2638 return phone.getServiceState().getDataNetworkType();
2639 } else {
2640 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2641 }
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 }
2646
2647 /**
2648 * Returns the data network type
2649 */
2650 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002651 public int getDataNetworkType(String callingPackage) {
2652 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002653 }
2654
2655 /**
2656 * Returns the data network type for a subId
2657 */
2658 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002659 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002661 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002662 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2663 }
2664
Malcolm Chend965c8b2018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 if (phone != null) {
2669 return phone.getServiceState().getDataNetworkType();
2670 } else {
2671 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
2678 /**
Wink Saville36469e72014-06-11 15:17:00 -07002679 * Returns the Voice network type for a subId
2680 */
2681 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002682 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002684 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002685 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2686 }
2687
Malcolm Chend965c8b2018-02-28 15:00:40 -08002688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 final Phone phone = getPhone(subId);
2691 if (phone != null) {
2692 return phone.getServiceState().getVoiceNetworkType();
2693 } else {
2694 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2695 }
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
2700
2701 /**
2702 * @return true if a ICC card is present
2703 */
2704 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002705 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002706 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2707 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002708 }
2709
2710 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002711 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002712 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002714 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 final Phone phone = PhoneFactory.getPhone(slotIndex);
2718 if (phone != null) {
2719 return phone.getIccCard().hasIccCard();
2720 } else {
2721 return false;
2722 }
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 }
2727
2728 /**
2729 * Return if the current radio is LTE on CDMA. This
2730 * is a tri-state return value as for a period of time
2731 * the mode may be unknown.
2732 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002733 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002735 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002737 @Override
2738 public int getLteOnCdmaMode(String callingPackage) {
2739 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002740 }
2741
Sanket Padawe356d7632015-06-22 14:03:32 -07002742 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002743 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002745 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002746 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2747 }
2748
Malcolm Chend965c8b2018-02-28 15:00:40 -08002749 final long identity = Binder.clearCallingIdentity();
2750 try {
2751 final Phone phone = getPhone(subId);
2752 if (phone == null) {
2753 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2754 } else {
2755 return phone.getLteOnCdmaMode();
2756 }
2757 } finally {
2758 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002759 }
Wink Saville36469e72014-06-11 15:17:00 -07002760 }
2761
2762 public void setPhone(Phone phone) {
2763 mPhone = phone;
2764 }
2765
2766 /**
2767 * {@hide}
2768 * Returns Default subId, 0 in the case of single standby.
2769 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002770 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002771 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002772 }
2773
Shishir Agrawala9f32182016-04-12 12:00:16 -07002774 private int getSlotForDefaultSubscription() {
2775 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2776 }
2777
Wink Savilleb564aae2014-10-23 10:18:09 -07002778 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002779 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002781
2782 /**
2783 * @see android.telephony.TelephonyManager.WifiCallingChoices
2784 */
2785 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2789 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2790 getWhenToMakeWifiCallsDefaultPreference());
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
2793 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002794 }
2795
2796 /**
2797 * @see android.telephony.TelephonyManager.WifiCallingChoices
2798 */
2799 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2803 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2804 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2805 } finally {
2806 Binder.restoreCallingIdentity(identity);
2807 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002808 }
2809
Sailesh Nepald1e68152013-12-12 19:08:02 -08002810 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002811 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002812 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002813 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002814
Shishir Agrawal566b7612013-10-28 14:41:00 -07002815 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002816 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2817 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2819 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002820 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002821
Malcolm Chend965c8b2018-02-28 15:00:40 -08002822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 if (TextUtils.equals(ISDR_AID, aid)) {
2825 // Only allows LPA to open logical channel to ISD-R.
2826 ComponentInfo bestComponent =
2827 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2828 if (bestComponent == null
2829 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2830 loge("The calling package is not allowed to access ISD-R.");
2831 throw new SecurityException(
2832 "The calling package is not allowed to access ISD-R.");
2833 }
Derek Tan740e1672017-06-27 14:56:27 -07002834 }
Derek Tan740e1672017-06-27 14:56:27 -07002835
Malcolm Chend965c8b2018-02-28 15:00:40 -08002836 if (DBG) {
2837 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2838 }
2839 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2840 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2841 if (DBG) log("iccOpenLogicalChannel: " + response);
2842 return response;
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
2845 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002846 }
2847
2848 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002849 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2851 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002852
Malcolm Chend965c8b2018-02-28 15:00:40 -08002853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2856 if (channel < 0) {
2857 return false;
2858 }
2859 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2860 if (DBG) log("iccCloseLogicalChannel: " + success);
2861 return success;
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002864 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002865 }
2866
2867 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002868 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002869 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2871 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002872
Malcolm Chend965c8b2018-02-28 15:00:40 -08002873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 if (DBG) {
2876 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2877 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2878 + p3 + " data=" + data);
2879 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002880
Malcolm Chend965c8b2018-02-28 15:00:40 -08002881 if (channel < 0) {
2882 return "";
2883 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002884
Malcolm Chend965c8b2018-02-28 15:00:40 -08002885 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2886 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2887 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002888
Malcolm Chend965c8b2018-02-28 15:00:40 -08002889 // Append the returned status code to the end of the response payload.
2890 String s = Integer.toHexString(
2891 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2892 if (response.payload != null) {
2893 s = IccUtils.bytesToHexString(response.payload) + s;
2894 }
2895 return s;
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002898 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002899 }
Jake Hambye994d462014-02-03 13:10:13 -08002900
Evan Charltonc66da362014-05-16 14:06:40 -07002901 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002902 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2903 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2905 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002906 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002907
Malcolm Chend965c8b2018-02-28 15:00:40 -08002908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2911 && TextUtils.equals(ISDR_AID, data)) {
2912 // Only allows LPA to select ISD-R.
2913 ComponentInfo bestComponent =
2914 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2915 if (bestComponent == null
2916 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2917 loge("The calling package is not allowed to select ISD-R.");
2918 throw new SecurityException(
2919 "The calling package is not allowed to select ISD-R.");
2920 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002921 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002922
Malcolm Chend965c8b2018-02-28 15:00:40 -08002923 if (DBG) {
2924 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2925 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2926 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002927
Malcolm Chend965c8b2018-02-28 15:00:40 -08002928 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2929 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2930 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002931
Malcolm Chend965c8b2018-02-28 15:00:40 -08002932 // Append the returned status code to the end of the response payload.
2933 String s = Integer.toHexString(
2934 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2935 if (response.payload != null) {
2936 s = IccUtils.bytesToHexString(response.payload) + s;
2937 }
2938 return s;
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002941 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002942 }
2943
2944 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002945 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002946 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2948 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002949
Malcolm Chend965c8b2018-02-28 15:00:40 -08002950 final long identity = Binder.clearCallingIdentity();
2951 try {
2952 if (DBG) {
2953 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2954 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2955 }
2956
2957 IccIoResult response =
2958 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2959 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2960 subId);
2961
2962 if (DBG) {
2963 log("Exchange SIM_IO [R]" + response);
2964 }
2965
2966 byte[] result = null;
2967 int length = 2;
2968 if (response.payload != null) {
2969 length = 2 + response.payload.length;
2970 result = new byte[length];
2971 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2972 } else {
2973 result = new byte[length];
2974 }
2975
2976 result[length - 1] = (byte) response.sw2;
2977 result[length - 2] = (byte) response.sw1;
2978 return result;
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002981 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002982 }
2983
Nathan Haroldb3014052017-01-25 15:57:32 -08002984 /**
2985 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2986 * on a particular subscription
2987 */
sqianb6e41952018-03-12 14:54:01 -07002988 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2990 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2991 return null;
2992 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002993
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 if (appType != TelephonyManager.APPTYPE_USIM
2997 && appType != TelephonyManager.APPTYPE_SIM) {
2998 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2999 return null;
3000 }
3001 Object response = sendRequest(
3002 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3003 if (response instanceof String[]) {
3004 return (String[]) response;
3005 }
3006 // Response is an Exception of some kind,
3007 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003008 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003009 } finally {
3010 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003011 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003012 }
3013
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003014 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003015 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3017 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003018
Malcolm Chend965c8b2018-02-28 15:00:40 -08003019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3022 if (response.payload == null) {
3023 return "";
3024 }
Evan Charltonc66da362014-05-16 14:06:40 -07003025
Malcolm Chend965c8b2018-02-28 15:00:40 -08003026 // Append the returned status code to the end of the response payload.
3027 String s = Integer.toHexString(
3028 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3029 s = IccUtils.bytesToHexString(response.payload) + s;
3030 return s;
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
Evan Charltonc66da362014-05-16 14:06:40 -07003034 }
3035
Jake Hambye994d462014-02-03 13:10:13 -08003036 /**
3037 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3038 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3039 *
3040 * @param itemID the ID of the item to read
3041 * @return the NV item as a String, or null on error.
3042 */
3043 @Override
3044 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3046 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003047
3048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 if (DBG) log("nvReadItem: item " + itemID);
3051 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3052 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3053 return value;
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
Jake Hambye994d462014-02-03 13:10:13 -08003057 }
3058
3059 /**
3060 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3061 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3062 *
3063 * @param itemID the ID of the item to read
3064 * @param itemValue the value to write, as a String
3065 * @return true on success; false on any failure
3066 */
3067 @Override
3068 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3070 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003071
3072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3075 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3076 new Pair<Integer, String>(itemID, itemValue));
3077 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3078 return success;
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
Jake Hambye994d462014-02-03 13:10:13 -08003082 }
3083
3084 /**
3085 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3086 * Used for device configuration by some CDMA operators.
3087 *
3088 * @param preferredRoamingList byte array containing the new PRL
3089 * @return true on success; false on any failure
3090 */
3091 @Override
3092 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3094 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003095
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3099 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3100 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3101 return success;
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
Jake Hambye994d462014-02-03 13:10:13 -08003105 }
3106
3107 /**
3108 * Perform the specified type of NV config reset.
3109 * Used for device configuration by some CDMA operators.
3110 *
3111 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3112 * @return true on success; false on any failure
3113 */
3114 @Override
3115 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3117 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003118
3119 final long identity = Binder.clearCallingIdentity();
3120 try {
3121 if (DBG) log("nvResetConfig: type " + resetType);
3122 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3123 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3124 return success;
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
Jake Hambye994d462014-02-03 13:10:13 -08003128 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003129
Svet Ganovb320e182015-04-16 12:30:10 -07003130 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003131 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003132 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003133 return new String[0];
3134 }
3135
Malcolm Chend965c8b2018-02-28 15:00:40 -08003136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 return mPhone.getPcscfAddress(apnType);
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
3141 }
Wink Saville36469e72014-06-11 15:17:00 -07003142 }
3143
Brad Ebinger51f743a2017-01-23 13:50:20 -08003144 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003145 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3146 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003147 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003148 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003149 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003150
3151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 PhoneFactory.getImsResolver().enableIms(slotId);
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003157 }
3158
3159 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003160 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3161 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003162 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003163 public void disableIms(int slotId) {
3164 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003165
3166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 PhoneFactory.getImsResolver().disableIms(slotId);
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003172 }
3173
3174 /**
3175 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3176 * feature or {@link null} if the service is not available. If the feature is available, the
3177 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3178 */
3179 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003180 IImsServiceFeatureCallback callback) {
3181 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003182
3183 final long identity = Binder.clearCallingIdentity();
3184 try {
3185 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003189 }
3190
3191 /**
3192 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3193 * feature during emergency calling or {@link null} if the service is not available. If the
3194 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3195 * listener for feature updates.
3196 */
3197 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3198 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003199
3200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3203 } finally {
3204 Binder.restoreCallingIdentity(identity);
3205 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003206 }
3207
Brad Ebinger5f64b052017-12-14 14:26:15 -08003208 /**
3209 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3210 * specified.
3211 */
3212 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3213 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003214
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003221 }
3222
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003223 /**
3224 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3225 * specified.
3226 */
3227 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3228 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003229
3230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003236 }
3237
Brad Ebinger884c07b2018-02-15 16:17:40 -08003238 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003239 * Sets the ImsService Package Name that Telephony will bind to.
3240 *
3241 * @param slotId the slot ID that the ImsService should bind for.
3242 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3243 * ImsService is the device default ImsService.
3244 * @param packageName The package name of the application that contains the ImsService to bind
3245 * to.
3246 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3247 * @hide
3248 */
3249 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003250 int[] subIds = SubscriptionManager.getSubId(slotId);
3251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3252 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3253 "setImsService");
3254
Malcolm Chend965c8b2018-02-28 15:00:40 -08003255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3258 isCarrierImsService, packageName);
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003262 }
3263
3264 /**
3265 * Return the ImsService configuration.
3266 *
3267 * @param slotId The slot that the ImsService is associated with.
3268 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3269 * the device default.
3270 * @return the package name of the ImsService configuration.
3271 */
3272 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003273 int[] subIds = SubscriptionManager.getSubId(slotId);
3274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3275 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3276 "getImsService");
3277
Malcolm Chend965c8b2018-02-28 15:00:40 -08003278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3281 isCarrierImsService);
3282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003285 }
3286
Wink Saville36469e72014-06-11 15:17:00 -07003287 public void setImsRegistrationState(boolean registered) {
3288 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003289
3290 final long identity = Binder.clearCallingIdentity();
3291 try {
3292 mPhone.setImsRegistrationState(registered);
3293 } finally {
3294 Binder.restoreCallingIdentity(identity);
3295 }
Wink Saville36469e72014-06-11 15:17:00 -07003296 }
3297
3298 /**
Stuart Scott54788802015-03-30 13:18:01 -07003299 * Set the network selection mode to automatic.
3300 *
3301 */
3302 @Override
3303 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3305 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003306
3307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3310 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3311 } finally {
3312 Binder.restoreCallingIdentity(identity);
3313 }
Stuart Scott54788802015-03-30 13:18:01 -07003314 }
3315
3316 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003317 * Set the network selection mode to manual with the selected carrier.
3318 */
3319 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003320 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003321 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3323 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003324
3325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003328 /* operatorAlphaLong */ "",
3329 /* operatorAlphaShort */ "",
Malcolm Chend965c8b2018-02-28 15:00:40 -08003330 operatorNumeric);
3331 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3332 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3333 persistSelection);
3334 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003338 }
3339
3340 /**
3341 * Scans for available networks.
3342 */
3343 @Override
3344 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3346 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003347
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3351 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3352 CMD_PERFORM_NETWORK_SCAN, null, subId);
3353 return result;
3354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003357 }
3358
3359 /**
yinxub1bed742017-04-17 11:45:04 -07003360 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003361 *
yinxub1bed742017-04-17 11:45:04 -07003362 * @param subId id of the subscription
3363 * @param request contains the radio access networks with bands/channels to scan
3364 * @param messenger callback messenger for scan results or errors
3365 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003366 * @return the id of the requested scan which can be used to stop the scan.
3367 */
3368 @Override
3369 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3370 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3372 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003373
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 return mNetworkScanRequestTracker.startNetworkScan(
3377 request, messenger, binder, getPhone(subId));
3378 } finally {
3379 Binder.restoreCallingIdentity(identity);
3380 }
yinxu504e1392017-04-12 16:03:22 -07003381 }
3382
3383 /**
3384 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003385 *
3386 * @param subId id of the subscription
3387 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003388 */
3389 @Override
3390 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3392 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003393
3394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
yinxu504e1392017-04-12 16:03:22 -07003400 }
3401
3402 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003403 * Get the calculated preferred network type.
3404 * Used for debugging incorrect network type.
3405 *
3406 * @return the preferred network type, defined in RILConstants.java.
3407 */
3408 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003409 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003411 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003412 return RILConstants.PREFERRED_NETWORK_MODE;
3413 }
3414
Malcolm Chend965c8b2018-02-28 15:00:40 -08003415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 // FIXME: need to get SubId from somewhere.
3418 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
Junda Liu84d15a22014-07-02 11:21:04 -07003422 }
3423
3424 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003425 * Get the preferred network type.
3426 * Used for device configuration by some CDMA operators.
3427 *
3428 * @return the preferred network type, defined in RILConstants.java.
3429 */
3430 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003431 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3433 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003434
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 if (DBG) log("getPreferredNetworkType");
3438 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3439 int networkType = (result != null ? result[0] : -1);
3440 if (DBG) log("getPreferredNetworkType: " + networkType);
3441 return networkType;
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003445 }
3446
3447 /**
3448 * Set the preferred network type.
3449 * Used for device configuration by some CDMA operators.
3450 *
3451 * @param networkType the preferred network type, defined in RILConstants.java.
3452 * @return true on success; false on any failure.
3453 */
3454 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003455 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3457 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003458
3459 final long identity = Binder.clearCallingIdentity();
3460 try {
3461 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3462 Boolean success = (Boolean) sendRequest(
3463 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3464 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3465 if (success) {
3466 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3467 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3468 }
3469 return success;
3470 } finally {
3471 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003472 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003473 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003474
3475 /**
Junda Liu475951f2014-11-07 16:45:03 -08003476 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3477 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3478 * tethering.
3479 *
3480 * @return 0: Not required. 1: required. 2: Not set.
3481 * @hide
3482 */
3483 @Override
3484 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003485 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003486
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3490 Settings.Global.TETHER_DUN_REQUIRED, 2);
3491 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3492 // config_tether_apndata.
3493 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3494 dunRequired = 1;
3495 }
3496 return dunRequired;
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003499 }
Junda Liu475951f2014-11-07 16:45:03 -08003500 }
3501
3502 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003503 * Set mobile data enabled
3504 * Used by the user through settings etc to turn on/off mobile data
3505 *
3506 * @param enable {@code true} turn turn data on, else {@code false}
3507 */
3508 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003509 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3511 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003512
3513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 int phoneId = mSubscriptionController.getPhoneId(subId);
3516 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3517 Phone phone = PhoneFactory.getPhone(phoneId);
3518 if (phone != null) {
3519 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3520 phone.setUserDataEnabled(enable);
3521 } else {
3522 loge("setUserDataEnabled: no phone for subId=" + subId);
3523 }
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003526 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003527 }
3528
3529 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003530 * Get the user enabled state of Mobile Data.
3531 *
3532 * TODO: remove and use isUserDataEnabled.
3533 * This can't be removed now because some vendor codes
3534 * calls through ITelephony directly while they should
3535 * use TelephonyManager.
3536 *
3537 * @return true on enabled
3538 */
3539 @Override
3540 public boolean getDataEnabled(int subId) {
3541 return isUserDataEnabled(subId);
3542 }
3543
3544 /**
3545 * Get whether mobile data is enabled per user setting.
3546 *
3547 * There are other factors deciding whether mobile data is actually enabled, but they are
3548 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003549 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003550 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003551 *
3552 * @return {@code true} if data is enabled else {@code false}
3553 */
3554 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003555 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003556 try {
3557 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3558 null);
3559 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3561 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003562 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003563
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 int phoneId = mSubscriptionController.getPhoneId(subId);
3567 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3568 Phone phone = PhoneFactory.getPhone(phoneId);
3569 if (phone != null) {
3570 boolean retVal = phone.isUserDataEnabled();
3571 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3572 return retVal;
3573 } else {
3574 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3575 return false;
3576 }
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003579 }
3580 }
3581
3582 /**
3583 * Get whether mobile data is enabled.
3584 *
3585 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3586 * whether mobile data is actually enabled.
3587 *
3588 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3589 *
3590 * @return {@code true} if data is enabled else {@code false}
3591 */
3592 @Override
3593 public boolean isDataEnabled(int subId) {
3594 try {
3595 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3596 null);
3597 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3599 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003600 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003601
3602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 int phoneId = mSubscriptionController.getPhoneId(subId);
3605 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3606 Phone phone = PhoneFactory.getPhone(phoneId);
3607 if (phone != null) {
3608 boolean retVal = phone.isDataEnabled();
3609 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3610 return retVal;
3611 } else {
3612 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3613 return false;
3614 }
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003617 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003618 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003619
3620 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003621 public int getCarrierPrivilegeStatus(int subId) {
3622 final Phone phone = getPhone(subId);
3623 if (phone == null) {
3624 loge("getCarrierPrivilegeStatus: Invalid subId");
3625 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3626 }
3627 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003628 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003629 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003630 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3631 }
3632 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003633 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003634 }
Junda Liu29340342014-07-10 15:23:27 -07003635
3636 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003637 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3638 final Phone phone = getPhone(subId);
3639 if (phone == null) {
3640 loge("getCarrierPrivilegeStatus: Invalid subId");
3641 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3642 }
3643 UiccProfile profile =
3644 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3645 if (profile == null) {
3646 loge("getCarrierPrivilegeStatus: No UICC");
3647 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3648 }
3649 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3650 }
3651
3652 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003653 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003654 if (TextUtils.isEmpty(pkgName))
3655 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003656 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003657 if (card == null) {
3658 loge("checkCarrierPrivilegesForPackage: No UICC");
3659 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3660 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003661 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3662 }
3663
3664 @Override
3665 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003666 if (TextUtils.isEmpty(pkgName))
3667 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003668 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3669 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3670 UiccCard card = UiccController.getInstance().getUiccCard(i);
3671 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003672 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003673 continue;
3674 }
3675
3676 result = card.getCarrierPrivilegeStatus(
3677 mPhone.getContext().getPackageManager(), pkgName);
3678 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3679 break;
3680 }
3681 }
3682
3683 return result;
Junda Liu29340342014-07-10 15:23:27 -07003684 }
Derek Tan89e89d42014-07-08 17:00:10 -07003685
3686 @Override
Junda Liue64de782015-04-16 17:19:16 -07003687 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3688 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3689 loge("phoneId " + phoneId + " is not valid.");
3690 return null;
3691 }
3692 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003693 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003694 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003695 return null ;
3696 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003697 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003698 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003699 }
3700
Amith Yamasani6e118872016-02-19 12:53:51 -08003701 @Override
3702 public List<String> getPackagesWithCarrierPrivileges() {
3703 PackageManager pm = mPhone.getContext().getPackageManager();
3704 List<String> privilegedPackages = new ArrayList<>();
3705 List<PackageInfo> packages = null;
3706 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3707 UiccCard card = UiccController.getInstance().getUiccCard(i);
3708 if (card == null) {
3709 // No UICC in that slot.
3710 continue;
3711 }
3712 if (card.hasCarrierPrivilegeRules()) {
3713 if (packages == null) {
3714 // Only check packages in user 0 for now
3715 packages = pm.getInstalledPackagesAsUser(
3716 PackageManager.MATCH_DISABLED_COMPONENTS
3717 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3718 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3719 }
3720 for (int p = packages.size() - 1; p >= 0; p--) {
3721 PackageInfo pkgInfo = packages.get(p);
3722 if (pkgInfo != null && pkgInfo.packageName != null
3723 && card.getCarrierPrivilegeStatus(pkgInfo)
3724 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3725 privilegedPackages.add(pkgInfo.packageName);
3726 }
3727 }
3728 }
3729 }
3730 return privilegedPackages;
3731 }
3732
Wink Savilleb564aae2014-10-23 10:18:09 -07003733 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003734 final Phone phone = getPhone(subId);
3735 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003736 if (card == null) {
3737 loge("getIccId: No UICC");
3738 return null;
3739 }
3740 String iccId = card.getIccId();
3741 if (TextUtils.isEmpty(iccId)) {
3742 loge("getIccId: ICC ID is null or empty.");
3743 return null;
3744 }
3745 return iccId;
3746 }
3747
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003748 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003749 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3750 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003751 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3752 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003753
Malcolm Chend965c8b2018-02-28 15:00:40 -08003754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 final String iccId = getIccId(subId);
3757 final Phone phone = getPhone(subId);
3758 if (phone == null) {
3759 return false;
3760 }
3761 final String subscriberId = phone.getSubscriberId();
3762
3763 if (DBG_MERGE) {
3764 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3765 + subscriberId + " to " + number);
3766 }
3767
3768 if (TextUtils.isEmpty(iccId)) {
3769 return false;
3770 }
3771
3772 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3773
3774 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3775 if (alphaTag == null) {
3776 editor.remove(alphaTagPrefKey);
3777 } else {
3778 editor.putString(alphaTagPrefKey, alphaTag);
3779 }
3780
3781 // Record both the line number and IMSI for this ICCID, since we need to
3782 // track all merged IMSIs based on line number
3783 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3784 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3785 if (number == null) {
3786 editor.remove(numberPrefKey);
3787 editor.remove(subscriberPrefKey);
3788 } else {
3789 editor.putString(numberPrefKey, number);
3790 editor.putString(subscriberPrefKey, subscriberId);
3791 }
3792
3793 editor.commit();
3794 return true;
3795 } finally {
3796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003797 }
Derek Tan7226c842014-07-02 17:42:23 -07003798 }
3799
3800 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003801 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003802 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003804 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003805 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003806 return null;
3807 }
Derek Tan97ebb422014-09-05 16:55:38 -07003808
Malcolm Chend965c8b2018-02-28 15:00:40 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 String iccId = getIccId(subId);
3812 if (iccId != null) {
3813 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3814 if (DBG_MERGE) {
3815 log("getLine1NumberForDisplay returning "
3816 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3817 }
3818 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003819 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003820 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3821 return null;
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003824 }
Derek Tan7226c842014-07-02 17:42:23 -07003825 }
3826
3827 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003828 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003830 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003831 return null;
3832 }
Derek Tan97ebb422014-09-05 16:55:38 -07003833
Malcolm Chend965c8b2018-02-28 15:00:40 -08003834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 String iccId = getIccId(subId);
3837 if (iccId != null) {
3838 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3839 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3840 }
3841 return null;
3842 } finally {
3843 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003844 }
Derek Tan7226c842014-07-02 17:42:23 -07003845 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003846
3847 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003848 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003849 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3850 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003852 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3853 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003854 return null;
3855 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003856
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003857 final long identity = Binder.clearCallingIdentity();
3858 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003859 final Context context = mPhone.getContext();
3860 final TelephonyManager tele = TelephonyManager.from(context);
3861 final SubscriptionManager sub = SubscriptionManager.from(context);
3862
3863 // Figure out what subscribers are currently active
3864 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3865 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3866 // the process, where TelephonyManager was instantiated.
3867 // Otherwise AppOps check will fail.
3868
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003869 final int[] subIds = sub.getActiveSubscriptionIdList();
3870 for (int subId : subIds) {
3871 activeSubscriberIds.add(tele.getSubscriberId(subId));
3872 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003873
3874 // First pass, find a number override for an active subscriber
3875 String mergeNumber = null;
3876 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3877 for (String key : prefs.keySet()) {
3878 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3879 final String subscriberId = (String) prefs.get(key);
3880 if (activeSubscriberIds.contains(subscriberId)) {
3881 final String iccId = key.substring(
3882 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3883 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3884 mergeNumber = (String) prefs.get(numberKey);
3885 if (DBG_MERGE) {
3886 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3887 + " for active subscriber " + subscriberId);
3888 }
3889 if (!TextUtils.isEmpty(mergeNumber)) {
3890 break;
3891 }
3892 }
3893 }
3894 }
3895
3896 // Shortcut when no active merged subscribers
3897 if (TextUtils.isEmpty(mergeNumber)) {
3898 return null;
3899 }
3900
3901 // Second pass, find all subscribers under that line override
3902 final ArraySet<String> result = new ArraySet<>();
3903 for (String key : prefs.keySet()) {
3904 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3905 final String number = (String) prefs.get(key);
3906 if (mergeNumber.equals(number)) {
3907 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3908 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3909 final String subscriberId = (String) prefs.get(subscriberKey);
3910 if (!TextUtils.isEmpty(subscriberId)) {
3911 result.add(subscriberId);
3912 }
3913 }
3914 }
3915 }
3916
3917 final String[] resultArray = result.toArray(new String[result.size()]);
3918 Arrays.sort(resultArray);
3919 if (DBG_MERGE) {
3920 Slog.d(LOG_TAG,
3921 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3922 }
3923 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003924 } finally {
3925 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003926 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003927 }
3928
3929 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003930 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003931 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3932 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003933
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 final Phone phone = getPhone(subId);
3937 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3938 } finally {
3939 Binder.restoreCallingIdentity(identity);
3940 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003941 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003942
3943 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003944 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003945 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3946 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003947 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003948
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 final Phone phone = getPhone(subId);
3952 if (phone == null) {
3953 return false;
3954 }
3955 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3956 cdmaNonRoamingList);
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003959 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003960 }
3961
3962 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003963 @Deprecated
3964 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3965 enforceModifyPermission();
3966
3967 int returnValue = 0;
3968 try {
3969 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3970 if(result.exception == null) {
3971 if (result.result != null) {
3972 byte[] responseData = (byte[])(result.result);
3973 if(responseData.length > oemResp.length) {
3974 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3975 responseData.length + "bytes. Buffer Size is " +
3976 oemResp.length + "bytes.");
3977 }
3978 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3979 returnValue = responseData.length;
3980 }
3981 } else {
3982 CommandException ex = (CommandException) result.exception;
3983 returnValue = ex.getCommandError().ordinal();
3984 if(returnValue > 0) returnValue *= -1;
3985 }
3986 } catch (RuntimeException e) {
3987 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3988 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3989 if(returnValue > 0) returnValue *= -1;
3990 }
3991
3992 return returnValue;
3993 }
3994
3995 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003996 public void setRadioCapability(RadioAccessFamily[] rafs) {
3997 try {
3998 ProxyController.getInstance().setRadioCapability(rafs);
3999 } catch (RuntimeException e) {
4000 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4001 }
4002 }
4003
4004 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004005 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004006 Phone phone = PhoneFactory.getPhone(phoneId);
4007 if (phone == null) {
4008 return RadioAccessFamily.RAF_UNKNOWN;
4009 }
4010 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004012 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004013 return RadioAccessFamily.RAF_UNKNOWN;
4014 }
4015
Malcolm Chend965c8b2018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004022 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004023
4024 @Override
4025 public void enableVideoCalling(boolean enable) {
4026 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004034 }
4035
4036 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004037 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4039 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4040 return false;
4041 }
Svet Ganovb320e182015-04-16 12:30:10 -07004042
Malcolm Chend965c8b2018-02-28 15:00:40 -08004043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 // Check the user preference and the system-level IMS setting. Even if the user has
4046 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4047 // In the long run, we may instead need to check if there exists a connection service
4048 // which can support video calling.
4049 ImsManager imsManager =
4050 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4051 return imsManager.isVtEnabledByPlatform()
4052 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4053 && imsManager.isVtEnabledByUser();
4054 } finally {
4055 Binder.restoreCallingIdentity(identity);
4056 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004057 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004058
Andrew Leea1239f22015-03-02 17:44:07 -08004059 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004060 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4062 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4063 return false;
4064 }
4065
4066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 CarrierConfigManager configManager =
4069 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4070 return configManager.getConfigForSubId(mPhone.getSubId())
4071 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
Andrew Leea1239f22015-03-02 17:44:07 -08004075 }
4076
4077 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004078 public boolean isWorldPhone(int subId, String callingPackage) {
4079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4080 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4081 return false;
4082 }
4083
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 CarrierConfigManager configManager =
4087 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4088 return configManager.getConfigForSubId(mPhone.getSubId())
4089 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4090 } finally {
4091 Binder.restoreCallingIdentity(identity);
4092 }
Andrew Leea1239f22015-03-02 17:44:07 -08004093 }
4094
Andrew Lee9431b832015-03-09 18:46:45 -07004095 @Override
4096 public boolean isTtyModeSupported() {
4097 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004098 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004099 }
4100
4101 @Override
4102 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4106 } finally {
4107 Binder.restoreCallingIdentity(identity);
4108 }
Andrew Lee9431b832015-03-09 18:46:45 -07004109 }
4110
Hall Liu98187582018-01-22 19:15:32 -08004111 public boolean isRttSupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4115 mPhone.getSubId()).getBoolean(
4116 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4117 boolean isDeviceSupported =
4118 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4119 return isCarrierSupported && isDeviceSupported;
4120 } finally {
4121 Binder.restoreCallingIdentity(identity);
4122 }
Hall Liu98187582018-01-22 19:15:32 -08004123 }
4124
Hall Liu3ad5f012018-04-06 16:23:39 -07004125 public boolean isRttEnabled() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 return isRttSupported() && Settings.Secure.getInt(
4129 mPhone.getContext().getContentResolver(),
4130 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004134 }
4135
Sanket Padawe7310cc72015-01-14 09:53:20 -08004136 /**
4137 * Returns the unique device ID of phone, for example, the IMEI for
4138 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4139 *
4140 * <p>Requires Permission:
4141 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4142 */
4143 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004144 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004145 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004146 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004147 return null;
4148 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004149 int subId = phone.getSubId();
4150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4151 mApp, subId, callingPackage, "getDeviceId")) {
4152 return null;
4153 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004154
4155 final long identity = Binder.clearCallingIdentity();
4156 try {
4157 return phone.getDeviceId();
4158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004161 }
4162
Ping Sunc67b7c22016-03-02 19:16:45 +08004163 /**
4164 * {@hide}
4165 * Returns the IMS Registration Status on a particular subid
4166 *
4167 * @param subId
4168 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004169 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004170 Phone phone = getPhone(subId);
4171 if (phone != null) {
4172 return phone.isImsRegistered();
4173 } else {
4174 return false;
4175 }
4176 }
4177
Santos Cordon7a1885b2015-02-03 11:15:19 -08004178 @Override
4179 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004186 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004187
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004188 /**
4189 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004190 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004191 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004192 final long identity = Binder.clearCallingIdentity();
4193 try {
4194 Phone phone = getPhone(subId);
4195 if (phone != null) {
4196 return phone.isWifiCallingEnabled();
4197 } else {
4198 return false;
4199 }
4200 } finally {
4201 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004202 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004203 }
4204
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004205 /**
4206 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004207 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004208 public boolean isVolteAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004209 final long identity = Binder.clearCallingIdentity();
4210 try {
4211 Phone phone = getPhone(subId);
4212 if (phone != null) {
4213 return phone.isVolteEnabled();
4214 } else {
4215 return false;
4216 }
4217 } finally {
4218 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004219 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004220 }
Svet Ganovb320e182015-04-16 12:30:10 -07004221
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004222 /**
4223 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004224 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004225 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004226 final long identity = Binder.clearCallingIdentity();
4227 try {
4228 Phone phone = getPhone(subId);
4229 if (phone != null) {
4230 return phone.isVideoEnabled();
4231 } else {
4232 return false;
4233 }
4234 } finally {
4235 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004236 }
4237 }
4238
4239 /**
4240 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4241 * defined in {@link ImsRegistrationImplBase}.
4242 */
4243 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004244 final long identity = Binder.clearCallingIdentity();
4245 try {
4246 Phone phone = getPhone(subId);
4247 if (phone != null) {
4248 return phone.getImsRegistrationTech();
4249 } else {
4250 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4251 }
4252 } finally {
4253 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004254 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004255 }
4256
Stuart Scott8eef64f2015-04-08 15:13:54 -07004257 @Override
4258 public void factoryReset(int subId) {
4259 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004260 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4261 return;
4262 }
4263
Svet Ganovcc087f82015-05-12 20:35:54 -07004264 final long identity = Binder.clearCallingIdentity();
4265 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004266 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4267 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004268 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004269 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004270 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4271 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004272 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004273 }
4274 } finally {
4275 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004276 }
4277 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004278
4279 @Override
4280 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 // We query all subscriptions instead of just the active ones, because
4284 // this might be called early on in the provisioning flow when the
4285 // subscriptions potentially aren't active yet.
4286 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4287 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004288 return null;
4289 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004290
Malcolm Chend965c8b2018-02-28 15:00:40 -08004291 // This function may be called very early, say, from the setup wizard, at
4292 // which point we won't have a default subscription set. If that's the case
4293 // we just choose the first, which will be valid in "most cases".
4294 final int defaultSubId = getDefaultSubscription();
4295 SubscriptionInfo info = null;
4296 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4297 info = slist.get(0);
4298 } else {
4299 for (SubscriptionInfo item : slist) {
4300 if (item.getSubscriptionId() == defaultSubId) {
4301 info = item;
4302 break;
4303 }
4304 }
4305
4306 if (info == null) {
4307 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004308 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004309 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004310
Malcolm Chend965c8b2018-02-28 15:00:40 -08004311 // Try and fetch the locale from the carrier properties or from the SIM language
4312 // preferences (EF-PL and EF-LI)...
4313 final int mcc = info.getMcc();
4314 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4315 String simLanguage = null;
4316 if (defaultPhone != null) {
4317 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4318 if (localeFromDefaultSim != null) {
4319 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4320 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4321 return localeFromDefaultSim.toLanguageTag();
4322 } else {
4323 simLanguage = localeFromDefaultSim.getLanguage();
4324 }
4325 }
4326 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004327
Malcolm Chend965c8b2018-02-28 15:00:40 -08004328 // The SIM language preferences only store a language (e.g. fr = French), not an
4329 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4330 // the SIM and carrier preferences does not include a country we add the country
4331 // determined from the SIM MCC to provide an exact locale.
4332 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4333 simLanguage);
4334 if (mccLocale != null) {
4335 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4336 return mccLocale.toLanguageTag();
4337 }
4338
4339 if (DBG) log("No locale found - returning null");
4340 return null;
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004344 }
4345
4346 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004347 return mSubscriptionController.getAllSubInfoList(
4348 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004349 }
4350
Malcolm Chend965c8b2018-02-28 15:00:40 -08004351 /**
4352 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4353 */
4354 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4355 return mSubscriptionController.getActiveSubscriptionInfoList(
4356 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004357 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004358
Chenjie Yu1ba97252018-01-11 18:16:20 -08004359 private final ModemActivityInfo mLastModemActivityInfo =
4360 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4361
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004362 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004363 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4364 * representing the state of the modem.
4365 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004366 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4367 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004368 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004369 */
4370 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004371 public void requestModemActivityInfo(ResultReceiver result) {
4372 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004373
4374 final long identity = Binder.clearCallingIdentity();
4375 try {
4376 ModemActivityInfo ret = null;
4377 synchronized (mLastModemActivityInfo) {
4378 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
4379 null);
4380 if (isModemActivityInfoValid(info)) {
4381 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4382 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4383 mergedTxTimeMs[i] =
4384 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4385 }
4386 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4387 mLastModemActivityInfo.setSleepTimeMillis(
4388 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4389 mLastModemActivityInfo.setIdleTimeMillis(
4390 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4391 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4392 mLastModemActivityInfo.setRxTimeMillis(
4393 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4394 mLastModemActivityInfo.setEnergyUsed(
4395 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004396 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004397 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4398 mLastModemActivityInfo.getSleepTimeMillis(),
4399 mLastModemActivityInfo.getIdleTimeMillis(),
4400 mLastModemActivityInfo.getTxTimeMillis(),
4401 mLastModemActivityInfo.getRxTimeMillis(),
4402 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004403 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004404 Bundle bundle = new Bundle();
4405 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4406 result.send(0, bundle);
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004409 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004410 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004411
Siddharth Rayf5d29552018-06-17 15:02:38 -07004412 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4413 // less than total activity duration.
4414 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4415 if (info == null) {
4416 return false;
4417 }
4418 int activityDurationMs =
4419 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4420 int totalTxTimeMs = 0;
4421 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4422 totalTxTimeMs += info.getTxTimeMillis()[i];
4423 }
4424 return (info.isValid()
4425 && (info.getSleepTimeMillis() <= activityDurationMs)
4426 && (info.getIdleTimeMillis() <= activityDurationMs)
4427 && (info.getRxTimeMillis() <= activityDurationMs)
4428 && (totalTxTimeMs <= activityDurationMs));
4429 }
4430
Jack Yu85bd38a2015-11-09 11:34:32 -08004431 /**
4432 * {@hide}
4433 * Returns the service state information on specified subscription.
4434 */
4435 @Override
4436 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004438 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004439 return null;
4440 }
4441
Malcolm Chend965c8b2018-02-28 15:00:40 -08004442 final long identity = Binder.clearCallingIdentity();
4443 try {
4444 final Phone phone = getPhone(subId);
4445 if (phone == null) {
4446 return null;
4447 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004448
Malcolm Chend965c8b2018-02-28 15:00:40 -08004449 return phone.getServiceState();
4450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004453 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004454
4455 /**
4456 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4457 *
4458 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4459 * voicemail ringtone.
4460 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4461 * PhoneAccount.
4462 */
4463 @Override
4464 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004465 final long identity = Binder.clearCallingIdentity();
4466 try {
4467 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4468 if (phone == null) {
4469 phone = mPhone;
4470 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004471
Malcolm Chend965c8b2018-02-28 15:00:40 -08004472 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4473 } finally {
4474 Binder.restoreCallingIdentity(identity);
4475 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004476 }
4477
4478 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004479 * Sets the per-account voicemail ringtone.
4480 *
4481 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4482 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4483 *
4484 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4485 * voicemail ringtone.
4486 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4487 * PhoneAccount.
4488 */
4489 @Override
4490 public void setVoicemailRingtoneUri(String callingPackage,
4491 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4492 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4493 if (!TextUtils.equals(callingPackage,
4494 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4496 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4497 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004498 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004499
4500 final long identity = Binder.clearCallingIdentity();
4501 try {
4502 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4503 if (phone == null) {
4504 phone = mPhone;
4505 }
4506 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4507 } finally {
4508 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004509 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004510 }
4511
4512 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004513 * Returns whether vibration is set for voicemail notification in Phone settings.
4514 *
4515 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4516 * voicemail vibration setting.
4517 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4518 */
4519 @Override
4520 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004521 final long identity = Binder.clearCallingIdentity();
4522 try {
4523 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4524 if (phone == null) {
4525 phone = mPhone;
4526 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004527
Malcolm Chend965c8b2018-02-28 15:00:40 -08004528 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004532 }
4533
Youhan Wange64578a2016-05-02 15:32:42 -07004534 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004535 * Sets the per-account voicemail vibration.
4536 *
4537 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4538 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4539 *
4540 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4541 * voicemail vibration setting.
4542 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4543 * specific PhoneAccount.
4544 */
4545 @Override
4546 public void setVoicemailVibrationEnabled(String callingPackage,
4547 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4548 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4549 if (!TextUtils.equals(callingPackage,
4550 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4552 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4553 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004554 }
4555
Malcolm Chend965c8b2018-02-28 15:00:40 -08004556 final long identity = Binder.clearCallingIdentity();
4557 try {
4558 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4559 if (phone == null) {
4560 phone = mPhone;
4561 }
4562 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4563 } finally {
4564 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004565 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004566 }
4567
4568 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004569 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4570 *
4571 * @throws SecurityException if the caller does not have the required permission
4572 */
4573 private void enforceReadPrivilegedPermission() {
4574 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4575 null);
4576 }
4577
4578 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004579 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4580 * permission.
4581 *
4582 * @throws SecurityException if the caller does not have the required permission
4583 */
4584 private void enforceSendSmsPermission() {
4585 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4586 }
4587
4588 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004589 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004590 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004591 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004592 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004593 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004594 final long identity = Binder.clearCallingIdentity();
4595 try {
4596 ComponentName componentName =
4597 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4598 if (componentName == null) {
4599 throw new SecurityException(
4600 "Caller not current active visual voicemail package[null]");
4601 }
4602 String vvmPackage = componentName.getPackageName();
4603 if (!callingPackage.equals(vvmPackage)) {
4604 throw new SecurityException("Caller not current active visual voicemail package["
4605 + vvmPackage + "]");
4606 }
4607 } finally {
4608 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004609 }
4610 }
4611
4612 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004613 * Return the application ID for the app type.
4614 *
4615 * @param subId the subscription ID that this request applies to.
4616 * @param appType the uicc app type.
4617 * @return Application ID for specificied app type, or null if no uicc.
4618 */
4619 @Override
4620 public String getAidForAppType(int subId, int appType) {
4621 enforceReadPrivilegedPermission();
4622 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004623
4624 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004625 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004626 if (phone == null) {
4627 return null;
4628 }
4629 String aid = null;
4630 try {
4631 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4632 .getApplicationByType(appType).getAid();
4633 } catch (Exception e) {
4634 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4635 }
4636 return aid;
4637 } finally {
4638 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004639 }
Youhan Wange64578a2016-05-02 15:32:42 -07004640 }
4641
Youhan Wang4001d252016-05-11 10:29:41 -07004642 /**
4643 * Return the Electronic Serial Number.
4644 *
4645 * @param subId the subscription ID that this request applies to.
4646 * @return ESN or null if error.
4647 */
4648 @Override
4649 public String getEsn(int subId) {
4650 enforceReadPrivilegedPermission();
4651 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004652
4653 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004654 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004655 if (phone == null) {
4656 return null;
4657 }
4658 String esn = null;
4659 try {
4660 esn = phone.getEsn();
4661 } catch (Exception e) {
4662 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4663 }
4664 return esn;
4665 } finally {
4666 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004667 }
Youhan Wang4001d252016-05-11 10:29:41 -07004668 }
4669
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004670 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004671 * Return the Preferred Roaming List Version.
4672 *
4673 * @param subId the subscription ID that this request applies to.
4674 * @return PRLVersion or null if error.
4675 */
4676 @Override
4677 public String getCdmaPrlVersion(int subId) {
4678 enforceReadPrivilegedPermission();
4679 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004680
4681 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004682 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004683 if (phone == null) {
4684 return null;
4685 }
4686 String cdmaPrlVersion = null;
4687 try {
4688 cdmaPrlVersion = phone.getCdmaPrlVersion();
4689 } catch (Exception e) {
4690 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4691 }
4692 return cdmaPrlVersion;
4693 } finally {
4694 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004695 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004696 }
4697
4698 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004699 * Get snapshot of Telephony histograms
4700 * @return List of Telephony histograms
4701 * @hide
4702 */
4703 @Override
4704 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4706 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004707
4708 final long identity = Binder.clearCallingIdentity();
4709 try {
4710 return RIL.getTelephonyRILTimingHistograms();
4711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004714 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004715
4716 /**
4717 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004718 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004719 * Require system privileges. In the future we may add this to carrier APIs.
4720 *
4721 * @return The number of carriers set successfully, should match length of carriers
4722 */
4723 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004724 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004725 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004726
Meng Wang9b7c4e92017-02-17 11:41:27 -08004727 if (carriers == null) {
4728 throw new NullPointerException("carriers cannot be null");
4729 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004730
Malcolm Chend965c8b2018-02-28 15:00:40 -08004731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4734 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4735 return retVal[0];
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004739 }
4740
4741 /**
4742 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004743 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004744 * Require system privileges. In the future we may add this to carrier APIs.
4745 *
4746 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4747 * means all carriers are allowed.
4748 */
4749 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004750 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004751 enforceReadPrivilegedPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004752
4753 final long identity = Binder.clearCallingIdentity();
4754 try {
4755 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4756 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004760 }
4761
fionaxu59545b42016-05-25 15:53:37 -07004762 /**
4763 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4764 * @param subId the subscription ID that this action applies to.
4765 * @param enabled control enable or disable metered apns.
4766 * {@hide}
4767 */
4768 @Override
4769 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4770 enforceModifyPermission();
4771 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004772
4773 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004774 if (phone == null) {
4775 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4776 return;
4777 }
4778 try {
4779 phone.carrierActionSetMeteredApnsEnabled(enabled);
4780 } catch (Exception e) {
4781 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004782 } finally {
4783 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004784 }
4785 }
4786
4787 /**
4788 * Action set from carrier signalling broadcast receivers to enable/disable radio
4789 * @param subId the subscription ID that this action applies to.
4790 * @param enabled control enable or disable radio.
4791 * {@hide}
4792 */
4793 @Override
4794 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4795 enforceModifyPermission();
4796 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004797
4798 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004799 if (phone == null) {
4800 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4801 return;
4802 }
4803 try {
4804 phone.carrierActionSetRadioEnabled(enabled);
4805 } catch (Exception e) {
4806 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004807 } finally {
4808 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004809 }
4810 }
4811
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004812 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004813 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4814 * network status based on which carrier apps could apply actions accordingly,
4815 * enable/disable default url handler for example.
4816 *
4817 * @param subId the subscription ID that this action applies to.
4818 * @param report control start/stop reporting the default network status.
4819 * {@hide}
4820 */
4821 @Override
4822 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4823 enforceModifyPermission();
4824 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004825
4826 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004827 if (phone == null) {
4828 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4829 return;
4830 }
4831 try {
4832 phone.carrierActionReportDefaultNetworkStatus(report);
4833 } catch (Exception e) {
4834 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004835 } finally {
4836 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004837 }
4838 }
4839
4840 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004841 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4842 * bug report is being generated.
4843 */
4844 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004845 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004846 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4847 != PackageManager.PERMISSION_GRANTED) {
4848 writer.println("Permission Denial: can't dump Phone from pid="
4849 + Binder.getCallingPid()
4850 + ", uid=" + Binder.getCallingUid()
4851 + "without permission "
4852 + android.Manifest.permission.DUMP);
4853 return;
4854 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004855 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004856 }
Jack Yueb89b242016-06-22 13:27:47 -07004857
Brad Ebingerdac2f002018-04-03 15:17:52 -07004858 @Override
4859 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4860 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4861 throws RemoteException {
4862 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4863 }
4864
Jack Yueb89b242016-06-22 13:27:47 -07004865 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004866 * Get aggregated video call data usage since boot.
4867 *
4868 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4869 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004870 * {@hide}
4871 */
4872 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004873 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004874 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4875 null);
4876
Malcolm Chend965c8b2018-02-28 15:00:40 -08004877 final long identity = Binder.clearCallingIdentity();
4878 try {
4879 // NetworkStatsService keeps tracking the active network interface and identity. It
4880 // records the delta with the corresponding network identity.
4881 // We just return the total video call data usage snapshot since boot.
4882 Phone phone = getPhone(subId);
4883 if (phone != null) {
4884 return phone.getVtDataUsage(perUidStats);
4885 }
4886 return null;
4887 } finally {
4888 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004889 }
Jack Yueb89b242016-06-22 13:27:47 -07004890 }
Jack Yu75ab2952016-07-08 14:29:33 -07004891
4892 /**
4893 * Policy control of data connection. Usually used when data limit is passed.
4894 * @param enabled True if enabling the data, otherwise disabling.
4895 * @param subId Subscription index
4896 * {@hide}
4897 */
4898 @Override
4899 public void setPolicyDataEnabled(boolean enabled, int subId) {
4900 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004901
4902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 Phone phone = getPhone(subId);
4905 if (phone != null) {
4906 phone.setPolicyDataEnabled(enabled);
4907 }
4908 } finally {
4909 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004910 }
4911 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004912
4913 /**
4914 * Get Client request stats
4915 * @return List of Client Request Stats
4916 * @hide
4917 */
4918 @Override
4919 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004921 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004922 return null;
4923 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004924 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004925
Malcolm Chend965c8b2018-02-28 15:00:40 -08004926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 if (phone != null) {
4929 return phone.getClientRequestStats();
4930 }
4931
4932 return null;
4933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004936 }
4937
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004938 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004939 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004940 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004941 }
Jack Yueb4124c2017-02-16 15:32:43 -08004942
4943 /**
Grace Chen70990072017-03-24 17:21:30 -07004944 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004945 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004946 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004947 * @param state State of SIM (power down, power up, pass through)
4948 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4949 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4950 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004951 *
4952 **/
4953 @Override
Grace Chen70990072017-03-24 17:21:30 -07004954 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004955 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004956 Phone phone = PhoneFactory.getPhone(slotIndex);
4957
Malcolm Chend965c8b2018-02-28 15:00:40 -08004958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 if (phone != null) {
4961 phone.setSimPowerState(state);
4962 }
4963 } finally {
4964 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004965 }
4966 }
Shuo Qiandd210312017-04-12 22:11:33 +00004967
Tyler Gunn65d45c22017-06-05 11:22:26 -07004968 private boolean isUssdApiAllowed(int subId) {
4969 CarrierConfigManager configManager =
4970 (CarrierConfigManager) mPhone.getContext().getSystemService(
4971 Context.CARRIER_CONFIG_SERVICE);
4972 if (configManager == null) {
4973 return false;
4974 }
4975 PersistableBundle pb = configManager.getConfigForSubId(subId);
4976 if (pb == null) {
4977 return false;
4978 }
4979 return pb.getBoolean(
4980 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4981 }
4982
Shuo Qiandd210312017-04-12 22:11:33 +00004983 /**
4984 * Check if phone is in emergency callback mode
4985 * @return true if phone is in emergency callback mode
4986 * @param subId sub id
4987 */
goneil9c5f4872017-12-05 14:07:56 -08004988 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004989 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004990 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004991 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004992
4993 final long identity = Binder.clearCallingIdentity();
4994 try {
4995 if (phone != null) {
4996 return phone.isInEcm();
4997 } else {
4998 return false;
4999 }
5000 } finally {
5001 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005002 }
5003 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005004
5005 /**
5006 * Get the current signal strength information for the given subscription.
5007 * Because this information is not updated when the device is in a low power state
5008 * it should not be relied-upon to be current.
5009 * @param subId Subscription index
5010 * @return the most recent cached signal strength info from the modem
5011 */
5012 @Override
5013 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 Phone p = getPhone(subId);
5017 if (p == null) {
5018 return null;
5019 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005020
Malcolm Chend965c8b2018-02-28 15:00:40 -08005021 return p.getSignalStrength();
5022 } finally {
5023 Binder.restoreCallingIdentity(identity);
5024 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005025 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005026
5027 @Override
5028 public UiccSlotInfo[] getUiccSlotsInfo() {
5029 enforceReadPrivilegedPermission();
5030
Malcolm Chend965c8b2018-02-28 15:00:40 -08005031 final long identity = Binder.clearCallingIdentity();
5032 try {
5033 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5034 if (slots == null) {
5035 Rlog.i(LOG_TAG, "slots is null.");
5036 return null;
5037 }
5038
5039 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5040 for (int i = 0; i < slots.length; i++) {
5041 UiccSlot slot = slots[i];
5042 if (slot == null) {
5043 continue;
5044 }
5045
5046 String cardId;
5047 UiccCard card = slot.getUiccCard();
5048 if (card != null) {
5049 cardId = card.getCardId();
5050 } else {
5051 cardId = slot.getIccId();
5052 }
5053
5054 int cardState = 0;
5055 switch (slot.getCardState()) {
5056 case CARDSTATE_ABSENT:
5057 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5058 break;
5059 case CARDSTATE_PRESENT:
5060 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5061 break;
5062 case CARDSTATE_ERROR:
5063 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5064 break;
5065 case CARDSTATE_RESTRICTED:
5066 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5067 break;
5068 default:
5069 break;
5070
5071 }
5072
5073 infos[i] = new UiccSlotInfo(
5074 slot.isActive(),
5075 slot.isEuicc(),
5076 cardId,
5077 cardState,
5078 slot.getPhoneId(),
5079 slot.isExtendedApduSupported());
5080 }
5081 return infos;
5082 } finally {
5083 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005084 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005085 }
5086
5087 @Override
5088 public boolean switchSlots(int[] physicalSlots) {
5089 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005090
5091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005097 }
Jack Yu4c988042018-02-27 15:30:01 -08005098
5099 @Override
5100 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5101 enforceModifyPermission();
5102 final Phone phone = getPhone(subId);
5103 if (phone == null) {
5104 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5105 return;
5106 }
5107
Malcolm Chend965c8b2018-02-28 15:00:40 -08005108 final long identity = Binder.clearCallingIdentity();
5109 try {
5110 phone.setRadioIndicationUpdateMode(filters, mode);
5111 } finally {
5112 Binder.restoreCallingIdentity(identity);
5113 }
Jack Yu4c988042018-02-27 15:30:01 -08005114 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005115
5116 /**
goneil47ffb6e2018-04-06 15:40:58 -07005117 * A test API to reload the UICC profile.
5118 *
5119 * <p>Requires that the calling app has permission
5120 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5121 * @hide
5122 */
5123 @Override
5124 public void refreshUiccProfile(int subId) {
5125 enforceModifyPermission();
5126
5127 final long identity = Binder.clearCallingIdentity();
5128 try {
5129 Phone phone = getPhone(subId);
5130 if (phone == null) {
5131 return;
5132 }
5133 UiccCard uiccCard = phone.getUiccCard();
5134 if (uiccCard == null) {
5135 return;
5136 }
5137 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5138 if (uiccProfile == null) {
5139 return;
5140 }
5141 uiccProfile.refresh();
5142 } finally {
5143 Binder.restoreCallingIdentity(identity);
5144 }
5145 }
5146
5147 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005148 * Returns false if the mobile data is disabled by default, otherwise return true.
5149 */
5150 private boolean getDefaultDataEnabled() {
5151 return "true".equalsIgnoreCase(
5152 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5153 }
5154
5155 /**
5156 * Returns true if the data roaming is enabled by default, i.e the system property
5157 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5158 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5159 */
5160 private boolean getDefaultDataRoamingEnabled(int subId) {
5161 final CarrierConfigManager configMgr = (CarrierConfigManager)
5162 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5163 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5164 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5165 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5166 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5167 return isDataRoamingEnabled;
5168 }
5169
5170 /**
5171 * Returns the default network type for the given {@code subId}, if the default network type is
5172 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5173 */
5174 private int getDefaultNetworkType(int subId) {
5175 return Integer.parseInt(
5176 TelephonyManager.getTelephonyProperty(
5177 mSubscriptionController.getPhoneId(subId),
5178 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5179 String.valueOf(Phone.PREFERRED_NT_MODE)));
5180 }
fionaxua13278b2018-03-21 00:08:13 -07005181
5182 @Override
5183 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5184 gid1, String gid2, String plmn, String spn) {
5185 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005186
5187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 final Phone phone = getPhone(subId);
5190 if (phone == null) {
5191 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5192 return;
5193 }
5194 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5195 } finally {
5196 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005197 }
fionaxua13278b2018-03-21 00:08:13 -07005198 }
5199
5200 @Override
5201 public int getCarrierIdListVersion(int subId) {
5202 enforceReadPrivilegedPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005203
5204 final long identity = Binder.clearCallingIdentity();
5205 try {
5206 final Phone phone = getPhone(subId);
5207 if (phone == null) {
5208 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5209 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5210 }
5211 return phone.getCarrierIdListVersion();
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005214 }
fionaxua13278b2018-03-21 00:08:13 -07005215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005216}