blob: cc5c4ad23670bb72532f7b8b5e7bda8dc05acece [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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001208 if (!isValid) {
1209 return;
1210 }
Wink Saville08874612014-08-31 19:19:58 -07001211
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001653 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001654 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001947 public List<NeighboringCellInfo>
1948 getNeighboringCellInfo(String callingPackage, int targetSdk) {
1949 // FIXME: use the P constant when available
1950 if (targetSdk > android.os.Build.VERSION_CODES.O_MR1 + 1) return null;
1951
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001952 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001953 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001954 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
1957 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1958 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1959 return null;
1960 }
Svetoslav64fad262015-04-14 14:35:21 -07001961
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001962 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001964 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001966 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967
1968 final long identity = Binder.clearCallingIdentity();
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001969 try {
1970 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1971 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1972 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1973 } catch (RuntimeException e) {
1974 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 } finally {
1976 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001978 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
1980
1981
1982 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001983 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001984 mPhone.getContext().getSystemService(AppOpsManager.class)
1985 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001986 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001987 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001988 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001991 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001992 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001993 final long identity = Binder.clearCallingIdentity();
1994 try {
1995 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1996 for (Phone phone : PhoneFactory.getPhones()) {
1997 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1998 if (info != null) cellInfos.addAll(info);
1999 }
2000 return cellInfos;
2001 } finally {
2002 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 }
2004 }
2005
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002006 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002008 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002009 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002010
2011 final long identity = Binder.clearCallingIdentity();
2012 try {
2013 mPhone.setCellInfoListRate(rateInMillis, workSource);
2014 } finally {
2015 Binder.restoreCallingIdentity(identity);
2016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Shishir Agrawala9f32182016-04-12 12:00:16 -07002019 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002020 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002021 Phone phone = PhoneFactory.getPhone(slotIndex);
2022 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002023 return null;
2024 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002025 int subId = phone.getSubId();
2026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2027 mApp, subId, callingPackage, "getImeiForSlot")) {
2028 return null;
2029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030
2031 final long identity = Binder.clearCallingIdentity();
2032 try {
2033 return phone.getImei();
2034 } finally {
2035 Binder.restoreCallingIdentity(identity);
2036 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002037 }
2038
2039 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002040 public String getTypeAllocationCodeForSlot(int slotIndex) {
2041 Phone phone = PhoneFactory.getPhone(slotIndex);
2042 String tac = null;
2043 if (phone != null) {
2044 String imei = phone.getImei();
2045 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2046 }
2047 return tac;
2048 }
2049
2050 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002051 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002052 Phone phone = PhoneFactory.getPhone(slotIndex);
2053 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002054 return null;
2055 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002056 int subId = phone.getSubId();
2057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2058 mApp, subId, callingPackage, "getMeidForSlot")) {
2059 return null;
2060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061
2062 final long identity = Binder.clearCallingIdentity();
2063 try {
2064 return phone.getMeid();
2065 } finally {
2066 Binder.restoreCallingIdentity(identity);
2067 }
Jack Yu2af8d712017-03-15 17:14:14 -07002068 }
2069
2070 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002071 public String getManufacturerCodeForSlot(int slotIndex) {
2072 Phone phone = PhoneFactory.getPhone(slotIndex);
2073 String manufacturerCode = null;
2074 if (phone != null) {
2075 String meid = phone.getMeid();
2076 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2077 }
2078 return manufacturerCode;
2079 }
2080
2081 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002082 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002083 Phone phone = PhoneFactory.getPhone(slotIndex);
2084 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002085 return null;
2086 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002087 int subId = phone.getSubId();
2088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2089 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2090 return null;
2091 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002092
2093 final long identity = Binder.clearCallingIdentity();
2094 try {
2095 return phone.getDeviceSvn();
2096 } finally {
2097 Binder.restoreCallingIdentity(identity);
2098 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002099 }
2100
fionaxu43304da2017-11-27 22:51:16 -08002101 @Override
2102 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 final Phone phone = getPhone(subId);
2106 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
2109 }
fionaxu43304da2017-11-27 22:51:16 -08002110 }
2111
2112 @Override
2113 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 final Phone phone = getPhone(subId);
2117 return phone == null ? null : phone.getCarrierName();
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
fionaxu43304da2017-11-27 22:51:16 -08002121 }
2122
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 //
2124 // Internal helper methods.
2125 //
2126
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002127 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2129 *
2130 * @throws SecurityException if the caller does not have the required permission
2131 */
2132 private void enforceModifyPermission() {
2133 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2134 }
2135
2136 /**
2137 * Make sure the caller has the CALL_PHONE permission.
2138 *
2139 * @throws SecurityException if the caller does not have the required permission
2140 */
2141 private void enforceCallPermission() {
2142 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2143 }
2144
Stuart Scott8eef64f2015-04-08 15:13:54 -07002145 private void enforceConnectivityInternalPermission() {
2146 mApp.enforceCallingOrSelfPermission(
2147 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2148 "ConnectivityService");
2149 }
2150
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 private String createTelUrl(String number) {
2152 if (TextUtils.isEmpty(number)) {
2153 return null;
2154 }
2155
Jake Hambye994d462014-02-03 13:10:13 -08002156 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 }
2158
Ihab Awadf9e92732013-12-05 18:02:52 -08002159 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2161 }
2162
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002163 private static void logv(String msg) {
2164 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2165 }
2166
Ihab Awadf9e92732013-12-05 18:02:52 -08002167 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2169 }
2170
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002171 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002173 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002174 }
2175
Sanket Padawe356d7632015-06-22 14:03:32 -07002176 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002177 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002178 final long identity = Binder.clearCallingIdentity();
2179 try {
2180 final Phone phone = PhoneFactory.getPhone(slotIndex);
2181 if (phone == null) {
2182 return PhoneConstants.PHONE_TYPE_NONE;
2183 } else {
2184 return phone.getPhoneType();
2185 }
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 }
2190
2191 /**
2192 * Returns the CDMA ERI icon index to display
2193 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002194 @Override
2195 public int getCdmaEriIconIndex(String callingPackage) {
2196 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002197 }
2198
Sanket Padawe356d7632015-06-22 14:03:32 -07002199 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002200 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002202 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002203 return -1;
2204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 final Phone phone = getPhone(subId);
2209 if (phone != null) {
2210 return phone.getCdmaEriIconIndex();
2211 } else {
2212 return -1;
2213 }
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
2219 /**
2220 * Returns the CDMA ERI icon mode,
2221 * 0 - ON
2222 * 1 - FLASHING
2223 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002224 @Override
2225 public int getCdmaEriIconMode(String callingPackage) {
2226 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002227 }
2228
Sanket Padawe356d7632015-06-22 14:03:32 -07002229 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002232 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 return -1;
2234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235
2236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 final Phone phone = getPhone(subId);
2239 if (phone != null) {
2240 return phone.getCdmaEriIconMode();
2241 } else {
2242 return -1;
2243 }
2244 } finally {
2245 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 }
2248
2249 /**
2250 * Returns the CDMA ERI text,
2251 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002252 @Override
2253 public String getCdmaEriText(String callingPackage) {
2254 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002255 }
2256
Sanket Padawe356d7632015-06-22 14:03:32 -07002257 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002258 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002260 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002261 return null;
2262 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263
2264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 final Phone phone = getPhone(subId);
2267 if (phone != null) {
2268 return phone.getCdmaEriText();
2269 } else {
2270 return null;
2271 }
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
2276
2277 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002278 * Returns the CDMA MDN.
2279 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002281 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2283 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284
2285 final long identity = Binder.clearCallingIdentity();
2286 try {
2287 final Phone phone = getPhone(subId);
2288 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2289 return phone.getLine1Number();
2290 } else {
2291 return null;
2292 }
2293 } finally {
2294 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002295 }
2296 }
2297
2298 /**
2299 * Returns the CDMA MIN.
2300 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002301 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002302 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2304 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305
2306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 final Phone phone = getPhone(subId);
2309 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2310 return phone.getCdmaMin();
2311 } else {
2312 return null;
2313 }
2314 } finally {
2315 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002316 }
2317 }
2318
2319 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 * Returns true if CDMA provisioning needs to run.
2321 */
2322 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 return mPhone.needsOtaServiceProvisioning();
2326 } finally {
2327 Binder.restoreCallingIdentity(identity);
2328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 }
2330
2331 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002332 * Sets the voice mail number of a given subId.
2333 */
2334 @Override
2335 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002336 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337
2338 final long identity = Binder.clearCallingIdentity();
2339 try {
2340 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2341 new Pair<String, String>(alphaTag, number), new Integer(subId));
2342 return success;
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
2345 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002346 }
2347
Ta-wei Yen87c49842016-05-13 21:19:52 -07002348 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002349 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2350 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2351 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2352 if (!TextUtils.equals(callingPackage, systemDialer)) {
2353 throw new SecurityException("caller must be system dialer");
2354 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355
2356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2359 if (phoneAccountHandle == null) {
2360 return null;
2361 }
2362 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002365 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002366 }
2367
2368 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002369 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002370 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002372 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002373 return null;
2374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 return RemoteVvmTaskManager
2379 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2380 } finally {
2381 Binder.restoreCallingIdentity(identity);
2382 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002383 }
2384
2385 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002386 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2387 VisualVoicemailSmsFilterSettings settings) {
2388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002389
2390 final long identity = Binder.clearCallingIdentity();
2391 try {
2392 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2393 mPhone.getContext(), callingPackage, subId, settings);
2394 } finally {
2395 Binder.restoreCallingIdentity(identity);
2396 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002397 }
2398
2399 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002400 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2401 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002402
2403 final long identity = Binder.clearCallingIdentity();
2404 try {
2405 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2406 mPhone.getContext(), callingPackage, subId);
2407 } finally {
2408 Binder.restoreCallingIdentity(identity);
2409 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002410 }
2411
2412 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002413 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2414 String callingPackage, int subId) {
2415 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416
2417 final long identity = Binder.clearCallingIdentity();
2418 try {
2419 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2420 mPhone.getContext(), callingPackage, subId);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
2423 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002424 }
2425
2426 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002427 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002428 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429
2430 final long identity = Binder.clearCallingIdentity();
2431 try {
2432 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2433 mPhone.getContext(), subId);
2434 } finally {
2435 Binder.restoreCallingIdentity(identity);
2436 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002437 }
2438
2439 @Override
2440 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2441 String number, int port, String text, PendingIntent sentIntent) {
2442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002443 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002444 enforceSendSmsPermission();
2445 // Make the calls as the phone process.
2446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2449 if (port == 0) {
2450 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2451 sentIntent, null, false);
2452 } else {
2453 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2454 smsManager.sendDataMessageWithSelfPermissions(number, null,
2455 (short) port, data, sentIntent, null);
2456 }
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
2459 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002460 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002461 /**
fionaxu0152e512016-11-14 13:36:14 -08002462 * Sets the voice activation state of a given subId.
2463 */
2464 @Override
2465 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2467 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468
2469 final long identity = Binder.clearCallingIdentity();
2470 try {
2471 final Phone phone = getPhone(subId);
2472 if (phone != null) {
2473 phone.setVoiceActivationState(activationState);
2474 } else {
2475 loge("setVoiceActivationState fails with invalid subId: " + subId);
2476 }
2477 } finally {
2478 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002479 }
2480 }
2481
2482 /**
2483 * Sets the data activation state of a given subId.
2484 */
2485 @Override
2486 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2488 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489
2490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 final Phone phone = getPhone(subId);
2493 if (phone != null) {
2494 phone.setDataActivationState(activationState);
2495 } else {
2496 loge("setVoiceActivationState fails with invalid subId: " + subId);
2497 }
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002500 }
2501 }
2502
2503 /**
2504 * Returns the voice activation state of a given subId.
2505 */
2506 @Override
2507 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002508 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509
fionaxu0152e512016-11-14 13:36:14 -08002510 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 if (phone != null) {
2514 return phone.getVoiceActivationState();
2515 } else {
2516 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2517 }
2518 } finally {
2519 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002520 }
2521 }
2522
2523 /**
2524 * Returns the data activation state of a given subId.
2525 */
2526 @Override
2527 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002528 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529
fionaxu0152e512016-11-14 13:36:14 -08002530 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 if (phone != null) {
2534 return phone.getDataActivationState();
2535 } else {
2536 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2537 }
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002540 }
2541 }
2542
2543 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002544 * Returns the unread count of voicemails
2545 */
2546 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002547 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002548 }
2549
2550 /**
2551 * Returns the unread count of voicemails for a subId
2552 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002553 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002554 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 final Phone phone = getPhone(subId);
2558 if (phone != null) {
2559 return phone.getVoiceMessageCount();
2560 } else {
2561 return 0;
2562 }
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 }
2567
2568 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002569 * returns true, if the device is in a state where both voice and data
2570 * are supported simultaneously. This can change based on location or network condition.
2571 */
2572 @Override
2573 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone phone = getPhone(subId);
2577 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
2580 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002581 }
2582
2583 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002584 * Send the dialer code if called from the current default dialer or the caller has
2585 * carrier privilege.
2586 * @param inputCode The dialer code to send
2587 */
2588 @Override
2589 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2591 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2592 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002593 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2594 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 mPhone.sendDialerSpecialCode(inputCode);
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
2602 }
fionaxu235cc5e2017-03-06 22:25:57 -08002603 }
2604
2605 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002606 * Returns the data network type.
2607 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 *
2609 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2610 */
2611 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002612 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 final Phone phone = getPhone(getDefaultSubscription());
2616 if (phone != null) {
2617 return phone.getServiceState().getDataNetworkType();
2618 } else {
2619 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002623 }
Wink Saville36469e72014-06-11 15:17:00 -07002624 }
2625
2626 /**
2627 * Returns the network type for a subId
2628 */
2629 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002632 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002633 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2634 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 final Phone phone = getPhone(subId);
2639 if (phone != null) {
2640 return phone.getServiceState().getDataNetworkType();
2641 } else {
2642 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2643 }
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648
2649 /**
2650 * Returns the data network type
2651 */
2652 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002653 public int getDataNetworkType(String callingPackage) {
2654 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002655 }
2656
2657 /**
2658 * Returns the data network type for a subId
2659 */
2660 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002661 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002662 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002663 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002664 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2665 }
2666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 final Phone phone = getPhone(subId);
2670 if (phone != null) {
2671 return phone.getServiceState().getDataNetworkType();
2672 } else {
2673 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2674 }
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
2679
2680 /**
Wink Saville36469e72014-06-11 15:17:00 -07002681 * Returns the Voice network type for a subId
2682 */
2683 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002684 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002686 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002687 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2688 }
2689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 final long identity = Binder.clearCallingIdentity();
2691 try {
2692 final Phone phone = getPhone(subId);
2693 if (phone != null) {
2694 return phone.getServiceState().getVoiceNetworkType();
2695 } else {
2696 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2697 }
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 }
2702
2703 /**
2704 * @return true if a ICC card is present
2705 */
2706 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002707 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002708 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2709 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002710 }
2711
2712 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002713 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002714 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002716 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 final Phone phone = PhoneFactory.getPhone(slotIndex);
2720 if (phone != null) {
2721 return phone.getIccCard().hasIccCard();
2722 } else {
2723 return false;
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728 }
2729
2730 /**
2731 * Return if the current radio is LTE on CDMA. This
2732 * is a tri-state return value as for a period of time
2733 * the mode may be unknown.
2734 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002735 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002737 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002739 @Override
2740 public int getLteOnCdmaMode(String callingPackage) {
2741 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002742 }
2743
Sanket Padawe356d7632015-06-22 14:03:32 -07002744 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002745 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002746 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002747 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002748 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2749 }
2750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 final Phone phone = getPhone(subId);
2754 if (phone == null) {
2755 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2756 } else {
2757 return phone.getLteOnCdmaMode();
2758 }
2759 } finally {
2760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002761 }
Wink Saville36469e72014-06-11 15:17:00 -07002762 }
2763
2764 public void setPhone(Phone phone) {
2765 mPhone = phone;
2766 }
2767
2768 /**
2769 * {@hide}
2770 * Returns Default subId, 0 in the case of single standby.
2771 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002772 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002773 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002774 }
2775
Shishir Agrawala9f32182016-04-12 12:00:16 -07002776 private int getSlotForDefaultSubscription() {
2777 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2778 }
2779
Wink Savilleb564aae2014-10-23 10:18:09 -07002780 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002781 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002783
2784 /**
2785 * @see android.telephony.TelephonyManager.WifiCallingChoices
2786 */
2787 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2791 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2792 getWhenToMakeWifiCallsDefaultPreference());
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
2795 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002796 }
2797
2798 /**
2799 * @see android.telephony.TelephonyManager.WifiCallingChoices
2800 */
2801 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2805 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2806 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2807 } finally {
2808 Binder.restoreCallingIdentity(identity);
2809 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002810 }
2811
Sailesh Nepald1e68152013-12-12 19:08:02 -08002812 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002813 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002814 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002815 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002816
Shishir Agrawal566b7612013-10-28 14:41:00 -07002817 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002818 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2819 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2821 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 if (TextUtils.equals(ISDR_AID, aid)) {
2827 // Only allows LPA to open logical channel to ISD-R.
2828 ComponentInfo bestComponent =
2829 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2830 if (bestComponent == null
2831 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2832 loge("The calling package is not allowed to access ISD-R.");
2833 throw new SecurityException(
2834 "The calling package is not allowed to access ISD-R.");
2835 }
Derek Tan740e1672017-06-27 14:56:27 -07002836 }
Derek Tan740e1672017-06-27 14:56:27 -07002837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 if (DBG) {
2839 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2840 }
2841 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2842 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2843 if (DBG) log("iccOpenLogicalChannel: " + response);
2844 return response;
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002848 }
2849
2850 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002851 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2853 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2858 if (channel < 0) {
2859 return false;
2860 }
2861 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2862 if (DBG) log("iccCloseLogicalChannel: " + success);
2863 return success;
2864 } finally {
2865 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002866 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002867 }
2868
2869 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002870 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002871 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2873 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 if (DBG) {
2878 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2879 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2880 + p3 + " data=" + data);
2881 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883 if (channel < 0) {
2884 return "";
2885 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2888 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2889 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 // Append the returned status code to the end of the response payload.
2892 String s = Integer.toHexString(
2893 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2894 if (response.payload != null) {
2895 s = IccUtils.bytesToHexString(response.payload) + s;
2896 }
2897 return s;
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002900 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002901 }
Jake Hambye994d462014-02-03 13:10:13 -08002902
Evan Charltonc66da362014-05-16 14:06:40 -07002903 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002904 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2905 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2907 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2913 && TextUtils.equals(ISDR_AID, data)) {
2914 // Only allows LPA to select ISD-R.
2915 ComponentInfo bestComponent =
2916 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2917 if (bestComponent == null
2918 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2919 loge("The calling package is not allowed to select ISD-R.");
2920 throw new SecurityException(
2921 "The calling package is not allowed to select ISD-R.");
2922 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002923 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925 if (DBG) {
2926 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2927 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2928 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2931 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2932 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 // Append the returned status code to the end of the response payload.
2935 String s = Integer.toHexString(
2936 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2937 if (response.payload != null) {
2938 s = IccUtils.bytesToHexString(response.payload) + s;
2939 }
2940 return s;
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002943 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002944 }
2945
2946 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002947 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002948 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2950 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 if (DBG) {
2955 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2956 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2957 }
2958
2959 IccIoResult response =
2960 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2961 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2962 subId);
2963
2964 if (DBG) {
2965 log("Exchange SIM_IO [R]" + response);
2966 }
2967
2968 byte[] result = null;
2969 int length = 2;
2970 if (response.payload != null) {
2971 length = 2 + response.payload.length;
2972 result = new byte[length];
2973 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2974 } else {
2975 result = new byte[length];
2976 }
2977
2978 result[length - 1] = (byte) response.sw2;
2979 result[length - 2] = (byte) response.sw1;
2980 return result;
2981 } finally {
2982 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002983 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002984 }
2985
Nathan Haroldb3014052017-01-25 15:57:32 -08002986 /**
2987 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2988 * on a particular subscription
2989 */
sqianb6e41952018-03-12 14:54:01 -07002990 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2992 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2993 return null;
2994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995
2996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 if (appType != TelephonyManager.APPTYPE_USIM
2999 && appType != TelephonyManager.APPTYPE_SIM) {
3000 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3001 return null;
3002 }
3003 Object response = sendRequest(
3004 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3005 if (response instanceof String[]) {
3006 return (String[]) response;
3007 }
3008 // Response is an Exception of some kind,
3009 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003010 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011 } finally {
3012 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003013 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003014 }
3015
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003016 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003017 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3019 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3024 if (response.payload == null) {
3025 return "";
3026 }
Evan Charltonc66da362014-05-16 14:06:40 -07003027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 // Append the returned status code to the end of the response payload.
3029 String s = Integer.toHexString(
3030 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3031 s = IccUtils.bytesToHexString(response.payload) + s;
3032 return s;
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
3035 }
Evan Charltonc66da362014-05-16 14:06:40 -07003036 }
3037
Jake Hambye994d462014-02-03 13:10:13 -08003038 /**
3039 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3040 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3041 *
3042 * @param itemID the ID of the item to read
3043 * @return the NV item as a String, or null on error.
3044 */
3045 @Override
3046 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3048 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049
3050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 if (DBG) log("nvReadItem: item " + itemID);
3053 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3054 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3055 return value;
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
Jake Hambye994d462014-02-03 13:10:13 -08003059 }
3060
3061 /**
3062 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3063 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3064 *
3065 * @param itemID the ID of the item to read
3066 * @param itemValue the value to write, as a String
3067 * @return true on success; false on any failure
3068 */
3069 @Override
3070 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3072 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3077 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3078 new Pair<Integer, String>(itemID, itemValue));
3079 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3080 return success;
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
Jake Hambye994d462014-02-03 13:10:13 -08003084 }
3085
3086 /**
3087 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3088 * Used for device configuration by some CDMA operators.
3089 *
3090 * @param preferredRoamingList byte array containing the new PRL
3091 * @return true on success; false on any failure
3092 */
3093 @Override
3094 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3096 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097
3098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3101 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3102 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3103 return success;
3104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
Jake Hambye994d462014-02-03 13:10:13 -08003107 }
3108
3109 /**
3110 * Perform the specified type of NV config reset.
3111 * Used for device configuration by some CDMA operators.
3112 *
3113 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3114 * @return true on success; false on any failure
3115 */
3116 @Override
3117 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3119 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120
3121 final long identity = Binder.clearCallingIdentity();
3122 try {
3123 if (DBG) log("nvResetConfig: type " + resetType);
3124 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3125 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3126 return success;
3127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
Jake Hambye994d462014-02-03 13:10:13 -08003130 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003131
Svet Ganovb320e182015-04-16 12:30:10 -07003132 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003134 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003135 return new String[0];
3136 }
3137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 return mPhone.getPcscfAddress(apnType);
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
3143 }
Wink Saville36469e72014-06-11 15:17:00 -07003144 }
3145
Brad Ebinger51f743a2017-01-23 13:50:20 -08003146 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003147 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3148 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003149 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003150 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003151 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152
3153 final long identity = Binder.clearCallingIdentity();
3154 try {
3155 PhoneFactory.getImsResolver().enableIms(slotId);
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
3158 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003159 }
3160
3161 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003162 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3163 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003164 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003165 public void disableIms(int slotId) {
3166 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167
3168 final long identity = Binder.clearCallingIdentity();
3169 try {
3170 PhoneFactory.getImsResolver().disableIms(slotId);
3171 } finally {
3172 Binder.restoreCallingIdentity(identity);
3173 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003174 }
3175
3176 /**
3177 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3178 * feature or {@link null} if the service is not available. If the feature is available, the
3179 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3180 */
3181 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003182 IImsServiceFeatureCallback callback) {
3183 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003191 }
3192
3193 /**
3194 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3195 * feature during emergency calling or {@link null} if the service is not available. If the
3196 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3197 * listener for feature updates.
3198 */
3199 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3200 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003208 }
3209
Brad Ebinger5f64b052017-12-14 14:26:15 -08003210 /**
3211 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3212 * specified.
3213 */
3214 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3215 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003223 }
3224
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003225 /**
3226 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3227 * specified.
3228 */
3229 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3230 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003231
3232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003238 }
3239
Brad Ebinger884c07b2018-02-15 16:17:40 -08003240 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003241 * Sets the ImsService Package Name that Telephony will bind to.
3242 *
3243 * @param slotId the slot ID that the ImsService should bind for.
3244 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3245 * ImsService is the device default ImsService.
3246 * @param packageName The package name of the application that contains the ImsService to bind
3247 * to.
3248 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3249 * @hide
3250 */
3251 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003252 int[] subIds = SubscriptionManager.getSubId(slotId);
3253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3254 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3255 "setImsService");
3256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3260 isCarrierImsService, packageName);
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
3263 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003264 }
3265
3266 /**
3267 * Return the ImsService configuration.
3268 *
3269 * @param slotId The slot that the ImsService is associated with.
3270 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3271 * the device default.
3272 * @return the package name of the ImsService configuration.
3273 */
3274 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003275 int[] subIds = SubscriptionManager.getSubId(slotId);
3276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3277 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3278 "getImsService");
3279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3283 isCarrierImsService);
3284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003287 }
3288
Wink Saville36469e72014-06-11 15:17:00 -07003289 public void setImsRegistrationState(boolean registered) {
3290 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291
3292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 mPhone.setImsRegistrationState(registered);
3295 } finally {
3296 Binder.restoreCallingIdentity(identity);
3297 }
Wink Saville36469e72014-06-11 15:17:00 -07003298 }
3299
3300 /**
Stuart Scott54788802015-03-30 13:18:01 -07003301 * Set the network selection mode to automatic.
3302 *
3303 */
3304 @Override
3305 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3307 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308
3309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3312 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
Stuart Scott54788802015-03-30 13:18:01 -07003316 }
3317
3318 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003319 * Set the network selection mode to manual with the selected carrier.
3320 */
3321 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003322 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003323 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3325 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003330 /* operatorAlphaLong */ "",
3331 /* operatorAlphaShort */ "",
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332 operatorNumeric);
3333 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3334 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3335 persistSelection);
3336 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003340 }
3341
3342 /**
3343 * Scans for available networks.
3344 */
3345 @Override
3346 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3348 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349
3350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3353 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3354 CMD_PERFORM_NETWORK_SCAN, null, subId);
3355 return result;
3356 } finally {
3357 Binder.restoreCallingIdentity(identity);
3358 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003359 }
3360
3361 /**
yinxub1bed742017-04-17 11:45:04 -07003362 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003363 *
yinxub1bed742017-04-17 11:45:04 -07003364 * @param subId id of the subscription
3365 * @param request contains the radio access networks with bands/channels to scan
3366 * @param messenger callback messenger for scan results or errors
3367 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003368 * @return the id of the requested scan which can be used to stop the scan.
3369 */
3370 @Override
3371 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3372 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3374 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 return mNetworkScanRequestTracker.startNetworkScan(
3379 request, messenger, binder, getPhone(subId));
3380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
yinxu504e1392017-04-12 16:03:22 -07003383 }
3384
3385 /**
3386 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003387 *
3388 * @param subId id of the subscription
3389 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003390 */
3391 @Override
3392 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3394 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395
3396 final long identity = Binder.clearCallingIdentity();
3397 try {
3398 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
yinxu504e1392017-04-12 16:03:22 -07003402 }
3403
3404 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003405 * Get the calculated preferred network type.
3406 * Used for debugging incorrect network type.
3407 *
3408 * @return the preferred network type, defined in RILConstants.java.
3409 */
3410 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003411 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003412 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003413 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003414 return RILConstants.PREFERRED_NETWORK_MODE;
3415 }
3416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003417 final long identity = Binder.clearCallingIdentity();
3418 try {
3419 // FIXME: need to get SubId from somewhere.
3420 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3421 } finally {
3422 Binder.restoreCallingIdentity(identity);
3423 }
Junda Liu84d15a22014-07-02 11:21:04 -07003424 }
3425
3426 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003427 * Get the preferred network type.
3428 * Used for device configuration by some CDMA operators.
3429 *
3430 * @return the preferred network type, defined in RILConstants.java.
3431 */
3432 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003433 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3435 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003436
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 if (DBG) log("getPreferredNetworkType");
3440 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3441 int networkType = (result != null ? result[0] : -1);
3442 if (DBG) log("getPreferredNetworkType: " + networkType);
3443 return networkType;
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003447 }
3448
3449 /**
3450 * Set the preferred network type.
3451 * Used for device configuration by some CDMA operators.
3452 *
3453 * @param networkType the preferred network type, defined in RILConstants.java.
3454 * @return true on success; false on any failure.
3455 */
3456 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003457 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3459 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003460
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3464 Boolean success = (Boolean) sendRequest(
3465 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3466 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3467 if (success) {
3468 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3469 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3470 }
3471 return success;
3472 } finally {
3473 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003474 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003475 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003476
3477 /**
Junda Liu475951f2014-11-07 16:45:03 -08003478 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3479 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3480 * tethering.
3481 *
3482 * @return 0: Not required. 1: required. 2: Not set.
3483 * @hide
3484 */
3485 @Override
3486 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003487 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3492 Settings.Global.TETHER_DUN_REQUIRED, 2);
3493 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3494 // config_tether_apndata.
3495 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3496 dunRequired = 1;
3497 }
3498 return dunRequired;
3499 } finally {
3500 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003501 }
Junda Liu475951f2014-11-07 16:45:03 -08003502 }
3503
3504 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003505 * Set mobile data enabled
3506 * Used by the user through settings etc to turn on/off mobile data
3507 *
3508 * @param enable {@code true} turn turn data on, else {@code false}
3509 */
3510 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003511 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3513 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514
3515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 int phoneId = mSubscriptionController.getPhoneId(subId);
3518 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3519 Phone phone = PhoneFactory.getPhone(phoneId);
3520 if (phone != null) {
3521 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3522 phone.setUserDataEnabled(enable);
3523 } else {
3524 loge("setUserDataEnabled: no phone for subId=" + subId);
3525 }
3526 } finally {
3527 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003528 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003529 }
3530
3531 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003532 * Get the user enabled state of Mobile Data.
3533 *
3534 * TODO: remove and use isUserDataEnabled.
3535 * This can't be removed now because some vendor codes
3536 * calls through ITelephony directly while they should
3537 * use TelephonyManager.
3538 *
3539 * @return true on enabled
3540 */
3541 @Override
3542 public boolean getDataEnabled(int subId) {
3543 return isUserDataEnabled(subId);
3544 }
3545
3546 /**
3547 * Get whether mobile data is enabled per user setting.
3548 *
3549 * There are other factors deciding whether mobile data is actually enabled, but they are
3550 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003551 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003552 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003553 *
3554 * @return {@code true} if data is enabled else {@code false}
3555 */
3556 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003557 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003558 try {
3559 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3560 null);
3561 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3563 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 int phoneId = mSubscriptionController.getPhoneId(subId);
3569 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3570 Phone phone = PhoneFactory.getPhone(phoneId);
3571 if (phone != null) {
3572 boolean retVal = phone.isUserDataEnabled();
3573 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3574 return retVal;
3575 } else {
3576 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3577 return false;
3578 }
3579 } finally {
3580 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003581 }
3582 }
3583
3584 /**
3585 * Get whether mobile data is enabled.
3586 *
3587 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3588 * whether mobile data is actually enabled.
3589 *
3590 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3591 *
3592 * @return {@code true} if data is enabled else {@code false}
3593 */
3594 @Override
3595 public boolean isDataEnabled(int subId) {
3596 try {
3597 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3598 null);
3599 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3601 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003602 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603
3604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 int phoneId = mSubscriptionController.getPhoneId(subId);
3607 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3608 Phone phone = PhoneFactory.getPhone(phoneId);
3609 if (phone != null) {
3610 boolean retVal = phone.isDataEnabled();
3611 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3612 return retVal;
3613 } else {
3614 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3615 return false;
3616 }
3617 } finally {
3618 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003619 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003620 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003621
3622 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003623 public int getCarrierPrivilegeStatus(int subId) {
3624 final Phone phone = getPhone(subId);
3625 if (phone == null) {
3626 loge("getCarrierPrivilegeStatus: Invalid subId");
3627 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3628 }
3629 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003630 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003631 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003632 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3633 }
3634 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003635 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003636 }
Junda Liu29340342014-07-10 15:23:27 -07003637
3638 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003639 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3640 final Phone phone = getPhone(subId);
3641 if (phone == null) {
3642 loge("getCarrierPrivilegeStatus: Invalid subId");
3643 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3644 }
3645 UiccProfile profile =
3646 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3647 if (profile == null) {
3648 loge("getCarrierPrivilegeStatus: No UICC");
3649 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3650 }
3651 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3652 }
3653
3654 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003655 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003656 if (TextUtils.isEmpty(pkgName))
3657 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003658 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003659 if (card == null) {
3660 loge("checkCarrierPrivilegesForPackage: No UICC");
3661 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3662 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003663 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3664 }
3665
3666 @Override
3667 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003668 if (TextUtils.isEmpty(pkgName))
3669 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003670 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3671 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3672 UiccCard card = UiccController.getInstance().getUiccCard(i);
3673 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003674 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003675 continue;
3676 }
3677
3678 result = card.getCarrierPrivilegeStatus(
3679 mPhone.getContext().getPackageManager(), pkgName);
3680 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3681 break;
3682 }
3683 }
3684
3685 return result;
Junda Liu29340342014-07-10 15:23:27 -07003686 }
Derek Tan89e89d42014-07-08 17:00:10 -07003687
3688 @Override
Junda Liue64de782015-04-16 17:19:16 -07003689 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3690 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3691 loge("phoneId " + phoneId + " is not valid.");
3692 return null;
3693 }
3694 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003695 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003696 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003697 return null ;
3698 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003699 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003700 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003701 }
3702
Amith Yamasani6e118872016-02-19 12:53:51 -08003703 @Override
3704 public List<String> getPackagesWithCarrierPrivileges() {
3705 PackageManager pm = mPhone.getContext().getPackageManager();
3706 List<String> privilegedPackages = new ArrayList<>();
3707 List<PackageInfo> packages = null;
3708 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3709 UiccCard card = UiccController.getInstance().getUiccCard(i);
3710 if (card == null) {
3711 // No UICC in that slot.
3712 continue;
3713 }
3714 if (card.hasCarrierPrivilegeRules()) {
3715 if (packages == null) {
3716 // Only check packages in user 0 for now
3717 packages = pm.getInstalledPackagesAsUser(
3718 PackageManager.MATCH_DISABLED_COMPONENTS
3719 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3720 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3721 }
3722 for (int p = packages.size() - 1; p >= 0; p--) {
3723 PackageInfo pkgInfo = packages.get(p);
3724 if (pkgInfo != null && pkgInfo.packageName != null
3725 && card.getCarrierPrivilegeStatus(pkgInfo)
3726 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3727 privilegedPackages.add(pkgInfo.packageName);
3728 }
3729 }
3730 }
3731 }
3732 return privilegedPackages;
3733 }
3734
Wink Savilleb564aae2014-10-23 10:18:09 -07003735 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003736 final Phone phone = getPhone(subId);
3737 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003738 if (card == null) {
3739 loge("getIccId: No UICC");
3740 return null;
3741 }
3742 String iccId = card.getIccId();
3743 if (TextUtils.isEmpty(iccId)) {
3744 loge("getIccId: ICC ID is null or empty.");
3745 return null;
3746 }
3747 return iccId;
3748 }
3749
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003750 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003751 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3752 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003753 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3754 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756 final long identity = Binder.clearCallingIdentity();
3757 try {
3758 final String iccId = getIccId(subId);
3759 final Phone phone = getPhone(subId);
3760 if (phone == null) {
3761 return false;
3762 }
3763 final String subscriberId = phone.getSubscriberId();
3764
3765 if (DBG_MERGE) {
3766 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3767 + subscriberId + " to " + number);
3768 }
3769
3770 if (TextUtils.isEmpty(iccId)) {
3771 return false;
3772 }
3773
3774 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3775
3776 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3777 if (alphaTag == null) {
3778 editor.remove(alphaTagPrefKey);
3779 } else {
3780 editor.putString(alphaTagPrefKey, alphaTag);
3781 }
3782
3783 // Record both the line number and IMSI for this ICCID, since we need to
3784 // track all merged IMSIs based on line number
3785 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3786 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3787 if (number == null) {
3788 editor.remove(numberPrefKey);
3789 editor.remove(subscriberPrefKey);
3790 } else {
3791 editor.putString(numberPrefKey, number);
3792 editor.putString(subscriberPrefKey, subscriberId);
3793 }
3794
3795 editor.commit();
3796 return true;
3797 } finally {
3798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003799 }
Derek Tan7226c842014-07-02 17:42:23 -07003800 }
3801
3802 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003803 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003804 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003806 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003807 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003808 return null;
3809 }
Derek Tan97ebb422014-09-05 16:55:38 -07003810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 String iccId = getIccId(subId);
3814 if (iccId != null) {
3815 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3816 if (DBG_MERGE) {
3817 log("getLine1NumberForDisplay returning "
3818 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3819 }
3820 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003822 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3823 return null;
3824 } finally {
3825 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003826 }
Derek Tan7226c842014-07-02 17:42:23 -07003827 }
3828
3829 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003830 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003832 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003833 return null;
3834 }
Derek Tan97ebb422014-09-05 16:55:38 -07003835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 String iccId = getIccId(subId);
3839 if (iccId != null) {
3840 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3841 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3842 }
3843 return null;
3844 } finally {
3845 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003846 }
Derek Tan7226c842014-07-02 17:42:23 -07003847 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003848
3849 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003850 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003851 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3852 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003853 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003854 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3855 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003856 return null;
3857 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003858
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003859 final long identity = Binder.clearCallingIdentity();
3860 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 final Context context = mPhone.getContext();
3862 final TelephonyManager tele = TelephonyManager.from(context);
3863 final SubscriptionManager sub = SubscriptionManager.from(context);
3864
3865 // Figure out what subscribers are currently active
3866 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3867 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3868 // the process, where TelephonyManager was instantiated.
3869 // Otherwise AppOps check will fail.
3870
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003871 final int[] subIds = sub.getActiveSubscriptionIdList();
3872 for (int subId : subIds) {
3873 activeSubscriberIds.add(tele.getSubscriberId(subId));
3874 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875
3876 // First pass, find a number override for an active subscriber
3877 String mergeNumber = null;
3878 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3879 for (String key : prefs.keySet()) {
3880 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3881 final String subscriberId = (String) prefs.get(key);
3882 if (activeSubscriberIds.contains(subscriberId)) {
3883 final String iccId = key.substring(
3884 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3885 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3886 mergeNumber = (String) prefs.get(numberKey);
3887 if (DBG_MERGE) {
3888 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3889 + " for active subscriber " + subscriberId);
3890 }
3891 if (!TextUtils.isEmpty(mergeNumber)) {
3892 break;
3893 }
3894 }
3895 }
3896 }
3897
3898 // Shortcut when no active merged subscribers
3899 if (TextUtils.isEmpty(mergeNumber)) {
3900 return null;
3901 }
3902
3903 // Second pass, find all subscribers under that line override
3904 final ArraySet<String> result = new ArraySet<>();
3905 for (String key : prefs.keySet()) {
3906 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3907 final String number = (String) prefs.get(key);
3908 if (mergeNumber.equals(number)) {
3909 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3910 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3911 final String subscriberId = (String) prefs.get(subscriberKey);
3912 if (!TextUtils.isEmpty(subscriberId)) {
3913 result.add(subscriberId);
3914 }
3915 }
3916 }
3917 }
3918
3919 final String[] resultArray = result.toArray(new String[result.size()]);
3920 Arrays.sort(resultArray);
3921 if (DBG_MERGE) {
3922 Slog.d(LOG_TAG,
3923 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3924 }
3925 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003926 } finally {
3927 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003928 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003929 }
3930
3931 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003932 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003933 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3934 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935
3936 final long identity = Binder.clearCallingIdentity();
3937 try {
3938 final Phone phone = getPhone(subId);
3939 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
3942 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003943 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003944
3945 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003946 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003947 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3948 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003949 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950
3951 final long identity = Binder.clearCallingIdentity();
3952 try {
3953 final Phone phone = getPhone(subId);
3954 if (phone == null) {
3955 return false;
3956 }
3957 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3958 cdmaNonRoamingList);
3959 } finally {
3960 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003961 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003962 }
3963
3964 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003965 @Deprecated
3966 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3967 enforceModifyPermission();
3968
3969 int returnValue = 0;
3970 try {
3971 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3972 if(result.exception == null) {
3973 if (result.result != null) {
3974 byte[] responseData = (byte[])(result.result);
3975 if(responseData.length > oemResp.length) {
3976 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3977 responseData.length + "bytes. Buffer Size is " +
3978 oemResp.length + "bytes.");
3979 }
3980 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3981 returnValue = responseData.length;
3982 }
3983 } else {
3984 CommandException ex = (CommandException) result.exception;
3985 returnValue = ex.getCommandError().ordinal();
3986 if(returnValue > 0) returnValue *= -1;
3987 }
3988 } catch (RuntimeException e) {
3989 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3990 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3991 if(returnValue > 0) returnValue *= -1;
3992 }
3993
3994 return returnValue;
3995 }
3996
3997 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003998 public void setRadioCapability(RadioAccessFamily[] rafs) {
3999 try {
4000 ProxyController.getInstance().setRadioCapability(rafs);
4001 } catch (RuntimeException e) {
4002 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4003 }
4004 }
4005
4006 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004007 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004008 Phone phone = PhoneFactory.getPhone(phoneId);
4009 if (phone == null) {
4010 return RadioAccessFamily.RAF_UNKNOWN;
4011 }
4012 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004014 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004015 return RadioAccessFamily.RAF_UNKNOWN;
4016 }
4017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018 final long identity = Binder.clearCallingIdentity();
4019 try {
4020 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4021 } finally {
4022 Binder.restoreCallingIdentity(identity);
4023 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004024 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004025
4026 @Override
4027 public void enableVideoCalling(boolean enable) {
4028 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029
4030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4033 } finally {
4034 Binder.restoreCallingIdentity(identity);
4035 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004036 }
4037
4038 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004039 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4041 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4042 return false;
4043 }
Svet Ganovb320e182015-04-16 12:30:10 -07004044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 // Check the user preference and the system-level IMS setting. Even if the user has
4048 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4049 // In the long run, we may instead need to check if there exists a connection service
4050 // which can support video calling.
4051 ImsManager imsManager =
4052 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4053 return imsManager.isVtEnabledByPlatform()
4054 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4055 && imsManager.isVtEnabledByUser();
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004059 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004060
Andrew Leea1239f22015-03-02 17:44:07 -08004061 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4064 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4065 return false;
4066 }
4067
4068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 CarrierConfigManager configManager =
4071 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4072 return configManager.getConfigForSubId(mPhone.getSubId())
4073 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Andrew Leea1239f22015-03-02 17:44:07 -08004077 }
4078
4079 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080 public boolean isWorldPhone(int subId, String callingPackage) {
4081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4082 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4083 return false;
4084 }
4085
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 CarrierConfigManager configManager =
4089 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4090 return configManager.getConfigForSubId(mPhone.getSubId())
4091 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4092 } finally {
4093 Binder.restoreCallingIdentity(identity);
4094 }
Andrew Leea1239f22015-03-02 17:44:07 -08004095 }
4096
Andrew Lee9431b832015-03-09 18:46:45 -07004097 @Override
4098 public boolean isTtyModeSupported() {
4099 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004100 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004101 }
4102
4103 @Override
4104 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
Andrew Lee9431b832015-03-09 18:46:45 -07004111 }
4112
Hall Liu98187582018-01-22 19:15:32 -08004113 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4117 mPhone.getSubId()).getBoolean(
4118 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4119 boolean isDeviceSupported =
4120 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4121 return isCarrierSupported && isDeviceSupported;
4122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
Hall Liu98187582018-01-22 19:15:32 -08004125 }
4126
Hall Liu3ad5f012018-04-06 16:23:39 -07004127 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 return isRttSupported() && Settings.Secure.getInt(
4131 mPhone.getContext().getContentResolver(),
4132 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4133 } finally {
4134 Binder.restoreCallingIdentity(identity);
4135 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004136 }
4137
Sanket Padawe7310cc72015-01-14 09:53:20 -08004138 /**
4139 * Returns the unique device ID of phone, for example, the IMEI for
4140 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4141 *
4142 * <p>Requires Permission:
4143 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4144 */
4145 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004146 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004147 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004148 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004149 return null;
4150 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004151 int subId = phone.getSubId();
4152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4153 mApp, subId, callingPackage, "getDeviceId")) {
4154 return null;
4155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156
4157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 return phone.getDeviceId();
4160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004163 }
4164
Ping Sunc67b7c22016-03-02 19:16:45 +08004165 /**
4166 * {@hide}
4167 * Returns the IMS Registration Status on a particular subid
4168 *
4169 * @param subId
4170 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004171 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004172 Phone phone = getPhone(subId);
4173 if (phone != null) {
4174 return phone.isImsRegistered();
4175 } else {
4176 return false;
4177 }
4178 }
4179
Santos Cordon7a1885b2015-02-03 11:15:19 -08004180 @Override
4181 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004182 final long identity = Binder.clearCallingIdentity();
4183 try {
4184 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004188 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004189
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004190 /**
4191 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004192 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004193 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 Phone phone = getPhone(subId);
4197 if (phone != null) {
4198 return phone.isWifiCallingEnabled();
4199 } else {
4200 return false;
4201 }
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004204 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004205 }
4206
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004207 /**
4208 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004209 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004210 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 final long identity = Binder.clearCallingIdentity();
4212 try {
4213 Phone phone = getPhone(subId);
4214 if (phone != null) {
4215 return phone.isVolteEnabled();
4216 } else {
4217 return false;
4218 }
4219 } finally {
4220 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004221 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004222 }
Svet Ganovb320e182015-04-16 12:30:10 -07004223
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004224 /**
4225 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004226 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004227 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228 final long identity = Binder.clearCallingIdentity();
4229 try {
4230 Phone phone = getPhone(subId);
4231 if (phone != null) {
4232 return phone.isVideoEnabled();
4233 } else {
4234 return false;
4235 }
4236 } finally {
4237 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004238 }
4239 }
4240
4241 /**
4242 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4243 * defined in {@link ImsRegistrationImplBase}.
4244 */
4245 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246 final long identity = Binder.clearCallingIdentity();
4247 try {
4248 Phone phone = getPhone(subId);
4249 if (phone != null) {
4250 return phone.getImsRegistrationTech();
4251 } else {
4252 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4253 }
4254 } finally {
4255 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004256 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004257 }
4258
Stuart Scott8eef64f2015-04-08 15:13:54 -07004259 @Override
4260 public void factoryReset(int subId) {
4261 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004262 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4263 return;
4264 }
4265
Svet Ganovcc087f82015-05-12 20:35:54 -07004266 final long identity = Binder.clearCallingIdentity();
4267 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004268 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4269 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004270 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004271 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004272 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4273 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004274 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004275 }
4276 } finally {
4277 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004278 }
4279 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004280
4281 @Override
4282 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 final long identity = Binder.clearCallingIdentity();
4284 try {
4285 // We query all subscriptions instead of just the active ones, because
4286 // this might be called early on in the provisioning flow when the
4287 // subscriptions potentially aren't active yet.
4288 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4289 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004290 return null;
4291 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 // This function may be called very early, say, from the setup wizard, at
4294 // which point we won't have a default subscription set. If that's the case
4295 // we just choose the first, which will be valid in "most cases".
4296 final int defaultSubId = getDefaultSubscription();
4297 SubscriptionInfo info = null;
4298 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4299 info = slist.get(0);
4300 } else {
4301 for (SubscriptionInfo item : slist) {
4302 if (item.getSubscriptionId() == defaultSubId) {
4303 info = item;
4304 break;
4305 }
4306 }
4307
4308 if (info == null) {
4309 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004310 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004311 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004313 // Try and fetch the locale from the carrier properties or from the SIM language
4314 // preferences (EF-PL and EF-LI)...
4315 final int mcc = info.getMcc();
4316 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4317 String simLanguage = null;
4318 if (defaultPhone != null) {
4319 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4320 if (localeFromDefaultSim != null) {
4321 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4322 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4323 return localeFromDefaultSim.toLanguageTag();
4324 } else {
4325 simLanguage = localeFromDefaultSim.getLanguage();
4326 }
4327 }
4328 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 // The SIM language preferences only store a language (e.g. fr = French), not an
4331 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4332 // the SIM and carrier preferences does not include a country we add the country
4333 // determined from the SIM MCC to provide an exact locale.
4334 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4335 simLanguage);
4336 if (mccLocale != null) {
4337 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4338 return mccLocale.toLanguageTag();
4339 }
4340
4341 if (DBG) log("No locale found - returning null");
4342 return null;
4343 } finally {
4344 Binder.restoreCallingIdentity(identity);
4345 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004346 }
4347
4348 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349 return mSubscriptionController.getAllSubInfoList(
4350 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004351 }
4352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 /**
4354 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4355 */
4356 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4357 return mSubscriptionController.getActiveSubscriptionInfoList(
4358 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004359 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004360
Chenjie Yu1ba97252018-01-11 18:16:20 -08004361 private final ModemActivityInfo mLastModemActivityInfo =
4362 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4363
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004364 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004365 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4366 * representing the state of the modem.
4367 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004368 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4369 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004370 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004371 */
4372 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004373 public void requestModemActivityInfo(ResultReceiver result) {
4374 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375
4376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 ModemActivityInfo ret = null;
4379 synchronized (mLastModemActivityInfo) {
4380 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4381 CMD_GET_MODEM_ACTIVITY_INFO,
4382 null);
Siddharth Rayb8114062018-06-17 15:02:38 -07004383 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4385 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4386 mergedTxTimeMs[i] =
4387 info.getTxTimeMillis()[i]
4388 + mLastModemActivityInfo.getTxTimeMillis()[i];
4389 }
4390 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4391 mLastModemActivityInfo.setSleepTimeMillis(
4392 info.getSleepTimeMillis()
4393 + mLastModemActivityInfo.getSleepTimeMillis());
4394 mLastModemActivityInfo.setIdleTimeMillis(
4395 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4396 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4397 mLastModemActivityInfo.setRxTimeMillis(
4398 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4399 mLastModemActivityInfo.setEnergyUsed(
4400 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4403 mLastModemActivityInfo.getSleepTimeMillis(),
4404 mLastModemActivityInfo.getIdleTimeMillis(),
4405 mLastModemActivityInfo.getTxTimeMillis(),
4406 mLastModemActivityInfo.getRxTimeMillis(),
4407 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 Bundle bundle = new Bundle();
4410 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4411 result.send(0, bundle);
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004414 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004415 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004416
Siddharth Rayb8114062018-06-17 15:02:38 -07004417 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4418 // less than total activity duration.
4419 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4420 if (info == null) {
4421 return false;
4422 }
4423 int activityDurationMs =
4424 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4425 int totalTxTimeMs = 0;
4426 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4427 totalTxTimeMs += info.getTxTimeMillis()[i];
4428 }
4429 return (info.isValid()
4430 && (info.getSleepTimeMillis() <= activityDurationMs)
4431 && (info.getIdleTimeMillis() <= activityDurationMs)
4432 && (info.getRxTimeMillis() <= activityDurationMs)
4433 && (totalTxTimeMs <= activityDurationMs));
4434 }
4435
Jack Yu85bd38a2015-11-09 11:34:32 -08004436 /**
4437 * {@hide}
4438 * Returns the service state information on specified subscription.
4439 */
4440 @Override
4441 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004443 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004444 return null;
4445 }
4446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 final long identity = Binder.clearCallingIdentity();
4448 try {
4449 final Phone phone = getPhone(subId);
4450 if (phone == null) {
4451 return null;
4452 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004453
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004454 return phone.getServiceState();
4455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004458 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004459
4460 /**
4461 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4462 *
4463 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4464 * voicemail ringtone.
4465 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4466 * PhoneAccount.
4467 */
4468 @Override
4469 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4473 if (phone == null) {
4474 phone = mPhone;
4475 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4478 } finally {
4479 Binder.restoreCallingIdentity(identity);
4480 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004481 }
4482
4483 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004484 * Sets the per-account voicemail ringtone.
4485 *
4486 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4487 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4488 *
4489 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4490 * voicemail ringtone.
4491 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4492 * PhoneAccount.
4493 */
4494 @Override
4495 public void setVoicemailRingtoneUri(String callingPackage,
4496 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4497 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4498 if (!TextUtils.equals(callingPackage,
4499 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4501 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4502 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004504
4505 final long identity = Binder.clearCallingIdentity();
4506 try {
4507 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4508 if (phone == null) {
4509 phone = mPhone;
4510 }
4511 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4512 } finally {
4513 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004514 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004515 }
4516
4517 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004518 * Returns whether vibration is set for voicemail notification in Phone settings.
4519 *
4520 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4521 * voicemail vibration setting.
4522 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4523 */
4524 @Override
4525 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 final long identity = Binder.clearCallingIdentity();
4527 try {
4528 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4529 if (phone == null) {
4530 phone = mPhone;
4531 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4534 } finally {
4535 Binder.restoreCallingIdentity(identity);
4536 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004537 }
4538
Youhan Wange64578a2016-05-02 15:32:42 -07004539 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004540 * Sets the per-account voicemail vibration.
4541 *
4542 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4543 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4544 *
4545 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4546 * voicemail vibration setting.
4547 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4548 * specific PhoneAccount.
4549 */
4550 @Override
4551 public void setVoicemailVibrationEnabled(String callingPackage,
4552 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4553 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4554 if (!TextUtils.equals(callingPackage,
4555 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4557 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4558 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004559 }
4560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 final long identity = Binder.clearCallingIdentity();
4562 try {
4563 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4564 if (phone == null) {
4565 phone = mPhone;
4566 }
4567 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4568 } finally {
4569 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004570 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004571 }
4572
4573 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004574 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4575 *
4576 * @throws SecurityException if the caller does not have the required permission
4577 */
4578 private void enforceReadPrivilegedPermission() {
4579 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4580 null);
4581 }
4582
4583 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004584 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4585 * permission.
4586 *
4587 * @throws SecurityException if the caller does not have the required permission
4588 */
4589 private void enforceSendSmsPermission() {
4590 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4591 }
4592
4593 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004594 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004595 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004596 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004597 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004598 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599 final long identity = Binder.clearCallingIdentity();
4600 try {
4601 ComponentName componentName =
4602 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4603 if (componentName == null) {
4604 throw new SecurityException(
4605 "Caller not current active visual voicemail package[null]");
4606 }
4607 String vvmPackage = componentName.getPackageName();
4608 if (!callingPackage.equals(vvmPackage)) {
4609 throw new SecurityException("Caller not current active visual voicemail package["
4610 + vvmPackage + "]");
4611 }
4612 } finally {
4613 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004614 }
4615 }
4616
4617 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004618 * Return the application ID for the app type.
4619 *
4620 * @param subId the subscription ID that this request applies to.
4621 * @param appType the uicc app type.
4622 * @return Application ID for specificied app type, or null if no uicc.
4623 */
4624 @Override
4625 public String getAidForAppType(int subId, int appType) {
4626 enforceReadPrivilegedPermission();
4627 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628
4629 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004630 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 if (phone == null) {
4632 return null;
4633 }
4634 String aid = null;
4635 try {
4636 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4637 .getApplicationByType(appType).getAid();
4638 } catch (Exception e) {
4639 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4640 }
4641 return aid;
4642 } finally {
4643 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004644 }
Youhan Wange64578a2016-05-02 15:32:42 -07004645 }
4646
Youhan Wang4001d252016-05-11 10:29:41 -07004647 /**
4648 * Return the Electronic Serial Number.
4649 *
4650 * @param subId the subscription ID that this request applies to.
4651 * @return ESN or null if error.
4652 */
4653 @Override
4654 public String getEsn(int subId) {
4655 enforceReadPrivilegedPermission();
4656 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657
4658 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004659 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 if (phone == null) {
4661 return null;
4662 }
4663 String esn = null;
4664 try {
4665 esn = phone.getEsn();
4666 } catch (Exception e) {
4667 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4668 }
4669 return esn;
4670 } finally {
4671 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004672 }
Youhan Wang4001d252016-05-11 10:29:41 -07004673 }
4674
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004675 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004676 * Return the Preferred Roaming List Version.
4677 *
4678 * @param subId the subscription ID that this request applies to.
4679 * @return PRLVersion or null if error.
4680 */
4681 @Override
4682 public String getCdmaPrlVersion(int subId) {
4683 enforceReadPrivilegedPermission();
4684 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004687 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 if (phone == null) {
4689 return null;
4690 }
4691 String cdmaPrlVersion = null;
4692 try {
4693 cdmaPrlVersion = phone.getCdmaPrlVersion();
4694 } catch (Exception e) {
4695 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4696 }
4697 return cdmaPrlVersion;
4698 } finally {
4699 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004700 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004701 }
4702
4703 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004704 * Get snapshot of Telephony histograms
4705 * @return List of Telephony histograms
4706 * @hide
4707 */
4708 @Override
4709 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4711 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004712
4713 final long identity = Binder.clearCallingIdentity();
4714 try {
4715 return RIL.getTelephonyRILTimingHistograms();
4716 } finally {
4717 Binder.restoreCallingIdentity(identity);
4718 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004719 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004720
4721 /**
4722 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004723 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004724 * Require system privileges. In the future we may add this to carrier APIs.
4725 *
4726 * @return The number of carriers set successfully, should match length of carriers
4727 */
4728 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004729 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004730 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004731
Meng Wang9b7c4e92017-02-17 11:41:27 -08004732 if (carriers == null) {
4733 throw new NullPointerException("carriers cannot be null");
4734 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736 final long identity = Binder.clearCallingIdentity();
4737 try {
4738 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4739 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4740 return retVal[0];
4741 } finally {
4742 Binder.restoreCallingIdentity(identity);
4743 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004744 }
4745
4746 /**
4747 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004748 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004749 * Require system privileges. In the future we may add this to carrier APIs.
4750 *
4751 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4752 * means all carriers are allowed.
4753 */
4754 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004755 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004756 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757
4758 final long identity = Binder.clearCallingIdentity();
4759 try {
4760 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4761 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
4764 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004765 }
4766
fionaxu59545b42016-05-25 15:53:37 -07004767 /**
4768 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4769 * @param subId the subscription ID that this action applies to.
4770 * @param enabled control enable or disable metered apns.
4771 * {@hide}
4772 */
4773 @Override
4774 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4775 enforceModifyPermission();
4776 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777
4778 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004779 if (phone == null) {
4780 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4781 return;
4782 }
4783 try {
4784 phone.carrierActionSetMeteredApnsEnabled(enabled);
4785 } catch (Exception e) {
4786 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004787 } finally {
4788 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004789 }
4790 }
4791
4792 /**
4793 * Action set from carrier signalling broadcast receivers to enable/disable radio
4794 * @param subId the subscription ID that this action applies to.
4795 * @param enabled control enable or disable radio.
4796 * {@hide}
4797 */
4798 @Override
4799 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4800 enforceModifyPermission();
4801 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802
4803 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004804 if (phone == null) {
4805 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4806 return;
4807 }
4808 try {
4809 phone.carrierActionSetRadioEnabled(enabled);
4810 } catch (Exception e) {
4811 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812 } finally {
4813 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004814 }
4815 }
4816
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004817 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004818 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4819 * network status based on which carrier apps could apply actions accordingly,
4820 * enable/disable default url handler for example.
4821 *
4822 * @param subId the subscription ID that this action applies to.
4823 * @param report control start/stop reporting the default network status.
4824 * {@hide}
4825 */
4826 @Override
4827 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4828 enforceModifyPermission();
4829 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830
4831 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004832 if (phone == null) {
4833 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4834 return;
4835 }
4836 try {
4837 phone.carrierActionReportDefaultNetworkStatus(report);
4838 } catch (Exception e) {
4839 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004840 } finally {
4841 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004842 }
4843 }
4844
4845 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004846 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4847 * bug report is being generated.
4848 */
4849 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004850 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004851 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4852 != PackageManager.PERMISSION_GRANTED) {
4853 writer.println("Permission Denial: can't dump Phone from pid="
4854 + Binder.getCallingPid()
4855 + ", uid=" + Binder.getCallingUid()
4856 + "without permission "
4857 + android.Manifest.permission.DUMP);
4858 return;
4859 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004860 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004861 }
Jack Yueb89b242016-06-22 13:27:47 -07004862
Brad Ebingerdac2f002018-04-03 15:17:52 -07004863 @Override
4864 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4865 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4866 throws RemoteException {
4867 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4868 }
4869
Jack Yueb89b242016-06-22 13:27:47 -07004870 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004871 * Get aggregated video call data usage since boot.
4872 *
4873 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4874 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004875 * {@hide}
4876 */
4877 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004878 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004879 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4880 null);
4881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004882 final long identity = Binder.clearCallingIdentity();
4883 try {
4884 // NetworkStatsService keeps tracking the active network interface and identity. It
4885 // records the delta with the corresponding network identity.
4886 // We just return the total video call data usage snapshot since boot.
4887 Phone phone = getPhone(subId);
4888 if (phone != null) {
4889 return phone.getVtDataUsage(perUidStats);
4890 }
4891 return null;
4892 } finally {
4893 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004894 }
Jack Yueb89b242016-06-22 13:27:47 -07004895 }
Jack Yu75ab2952016-07-08 14:29:33 -07004896
4897 /**
4898 * Policy control of data connection. Usually used when data limit is passed.
4899 * @param enabled True if enabling the data, otherwise disabling.
4900 * @param subId Subscription index
4901 * {@hide}
4902 */
4903 @Override
4904 public void setPolicyDataEnabled(boolean enabled, int subId) {
4905 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906
4907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 Phone phone = getPhone(subId);
4910 if (phone != null) {
4911 phone.setPolicyDataEnabled(enabled);
4912 }
4913 } finally {
4914 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004915 }
4916 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004917
4918 /**
4919 * Get Client request stats
4920 * @return List of Client Request Stats
4921 * @hide
4922 */
4923 @Override
4924 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004926 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004927 return null;
4928 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004929 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 if (phone != null) {
4934 return phone.getClientRequestStats();
4935 }
4936
4937 return null;
4938 } finally {
4939 Binder.restoreCallingIdentity(identity);
4940 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004941 }
4942
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004943 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004944 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004945 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004946 }
Jack Yueb4124c2017-02-16 15:32:43 -08004947
4948 /**
Grace Chen70990072017-03-24 17:21:30 -07004949 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004950 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004951 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004952 * @param state State of SIM (power down, power up, pass through)
4953 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4954 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4955 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004956 *
4957 **/
4958 @Override
Grace Chen70990072017-03-24 17:21:30 -07004959 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004960 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004961 Phone phone = PhoneFactory.getPhone(slotIndex);
4962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 final long identity = Binder.clearCallingIdentity();
4964 try {
4965 if (phone != null) {
4966 phone.setSimPowerState(state);
4967 }
4968 } finally {
4969 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004970 }
4971 }
Shuo Qiandd210312017-04-12 22:11:33 +00004972
Tyler Gunn65d45c22017-06-05 11:22:26 -07004973 private boolean isUssdApiAllowed(int subId) {
4974 CarrierConfigManager configManager =
4975 (CarrierConfigManager) mPhone.getContext().getSystemService(
4976 Context.CARRIER_CONFIG_SERVICE);
4977 if (configManager == null) {
4978 return false;
4979 }
4980 PersistableBundle pb = configManager.getConfigForSubId(subId);
4981 if (pb == null) {
4982 return false;
4983 }
4984 return pb.getBoolean(
4985 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4986 }
4987
Shuo Qiandd210312017-04-12 22:11:33 +00004988 /**
4989 * Check if phone is in emergency callback mode
4990 * @return true if phone is in emergency callback mode
4991 * @param subId sub id
4992 */
goneil9c5f4872017-12-05 14:07:56 -08004993 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004994 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004995 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004996 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004997
4998 final long identity = Binder.clearCallingIdentity();
4999 try {
5000 if (phone != null) {
5001 return phone.isInEcm();
5002 } else {
5003 return false;
5004 }
5005 } finally {
5006 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005007 }
5008 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005009
5010 /**
5011 * Get the current signal strength information for the given subscription.
5012 * Because this information is not updated when the device is in a low power state
5013 * it should not be relied-upon to be current.
5014 * @param subId Subscription index
5015 * @return the most recent cached signal strength info from the modem
5016 */
5017 @Override
5018 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005019 final long identity = Binder.clearCallingIdentity();
5020 try {
5021 Phone p = getPhone(subId);
5022 if (p == null) {
5023 return null;
5024 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 return p.getSignalStrength();
5027 } finally {
5028 Binder.restoreCallingIdentity(identity);
5029 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005030 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005031
5032 @Override
5033 public UiccSlotInfo[] getUiccSlotsInfo() {
5034 enforceReadPrivilegedPermission();
5035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 final long identity = Binder.clearCallingIdentity();
5037 try {
5038 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5039 if (slots == null) {
5040 Rlog.i(LOG_TAG, "slots is null.");
5041 return null;
5042 }
5043
5044 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5045 for (int i = 0; i < slots.length; i++) {
5046 UiccSlot slot = slots[i];
5047 if (slot == null) {
5048 continue;
5049 }
5050
5051 String cardId;
5052 UiccCard card = slot.getUiccCard();
5053 if (card != null) {
5054 cardId = card.getCardId();
5055 } else {
5056 cardId = slot.getIccId();
5057 }
5058
5059 int cardState = 0;
5060 switch (slot.getCardState()) {
5061 case CARDSTATE_ABSENT:
5062 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5063 break;
5064 case CARDSTATE_PRESENT:
5065 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5066 break;
5067 case CARDSTATE_ERROR:
5068 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5069 break;
5070 case CARDSTATE_RESTRICTED:
5071 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5072 break;
5073 default:
5074 break;
5075
5076 }
5077
5078 infos[i] = new UiccSlotInfo(
5079 slot.isActive(),
5080 slot.isEuicc(),
5081 cardId,
5082 cardState,
5083 slot.getPhoneId(),
5084 slot.isExtendedApduSupported());
5085 }
5086 return infos;
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005089 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005090 }
5091
5092 @Override
5093 public boolean switchSlots(int[] physicalSlots) {
5094 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095
5096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5099 } finally {
5100 Binder.restoreCallingIdentity(identity);
5101 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005102 }
Jack Yu4c988042018-02-27 15:30:01 -08005103
5104 @Override
5105 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5106 enforceModifyPermission();
5107 final Phone phone = getPhone(subId);
5108 if (phone == null) {
5109 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5110 return;
5111 }
5112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 phone.setRadioIndicationUpdateMode(filters, mode);
5116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
Jack Yu4c988042018-02-27 15:30:01 -08005119 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005120
5121 /**
goneil47ffb6e2018-04-06 15:40:58 -07005122 * A test API to reload the UICC profile.
5123 *
5124 * <p>Requires that the calling app has permission
5125 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5126 * @hide
5127 */
5128 @Override
5129 public void refreshUiccProfile(int subId) {
5130 enforceModifyPermission();
5131
5132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 Phone phone = getPhone(subId);
5135 if (phone == null) {
5136 return;
5137 }
5138 UiccCard uiccCard = phone.getUiccCard();
5139 if (uiccCard == null) {
5140 return;
5141 }
5142 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5143 if (uiccProfile == null) {
5144 return;
5145 }
5146 uiccProfile.refresh();
5147 } finally {
5148 Binder.restoreCallingIdentity(identity);
5149 }
5150 }
5151
5152 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005153 * Returns false if the mobile data is disabled by default, otherwise return true.
5154 */
5155 private boolean getDefaultDataEnabled() {
5156 return "true".equalsIgnoreCase(
5157 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5158 }
5159
5160 /**
5161 * Returns true if the data roaming is enabled by default, i.e the system property
5162 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5163 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5164 */
5165 private boolean getDefaultDataRoamingEnabled(int subId) {
5166 final CarrierConfigManager configMgr = (CarrierConfigManager)
5167 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5168 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5169 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5170 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5171 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5172 return isDataRoamingEnabled;
5173 }
5174
5175 /**
5176 * Returns the default network type for the given {@code subId}, if the default network type is
5177 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5178 */
5179 private int getDefaultNetworkType(int subId) {
5180 return Integer.parseInt(
5181 TelephonyManager.getTelephonyProperty(
5182 mSubscriptionController.getPhoneId(subId),
5183 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5184 String.valueOf(Phone.PREFERRED_NT_MODE)));
5185 }
fionaxua13278b2018-03-21 00:08:13 -07005186
5187 @Override
5188 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5189 gid1, String gid2, String plmn, String spn) {
5190 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191
5192 final long identity = Binder.clearCallingIdentity();
5193 try {
5194 final Phone phone = getPhone(subId);
5195 if (phone == null) {
5196 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5197 return;
5198 }
5199 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005202 }
fionaxua13278b2018-03-21 00:08:13 -07005203 }
5204
5205 @Override
5206 public int getCarrierIdListVersion(int subId) {
5207 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208
5209 final long identity = Binder.clearCallingIdentity();
5210 try {
5211 final Phone phone = getPhone(subId);
5212 if (phone == null) {
5213 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5214 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5215 }
5216 return phone.getCarrierIdListVersion();
5217 } finally {
5218 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005219 }
fionaxua13278b2018-03-21 00:08:13 -07005220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005221}