blob: ba51dd3b93d0d8a44d24b29de20b5c6c3e23237e [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;
Narayan Kamath1c496c22015-04-16 14:40:19 +010098import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070099import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700100import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800102import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700103import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700104import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700105import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700107import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800108import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800109import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700110import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700111import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700112import com.android.internal.telephony.uicc.IccIoResult;
113import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800114import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700115import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800116import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800118import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000119import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700120import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800121import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700122import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800123import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700124import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700125import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800126
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700127import java.io.FileDescriptor;
128import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800129import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800131import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800132import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100133import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800134import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135
136/**
137 * Implementation of the ITelephony interface.
138 */
Santos Cordon117fee72014-05-16 17:56:12 -0700139public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140 private static final String LOG_TAG = "PhoneInterfaceManager";
141 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
142 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800143 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144
145 // Message codes used with mMainThreadHandler
146 private static final int CMD_HANDLE_PIN_MMI = 1;
147 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
148 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
149 private static final int CMD_ANSWER_RINGING_CALL = 4;
150 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700151 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
152 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153 private static final int CMD_OPEN_CHANNEL = 9;
154 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
155 private static final int CMD_CLOSE_CHANNEL = 11;
156 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800157 private static final int CMD_NV_READ_ITEM = 13;
158 private static final int EVENT_NV_READ_ITEM_DONE = 14;
159 private static final int CMD_NV_WRITE_ITEM = 15;
160 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
161 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
162 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
163 private static final int CMD_NV_RESET_CONFIG = 19;
164 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800165 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
166 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
167 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
168 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800169 private static final int CMD_SEND_ENVELOPE = 25;
170 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700171 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
172 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
173 private static final int CMD_EXCHANGE_SIM_IO = 31;
174 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800175 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
176 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700177 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
178 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700179 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
180 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700181 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
182 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
183 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
184 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700185 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
186 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
187 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
188 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700189 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
191 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000192 private static final int CMD_SWITCH_SLOTS = 50;
193 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800195 // Parameters of select command.
196 private static final int SELECT_COMMAND = 0xA4;
197 private static final int SELECT_P1 = 0x04;
198 private static final int SELECT_P2 = 0;
199 private static final int SELECT_P3 = 0x10;
200
Pengquan Meng85728fb2018-03-12 16:31:21 -0700201 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
202 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
203 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
204
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205 /** The singleton instance. */
206 private static PhoneInterfaceManager sInstance;
207
Wink Saville3ab207e2014-11-20 13:07:20 -0800208 private PhoneGlobals mApp;
209 private Phone mPhone;
210 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700211 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800212 private AppOpsManager mAppOps;
213 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800214 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800215 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216
Derek Tan97ebb422014-09-05 16:55:38 -0700217 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
218 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800219 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700220
Derek Tan740e1672017-06-27 14:56:27 -0700221 // The AID of ISD-R.
222 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
223
yinxub1bed742017-04-17 11:45:04 -0700224 private NetworkScanRequestTracker mNetworkScanRequestTracker;
225
Derek Tan89e89d42014-07-08 17:00:10 -0700226 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700227 * A request object to use for transmitting data to an ICC.
228 */
229 private static final class IccAPDUArgument {
230 public int channel, cla, command, p1, p2, p3;
231 public String data;
232
233 public IccAPDUArgument(int channel, int cla, int command,
234 int p1, int p2, int p3, String data) {
235 this.channel = channel;
236 this.cla = cla;
237 this.command = command;
238 this.p1 = p1;
239 this.p2 = p2;
240 this.p3 = p3;
241 this.data = data;
242 }
243 }
244
245 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700246 * A request object to use for transmitting data to an ICC.
247 */
248 private static final class ManualNetworkSelectionArgument {
249 public OperatorInfo operatorInfo;
250 public boolean persistSelection;
251
252 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
253 this.operatorInfo = operatorInfo;
254 this.persistSelection = persistSelection;
255 }
256 }
257
258 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
260 * request after sending. The main thread will notify the request when it is complete.
261 */
262 private static final class MainThreadRequest {
263 /** The argument to use for the request */
264 public Object argument;
265 /** The result of the request that is run on the main thread */
266 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800267 // The subscriber id that this request applies to. Defaults to
268 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
269 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
271 public MainThreadRequest(Object argument) {
272 this.argument = argument;
273 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800274
275 public MainThreadRequest(Object argument, Integer subId) {
276 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800277 if (subId != null) {
278 this.subId = subId;
279 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281 }
282
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800283 private static final class IncomingThirdPartyCallArgs {
284 public final ComponentName component;
285 public final String callId;
286 public final String callerDisplayName;
287
288 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
289 String callerDisplayName) {
290 this.component = component;
291 this.callId = callId;
292 this.callerDisplayName = callerDisplayName;
293 }
294 }
295
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 /**
297 * A handler that processes messages on the main thread in the phone process. Since many
298 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
299 * inbound binder threads to the main thread in the phone process. The Binder thread
300 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
301 * on, which will be notified when the operation completes and will contain the result of the
302 * request.
303 *
304 * <p>If a MainThreadRequest object is provided in the msg.obj field,
305 * note that request.result must be set to something non-null for the calling thread to
306 * unblock.
307 */
308 private final class MainThreadHandler extends Handler {
309 @Override
310 public void handleMessage(Message msg) {
311 MainThreadRequest request;
312 Message onCompleted;
313 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800314 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700315 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316
317 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700318 case CMD_HANDLE_USSD_REQUEST: {
319 request = (MainThreadRequest) msg.obj;
320 final Phone phone = getPhoneFromRequest(request);
321 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
322 String ussdRequest = ussdObject.first;
323 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700324
325 if (!isUssdApiAllowed(request.subId)) {
326 // Carrier does not support use of this API, return failure.
327 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
328 UssdResponse response = new UssdResponse(ussdRequest, null);
329 Bundle returnData = new Bundle();
330 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
331 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
332
333 request.result = true;
334 synchronized (request) {
335 request.notifyAll();
336 }
337 return;
338 }
339
Tyler Gunn52dcf772017-04-26 11:30:31 -0700340 try {
341 request.result = phone != null ?
342 phone.handleUssdRequest(ussdRequest, wrappedCallback)
343 : false;
344 } catch (CallStateException cse) {
345 request.result = false;
346 }
pkanwar32d516d2016-10-14 19:37:38 -0700347 // Wake up the requesting thread
348 synchronized (request) {
349 request.notifyAll();
350 }
351 break;
352 }
353
Yorke Lee716f67e2015-06-17 15:39:16 -0700354 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700356 final Phone phone = getPhoneFromRequest(request);
357 request.result = phone != null ?
358 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
359 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 // Wake up the requesting thread
361 synchronized (request) {
362 request.notifyAll();
363 }
364 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
367 case CMD_HANDLE_NEIGHBORING_CELL:
368 request = (MainThreadRequest) msg.obj;
369 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
370 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700371 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 break;
373
374 case EVENT_NEIGHBORING_CELL_DONE:
375 ar = (AsyncResult) msg.obj;
376 request = (MainThreadRequest) ar.userObj;
377 if (ar.exception == null && ar.result != null) {
378 request.result = ar.result;
379 } else {
380 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800381 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 }
383 // Wake up the requesting thread
384 synchronized (request) {
385 request.notifyAll();
386 }
387 break;
388
389 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700390 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800391 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700392 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 break;
394
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 case CMD_END_CALL:
396 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800397 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700398 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700399 Phone phone = getPhone(end_subId);
400 if (phone == null) {
401 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
402 break;
403 }
404 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
406 // CDMA: If the user presses the Power button we treat it as
407 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700408 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
410 // GSM: End the call as per the Phone state
411 hungUp = PhoneUtils.hangup(mCM);
412 } else {
413 throw new IllegalStateException("Unexpected phone type: " + phoneType);
414 }
415 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
416 request.result = hungUp;
417 // Wake up the requesting thread
418 synchronized (request) {
419 request.notifyAll();
420 }
421 break;
422
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800426 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 if (uiccCard == null) {
428 loge("iccTransmitApduLogicalChannel: No UICC");
429 request.result = new IccIoResult(0x6F, 0, (byte[])null);
430 synchronized (request) {
431 request.notifyAll();
432 }
433 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
435 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700436 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 iccArgument.channel, iccArgument.cla, iccArgument.command,
438 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700440 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700441 break;
442
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 ar = (AsyncResult) msg.obj;
445 request = (MainThreadRequest) ar.userObj;
446 if (ar.exception == null && ar.result != null) {
447 request.result = ar.result;
448 } else {
449 request.result = new IccIoResult(0x6F, 0, (byte[])null);
450 if (ar.result == null) {
451 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800452 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800454 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 } else {
456 loge("iccTransmitApduLogicalChannel: Unknown exception");
457 }
458 }
459 synchronized (request) {
460 request.notifyAll();
461 }
462 break;
463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
465 request = (MainThreadRequest) msg.obj;
466 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800467 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 if (uiccCard == null) {
469 loge("iccTransmitApduBasicChannel: No UICC");
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 synchronized (request) {
472 request.notifyAll();
473 }
474 } else {
475 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
476 request);
477 uiccCard.iccTransmitApduBasicChannel(
478 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
479 iccArgument.p3, iccArgument.data, onCompleted);
480 }
481 break;
482
483 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
484 ar = (AsyncResult) msg.obj;
485 request = (MainThreadRequest) ar.userObj;
486 if (ar.exception == null && ar.result != null) {
487 request.result = ar.result;
488 } else {
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
490 if (ar.result == null) {
491 loge("iccTransmitApduBasicChannel: Empty response");
492 } else if (ar.exception instanceof CommandException) {
493 loge("iccTransmitApduBasicChannel: CommandException: " +
494 ar.exception);
495 } else {
496 loge("iccTransmitApduBasicChannel: Unknown exception");
497 }
498 }
499 synchronized (request) {
500 request.notifyAll();
501 }
502 break;
503
504 case CMD_EXCHANGE_SIM_IO:
505 request = (MainThreadRequest) msg.obj;
506 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800507 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 if (uiccCard == null) {
509 loge("iccExchangeSimIO: No UICC");
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
511 synchronized (request) {
512 request.notifyAll();
513 }
514 } else {
515 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
516 request);
517 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
518 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
519 iccArgument.data, onCompleted);
520 }
521 break;
522
523 case EVENT_EXCHANGE_SIM_IO_DONE:
524 ar = (AsyncResult) msg.obj;
525 request = (MainThreadRequest) ar.userObj;
526 if (ar.exception == null && ar.result != null) {
527 request.result = ar.result;
528 } else {
529 request.result = new IccIoResult(0x6f, 0, (byte[])null);
530 }
531 synchronized (request) {
532 request.notifyAll();
533 }
534 break;
535
Derek Tan4d5e5c12014-02-04 11:54:58 -0800536 case CMD_SEND_ENVELOPE:
537 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 if (uiccCard == null) {
540 loge("sendEnvelopeWithStatus: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
542 synchronized (request) {
543 request.notifyAll();
544 }
545 } else {
546 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
547 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
548 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 break;
550
551 case EVENT_SEND_ENVELOPE_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
558 if (ar.result == null) {
559 loge("sendEnvelopeWithStatus: Empty response");
560 } else if (ar.exception instanceof CommandException) {
561 loge("sendEnvelopeWithStatus: CommandException: " +
562 ar.exception);
563 } else {
564 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
565 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 }
567 synchronized (request) {
568 request.notifyAll();
569 }
570 break;
571
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 case CMD_OPEN_CHANNEL:
573 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800574 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800575 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 if (uiccCard == null) {
577 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800578 request.result = new IccOpenLogicalChannelResponse(-1,
579 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 synchronized (request) {
581 request.notifyAll();
582 }
583 } else {
584 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800585 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
586 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
590 case EVENT_OPEN_CHANNEL_DONE:
591 ar = (AsyncResult) msg.obj;
592 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 int[] result = (int[]) ar.result;
596 int channelId = result[0];
597 byte[] selectResponse = null;
598 if (result.length > 1) {
599 selectResponse = new byte[result.length - 1];
600 for (int i = 1; i < result.length; ++i) {
601 selectResponse[i - 1] = (byte) result[i];
602 }
603 }
604 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700605 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 if (ar.result == null) {
608 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 if (ar.exception != null) {
611 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
612 }
613
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700614 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700615 if (ar.exception instanceof CommandException) {
616 CommandException.Error error =
617 ((CommandException) (ar.exception)).getCommandError();
618 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700619 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700620 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700621 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 }
623 }
624 openChannelResp = new IccOpenLogicalChannelResponse(
625 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700627 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 synchronized (request) {
629 request.notifyAll();
630 }
631 break;
632
633 case CMD_CLOSE_CHANNEL:
634 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800635 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 if (uiccCard == null) {
637 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900638 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 synchronized (request) {
640 request.notifyAll();
641 }
642 } else {
643 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
644 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
645 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800649 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
650 break;
651
652 case CMD_NV_READ_ITEM:
653 request = (MainThreadRequest) msg.obj;
654 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
655 mPhone.nvReadItem((Integer) request.argument, onCompleted);
656 break;
657
658 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 ar = (AsyncResult) msg.obj;
660 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800661 if (ar.exception == null && ar.result != null) {
662 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800664 request.result = "";
665 if (ar.result == null) {
666 loge("nvReadItem: Empty response");
667 } else if (ar.exception instanceof CommandException) {
668 loge("nvReadItem: CommandException: " +
669 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800671 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 }
673 }
674 synchronized (request) {
675 request.notifyAll();
676 }
677 break;
678
Jake Hambye994d462014-02-03 13:10:13 -0800679 case CMD_NV_WRITE_ITEM:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
682 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
683 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
684 break;
685
686 case EVENT_NV_WRITE_ITEM_DONE:
687 handleNullReturnEvent(msg, "nvWriteItem");
688 break;
689
690 case CMD_NV_WRITE_CDMA_PRL:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
693 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
694 break;
695
696 case EVENT_NV_WRITE_CDMA_PRL_DONE:
697 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
698 break;
699
700 case CMD_NV_RESET_CONFIG:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
703 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
704 break;
705
706 case EVENT_NV_RESET_CONFIG_DONE:
707 handleNullReturnEvent(msg, "nvResetConfig");
708 break;
709
Jake Hamby7c27be32014-03-03 13:25:59 -0800710 case CMD_GET_PREFERRED_NETWORK_TYPE:
711 request = (MainThreadRequest) msg.obj;
712 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700713 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 break;
715
716 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
717 ar = (AsyncResult) msg.obj;
718 request = (MainThreadRequest) ar.userObj;
719 if (ar.exception == null && ar.result != null) {
720 request.result = ar.result; // Integer
721 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800722 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 if (ar.result == null) {
724 loge("getPreferredNetworkType: Empty response");
725 } else if (ar.exception instanceof CommandException) {
726 loge("getPreferredNetworkType: CommandException: " +
727 ar.exception);
728 } else {
729 loge("getPreferredNetworkType: Unknown exception");
730 }
731 }
732 synchronized (request) {
733 request.notifyAll();
734 }
735 break;
736
737 case CMD_SET_PREFERRED_NETWORK_TYPE:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
740 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700741 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800742 break;
743
744 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
745 handleNullReturnEvent(msg, "setPreferredNetworkType");
746 break;
747
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800748 case CMD_SET_VOICEMAIL_NUMBER:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
751 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800752 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
753 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800754 break;
755
756 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
757 handleNullReturnEvent(msg, "setVoicemailNumber");
758 break;
759
Stuart Scott54788802015-03-30 13:18:01 -0700760 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
763 request);
764 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
765 break;
766
767 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
768 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
769 break;
770
Shishir Agrawal302c8692015-06-19 13:49:39 -0700771 case CMD_PERFORM_NETWORK_SCAN:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
774 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
775 break;
776
777 case EVENT_PERFORM_NETWORK_SCAN_DONE:
778 ar = (AsyncResult) msg.obj;
779 request = (MainThreadRequest) ar.userObj;
780 CellNetworkScanResult cellScanResult;
781 if (ar.exception == null && ar.result != null) {
782 cellScanResult = new CellNetworkScanResult(
783 CellNetworkScanResult.STATUS_SUCCESS,
784 (List<OperatorInfo>) ar.result);
785 } else {
786 if (ar.result == null) {
787 loge("getCellNetworkScanResults: Empty response");
788 }
789 if (ar.exception != null) {
790 loge("getCellNetworkScanResults: Exception: " + ar.exception);
791 }
792 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
793 if (ar.exception instanceof CommandException) {
794 CommandException.Error error =
795 ((CommandException) (ar.exception)).getCommandError();
796 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
797 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
798 } else if (error == CommandException.Error.GENERIC_FAILURE) {
799 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
800 }
801 }
802 cellScanResult = new CellNetworkScanResult(errorCode, null);
803 }
804 request.result = cellScanResult;
805 synchronized (request) {
806 request.notifyAll();
807 }
808 break;
809
810 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
811 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700812 ManualNetworkSelectionArgument selArg =
813 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700814 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
815 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700816 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
817 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 break;
819
820 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
821 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
822 break;
823
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700824 case CMD_GET_MODEM_ACTIVITY_INFO:
825 request = (MainThreadRequest) msg.obj;
826 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700827 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700828 break;
829
830 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
831 ar = (AsyncResult) msg.obj;
832 request = (MainThreadRequest) ar.userObj;
833 if (ar.exception == null && ar.result != null) {
834 request.result = ar.result;
835 } else {
836 if (ar.result == null) {
837 loge("queryModemActivityInfo: Empty response");
838 } else if (ar.exception instanceof CommandException) {
839 loge("queryModemActivityInfo: CommandException: " +
840 ar.exception);
841 } else {
842 loge("queryModemActivityInfo: Unknown exception");
843 }
844 }
Amit Mahajand4766222016-01-28 15:28:28 -0800845 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
846 if (request.result == null) {
847 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
848 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700849 synchronized (request) {
850 request.notifyAll();
851 }
852 break;
853
Meng Wang1a7c35a2016-05-05 20:56:15 -0700854 case CMD_SET_ALLOWED_CARRIERS:
855 request = (MainThreadRequest) msg.obj;
856 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
857 mPhone.setAllowedCarriers(
858 (List<CarrierIdentifier>) request.argument,
859 onCompleted);
860 break;
861
862 case EVENT_SET_ALLOWED_CARRIERS_DONE:
863 ar = (AsyncResult) msg.obj;
864 request = (MainThreadRequest) ar.userObj;
865 if (ar.exception == null && ar.result != null) {
866 request.result = ar.result;
867 } else {
868 if (ar.result == null) {
869 loge("setAllowedCarriers: Empty response");
870 } else if (ar.exception instanceof CommandException) {
871 loge("setAllowedCarriers: CommandException: " +
872 ar.exception);
873 } else {
874 loge("setAllowedCarriers: Unknown exception");
875 }
876 }
877 // Result cannot be null. Return -1 on error.
878 if (request.result == null) {
879 request.result = new int[]{-1};
880 }
881 synchronized (request) {
882 request.notifyAll();
883 }
884 break;
885
886 case CMD_GET_ALLOWED_CARRIERS:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
889 mPhone.getAllowedCarriers(onCompleted);
890 break;
891
892 case EVENT_GET_ALLOWED_CARRIERS_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result;
897 } else {
898 if (ar.result == null) {
899 loge("getAllowedCarriers: Empty response");
900 } else if (ar.exception instanceof CommandException) {
901 loge("getAllowedCarriers: CommandException: " +
902 ar.exception);
903 } else {
904 loge("getAllowedCarriers: Unknown exception");
905 }
906 }
907 // Result cannot be null. Return empty list of CarrierIdentifier.
908 if (request.result == null) {
909 request.result = new ArrayList<CarrierIdentifier>(0);
910 }
911 synchronized (request) {
912 request.notifyAll();
913 }
914 break;
915
Nathan Haroldb3014052017-01-25 15:57:32 -0800916 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null && ar.result != null) {
920 request.result = ar.result;
921 } else {
922 request.result = new IllegalArgumentException(
923 "Failed to retrieve Forbidden Plmns");
924 if (ar.result == null) {
925 loge("getForbiddenPlmns: Empty response");
926 } else {
927 loge("getForbiddenPlmns: Unknown exception");
928 }
929 }
930 synchronized (request) {
931 request.notifyAll();
932 }
933 break;
934
935 case CMD_GET_FORBIDDEN_PLMNS:
936 request = (MainThreadRequest) msg.obj;
937 uiccCard = getUiccCardFromRequest(request);
938 if (uiccCard == null) {
939 loge("getForbiddenPlmns() UiccCard is null");
940 request.result = new IllegalArgumentException(
941 "getForbiddenPlmns() UiccCard is null");
942 synchronized (request) {
943 request.notifyAll();
944 }
945 break;
946 }
947 Integer appType = (Integer) request.argument;
948 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
949 if (uiccApp == null) {
950 loge("getForbiddenPlmns() no app with specified type -- "
951 + appType);
952 request.result = new IllegalArgumentException("Failed to get UICC App");
953 synchronized (request) {
954 request.notifyAll();
955 }
956 break;
957 } else {
958 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
959 + " specified type -- " + appType);
960 }
961 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
962 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
963 onCompleted);
964 break;
965
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000966 case CMD_SWITCH_SLOTS:
967 request = (MainThreadRequest) msg.obj;
968 int[] physicalSlots = (int[]) request.argument;
969 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
970 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
971 break;
972
973 case EVENT_SWITCH_SLOTS_DONE:
974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
976 request.result = (ar.exception == null);
977 synchronized (request) {
978 request.notifyAll();
979 }
980 break;
981
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700982 default:
983 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
984 break;
985 }
986 }
Jake Hambye994d462014-02-03 13:10:13 -0800987
988 private void handleNullReturnEvent(Message msg, String command) {
989 AsyncResult ar = (AsyncResult) msg.obj;
990 MainThreadRequest request = (MainThreadRequest) ar.userObj;
991 if (ar.exception == null) {
992 request.result = true;
993 } else {
994 request.result = false;
995 if (ar.exception instanceof CommandException) {
996 loge(command + ": CommandException: " + ar.exception);
997 } else {
998 loge(command + ": Unknown exception");
999 }
1000 }
1001 synchronized (request) {
1002 request.notifyAll();
1003 }
1004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001005 }
1006
1007 /**
1008 * Posts the specified command to be executed on the main thread,
1009 * waits for the request to complete, and returns the result.
1010 * @see #sendRequestAsync
1011 */
1012 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001013 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001014 }
1015
1016 /**
1017 * Posts the specified command to be executed on the main thread,
1018 * waits for the request to complete, and returns the result.
1019 * @see #sendRequestAsync
1020 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001021 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001022 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1023 throw new RuntimeException("This method will deadlock if called from the main thread.");
1024 }
1025
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001026 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001027 Message msg = mMainThreadHandler.obtainMessage(command, request);
1028 msg.sendToTarget();
1029
1030 // Wait for the request to complete
1031 synchronized (request) {
1032 while (request.result == null) {
1033 try {
1034 request.wait();
1035 } catch (InterruptedException e) {
1036 // Do nothing, go back and wait until the request is complete
1037 }
1038 }
1039 }
1040 return request.result;
1041 }
1042
1043 /**
1044 * Asynchronous ("fire and forget") version of sendRequest():
1045 * Posts the specified command to be executed on the main thread, and
1046 * returns immediately.
1047 * @see #sendRequest
1048 */
1049 private void sendRequestAsync(int command) {
1050 mMainThreadHandler.sendEmptyMessage(command);
1051 }
1052
1053 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001054 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1055 * @see {@link #sendRequest(int,Object)}
1056 */
1057 private void sendRequestAsync(int command, Object argument) {
1058 MainThreadRequest request = new MainThreadRequest(argument);
1059 Message msg = mMainThreadHandler.obtainMessage(command, request);
1060 msg.sendToTarget();
1061 }
1062
1063 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001064 * Initialize the singleton PhoneInterfaceManager instance.
1065 * This is only done once, at startup, from PhoneApp.onCreate().
1066 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001067 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001068 synchronized (PhoneInterfaceManager.class) {
1069 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001070 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001071 } else {
1072 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1073 }
1074 return sInstance;
1075 }
1076 }
1077
1078 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001079 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001080 mApp = app;
1081 mPhone = phone;
1082 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001083 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001084 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1085 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001086 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001087 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001088 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001089 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001090
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 publish();
1092 }
1093
1094 private void publish() {
1095 if (DBG) log("publish: " + this);
1096
1097 ServiceManager.addService("phone", this);
1098 }
1099
Stuart Scott584921c2015-01-15 17:10:34 -08001100 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001101 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1102 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001103 }
1104
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001105 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1106 Phone phone = getPhoneFromRequest(request);
1107 return phone == null ? null :
1108 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1109 }
1110
Wink Saville36469e72014-06-11 15:17:00 -07001111 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001112 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001113 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001115 //
1116 // Implementation of the ITelephony interface.
1117 //
1118
1119 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001120 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001121 }
1122
Wink Savilleb564aae2014-10-23 10:18:09 -07001123 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001124 if (DBG) log("dial: " + number);
1125 // No permission check needed here: This is just a wrapper around the
1126 // ACTION_DIAL intent, which is available to any app since it puts up
1127 // the UI before it does anything.
1128
1129 String url = createTelUrl(number);
1130 if (url == null) {
1131 return;
1132 }
1133
1134 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001135 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1137 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1138 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1139 mApp.startActivity(intent);
1140 }
1141 }
1142
1143 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001144 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001145 }
1146
Wink Savilleb564aae2014-10-23 10:18:09 -07001147 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 if (DBG) log("call: " + number);
1149
1150 // This is just a wrapper around the ACTION_CALL intent, but we still
1151 // need to do a permission check since we're calling startActivity()
1152 // from the context of the phone app.
1153 enforceCallPermission();
1154
1155 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1156 != AppOpsManager.MODE_ALLOWED) {
1157 return;
1158 }
1159
1160 String url = createTelUrl(number);
1161 if (url == null) {
1162 return;
1163 }
1164
Wink Saville08874612014-08-31 19:19:58 -07001165 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001166 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001167 if (slist != null) {
1168 for (SubscriptionInfo subInfoRecord : slist) {
1169 if (subInfoRecord.getSubscriptionId() == subId) {
1170 isValid = true;
1171 break;
1172 }
Wink Saville08874612014-08-31 19:19:58 -07001173 }
1174 }
1175 if (isValid == false) {
1176 return;
1177 }
1178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001179 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001180 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001181 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1182 mApp.startActivity(intent);
1183 }
1184
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001185 /**
1186 * End a call based on call state
1187 * @return true is a call was ended
1188 */
1189 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001190 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001191 }
1192
1193 /**
1194 * End a call based on the call state of the subId
1195 * @return true is a call was ended
1196 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001197 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001198 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1199 != PackageManager.PERMISSION_GRANTED) {
1200 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1201 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1202 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1203 }
Stuart Scott584921c2015-01-15 17:10:34 -08001204 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 }
1206
1207 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001208 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001209 }
1210
Wink Savilleb564aae2014-10-23 10:18:09 -07001211 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001212 if (DBG) log("answerRingingCall...");
1213 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1214 // but that can probably wait till the big TelephonyManager API overhaul.
1215 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1216 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001217 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 }
1219
1220 /**
1221 * Make the actual telephony calls to implement answerRingingCall().
1222 * This should only be called from the main thread of the Phone app.
1223 * @see #answerRingingCall
1224 *
1225 * TODO: it would be nice to return true if we answered the call, or
1226 * false if there wasn't actually a ringing incoming call, or some
1227 * other error occurred. (In other words, pass back the return value
1228 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1229 * But that would require calling this method via sendRequest() rather
1230 * than sendRequestAsync(), and right now we don't actually *need* that
1231 * return value, so let's just return void for now.
1232 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001233 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001234 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001236 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1237 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001238 if (hasActiveCall && hasHoldingCall) {
1239 // Both lines are in use!
1240 // TODO: provide a flag to let the caller specify what
1241 // policy to use if both lines are in use. (The current
1242 // behavior is hardwired to "answer incoming, end ongoing",
1243 // which is how the CALL button is specced to behave.)
1244 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1245 return;
1246 } else {
1247 // answerCall() will automatically hold the current active
1248 // call, if there is one.
1249 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1250 return;
1251 }
1252 } else {
1253 // No call was ringing.
1254 return;
1255 }
1256 }
1257
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001259 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001261 public void silenceRinger() {
1262 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 }
1264
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001265 @Override
1266 public boolean isOffhook(String callingPackage) {
1267 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001268 }
1269
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001270 @Override
1271 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001273 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001274 return false;
1275 }
1276
Sanket Padawe356d7632015-06-22 14:03:32 -07001277 final Phone phone = getPhone(subId);
1278 if (phone != null) {
1279 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1280 } else {
1281 return false;
1282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 }
1284
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001285 @Override
1286 public boolean isRinging(String callingPackage) {
1287 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001288 }
1289
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001290 @Override
1291 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001293 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001294 return false;
1295 }
1296
Sanket Padawe356d7632015-06-22 14:03:32 -07001297 final Phone phone = getPhone(subId);
1298 if (phone != null) {
1299 return (phone.getState() == PhoneConstants.State.RINGING);
1300 } else {
1301 return false;
1302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 }
1304
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001305 @Override
1306 public boolean isIdle(String callingPackage) {
1307 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001308 }
1309
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001310 @Override
1311 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001313 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001314 return false;
1315 }
1316
Sanket Padawe356d7632015-06-22 14:03:32 -07001317 final Phone phone = getPhone(subId);
1318 if (phone != null) {
1319 return (phone.getState() == PhoneConstants.State.IDLE);
1320 } else {
1321 return false;
1322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 }
1324
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001326 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001327 }
1328
Wink Savilleb564aae2014-10-23 10:18:09 -07001329 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001330 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001331 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1332 }
1333
1334 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001335 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001336 }
1337
Wink Savilleb564aae2014-10-23 10:18:09 -07001338 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001339 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001340 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1341 }
1342
1343 /** {@hide} */
1344 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001345 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001346 }
1347
Wink Savilleb564aae2014-10-23 10:18:09 -07001348 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001350 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351 checkSimPin.start();
1352 return checkSimPin.unlockSim(null, pin);
1353 }
1354
Wink Saville9de0f752013-10-22 19:04:03 -07001355 /** {@hide} */
1356 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001357 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001358 }
1359
Wink Savilleb564aae2014-10-23 10:18:09 -07001360 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001362 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 checkSimPuk.start();
1364 return checkSimPuk.unlockSim(puk, pin);
1365 }
1366
1367 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001368 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001369 * a synchronous one.
1370 */
1371 private static class UnlockSim extends Thread {
1372
1373 private final IccCard mSimCard;
1374
1375 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001376 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1377 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378
1379 // For replies from SimCard interface
1380 private Handler mHandler;
1381
1382 // For async handler to identify request type
1383 private static final int SUPPLY_PIN_COMPLETE = 100;
1384
1385 public UnlockSim(IccCard simCard) {
1386 mSimCard = simCard;
1387 }
1388
1389 @Override
1390 public void run() {
1391 Looper.prepare();
1392 synchronized (UnlockSim.this) {
1393 mHandler = new Handler() {
1394 @Override
1395 public void handleMessage(Message msg) {
1396 AsyncResult ar = (AsyncResult) msg.obj;
1397 switch (msg.what) {
1398 case SUPPLY_PIN_COMPLETE:
1399 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1400 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001401 mRetryCount = msg.arg1;
1402 if (ar.exception != null) {
1403 if (ar.exception instanceof CommandException &&
1404 ((CommandException)(ar.exception)).getCommandError()
1405 == CommandException.Error.PASSWORD_INCORRECT) {
1406 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1407 } else {
1408 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1409 }
1410 } else {
1411 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 mDone = true;
1414 UnlockSim.this.notifyAll();
1415 }
1416 break;
1417 }
1418 }
1419 };
1420 UnlockSim.this.notifyAll();
1421 }
1422 Looper.loop();
1423 }
1424
1425 /*
1426 * Use PIN or PUK to unlock SIM card
1427 *
1428 * If PUK is null, unlock SIM card with PIN
1429 *
1430 * If PUK is not null, unlock SIM card with PUK and set PIN code
1431 */
Wink Saville9de0f752013-10-22 19:04:03 -07001432 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433
1434 while (mHandler == null) {
1435 try {
1436 wait();
1437 } catch (InterruptedException e) {
1438 Thread.currentThread().interrupt();
1439 }
1440 }
1441 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1442
1443 if (puk == null) {
1444 mSimCard.supplyPin(pin, callback);
1445 } else {
1446 mSimCard.supplyPuk(puk, pin, callback);
1447 }
1448
1449 while (!mDone) {
1450 try {
1451 Log.d(LOG_TAG, "wait for done");
1452 wait();
1453 } catch (InterruptedException e) {
1454 // Restore the interrupted status
1455 Thread.currentThread().interrupt();
1456 }
1457 }
1458 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001459 int[] resultArray = new int[2];
1460 resultArray[0] = mResult;
1461 resultArray[1] = mRetryCount;
1462 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001463 }
1464 }
1465
1466 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001467 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001468
1469 }
1470
Wink Savilleb564aae2014-10-23 10:18:09 -07001471 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 // No permission check needed here: this call is harmless, and it's
1473 // needed for the ServiceState.requestStateUpdate() call (which is
1474 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001475 final Phone phone = getPhone(subId);
1476 if (phone != null) {
1477 phone.updateServiceLocation();
1478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001481 @Override
1482 public boolean isRadioOn(String callingPackage) {
1483 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001486 @Override
1487 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001489 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001490 return false;
1491 }
1492 return isRadioOnForSubscriber(subId);
1493 }
1494
1495 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001496 final Phone phone = getPhone(subId);
1497 if (phone != null) {
1498 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1499 } else {
1500 return false;
1501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 }
1503
1504 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001505 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001506
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507 }
Wink Saville36469e72014-06-11 15:17:00 -07001508
Wink Savilleb564aae2014-10-23 10:18:09 -07001509 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001511 final Phone phone = getPhone(subId);
1512 if (phone != null) {
1513 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1514 }
Wink Saville36469e72014-06-11 15:17:00 -07001515 }
1516
1517 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001518 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001519 }
1520
Wink Savilleb564aae2014-10-23 10:18:09 -07001521 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001522 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001523 final Phone phone = getPhone(subId);
1524 if (phone == null) {
1525 return false;
1526 }
1527 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001528 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001529 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 }
1531 return true;
1532 }
Wink Saville36469e72014-06-11 15:17:00 -07001533
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001534 public boolean needMobileRadioShutdown() {
1535 /*
1536 * If any of the Radios are available, it will need to be
1537 * shutdown. So return true if any Radio is available.
1538 */
1539 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1540 Phone phone = PhoneFactory.getPhone(i);
1541 if (phone != null && phone.isRadioAvailable()) return true;
1542 }
1543 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1544 return false;
1545 }
1546
1547 public void shutdownMobileRadios() {
1548 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1549 logv("Shutting down Phone " + i);
1550 shutdownRadioUsingPhoneId(i);
1551 }
1552 }
1553
1554 private void shutdownRadioUsingPhoneId(int phoneId) {
1555 enforceModifyPermission();
1556 Phone phone = PhoneFactory.getPhone(phoneId);
1557 if (phone != null && phone.isRadioAvailable()) {
1558 phone.shutdownRadio();
1559 }
1560 }
1561
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001563 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001564 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1565 if (defaultPhone != null) {
1566 defaultPhone.setRadioPower(turnOn);
1567 return true;
1568 } else {
1569 loge("There's no default phone.");
1570 return false;
1571 }
Wink Saville36469e72014-06-11 15:17:00 -07001572 }
1573
Wink Savilleb564aae2014-10-23 10:18:09 -07001574 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 final Phone phone = getPhone(subId);
1577 if (phone != null) {
1578 phone.setRadioPower(turnOn);
1579 return true;
1580 } else {
1581 return false;
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
Wink Saville36469e72014-06-11 15:17:00 -07001585 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 public boolean enableDataConnectivity() {
1588 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001589 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 final Phone phone = getPhone(subId);
1591 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001592 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 return true;
1594 } else {
1595 return false;
1596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 }
1598
Wink Saville36469e72014-06-11 15:17:00 -07001599 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001600 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 public boolean disableDataConnectivity() {
1602 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001603 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 final Phone phone = getPhone(subId);
1605 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001606 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 return true;
1608 } else {
1609 return false;
1610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 }
1612
Sanket Padawe356d7632015-06-22 14:03:32 -07001613 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001614 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001615 final Phone phone = getPhone(subId);
1616 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001617 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 } else {
1619 return false;
1620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
1623 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001624 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001625 }
1626
pkanwarae03a6b2016-11-06 20:37:09 -08001627 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001628 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001629 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1630 return;
1631 }
1632 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1633 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1634 };
1635
Wink Savilleb564aae2014-10-23 10:18:09 -07001636 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1639 return false;
1640 }
Wink Saville36469e72014-06-11 15:17:00 -07001641 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 }
1643
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001645 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001646 }
1647
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001648 public int getCallStateForSlot(int slotIndex) {
1649 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001650 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001651 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001656 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001657 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001658 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001659 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001660 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 }
1663
Sanket Padawe356d7632015-06-22 14:03:32 -07001664 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001666 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001667 if (phone != null) {
1668 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1669 } else {
1670 return TelephonyManager.DATA_ACTIVITY_NONE;
1671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 }
1673
1674 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001675 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001676 mPhone.getContext().getSystemService(AppOpsManager.class)
1677 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001678 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001679 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001680 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001683 if (DBG_LOC) log("getCellLocation: is active user");
1684 Bundle data = new Bundle();
1685 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1686 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 return null;
1688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001690 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001691 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1692 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001693 }
1694
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001696 public String getNetworkCountryIsoForPhone(int phoneId) {
1697 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1698 // registered cell info, so return a NULL country instead.
1699 final long identity = Binder.clearCallingIdentity();
1700 try {
1701 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1702 if (TelephonyManager.NETWORK_TYPE_IWLAN
1703 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1704 return "";
1705 }
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
1708 }
1709 return TelephonyManager.getTelephonyProperty(
1710 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1711 }
1712
1713 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001715 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001716 }
1717
Sanket Padawe356d7632015-06-22 14:03:32 -07001718 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001719 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 mApp.enforceCallingOrSelfPermission(
1721 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 final Phone phone = getPhone(subId);
1723 if (phone != null) {
1724 phone.enableLocationUpdates();
1725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
1728 @Override
1729 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001730 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001731 }
1732
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001734 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 mApp.enforceCallingOrSelfPermission(
1736 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001737 final Phone phone = getPhone(subId);
1738 if (phone != null) {
1739 phone.disableLocationUpdates();
1740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
1742
1743 @Override
1744 @SuppressWarnings("unchecked")
1745 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001746 mPhone.getContext().getSystemService(AppOpsManager.class)
1747 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001748 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001749 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001750 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
1752
1753 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1754 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1755 return null;
1756 }
Svetoslav64fad262015-04-14 14:35:21 -07001757
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001758 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001760 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001762 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001763 try {
1764 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1765 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1766 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1767 } catch (RuntimeException e) {
1768 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001770 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
1773
1774 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001775 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001776 mPhone.getContext().getSystemService(AppOpsManager.class)
1777 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001778 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001779 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001780 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 }
1782
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001783 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001784 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001785 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1786 for (Phone phone : PhoneFactory.getPhones()) {
1787 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1788 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001790 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 }
1792
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001795 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001796 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001797 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 }
1799
Shishir Agrawala9f32182016-04-12 12:00:16 -07001800 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001801 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001802 Phone phone = PhoneFactory.getPhone(slotIndex);
1803 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001804 return null;
1805 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001806 int subId = phone.getSubId();
1807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1808 mApp, subId, callingPackage, "getImeiForSlot")) {
1809 return null;
1810 }
1811 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001812 }
1813
1814 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001815 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001816 Phone phone = PhoneFactory.getPhone(slotIndex);
1817 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001818 return null;
1819 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001820 int subId = phone.getSubId();
1821 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1822 mApp, subId, callingPackage, "getMeidForSlot")) {
1823 return null;
1824 }
1825 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001826 }
1827
1828 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001829 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001830 Phone phone = PhoneFactory.getPhone(slotIndex);
1831 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001832 return null;
1833 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001834 int subId = phone.getSubId();
1835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1836 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1837 return null;
1838 }
1839 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001840 }
1841
fionaxu43304da2017-11-27 22:51:16 -08001842 @Override
1843 public int getSubscriptionCarrierId(int subId) {
1844 final Phone phone = getPhone(subId);
1845 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1846 }
1847
1848 @Override
1849 public String getSubscriptionCarrierName(int subId) {
1850 final Phone phone = getPhone(subId);
1851 return phone == null ? null : phone.getCarrierName();
1852 }
1853
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 //
1855 // Internal helper methods.
1856 //
1857
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001858 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1860 *
1861 * @throws SecurityException if the caller does not have the required permission
1862 */
1863 private void enforceModifyPermission() {
1864 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1865 }
1866
1867 /**
1868 * Make sure the caller has the CALL_PHONE permission.
1869 *
1870 * @throws SecurityException if the caller does not have the required permission
1871 */
1872 private void enforceCallPermission() {
1873 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1874 }
1875
Stuart Scott8eef64f2015-04-08 15:13:54 -07001876 private void enforceConnectivityInternalPermission() {
1877 mApp.enforceCallingOrSelfPermission(
1878 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1879 "ConnectivityService");
1880 }
1881
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 private String createTelUrl(String number) {
1883 if (TextUtils.isEmpty(number)) {
1884 return null;
1885 }
1886
Jake Hambye994d462014-02-03 13:10:13 -08001887 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 }
1889
Ihab Awadf9e92732013-12-05 18:02:52 -08001890 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1892 }
1893
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001894 private static void logv(String msg) {
1895 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1896 }
1897
Ihab Awadf9e92732013-12-05 18:02:52 -08001898 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1900 }
1901
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001902 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001904 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001905 }
1906
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001908 public int getActivePhoneTypeForSlot(int slotIndex) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00001909 final Phone phone = PhoneFactory.getPhone(slotIndex);
1910 if (phone == null) {
1911 return PhoneConstants.PHONE_TYPE_NONE;
1912 } else {
1913 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917 /**
1918 * Returns the CDMA ERI icon index to display
1919 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001920 @Override
1921 public int getCdmaEriIconIndex(String callingPackage) {
1922 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001923 }
1924
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001926 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001927 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001928 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001929 return -1;
1930 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001931 final Phone phone = getPhone(subId);
1932 if (phone != null) {
1933 return phone.getCdmaEriIconIndex();
1934 } else {
1935 return -1;
1936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 }
1938
1939 /**
1940 * Returns the CDMA ERI icon mode,
1941 * 0 - ON
1942 * 1 - FLASHING
1943 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001944 @Override
1945 public int getCdmaEriIconMode(String callingPackage) {
1946 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001947 }
1948
Sanket Padawe356d7632015-06-22 14:03:32 -07001949 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001952 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001953 return -1;
1954 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 final Phone phone = getPhone(subId);
1956 if (phone != null) {
1957 return phone.getCdmaEriIconMode();
1958 } else {
1959 return -1;
1960 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 }
1962
1963 /**
1964 * Returns the CDMA ERI text,
1965 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001966 @Override
1967 public String getCdmaEriText(String callingPackage) {
1968 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001969 }
1970
Sanket Padawe356d7632015-06-22 14:03:32 -07001971 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001972 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001974 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001975 return null;
1976 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 final Phone phone = getPhone(subId);
1978 if (phone != null) {
1979 return phone.getCdmaEriText();
1980 } else {
1981 return null;
1982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
1984
1985 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001986 * Returns the CDMA MDN.
1987 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001989 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1991 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001992 final Phone phone = getPhone(subId);
1993 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1994 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001995 } else {
1996 return null;
1997 }
1998 }
1999
2000 /**
2001 * Returns the CDMA MIN.
2002 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002003 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002004 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2006 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002007 final Phone phone = getPhone(subId);
2008 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2009 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002010 } else {
2011 return null;
2012 }
2013 }
2014
2015 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 * Returns true if CDMA provisioning needs to run.
2017 */
2018 public boolean needsOtaServiceProvisioning() {
2019 return mPhone.needsOtaServiceProvisioning();
2020 }
2021
2022 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002023 * Sets the voice mail number of a given subId.
2024 */
2025 @Override
2026 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002027 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002028 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2029 new Pair<String, String>(alphaTag, number), new Integer(subId));
2030 return success;
2031 }
2032
Ta-wei Yen87c49842016-05-13 21:19:52 -07002033 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002034 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2035 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2036 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2037 if (!TextUtils.equals(callingPackage, systemDialer)) {
2038 throw new SecurityException("caller must be system dialer");
2039 }
2040 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2041 if (phoneAccountHandle == null){
2042 return null;
2043 }
2044 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2045 }
2046
2047 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002048 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002049 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002051 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002052 return null;
2053 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002054 final long identity = Binder.clearCallingIdentity();
2055 try {
2056 return RemoteVvmTaskManager
2057 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2058 } finally {
2059 Binder.restoreCallingIdentity(identity);
2060 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002061 }
2062
2063 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002064 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2065 VisualVoicemailSmsFilterSettings settings) {
2066 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002067 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002068 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2069 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002070 }
2071
2072 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002073 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2074 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002075 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002076 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002077 }
2078
2079 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002080 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2081 String callingPackage, int subId) {
2082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002083 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002084 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002085 }
2086
2087 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002088 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002089 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002090 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002091 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2092 }
2093
2094 @Override
2095 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2096 String number, int port, String text, PendingIntent sentIntent) {
2097 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002098 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002099 enforceSendSmsPermission();
2100 // Make the calls as the phone process.
2101 final long identity = Binder.clearCallingIdentity();
2102 try {
2103 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2104 if (port == 0) {
2105 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2106 sentIntent, null, false);
2107 } else {
2108 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2109 smsManager.sendDataMessageWithSelfPermissions(number, null,
2110 (short) port, data, sentIntent, null);
2111 }
2112 } finally {
2113 Binder.restoreCallingIdentity(identity);
2114 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002115 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002116 /**
fionaxu0152e512016-11-14 13:36:14 -08002117 * Sets the voice activation state of a given subId.
2118 */
2119 @Override
2120 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2122 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002123 final Phone phone = getPhone(subId);
2124 if (phone != null) {
2125 phone.setVoiceActivationState(activationState);
2126 } else {
2127 loge("setVoiceActivationState fails with invalid subId: " + subId);
2128 }
2129 }
2130
2131 /**
2132 * Sets the data activation state of a given subId.
2133 */
2134 @Override
2135 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2137 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002138 final Phone phone = getPhone(subId);
2139 if (phone != null) {
2140 phone.setDataActivationState(activationState);
2141 } else {
2142 loge("setVoiceActivationState fails with invalid subId: " + subId);
2143 }
2144 }
2145
2146 /**
2147 * Returns the voice activation state of a given subId.
2148 */
2149 @Override
2150 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002151 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002152 final Phone phone = getPhone(subId);
2153 if (phone != null) {
2154 return phone.getVoiceActivationState();
2155 } else {
2156 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2157 }
2158 }
2159
2160 /**
2161 * Returns the data activation state of a given subId.
2162 */
2163 @Override
2164 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002165 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002166 final Phone phone = getPhone(subId);
2167 if (phone != null) {
2168 return phone.getDataActivationState();
2169 } else {
2170 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2171 }
2172 }
2173
2174 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 * Returns the unread count of voicemails
2176 */
2177 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002178 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002179 }
2180
2181 /**
2182 * Returns the unread count of voicemails for a subId
2183 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002184 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002185 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002186 final Phone phone = getPhone(subId);
2187 if (phone != null) {
2188 return phone.getVoiceMessageCount();
2189 } else {
2190 return 0;
2191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193
2194 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002195 * returns true, if the device is in a state where both voice and data
2196 * are supported simultaneously. This can change based on location or network condition.
2197 */
2198 @Override
2199 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2200 final Phone phone = getPhone(subId);
2201 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2202 }
2203
2204 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002205 * Send the dialer code if called from the current default dialer or the caller has
2206 * carrier privilege.
2207 * @param inputCode The dialer code to send
2208 */
2209 @Override
2210 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2211 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2212 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2213 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002214 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2215 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002216 }
2217 mPhone.sendDialerSpecialCode(inputCode);
2218 }
2219
2220 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002221 * Returns the data network type.
2222 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 *
2224 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2225 */
2226 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002227 public int getNetworkType() {
2228 final Phone phone = getPhone(getDefaultSubscription());
2229 if (phone != null) {
2230 return phone.getServiceState().getDataNetworkType();
2231 } else {
2232 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2233 }
Wink Saville36469e72014-06-11 15:17:00 -07002234 }
2235
2236 /**
2237 * Returns the network type for a subId
2238 */
2239 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002240 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002242 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002243 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2244 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002245
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002247 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002248 return phone.getServiceState().getDataNetworkType();
2249 } else {
2250 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 }
2253
2254 /**
2255 * Returns the data network type
2256 */
2257 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002258 public int getDataNetworkType(String callingPackage) {
2259 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002260 }
2261
2262 /**
2263 * Returns the data network type for a subId
2264 */
2265 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002266 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002268 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002269 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2270 }
2271
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 final Phone phone = getPhone(subId);
2273 if (phone != null) {
2274 return phone.getServiceState().getDataNetworkType();
2275 } else {
2276 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 }
2279
2280 /**
Wink Saville36469e72014-06-11 15:17:00 -07002281 * Returns the Voice network type for a subId
2282 */
2283 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002284 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002286 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002287 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2288 }
2289
Sanket Padawe356d7632015-06-22 14:03:32 -07002290 final Phone phone = getPhone(subId);
2291 if (phone != null) {
2292 return phone.getServiceState().getVoiceNetworkType();
2293 } else {
2294 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 }
2297
2298 /**
2299 * @return true if a ICC card is present
2300 */
2301 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002302 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002303 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2304 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002305 }
2306
2307 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002308 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002309 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002310 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002311 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2312 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002313 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002314 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002315 } else {
2316 return false;
2317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 }
2319
2320 /**
2321 * Return if the current radio is LTE on CDMA. This
2322 * is a tri-state return value as for a period of time
2323 * the mode may be unknown.
2324 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002325 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002327 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002329 @Override
2330 public int getLteOnCdmaMode(String callingPackage) {
2331 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002332 }
2333
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002335 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002337 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002338 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2339 }
2340
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 final Phone phone = getPhone(subId);
2342 if (phone == null) {
2343 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2344 } else {
2345 return phone.getLteOnCdmaMode();
2346 }
Wink Saville36469e72014-06-11 15:17:00 -07002347 }
2348
2349 public void setPhone(Phone phone) {
2350 mPhone = phone;
2351 }
2352
2353 /**
2354 * {@hide}
2355 * Returns Default subId, 0 in the case of single standby.
2356 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002357 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002358 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002359 }
2360
Shishir Agrawala9f32182016-04-12 12:00:16 -07002361 private int getSlotForDefaultSubscription() {
2362 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2363 }
2364
Wink Savilleb564aae2014-10-23 10:18:09 -07002365 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002366 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002368
2369 /**
2370 * @see android.telephony.TelephonyManager.WifiCallingChoices
2371 */
2372 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002373 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2374 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002375 }
2376
2377 /**
2378 * @see android.telephony.TelephonyManager.WifiCallingChoices
2379 */
2380 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002381 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2382 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2383 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002384 }
2385
Sailesh Nepald1e68152013-12-12 19:08:02 -08002386 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002387 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002388 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002389 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002390
Shishir Agrawal566b7612013-10-28 14:41:00 -07002391 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002392 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2393 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2395 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002396
Derek Tan740e1672017-06-27 14:56:27 -07002397 if (TextUtils.equals(ISDR_AID, aid)) {
2398 // Only allows LPA to open logical channel to ISD-R.
2399 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2400 ComponentInfo bestComponent =
2401 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2402 if (bestComponent == null
2403 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2404 loge("The calling package is not allowed to access ISD-R.");
2405 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2406 }
2407 }
2408
2409 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002410 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002411 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002412 if (DBG) log("iccOpenLogicalChannel: " + response);
2413 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002414 }
2415
2416 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002417 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2419 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002420
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002421 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002422 if (channel < 0) {
2423 return false;
2424 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002425 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002426 if (DBG) log("iccCloseLogicalChannel: " + success);
2427 return success;
2428 }
2429
2430 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002431 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002432 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2434 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002435
2436 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002437 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2438 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002439 " data=" + data);
2440 }
2441
2442 if (channel < 0) {
2443 return "";
2444 }
2445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002446 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002447 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002448 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2449
Shishir Agrawal566b7612013-10-28 14:41:00 -07002450 // Append the returned status code to the end of the response payload.
2451 String s = Integer.toHexString(
2452 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002453 if (response.payload != null) {
2454 s = IccUtils.bytesToHexString(response.payload) + s;
2455 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002456 return s;
2457 }
Jake Hambye994d462014-02-03 13:10:13 -08002458
Evan Charltonc66da362014-05-16 14:06:40 -07002459 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002460 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2461 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2463 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002464
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002465 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2466 && TextUtils.equals(ISDR_AID, data)) {
2467 // Only allows LPA to select ISD-R.
2468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2469 ComponentInfo bestComponent =
2470 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2471 if (bestComponent == null
2472 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2473 loge("The calling package is not allowed to select ISD-R.");
2474 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2475 }
2476 }
2477
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002478 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002479 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2480 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002481 }
2482
2483 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002484 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002485 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2486
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002487 // Append the returned status code to the end of the response payload.
2488 String s = Integer.toHexString(
2489 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002490 if (response.payload != null) {
2491 s = IccUtils.bytesToHexString(response.payload) + s;
2492 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002493 return s;
2494 }
2495
2496 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002497 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002498 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2500 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002501
2502 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002503 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002504 p1 + " " + p2 + " " + p3 + ":" + filePath);
2505 }
2506
2507 IccIoResult response =
2508 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002509 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2510 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002511
2512 if (DBG) {
2513 log("Exchange SIM_IO [R]" + response);
2514 }
2515
2516 byte[] result = null;
2517 int length = 2;
2518 if (response.payload != null) {
2519 length = 2 + response.payload.length;
2520 result = new byte[length];
2521 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2522 } else {
2523 result = new byte[length];
2524 }
2525
2526 result[length - 1] = (byte) response.sw2;
2527 result[length - 2] = (byte) response.sw1;
2528 return result;
2529 }
2530
Nathan Haroldb3014052017-01-25 15:57:32 -08002531 /**
2532 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2533 * on a particular subscription
2534 */
sqianb6e41952018-03-12 14:54:01 -07002535 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2536 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2537 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2538 return null;
2539 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002540 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2541 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2542 return null;
2543 }
2544 Object response = sendRequest(
2545 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2546 if (response instanceof String[]) {
2547 return (String[]) response;
2548 }
2549 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2550 return null;
2551 }
2552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002553 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002554 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2556 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002557
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002558 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002559 if (response.payload == null) {
2560 return "";
2561 }
2562
2563 // Append the returned status code to the end of the response payload.
2564 String s = Integer.toHexString(
2565 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2566 s = IccUtils.bytesToHexString(response.payload) + s;
2567 return s;
2568 }
2569
Jake Hambye994d462014-02-03 13:10:13 -08002570 /**
2571 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2572 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2573 *
2574 * @param itemID the ID of the item to read
2575 * @return the NV item as a String, or null on error.
2576 */
2577 @Override
2578 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2580 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002581 if (DBG) log("nvReadItem: item " + itemID);
2582 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2583 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2584 return value;
2585 }
2586
2587 /**
2588 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2589 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2590 *
2591 * @param itemID the ID of the item to read
2592 * @param itemValue the value to write, as a String
2593 * @return true on success; false on any failure
2594 */
2595 @Override
2596 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2598 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002599 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2600 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2601 new Pair<Integer, String>(itemID, itemValue));
2602 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2603 return success;
2604 }
2605
2606 /**
2607 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2608 * Used for device configuration by some CDMA operators.
2609 *
2610 * @param preferredRoamingList byte array containing the new PRL
2611 * @return true on success; false on any failure
2612 */
2613 @Override
2614 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2616 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002617 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2618 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2619 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2620 return success;
2621 }
2622
2623 /**
2624 * Perform the specified type of NV config reset.
2625 * Used for device configuration by some CDMA operators.
2626 *
2627 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2628 * @return true on success; false on any failure
2629 */
2630 @Override
2631 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2633 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002634 if (DBG) log("nvResetConfig: type " + resetType);
2635 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2636 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2637 return success;
2638 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002639
2640 /**
Wink Saville36469e72014-06-11 15:17:00 -07002641 * {@hide}
2642 * Returns Default sim, 0 in the case of single standby.
2643 */
2644 public int getDefaultSim() {
2645 //TODO Need to get it from Telephony Devcontroller
2646 return 0;
2647 }
2648
Svet Ganovb320e182015-04-16 12:30:10 -07002649 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002651 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002652 return new String[0];
2653 }
2654
2655
ram87fca6f2014-07-18 18:58:44 +05302656 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002657 }
2658
Brad Ebinger51f743a2017-01-23 13:50:20 -08002659 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002660 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2661 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002662 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002663 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002664 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002665 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002666 }
2667
2668 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002669 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2670 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002671 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002672 public void disableIms(int slotId) {
2673 enforceModifyPermission();
2674 PhoneFactory.getImsResolver().disableIms(slotId);
2675 }
2676
2677 /**
2678 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2679 * feature or {@link null} if the service is not available. If the feature is available, the
2680 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2681 */
2682 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002683 IImsServiceFeatureCallback callback) {
2684 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002685 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002686 }
2687
2688 /**
2689 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2690 * feature during emergency calling or {@link null} if the service is not available. If the
2691 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2692 * listener for feature updates.
2693 */
2694 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2695 enforceModifyPermission();
2696 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002697 }
2698
Brad Ebinger5f64b052017-12-14 14:26:15 -08002699 /**
2700 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2701 * specified.
2702 */
2703 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2704 enforceModifyPermission();
2705 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2706 }
2707
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002708 /**
2709 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2710 * specified.
2711 */
2712 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2713 enforceModifyPermission();
2714 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2715 }
2716
Brad Ebinger884c07b2018-02-15 16:17:40 -08002717 /**
Brad Ebinger304415d2018-03-02 13:43:36 -08002718 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2719 * available, false if the IMS resolver is idle.
2720 */
2721 public boolean isResolvingImsBinding() {
2722 enforceModifyPermission();
2723 return PhoneFactory.getImsResolver().isResolvingBinding();
2724 }
2725
Brad Ebingerdac2f002018-04-03 15:17:52 -07002726 /**
2727 * Sets the ImsService Package Name that Telephony will bind to.
2728 *
2729 * @param slotId the slot ID that the ImsService should bind for.
2730 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
2731 * ImsService is the device default ImsService.
2732 * @param packageName The package name of the application that contains the ImsService to bind
2733 * to.
2734 * @return true if setting the ImsService to bind to succeeded, false if it did not.
2735 * @hide
2736 */
2737 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002738 int[] subIds = SubscriptionManager.getSubId(slotId);
2739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2740 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2741 "setImsService");
2742
Brad Ebingerdac2f002018-04-03 15:17:52 -07002743 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
2744 isCarrierImsService, packageName);
2745 }
2746
2747 /**
2748 * Return the ImsService configuration.
2749 *
2750 * @param slotId The slot that the ImsService is associated with.
2751 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
2752 * the device default.
2753 * @return the package name of the ImsService configuration.
2754 */
2755 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002756 int[] subIds = SubscriptionManager.getSubId(slotId);
2757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2758 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2759 "getImsService");
2760
Brad Ebingerdac2f002018-04-03 15:17:52 -07002761 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
2762 isCarrierImsService);
2763 }
2764
Wink Saville36469e72014-06-11 15:17:00 -07002765 public void setImsRegistrationState(boolean registered) {
2766 enforceModifyPermission();
2767 mPhone.setImsRegistrationState(registered);
2768 }
2769
2770 /**
Stuart Scott54788802015-03-30 13:18:01 -07002771 * Set the network selection mode to automatic.
2772 *
2773 */
2774 @Override
2775 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2777 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002778 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2779 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2780 }
2781
2782 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002783 * Set the network selection mode to manual with the selected carrier.
2784 */
2785 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002786 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002787 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2789 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002790 OperatorInfo operator = new OperatorInfo(
2791 /* operatorAlphaLong */ "",
2792 /* operatorAlphaShort */ "",
2793 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002794 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002795 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2796 persistSelection);
2797 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002798 }
2799
2800 /**
2801 * Scans for available networks.
2802 */
2803 @Override
2804 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2806 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002807 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2808 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2809 CMD_PERFORM_NETWORK_SCAN, null, subId);
2810 return result;
2811 }
2812
2813 /**
yinxub1bed742017-04-17 11:45:04 -07002814 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002815 *
yinxub1bed742017-04-17 11:45:04 -07002816 * @param subId id of the subscription
2817 * @param request contains the radio access networks with bands/channels to scan
2818 * @param messenger callback messenger for scan results or errors
2819 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002820 * @return the id of the requested scan which can be used to stop the scan.
2821 */
2822 @Override
2823 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2824 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2826 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002827 return mNetworkScanRequestTracker.startNetworkScan(
2828 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002829 }
2830
2831 /**
2832 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002833 *
2834 * @param subId id of the subscription
2835 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002836 */
2837 @Override
2838 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2840 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002841 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002842 }
2843
2844 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002845 * Get the calculated preferred network type.
2846 * Used for debugging incorrect network type.
2847 *
2848 * @return the preferred network type, defined in RILConstants.java.
2849 */
2850 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002851 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002853 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002854 return RILConstants.PREFERRED_NETWORK_MODE;
2855 }
2856
Amit Mahajan43330e02014-11-18 11:54:45 -08002857 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002858 }
2859
2860 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002861 * Get the preferred network type.
2862 * Used for device configuration by some CDMA operators.
2863 *
2864 * @return the preferred network type, defined in RILConstants.java.
2865 */
2866 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002867 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2869 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002870 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002871 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002872 int networkType = (result != null ? result[0] : -1);
2873 if (DBG) log("getPreferredNetworkType: " + networkType);
2874 return networkType;
2875 }
2876
2877 /**
2878 * Set the preferred network type.
2879 * Used for device configuration by some CDMA operators.
2880 *
2881 * @param networkType the preferred network type, defined in RILConstants.java.
2882 * @return true on success; false on any failure.
2883 */
2884 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002885 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2887 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002888 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2889 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002890 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002891 if (success) {
2892 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002893 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002894 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002895 return success;
2896 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002897
2898 /**
Junda Liu475951f2014-11-07 16:45:03 -08002899 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2900 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2901 * tethering.
2902 *
2903 * @return 0: Not required. 1: required. 2: Not set.
2904 * @hide
2905 */
2906 @Override
2907 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002908 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002909 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2910 Settings.Global.TETHER_DUN_REQUIRED, 2);
2911 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2912 // config_tether_apndata.
2913 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2914 dunRequired = 1;
2915 }
2916 return dunRequired;
2917 }
2918
2919 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002920 * Set mobile data enabled
2921 * Used by the user through settings etc to turn on/off mobile data
2922 *
2923 * @param enable {@code true} turn turn data on, else {@code false}
2924 */
2925 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002926 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2928 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002929 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002930 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002931 Phone phone = PhoneFactory.getPhone(phoneId);
2932 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002933 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2934 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002935 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002936 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002937 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002938 }
2939
2940 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002941 * Get the user enabled state of Mobile Data.
2942 *
2943 * TODO: remove and use isUserDataEnabled.
2944 * This can't be removed now because some vendor codes
2945 * calls through ITelephony directly while they should
2946 * use TelephonyManager.
2947 *
2948 * @return true on enabled
2949 */
2950 @Override
2951 public boolean getDataEnabled(int subId) {
2952 return isUserDataEnabled(subId);
2953 }
2954
2955 /**
2956 * Get whether mobile data is enabled per user setting.
2957 *
2958 * There are other factors deciding whether mobile data is actually enabled, but they are
2959 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002960 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002961 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002962 *
2963 * @return {@code true} if data is enabled else {@code false}
2964 */
2965 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002966 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002967 try {
2968 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2969 null);
2970 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2972 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002973 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002974 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002975 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002976 Phone phone = PhoneFactory.getPhone(phoneId);
2977 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002978 boolean retVal = phone.isUserDataEnabled();
2979 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002980 return retVal;
2981 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002982 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2983 return false;
2984 }
2985 }
2986
2987 /**
2988 * Get whether mobile data is enabled.
2989 *
2990 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2991 * whether mobile data is actually enabled.
2992 *
2993 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2994 *
2995 * @return {@code true} if data is enabled else {@code false}
2996 */
2997 @Override
2998 public boolean isDataEnabled(int subId) {
2999 try {
3000 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3001 null);
3002 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3004 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003005 }
3006 int phoneId = mSubscriptionController.getPhoneId(subId);
3007 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3008 Phone phone = PhoneFactory.getPhone(phoneId);
3009 if (phone != null) {
3010 boolean retVal = phone.isDataEnabled();
3011 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3012 return retVal;
3013 } else {
3014 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08003015 return false;
3016 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003017 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003018
3019 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003020 public int getCarrierPrivilegeStatus(int subId) {
3021 final Phone phone = getPhone(subId);
3022 if (phone == null) {
3023 loge("getCarrierPrivilegeStatus: Invalid subId");
3024 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3025 }
3026 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003027 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003028 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003029 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3030 }
3031 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003032 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003033 }
Junda Liu29340342014-07-10 15:23:27 -07003034
3035 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003036 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3037 final Phone phone = getPhone(subId);
3038 if (phone == null) {
3039 loge("getCarrierPrivilegeStatus: Invalid subId");
3040 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3041 }
3042 UiccProfile profile =
3043 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3044 if (profile == null) {
3045 loge("getCarrierPrivilegeStatus: No UICC");
3046 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3047 }
3048 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3049 }
3050
3051 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003052 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003053 if (TextUtils.isEmpty(pkgName))
3054 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003055 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003056 if (card == null) {
3057 loge("checkCarrierPrivilegesForPackage: No UICC");
3058 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3059 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003060 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3061 }
3062
3063 @Override
3064 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003065 if (TextUtils.isEmpty(pkgName))
3066 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003067 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3068 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3069 UiccCard card = UiccController.getInstance().getUiccCard(i);
3070 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003071 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003072 continue;
3073 }
3074
3075 result = card.getCarrierPrivilegeStatus(
3076 mPhone.getContext().getPackageManager(), pkgName);
3077 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3078 break;
3079 }
3080 }
3081
3082 return result;
Junda Liu29340342014-07-10 15:23:27 -07003083 }
Derek Tan89e89d42014-07-08 17:00:10 -07003084
3085 @Override
Junda Liue64de782015-04-16 17:19:16 -07003086 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3087 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3088 loge("phoneId " + phoneId + " is not valid.");
3089 return null;
3090 }
3091 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003092 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003093 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003094 return null ;
3095 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003096 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003097 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003098 }
3099
Amith Yamasani6e118872016-02-19 12:53:51 -08003100 @Override
3101 public List<String> getPackagesWithCarrierPrivileges() {
3102 PackageManager pm = mPhone.getContext().getPackageManager();
3103 List<String> privilegedPackages = new ArrayList<>();
3104 List<PackageInfo> packages = null;
3105 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3106 UiccCard card = UiccController.getInstance().getUiccCard(i);
3107 if (card == null) {
3108 // No UICC in that slot.
3109 continue;
3110 }
3111 if (card.hasCarrierPrivilegeRules()) {
3112 if (packages == null) {
3113 // Only check packages in user 0 for now
3114 packages = pm.getInstalledPackagesAsUser(
3115 PackageManager.MATCH_DISABLED_COMPONENTS
3116 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3117 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3118 }
3119 for (int p = packages.size() - 1; p >= 0; p--) {
3120 PackageInfo pkgInfo = packages.get(p);
3121 if (pkgInfo != null && pkgInfo.packageName != null
3122 && card.getCarrierPrivilegeStatus(pkgInfo)
3123 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3124 privilegedPackages.add(pkgInfo.packageName);
3125 }
3126 }
3127 }
3128 }
3129 return privilegedPackages;
3130 }
3131
Wink Savilleb564aae2014-10-23 10:18:09 -07003132 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003133 final Phone phone = getPhone(subId);
3134 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003135 if (card == null) {
3136 loge("getIccId: No UICC");
3137 return null;
3138 }
3139 String iccId = card.getIccId();
3140 if (TextUtils.isEmpty(iccId)) {
3141 loge("getIccId: ICC ID is null or empty.");
3142 return null;
3143 }
3144 return iccId;
3145 }
3146
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003147 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003148 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3149 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003150 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3151 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003152
Jeff Sharkey85190e62014-12-05 09:40:12 -08003153 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003154 final Phone phone = getPhone(subId);
3155 if (phone == null) {
3156 return false;
3157 }
3158 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003159
3160 if (DBG_MERGE) {
3161 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3162 + subscriberId + " to " + number);
3163 }
3164
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003165 if (TextUtils.isEmpty(iccId)) {
3166 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003167 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003168
Jeff Sharkey85190e62014-12-05 09:40:12 -08003169 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3170
3171 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003172 if (alphaTag == null) {
3173 editor.remove(alphaTagPrefKey);
3174 } else {
3175 editor.putString(alphaTagPrefKey, alphaTag);
3176 }
3177
Jeff Sharkey85190e62014-12-05 09:40:12 -08003178 // Record both the line number and IMSI for this ICCID, since we need to
3179 // track all merged IMSIs based on line number
3180 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3181 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003182 if (number == null) {
3183 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003184 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003185 } else {
3186 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003187 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003188 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003189
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003190 editor.commit();
3191 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003192 }
3193
3194 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003195 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003196 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003198 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003199 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003200 return null;
3201 }
Derek Tan97ebb422014-09-05 16:55:38 -07003202
3203 String iccId = getIccId(subId);
3204 if (iccId != null) {
3205 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003206 if (DBG_MERGE) {
3207 log("getLine1NumberForDisplay returning " +
3208 mTelephonySharedPreferences.getString(numberPrefKey, null));
3209 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003210 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003211 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003212 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003213 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003214 }
3215
3216 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003217 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003219 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003220 return null;
3221 }
Derek Tan97ebb422014-09-05 16:55:38 -07003222
3223 String iccId = getIccId(subId);
3224 if (iccId != null) {
3225 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003226 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003227 }
Derek Tan97ebb422014-09-05 16:55:38 -07003228 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003229 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003230
3231 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003232 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003233 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3234 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003236 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3237 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003238 return null;
3239 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003240 final Context context = mPhone.getContext();
3241 final TelephonyManager tele = TelephonyManager.from(context);
3242 final SubscriptionManager sub = SubscriptionManager.from(context);
3243
3244 // Figure out what subscribers are currently active
3245 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003246 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3247 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 final int[] subIds = sub.getActiveSubscriptionIdList();
3251 for (int subId : subIds) {
3252 activeSubscriberIds.add(tele.getSubscriberId(subId));
3253 }
3254 } finally {
3255 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003256 }
3257
3258 // First pass, find a number override for an active subscriber
3259 String mergeNumber = null;
3260 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3261 for (String key : prefs.keySet()) {
3262 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3263 final String subscriberId = (String) prefs.get(key);
3264 if (activeSubscriberIds.contains(subscriberId)) {
3265 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3266 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3267 mergeNumber = (String) prefs.get(numberKey);
3268 if (DBG_MERGE) {
3269 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3270 + " for active subscriber " + subscriberId);
3271 }
3272 if (!TextUtils.isEmpty(mergeNumber)) {
3273 break;
3274 }
3275 }
3276 }
3277 }
3278
3279 // Shortcut when no active merged subscribers
3280 if (TextUtils.isEmpty(mergeNumber)) {
3281 return null;
3282 }
3283
3284 // Second pass, find all subscribers under that line override
3285 final ArraySet<String> result = new ArraySet<>();
3286 for (String key : prefs.keySet()) {
3287 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3288 final String number = (String) prefs.get(key);
3289 if (mergeNumber.equals(number)) {
3290 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3291 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3292 final String subscriberId = (String) prefs.get(subscriberKey);
3293 if (!TextUtils.isEmpty(subscriberId)) {
3294 result.add(subscriberId);
3295 }
3296 }
3297 }
3298 }
3299
3300 final String[] resultArray = result.toArray(new String[result.size()]);
3301 Arrays.sort(resultArray);
3302 if (DBG_MERGE) {
3303 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3304 }
3305 return resultArray;
3306 }
3307
3308 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003309 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003310 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3311 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003312 final Phone phone = getPhone(subId);
3313 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003314 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003315
3316 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003317 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003318 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3319 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003320 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003321 final Phone phone = getPhone(subId);
3322 if (phone == null) {
3323 return false;
3324 }
3325 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003326 cdmaNonRoamingList);
3327 }
3328
3329 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003330 public void setRadioCapability(RadioAccessFamily[] rafs) {
3331 try {
3332 ProxyController.getInstance().setRadioCapability(rafs);
3333 } catch (RuntimeException e) {
3334 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3335 }
3336 }
3337
3338 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003339 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003340 Phone phone = PhoneFactory.getPhone(phoneId);
3341 if (phone == null) {
3342 return RadioAccessFamily.RAF_UNKNOWN;
3343 }
3344 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003346 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003347 return RadioAccessFamily.RAF_UNKNOWN;
3348 }
3349
Wink Saville5d475dd2014-10-17 15:00:58 -07003350 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3351 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003352
3353 @Override
3354 public void enableVideoCalling(boolean enable) {
3355 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003356 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003357 }
3358
3359 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003360 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3362 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3363 return false;
3364 }
Svet Ganovb320e182015-04-16 12:30:10 -07003365
Andrew Lee77527ac2014-10-21 16:57:39 -07003366 // Check the user preference and the system-level IMS setting. Even if the user has
3367 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3368 // In the long run, we may instead need to check if there exists a connection service
3369 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003370 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3371 return imsManager.isVtEnabledByPlatform()
3372 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3373 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003374 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003375
Andrew Leea1239f22015-03-02 17:44:07 -08003376 @Override
3377 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003378 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003379 }
3380
3381 @Override
3382 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003383 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003384 }
3385
Andrew Lee9431b832015-03-09 18:46:45 -07003386 @Override
3387 public boolean isTtyModeSupported() {
3388 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3389 TelephonyManager telephonyManager =
3390 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003391 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003392 }
3393
3394 @Override
3395 public boolean isHearingAidCompatibilitySupported() {
3396 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3397 }
3398
Hall Liu98187582018-01-22 19:15:32 -08003399 public boolean isRttSupported() {
3400 boolean isCarrierSupported =
3401 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3402 boolean isDeviceSupported =
3403 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3404 return isCarrierSupported && isDeviceSupported;
3405 }
3406
Hall Liu3ad5f012018-04-06 16:23:39 -07003407 public boolean isRttEnabled() {
3408 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3409 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3410 }
3411
Sanket Padawe7310cc72015-01-14 09:53:20 -08003412 /**
3413 * Returns the unique device ID of phone, for example, the IMEI for
3414 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3415 *
3416 * <p>Requires Permission:
3417 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3418 */
3419 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003420 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003421 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003422 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003423 return null;
3424 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003425 int subId = phone.getSubId();
3426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3427 mApp, subId, callingPackage, "getDeviceId")) {
3428 return null;
3429 }
3430 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003431 }
3432
Ping Sunc67b7c22016-03-02 19:16:45 +08003433 /**
3434 * {@hide}
3435 * Returns the IMS Registration Status on a particular subid
3436 *
3437 * @param subId
3438 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003439 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003440 Phone phone = getPhone(subId);
3441 if (phone != null) {
3442 return phone.isImsRegistered();
3443 } else {
3444 return false;
3445 }
3446 }
3447
Santos Cordon7a1885b2015-02-03 11:15:19 -08003448 @Override
3449 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3450 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3451 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003452
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003453 /**
3454 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003455 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003456 public boolean isWifiCallingAvailable(int subId) {
3457 Phone phone = getPhone(subId);
3458 if (phone != null) {
3459 return phone.isWifiCallingEnabled();
3460 } else {
3461 return false;
3462 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003463 }
3464
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003465 /**
3466 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003467 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003468 public boolean isVolteAvailable(int subId) {
3469 Phone phone = getPhone(subId);
3470 if (phone != null) {
3471 return phone.isVolteEnabled();
3472 } else {
3473 return false;
3474 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003475 }
Svet Ganovb320e182015-04-16 12:30:10 -07003476
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003477 /**
3478 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003479 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003480 public boolean isVideoTelephonyAvailable(int subId) {
3481 Phone phone = getPhone(subId);
3482 if (phone != null) {
3483 return phone.isVideoEnabled();
3484 } else {
3485 return false;
3486 }
3487 }
3488
3489 /**
3490 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3491 * defined in {@link ImsRegistrationImplBase}.
3492 */
3493 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3494 Phone phone = getPhone(subId);
3495 if (phone != null) {
3496 return phone.getImsRegistrationTech();
3497 } else {
3498 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3499 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003500 }
3501
Stuart Scott8eef64f2015-04-08 15:13:54 -07003502 @Override
3503 public void factoryReset(int subId) {
3504 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003505 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3506 return;
3507 }
3508
Svet Ganovcc087f82015-05-12 20:35:54 -07003509 final long identity = Binder.clearCallingIdentity();
3510 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003511 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3512 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003513 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003514 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003515 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3516 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003517 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003518 }
3519 } finally {
3520 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003521 }
3522 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003523
3524 @Override
3525 public String getLocaleFromDefaultSim() {
3526 // We query all subscriptions instead of just the active ones, because
3527 // this might be called early on in the provisioning flow when the
3528 // subscriptions potentially aren't active yet.
3529 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3530 if (slist == null || slist.isEmpty()) {
3531 return null;
3532 }
3533
3534 // This function may be called very early, say, from the setup wizard, at
3535 // which point we won't have a default subscription set. If that's the case
3536 // we just choose the first, which will be valid in "most cases".
3537 final int defaultSubId = getDefaultSubscription();
3538 SubscriptionInfo info = null;
3539 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3540 info = slist.get(0);
3541 } else {
3542 for (SubscriptionInfo item : slist) {
3543 if (item.getSubscriptionId() == defaultSubId) {
3544 info = item;
3545 break;
3546 }
3547 }
3548
3549 if (info == null) {
3550 return null;
3551 }
3552 }
3553
3554 // Try and fetch the locale from the carrier properties or from the SIM language
3555 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003556 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003557 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003558 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003559 if (defaultPhone != null) {
3560 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3561 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003562 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003563 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3564 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003565 } else {
3566 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003567 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003568 }
3569 }
3570
Narayan Kamath011676f2015-07-29 12:04:08 +01003571 // The SIM language preferences only store a language (e.g. fr = French), not an
3572 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3573 // the SIM and carrier preferences does not include a country we add the country
3574 // determined from the SIM MCC to provide an exact locale.
3575 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003576 if (mccLocale != null) {
3577 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3578 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003579 }
3580
Tony Hill183b2de2015-06-24 14:53:58 +01003581 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003582 return null;
3583 }
3584
3585 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 return mSubscriptionController.getAllSubInfoList(
3589 mPhone.getContext().getOpPackageName());
3590 } finally {
3591 Binder.restoreCallingIdentity(identity);
3592 }
3593 }
3594
3595 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 return mSubscriptionController.getActiveSubscriptionInfoList(
3599 mPhone.getContext().getOpPackageName());
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
3602 }
3603 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003604
Chenjie Yu1ba97252018-01-11 18:16:20 -08003605 private final ModemActivityInfo mLastModemActivityInfo =
3606 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3607
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003608 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003609 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3610 * representing the state of the modem.
3611 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003612 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3613 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003614 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003615 */
3616 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003617 public void requestModemActivityInfo(ResultReceiver result) {
3618 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003619 ModemActivityInfo ret = null;
3620 synchronized (mLastModemActivityInfo) {
3621 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3622 null);
3623 if (info != null) {
3624 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3625 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3626 mergedTxTimeMs[i] =
3627 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3628 }
3629 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3630 mLastModemActivityInfo.setSleepTimeMillis(
3631 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3632 mLastModemActivityInfo.setIdleTimeMillis(
3633 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3634 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3635 mLastModemActivityInfo.setRxTimeMillis(
3636 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3637 mLastModemActivityInfo.setEnergyUsed(
3638 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3639 }
3640 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3641 mLastModemActivityInfo.getSleepTimeMillis(),
3642 mLastModemActivityInfo.getIdleTimeMillis(),
3643 mLastModemActivityInfo.getTxTimeMillis(),
3644 mLastModemActivityInfo.getRxTimeMillis(),
3645 mLastModemActivityInfo.getEnergyUsed());
3646 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003647 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003648 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003649 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003650 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003651
3652 /**
3653 * {@hide}
3654 * Returns the service state information on specified subscription.
3655 */
3656 @Override
3657 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3658
Jeff Davidson7e17e312018-02-13 18:17:36 -08003659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003660 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003661 return null;
3662 }
3663
3664 final Phone phone = getPhone(subId);
3665 if (phone == null) {
3666 return null;
3667 }
3668
3669 return phone.getServiceState();
3670 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003671
3672 /**
3673 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3674 *
3675 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3676 * voicemail ringtone.
3677 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3678 * PhoneAccount.
3679 */
3680 @Override
3681 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003682 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003683 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003684 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003685 }
3686
fionaxu7ed723d2017-05-30 18:58:54 -07003687 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003688 }
3689
3690 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003691 * Sets the per-account voicemail ringtone.
3692 *
3693 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3694 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3695 *
3696 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3697 * voicemail ringtone.
3698 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3699 * PhoneAccount.
3700 */
3701 @Override
3702 public void setVoicemailRingtoneUri(String callingPackage,
3703 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3705 if (!TextUtils.equals(callingPackage,
3706 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3708 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3709 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003710 }
3711 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3712 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003713 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003714 }
fionaxu7ed723d2017-05-30 18:58:54 -07003715 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003716 }
3717
3718 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003719 * Returns whether vibration is set for voicemail notification in Phone settings.
3720 *
3721 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3722 * voicemail vibration setting.
3723 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3724 */
3725 @Override
3726 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003727 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003728 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003729 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003730 }
3731
fionaxu7ed723d2017-05-30 18:58:54 -07003732 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003733 }
3734
Youhan Wange64578a2016-05-02 15:32:42 -07003735 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003736 * Sets the per-account voicemail vibration.
3737 *
3738 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3739 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3740 *
3741 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3742 * voicemail vibration setting.
3743 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3744 * specific PhoneAccount.
3745 */
3746 @Override
3747 public void setVoicemailVibrationEnabled(String callingPackage,
3748 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3750 if (!TextUtils.equals(callingPackage,
3751 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3753 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3754 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003755 }
3756
3757 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3758 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003759 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003760 }
fionaxu7ed723d2017-05-30 18:58:54 -07003761 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003762 }
3763
3764 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003765 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3766 *
3767 * @throws SecurityException if the caller does not have the required permission
3768 */
3769 private void enforceReadPrivilegedPermission() {
3770 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3771 null);
3772 }
3773
3774 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003775 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3776 * permission.
3777 *
3778 * @throws SecurityException if the caller does not have the required permission
3779 */
3780 private void enforceSendSmsPermission() {
3781 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3782 }
3783
3784 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003785 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003786 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003787 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003788 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003789 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003790 ComponentName componentName =
3791 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3792 if(componentName == null) {
3793 throw new SecurityException("Caller not current active visual voicemail package[null]");
3794 }
3795 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003796 if (!callingPackage.equals(vvmPackage)) {
3797 throw new SecurityException("Caller not current active visual voicemail package[" +
3798 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003799 }
3800 }
3801
3802 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003803 * Return the application ID for the app type.
3804 *
3805 * @param subId the subscription ID that this request applies to.
3806 * @param appType the uicc app type.
3807 * @return Application ID for specificied app type, or null if no uicc.
3808 */
3809 @Override
3810 public String getAidForAppType(int subId, int appType) {
3811 enforceReadPrivilegedPermission();
3812 Phone phone = getPhone(subId);
3813 if (phone == null) {
3814 return null;
3815 }
3816 String aid = null;
3817 try {
3818 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3819 .getApplicationByType(appType).getAid();
3820 } catch (Exception e) {
3821 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3822 }
3823 return aid;
3824 }
3825
Youhan Wang4001d252016-05-11 10:29:41 -07003826 /**
3827 * Return the Electronic Serial Number.
3828 *
3829 * @param subId the subscription ID that this request applies to.
3830 * @return ESN or null if error.
3831 */
3832 @Override
3833 public String getEsn(int subId) {
3834 enforceReadPrivilegedPermission();
3835 Phone phone = getPhone(subId);
3836 if (phone == null) {
3837 return null;
3838 }
3839 String esn = null;
3840 try {
3841 esn = phone.getEsn();
3842 } catch (Exception e) {
3843 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3844 }
3845 return esn;
3846 }
3847
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003848 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003849 * Return the Preferred Roaming List Version.
3850 *
3851 * @param subId the subscription ID that this request applies to.
3852 * @return PRLVersion or null if error.
3853 */
3854 @Override
3855 public String getCdmaPrlVersion(int subId) {
3856 enforceReadPrivilegedPermission();
3857 Phone phone = getPhone(subId);
3858 if (phone == null) {
3859 return null;
3860 }
3861 String cdmaPrlVersion = null;
3862 try {
3863 cdmaPrlVersion = phone.getCdmaPrlVersion();
3864 } catch (Exception e) {
3865 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3866 }
3867 return cdmaPrlVersion;
3868 }
3869
3870 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003871 * Get snapshot of Telephony histograms
3872 * @return List of Telephony histograms
3873 * @hide
3874 */
3875 @Override
3876 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3878 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003879 return RIL.getTelephonyRILTimingHistograms();
3880 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003881
3882 /**
3883 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003884 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003885 * Require system privileges. In the future we may add this to carrier APIs.
3886 *
3887 * @return The number of carriers set successfully, should match length of carriers
3888 */
3889 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003890 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003891 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003892
Meng Wang9b7c4e92017-02-17 11:41:27 -08003893 if (carriers == null) {
3894 throw new NullPointerException("carriers cannot be null");
3895 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003896
3897 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003898 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3899 return retVal[0];
3900 }
3901
3902 /**
3903 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003904 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003905 * Require system privileges. In the future we may add this to carrier APIs.
3906 *
3907 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3908 * means all carriers are allowed.
3909 */
3910 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003911 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003912 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003913 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003914 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3915 }
3916
fionaxu59545b42016-05-25 15:53:37 -07003917 /**
3918 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3919 * @param subId the subscription ID that this action applies to.
3920 * @param enabled control enable or disable metered apns.
3921 * {@hide}
3922 */
3923 @Override
3924 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3925 enforceModifyPermission();
3926 final Phone phone = getPhone(subId);
3927 if (phone == null) {
3928 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3929 return;
3930 }
3931 try {
3932 phone.carrierActionSetMeteredApnsEnabled(enabled);
3933 } catch (Exception e) {
3934 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3935 }
3936 }
3937
3938 /**
3939 * Action set from carrier signalling broadcast receivers to enable/disable radio
3940 * @param subId the subscription ID that this action applies to.
3941 * @param enabled control enable or disable radio.
3942 * {@hide}
3943 */
3944 @Override
3945 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3946 enforceModifyPermission();
3947 final Phone phone = getPhone(subId);
3948 if (phone == null) {
3949 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3950 return;
3951 }
3952 try {
3953 phone.carrierActionSetRadioEnabled(enabled);
3954 } catch (Exception e) {
3955 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3956 }
3957 }
3958
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003959 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003960 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3961 * network status based on which carrier apps could apply actions accordingly,
3962 * enable/disable default url handler for example.
3963 *
3964 * @param subId the subscription ID that this action applies to.
3965 * @param report control start/stop reporting the default network status.
3966 * {@hide}
3967 */
3968 @Override
3969 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3970 enforceModifyPermission();
3971 final Phone phone = getPhone(subId);
3972 if (phone == null) {
3973 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3974 return;
3975 }
3976 try {
3977 phone.carrierActionReportDefaultNetworkStatus(report);
3978 } catch (Exception e) {
3979 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3980 }
3981 }
3982
3983 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003984 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3985 * bug report is being generated.
3986 */
3987 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003988 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003989 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3990 != PackageManager.PERMISSION_GRANTED) {
3991 writer.println("Permission Denial: can't dump Phone from pid="
3992 + Binder.getCallingPid()
3993 + ", uid=" + Binder.getCallingUid()
3994 + "without permission "
3995 + android.Manifest.permission.DUMP);
3996 return;
3997 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003998 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003999 }
Jack Yueb89b242016-06-22 13:27:47 -07004000
Brad Ebingerdac2f002018-04-03 15:17:52 -07004001 @Override
4002 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4003 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4004 throws RemoteException {
4005 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4006 }
4007
Jack Yueb89b242016-06-22 13:27:47 -07004008 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004009 * Get aggregated video call data usage since boot.
4010 *
4011 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4012 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004013 * {@hide}
4014 */
4015 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004016 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004017 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4018 null);
4019
Jack Yu84291ec2017-05-26 16:07:50 -07004020 // NetworkStatsService keeps tracking the active network interface and identity. It
4021 // records the delta with the corresponding network identity. We just return the total video
4022 // call data usage snapshot since boot.
4023 Phone phone = getPhone(subId);
4024 if (phone != null) {
4025 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004026 }
Jack Yu84291ec2017-05-26 16:07:50 -07004027 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004028 }
Jack Yu75ab2952016-07-08 14:29:33 -07004029
4030 /**
4031 * Policy control of data connection. Usually used when data limit is passed.
4032 * @param enabled True if enabling the data, otherwise disabling.
4033 * @param subId Subscription index
4034 * {@hide}
4035 */
4036 @Override
4037 public void setPolicyDataEnabled(boolean enabled, int subId) {
4038 enforceModifyPermission();
4039 Phone phone = getPhone(subId);
4040 if (phone != null) {
4041 phone.setPolicyDataEnabled(enabled);
4042 }
4043 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004044
4045 /**
4046 * Get Client request stats
4047 * @return List of Client Request Stats
4048 * @hide
4049 */
4050 @Override
4051 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004053 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004054 return null;
4055 }
4056
4057 Phone phone = getPhone(subId);
4058 if (phone != null) {
4059 return phone.getClientRequestStats();
4060 }
4061
4062 return null;
4063 }
4064
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004065 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004066 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004067 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004068 }
Jack Yueb4124c2017-02-16 15:32:43 -08004069
4070 /**
Grace Chen70990072017-03-24 17:21:30 -07004071 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004072 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004073 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004074 * @param state State of SIM (power down, power up, pass through)
4075 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4076 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4077 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004078 *
4079 **/
4080 @Override
Grace Chen70990072017-03-24 17:21:30 -07004081 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004082 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004083 Phone phone = PhoneFactory.getPhone(slotIndex);
4084
Jack Yueb4124c2017-02-16 15:32:43 -08004085 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004086 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004087 }
4088 }
Shuo Qiandd210312017-04-12 22:11:33 +00004089
Tyler Gunn65d45c22017-06-05 11:22:26 -07004090 private boolean isUssdApiAllowed(int subId) {
4091 CarrierConfigManager configManager =
4092 (CarrierConfigManager) mPhone.getContext().getSystemService(
4093 Context.CARRIER_CONFIG_SERVICE);
4094 if (configManager == null) {
4095 return false;
4096 }
4097 PersistableBundle pb = configManager.getConfigForSubId(subId);
4098 if (pb == null) {
4099 return false;
4100 }
4101 return pb.getBoolean(
4102 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4103 }
4104
Shuo Qiandd210312017-04-12 22:11:33 +00004105 /**
4106 * Check if phone is in emergency callback mode
4107 * @return true if phone is in emergency callback mode
4108 * @param subId sub id
4109 */
goneil9c5f4872017-12-05 14:07:56 -08004110 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004111 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004112 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004113 final Phone phone = getPhone(subId);
4114 if (phone != null) {
4115 return phone.isInEcm();
4116 } else {
4117 return false;
4118 }
4119 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004120
4121 /**
4122 * Get the current signal strength information for the given subscription.
4123 * Because this information is not updated when the device is in a low power state
4124 * it should not be relied-upon to be current.
4125 * @param subId Subscription index
4126 * @return the most recent cached signal strength info from the modem
4127 */
4128 @Override
4129 public SignalStrength getSignalStrength(int subId) {
4130 Phone p = getPhone(subId);
4131 if (p == null) {
4132 return null;
4133 }
4134
4135 return p.getSignalStrength();
4136 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004137
4138 @Override
4139 public UiccSlotInfo[] getUiccSlotsInfo() {
4140 enforceReadPrivilegedPermission();
4141
4142 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004143 if (slots == null) {
4144 Rlog.i(LOG_TAG, "slots is null.");
4145 return null;
4146 }
4147
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004148 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4149 for (int i = 0; i < slots.length; i++) {
4150 UiccSlot slot = slots[i];
4151
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004152 String cardId = null;
4153 UiccCard card = slot.getUiccCard();
4154 if (card != null) {
4155 cardId = card.getCardId();
4156 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004157
4158 int cardState = 0;
4159 switch (slot.getCardState()) {
4160 case CARDSTATE_ABSENT:
4161 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4162 break;
4163 case CARDSTATE_PRESENT:
4164 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4165 break;
4166 case CARDSTATE_ERROR:
4167 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4168 break;
4169 case CARDSTATE_RESTRICTED:
4170 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4171 break;
4172 default:
4173 break;
4174
4175 }
4176
Qingxi Li795c5882018-01-31 13:43:27 -08004177 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004178 slot.isActive(),
4179 slot.isEuicc(),
4180 cardId,
4181 cardState,
4182 slot.getPhoneId(),
4183 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004184 }
4185 return infos;
4186 }
4187
4188 @Override
4189 public boolean switchSlots(int[] physicalSlots) {
4190 enforceModifyPermission();
4191 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4192 }
Jack Yu4c988042018-02-27 15:30:01 -08004193
4194 @Override
4195 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4196 enforceModifyPermission();
4197 final Phone phone = getPhone(subId);
4198 if (phone == null) {
4199 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4200 return;
4201 }
4202
4203 phone.setRadioIndicationUpdateMode(filters, mode);
4204 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004205
4206 /**
goneil47ffb6e2018-04-06 15:40:58 -07004207 * A test API to reload the UICC profile.
4208 *
4209 * <p>Requires that the calling app has permission
4210 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4211 * @hide
4212 */
4213 @Override
4214 public void refreshUiccProfile(int subId) {
4215 enforceModifyPermission();
4216
4217 final long identity = Binder.clearCallingIdentity();
4218 try {
4219 Phone phone = getPhone(subId);
4220 if (phone == null) {
4221 return;
4222 }
4223 UiccCard uiccCard = phone.getUiccCard();
4224 if (uiccCard == null) {
4225 return;
4226 }
4227 UiccProfile uiccProfile = uiccCard.getUiccProfile();
4228 if (uiccProfile == null) {
4229 return;
4230 }
4231 uiccProfile.refresh();
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
4234 }
4235 }
4236
4237 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07004238 * Returns false if the mobile data is disabled by default, otherwise return true.
4239 */
4240 private boolean getDefaultDataEnabled() {
4241 return "true".equalsIgnoreCase(
4242 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4243 }
4244
4245 /**
4246 * Returns true if the data roaming is enabled by default, i.e the system property
4247 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4248 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4249 */
4250 private boolean getDefaultDataRoamingEnabled(int subId) {
4251 final CarrierConfigManager configMgr = (CarrierConfigManager)
4252 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4253 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4254 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4255 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4256 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4257 return isDataRoamingEnabled;
4258 }
4259
4260 /**
4261 * Returns the default network type for the given {@code subId}, if the default network type is
4262 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4263 */
4264 private int getDefaultNetworkType(int subId) {
4265 return Integer.parseInt(
4266 TelephonyManager.getTelephonyProperty(
4267 mSubscriptionController.getPhoneId(subId),
4268 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4269 String.valueOf(Phone.PREFERRED_NT_MODE)));
4270 }
fionaxua13278b2018-03-21 00:08:13 -07004271
4272 @Override
4273 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4274 gid1, String gid2, String plmn, String spn) {
4275 enforceModifyPermission();
4276 final Phone phone = getPhone(subId);
4277 if (phone == null) {
4278 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4279 return;
4280 }
4281 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4282 }
4283
4284 @Override
4285 public int getCarrierIdListVersion(int subId) {
4286 enforceReadPrivilegedPermission();
4287 final Phone phone = getPhone(subId);
4288 if (phone == null) {
4289 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4290 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4291 }
4292 return phone.getCarrierIdListVersion();
4293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004294}