blob: fad4698ebe9068caedf162ec95ad8d8358fe49f8 [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) {
2738 enforceModifyPermission();
2739 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
2740 isCarrierImsService, packageName);
2741 }
2742
2743 /**
2744 * Return the ImsService configuration.
2745 *
2746 * @param slotId The slot that the ImsService is associated with.
2747 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
2748 * the device default.
2749 * @return the package name of the ImsService configuration.
2750 */
2751 public String getImsService(int slotId, boolean isCarrierImsService) {
2752 enforceReadPrivilegedPermission();
2753 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
2754 isCarrierImsService);
2755 }
2756
Wink Saville36469e72014-06-11 15:17:00 -07002757 public void setImsRegistrationState(boolean registered) {
2758 enforceModifyPermission();
2759 mPhone.setImsRegistrationState(registered);
2760 }
2761
2762 /**
Stuart Scott54788802015-03-30 13:18:01 -07002763 * Set the network selection mode to automatic.
2764 *
2765 */
2766 @Override
2767 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2769 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002770 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2771 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2772 }
2773
2774 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002775 * Set the network selection mode to manual with the selected carrier.
2776 */
2777 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002778 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002779 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2781 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002782 OperatorInfo operator = new OperatorInfo(
2783 /* operatorAlphaLong */ "",
2784 /* operatorAlphaShort */ "",
2785 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002786 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002787 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2788 persistSelection);
2789 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002790 }
2791
2792 /**
2793 * Scans for available networks.
2794 */
2795 @Override
2796 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2798 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002799 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2800 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2801 CMD_PERFORM_NETWORK_SCAN, null, subId);
2802 return result;
2803 }
2804
2805 /**
yinxub1bed742017-04-17 11:45:04 -07002806 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002807 *
yinxub1bed742017-04-17 11:45:04 -07002808 * @param subId id of the subscription
2809 * @param request contains the radio access networks with bands/channels to scan
2810 * @param messenger callback messenger for scan results or errors
2811 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002812 * @return the id of the requested scan which can be used to stop the scan.
2813 */
2814 @Override
2815 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2816 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2818 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002819 return mNetworkScanRequestTracker.startNetworkScan(
2820 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002821 }
2822
2823 /**
2824 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002825 *
2826 * @param subId id of the subscription
2827 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002828 */
2829 @Override
2830 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2832 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002833 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002834 }
2835
2836 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002837 * Get the calculated preferred network type.
2838 * Used for debugging incorrect network type.
2839 *
2840 * @return the preferred network type, defined in RILConstants.java.
2841 */
2842 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002843 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002845 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002846 return RILConstants.PREFERRED_NETWORK_MODE;
2847 }
2848
Amit Mahajan43330e02014-11-18 11:54:45 -08002849 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002850 }
2851
2852 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002853 * Get the preferred network type.
2854 * Used for device configuration by some CDMA operators.
2855 *
2856 * @return the preferred network type, defined in RILConstants.java.
2857 */
2858 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002859 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2861 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002862 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002863 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002864 int networkType = (result != null ? result[0] : -1);
2865 if (DBG) log("getPreferredNetworkType: " + networkType);
2866 return networkType;
2867 }
2868
2869 /**
2870 * Set the preferred network type.
2871 * Used for device configuration by some CDMA operators.
2872 *
2873 * @param networkType the preferred network type, defined in RILConstants.java.
2874 * @return true on success; false on any failure.
2875 */
2876 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002877 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2879 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002880 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2881 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002882 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002883 if (success) {
2884 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002885 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002886 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002887 return success;
2888 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002889
2890 /**
Junda Liu475951f2014-11-07 16:45:03 -08002891 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2892 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2893 * tethering.
2894 *
2895 * @return 0: Not required. 1: required. 2: Not set.
2896 * @hide
2897 */
2898 @Override
2899 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002900 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002901 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2902 Settings.Global.TETHER_DUN_REQUIRED, 2);
2903 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2904 // config_tether_apndata.
2905 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2906 dunRequired = 1;
2907 }
2908 return dunRequired;
2909 }
2910
2911 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002912 * Set mobile data enabled
2913 * Used by the user through settings etc to turn on/off mobile data
2914 *
2915 * @param enable {@code true} turn turn data on, else {@code false}
2916 */
2917 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002918 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2920 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002921 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002922 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002923 Phone phone = PhoneFactory.getPhone(phoneId);
2924 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002925 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2926 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002927 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002928 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002929 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002930 }
2931
2932 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002933 * Get the user enabled state of Mobile Data.
2934 *
2935 * TODO: remove and use isUserDataEnabled.
2936 * This can't be removed now because some vendor codes
2937 * calls through ITelephony directly while they should
2938 * use TelephonyManager.
2939 *
2940 * @return true on enabled
2941 */
2942 @Override
2943 public boolean getDataEnabled(int subId) {
2944 return isUserDataEnabled(subId);
2945 }
2946
2947 /**
2948 * Get whether mobile data is enabled per user setting.
2949 *
2950 * There are other factors deciding whether mobile data is actually enabled, but they are
2951 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002952 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002953 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002954 *
2955 * @return {@code true} if data is enabled else {@code false}
2956 */
2957 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002958 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002959 try {
2960 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2961 null);
2962 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2964 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002965 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002966 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002967 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002968 Phone phone = PhoneFactory.getPhone(phoneId);
2969 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002970 boolean retVal = phone.isUserDataEnabled();
2971 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002972 return retVal;
2973 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002974 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2975 return false;
2976 }
2977 }
2978
2979 /**
2980 * Get whether mobile data is enabled.
2981 *
2982 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2983 * whether mobile data is actually enabled.
2984 *
2985 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2986 *
2987 * @return {@code true} if data is enabled else {@code false}
2988 */
2989 @Override
2990 public boolean isDataEnabled(int subId) {
2991 try {
2992 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2993 null);
2994 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2996 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002997 }
2998 int phoneId = mSubscriptionController.getPhoneId(subId);
2999 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3000 Phone phone = PhoneFactory.getPhone(phoneId);
3001 if (phone != null) {
3002 boolean retVal = phone.isDataEnabled();
3003 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3004 return retVal;
3005 } else {
3006 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08003007 return false;
3008 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003009 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003010
3011 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003012 public int getCarrierPrivilegeStatus(int subId) {
3013 final Phone phone = getPhone(subId);
3014 if (phone == null) {
3015 loge("getCarrierPrivilegeStatus: Invalid subId");
3016 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3017 }
3018 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003019 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003020 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003021 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3022 }
3023 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003024 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003025 }
Junda Liu29340342014-07-10 15:23:27 -07003026
3027 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003028 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3029 final Phone phone = getPhone(subId);
3030 if (phone == null) {
3031 loge("getCarrierPrivilegeStatus: Invalid subId");
3032 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3033 }
3034 UiccProfile profile =
3035 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3036 if (profile == null) {
3037 loge("getCarrierPrivilegeStatus: No UICC");
3038 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3039 }
3040 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3041 }
3042
3043 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003044 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003045 if (TextUtils.isEmpty(pkgName))
3046 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003047 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003048 if (card == null) {
3049 loge("checkCarrierPrivilegesForPackage: No UICC");
3050 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3051 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003052 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3053 }
3054
3055 @Override
3056 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003057 if (TextUtils.isEmpty(pkgName))
3058 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003059 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3060 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3061 UiccCard card = UiccController.getInstance().getUiccCard(i);
3062 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003063 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003064 continue;
3065 }
3066
3067 result = card.getCarrierPrivilegeStatus(
3068 mPhone.getContext().getPackageManager(), pkgName);
3069 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3070 break;
3071 }
3072 }
3073
3074 return result;
Junda Liu29340342014-07-10 15:23:27 -07003075 }
Derek Tan89e89d42014-07-08 17:00:10 -07003076
3077 @Override
Junda Liue64de782015-04-16 17:19:16 -07003078 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3079 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3080 loge("phoneId " + phoneId + " is not valid.");
3081 return null;
3082 }
3083 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003084 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003085 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003086 return null ;
3087 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003088 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003089 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003090 }
3091
Amith Yamasani6e118872016-02-19 12:53:51 -08003092 @Override
3093 public List<String> getPackagesWithCarrierPrivileges() {
3094 PackageManager pm = mPhone.getContext().getPackageManager();
3095 List<String> privilegedPackages = new ArrayList<>();
3096 List<PackageInfo> packages = null;
3097 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3098 UiccCard card = UiccController.getInstance().getUiccCard(i);
3099 if (card == null) {
3100 // No UICC in that slot.
3101 continue;
3102 }
3103 if (card.hasCarrierPrivilegeRules()) {
3104 if (packages == null) {
3105 // Only check packages in user 0 for now
3106 packages = pm.getInstalledPackagesAsUser(
3107 PackageManager.MATCH_DISABLED_COMPONENTS
3108 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3109 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3110 }
3111 for (int p = packages.size() - 1; p >= 0; p--) {
3112 PackageInfo pkgInfo = packages.get(p);
3113 if (pkgInfo != null && pkgInfo.packageName != null
3114 && card.getCarrierPrivilegeStatus(pkgInfo)
3115 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3116 privilegedPackages.add(pkgInfo.packageName);
3117 }
3118 }
3119 }
3120 }
3121 return privilegedPackages;
3122 }
3123
Wink Savilleb564aae2014-10-23 10:18:09 -07003124 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003125 final Phone phone = getPhone(subId);
3126 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003127 if (card == null) {
3128 loge("getIccId: No UICC");
3129 return null;
3130 }
3131 String iccId = card.getIccId();
3132 if (TextUtils.isEmpty(iccId)) {
3133 loge("getIccId: ICC ID is null or empty.");
3134 return null;
3135 }
3136 return iccId;
3137 }
3138
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003139 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003140 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3141 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003142 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3143 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003144
Jeff Sharkey85190e62014-12-05 09:40:12 -08003145 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003146 final Phone phone = getPhone(subId);
3147 if (phone == null) {
3148 return false;
3149 }
3150 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003151
3152 if (DBG_MERGE) {
3153 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3154 + subscriberId + " to " + number);
3155 }
3156
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003157 if (TextUtils.isEmpty(iccId)) {
3158 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003159 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003160
Jeff Sharkey85190e62014-12-05 09:40:12 -08003161 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3162
3163 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003164 if (alphaTag == null) {
3165 editor.remove(alphaTagPrefKey);
3166 } else {
3167 editor.putString(alphaTagPrefKey, alphaTag);
3168 }
3169
Jeff Sharkey85190e62014-12-05 09:40:12 -08003170 // Record both the line number and IMSI for this ICCID, since we need to
3171 // track all merged IMSIs based on line number
3172 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3173 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003174 if (number == null) {
3175 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003176 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003177 } else {
3178 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003179 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003180 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003181
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003182 editor.commit();
3183 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003184 }
3185
3186 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003187 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003188 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003190 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003191 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003192 return null;
3193 }
Derek Tan97ebb422014-09-05 16:55:38 -07003194
3195 String iccId = getIccId(subId);
3196 if (iccId != null) {
3197 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003198 if (DBG_MERGE) {
3199 log("getLine1NumberForDisplay returning " +
3200 mTelephonySharedPreferences.getString(numberPrefKey, null));
3201 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003202 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003203 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003204 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003205 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003206 }
3207
3208 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003209 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003210 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003211 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003212 return null;
3213 }
Derek Tan97ebb422014-09-05 16:55:38 -07003214
3215 String iccId = getIccId(subId);
3216 if (iccId != null) {
3217 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003218 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003219 }
Derek Tan97ebb422014-09-05 16:55:38 -07003220 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003221 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003222
3223 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003224 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003225 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3226 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003227 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003228 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3229 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003230 return null;
3231 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003232 final Context context = mPhone.getContext();
3233 final TelephonyManager tele = TelephonyManager.from(context);
3234 final SubscriptionManager sub = SubscriptionManager.from(context);
3235
3236 // Figure out what subscribers are currently active
3237 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003238 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3239 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 final int[] subIds = sub.getActiveSubscriptionIdList();
3243 for (int subId : subIds) {
3244 activeSubscriberIds.add(tele.getSubscriberId(subId));
3245 }
3246 } finally {
3247 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003248 }
3249
3250 // First pass, find a number override for an active subscriber
3251 String mergeNumber = null;
3252 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3253 for (String key : prefs.keySet()) {
3254 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3255 final String subscriberId = (String) prefs.get(key);
3256 if (activeSubscriberIds.contains(subscriberId)) {
3257 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3258 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3259 mergeNumber = (String) prefs.get(numberKey);
3260 if (DBG_MERGE) {
3261 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3262 + " for active subscriber " + subscriberId);
3263 }
3264 if (!TextUtils.isEmpty(mergeNumber)) {
3265 break;
3266 }
3267 }
3268 }
3269 }
3270
3271 // Shortcut when no active merged subscribers
3272 if (TextUtils.isEmpty(mergeNumber)) {
3273 return null;
3274 }
3275
3276 // Second pass, find all subscribers under that line override
3277 final ArraySet<String> result = new ArraySet<>();
3278 for (String key : prefs.keySet()) {
3279 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3280 final String number = (String) prefs.get(key);
3281 if (mergeNumber.equals(number)) {
3282 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3283 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3284 final String subscriberId = (String) prefs.get(subscriberKey);
3285 if (!TextUtils.isEmpty(subscriberId)) {
3286 result.add(subscriberId);
3287 }
3288 }
3289 }
3290 }
3291
3292 final String[] resultArray = result.toArray(new String[result.size()]);
3293 Arrays.sort(resultArray);
3294 if (DBG_MERGE) {
3295 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3296 }
3297 return resultArray;
3298 }
3299
3300 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003301 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003302 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3303 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003304 final Phone phone = getPhone(subId);
3305 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003306 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003307
3308 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003309 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003310 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3311 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003312 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003313 final Phone phone = getPhone(subId);
3314 if (phone == null) {
3315 return false;
3316 }
3317 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003318 cdmaNonRoamingList);
3319 }
3320
3321 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003322 public void setRadioCapability(RadioAccessFamily[] rafs) {
3323 try {
3324 ProxyController.getInstance().setRadioCapability(rafs);
3325 } catch (RuntimeException e) {
3326 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3327 }
3328 }
3329
3330 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003331 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003332 Phone phone = PhoneFactory.getPhone(phoneId);
3333 if (phone == null) {
3334 return RadioAccessFamily.RAF_UNKNOWN;
3335 }
3336 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003338 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003339 return RadioAccessFamily.RAF_UNKNOWN;
3340 }
3341
Wink Saville5d475dd2014-10-17 15:00:58 -07003342 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3343 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003344
3345 @Override
3346 public void enableVideoCalling(boolean enable) {
3347 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003348 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003349 }
3350
3351 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003352 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003353 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3354 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3355 return false;
3356 }
Svet Ganovb320e182015-04-16 12:30:10 -07003357
Andrew Lee77527ac2014-10-21 16:57:39 -07003358 // Check the user preference and the system-level IMS setting. Even if the user has
3359 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3360 // In the long run, we may instead need to check if there exists a connection service
3361 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003362 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3363 return imsManager.isVtEnabledByPlatform()
3364 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3365 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003366 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003367
Andrew Leea1239f22015-03-02 17:44:07 -08003368 @Override
3369 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003370 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003371 }
3372
3373 @Override
3374 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003375 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003376 }
3377
Andrew Lee9431b832015-03-09 18:46:45 -07003378 @Override
3379 public boolean isTtyModeSupported() {
3380 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3381 TelephonyManager telephonyManager =
3382 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003383 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003384 }
3385
3386 @Override
3387 public boolean isHearingAidCompatibilitySupported() {
3388 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3389 }
3390
Hall Liu98187582018-01-22 19:15:32 -08003391 public boolean isRttSupported() {
3392 boolean isCarrierSupported =
3393 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3394 boolean isDeviceSupported =
3395 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3396 return isCarrierSupported && isDeviceSupported;
3397 }
3398
Sanket Padawe7310cc72015-01-14 09:53:20 -08003399 /**
3400 * Returns the unique device ID of phone, for example, the IMEI for
3401 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3402 *
3403 * <p>Requires Permission:
3404 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3405 */
3406 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003407 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003408 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003409 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003410 return null;
3411 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003412 int subId = phone.getSubId();
3413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3414 mApp, subId, callingPackage, "getDeviceId")) {
3415 return null;
3416 }
3417 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003418 }
3419
Ping Sunc67b7c22016-03-02 19:16:45 +08003420 /**
3421 * {@hide}
3422 * Returns the IMS Registration Status on a particular subid
3423 *
3424 * @param subId
3425 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003426 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003427 Phone phone = getPhone(subId);
3428 if (phone != null) {
3429 return phone.isImsRegistered();
3430 } else {
3431 return false;
3432 }
3433 }
3434
Santos Cordon7a1885b2015-02-03 11:15:19 -08003435 @Override
3436 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3437 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3438 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003439
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003440 /**
3441 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003442 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003443 public boolean isWifiCallingAvailable(int subId) {
3444 Phone phone = getPhone(subId);
3445 if (phone != null) {
3446 return phone.isWifiCallingEnabled();
3447 } else {
3448 return false;
3449 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003450 }
3451
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003452 /**
3453 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003454 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003455 public boolean isVolteAvailable(int subId) {
3456 Phone phone = getPhone(subId);
3457 if (phone != null) {
3458 return phone.isVolteEnabled();
3459 } else {
3460 return false;
3461 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003462 }
Svet Ganovb320e182015-04-16 12:30:10 -07003463
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003464 /**
3465 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003466 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003467 public boolean isVideoTelephonyAvailable(int subId) {
3468 Phone phone = getPhone(subId);
3469 if (phone != null) {
3470 return phone.isVideoEnabled();
3471 } else {
3472 return false;
3473 }
3474 }
3475
3476 /**
3477 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3478 * defined in {@link ImsRegistrationImplBase}.
3479 */
3480 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3481 Phone phone = getPhone(subId);
3482 if (phone != null) {
3483 return phone.getImsRegistrationTech();
3484 } else {
3485 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3486 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003487 }
3488
Stuart Scott8eef64f2015-04-08 15:13:54 -07003489 @Override
3490 public void factoryReset(int subId) {
3491 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003492 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3493 return;
3494 }
3495
Svet Ganovcc087f82015-05-12 20:35:54 -07003496 final long identity = Binder.clearCallingIdentity();
3497 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003498 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3499 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003500 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003501 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003502 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3503 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003504 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003505 }
3506 } finally {
3507 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003508 }
3509 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003510
3511 @Override
3512 public String getLocaleFromDefaultSim() {
3513 // We query all subscriptions instead of just the active ones, because
3514 // this might be called early on in the provisioning flow when the
3515 // subscriptions potentially aren't active yet.
3516 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3517 if (slist == null || slist.isEmpty()) {
3518 return null;
3519 }
3520
3521 // This function may be called very early, say, from the setup wizard, at
3522 // which point we won't have a default subscription set. If that's the case
3523 // we just choose the first, which will be valid in "most cases".
3524 final int defaultSubId = getDefaultSubscription();
3525 SubscriptionInfo info = null;
3526 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3527 info = slist.get(0);
3528 } else {
3529 for (SubscriptionInfo item : slist) {
3530 if (item.getSubscriptionId() == defaultSubId) {
3531 info = item;
3532 break;
3533 }
3534 }
3535
3536 if (info == null) {
3537 return null;
3538 }
3539 }
3540
3541 // Try and fetch the locale from the carrier properties or from the SIM language
3542 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003543 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003544 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003545 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003546 if (defaultPhone != null) {
3547 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3548 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003549 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003550 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3551 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003552 } else {
3553 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003554 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003555 }
3556 }
3557
Narayan Kamath011676f2015-07-29 12:04:08 +01003558 // The SIM language preferences only store a language (e.g. fr = French), not an
3559 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3560 // the SIM and carrier preferences does not include a country we add the country
3561 // determined from the SIM MCC to provide an exact locale.
3562 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003563 if (mccLocale != null) {
3564 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3565 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003566 }
3567
Tony Hill183b2de2015-06-24 14:53:58 +01003568 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003569 return null;
3570 }
3571
3572 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 return mSubscriptionController.getAllSubInfoList(
3576 mPhone.getContext().getOpPackageName());
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
3580 }
3581
3582 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 return mSubscriptionController.getActiveSubscriptionInfoList(
3586 mPhone.getContext().getOpPackageName());
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
3590 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003591
Chenjie Yu1ba97252018-01-11 18:16:20 -08003592 private final ModemActivityInfo mLastModemActivityInfo =
3593 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3594
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003595 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003596 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3597 * representing the state of the modem.
3598 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003599 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3600 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003601 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003602 */
3603 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003604 public void requestModemActivityInfo(ResultReceiver result) {
3605 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003606 ModemActivityInfo ret = null;
3607 synchronized (mLastModemActivityInfo) {
3608 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3609 null);
3610 if (info != null) {
3611 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3612 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3613 mergedTxTimeMs[i] =
3614 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3615 }
3616 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3617 mLastModemActivityInfo.setSleepTimeMillis(
3618 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3619 mLastModemActivityInfo.setIdleTimeMillis(
3620 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3621 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3622 mLastModemActivityInfo.setRxTimeMillis(
3623 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3624 mLastModemActivityInfo.setEnergyUsed(
3625 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3626 }
3627 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3628 mLastModemActivityInfo.getSleepTimeMillis(),
3629 mLastModemActivityInfo.getIdleTimeMillis(),
3630 mLastModemActivityInfo.getTxTimeMillis(),
3631 mLastModemActivityInfo.getRxTimeMillis(),
3632 mLastModemActivityInfo.getEnergyUsed());
3633 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003634 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003635 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003636 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003637 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003638
3639 /**
3640 * {@hide}
3641 * Returns the service state information on specified subscription.
3642 */
3643 @Override
3644 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3645
Jeff Davidson7e17e312018-02-13 18:17:36 -08003646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003647 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003648 return null;
3649 }
3650
3651 final Phone phone = getPhone(subId);
3652 if (phone == null) {
3653 return null;
3654 }
3655
3656 return phone.getServiceState();
3657 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003658
3659 /**
3660 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3661 *
3662 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3663 * voicemail ringtone.
3664 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3665 * PhoneAccount.
3666 */
3667 @Override
3668 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003669 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003670 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003671 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003672 }
3673
fionaxu7ed723d2017-05-30 18:58:54 -07003674 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003675 }
3676
3677 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003678 * Sets the per-account voicemail ringtone.
3679 *
3680 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3681 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3682 *
3683 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3684 * voicemail ringtone.
3685 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3686 * PhoneAccount.
3687 */
3688 @Override
3689 public void setVoicemailRingtoneUri(String callingPackage,
3690 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3691 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3692 if (!TextUtils.equals(callingPackage,
3693 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3695 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3696 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003697 }
3698 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3699 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003700 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003701 }
fionaxu7ed723d2017-05-30 18:58:54 -07003702 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003703 }
3704
3705 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003706 * Returns whether vibration is set for voicemail notification in Phone settings.
3707 *
3708 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3709 * voicemail vibration setting.
3710 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3711 */
3712 @Override
3713 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003714 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003715 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003716 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003717 }
3718
fionaxu7ed723d2017-05-30 18:58:54 -07003719 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003720 }
3721
Youhan Wange64578a2016-05-02 15:32:42 -07003722 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003723 * Sets the per-account voicemail vibration.
3724 *
3725 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3726 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3727 *
3728 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3729 * voicemail vibration setting.
3730 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3731 * specific PhoneAccount.
3732 */
3733 @Override
3734 public void setVoicemailVibrationEnabled(String callingPackage,
3735 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3737 if (!TextUtils.equals(callingPackage,
3738 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3740 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3741 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003742 }
3743
3744 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3745 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003746 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003747 }
fionaxu7ed723d2017-05-30 18:58:54 -07003748 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003749 }
3750
3751 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003752 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3753 *
3754 * @throws SecurityException if the caller does not have the required permission
3755 */
3756 private void enforceReadPrivilegedPermission() {
3757 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3758 null);
3759 }
3760
3761 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003762 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3763 * permission.
3764 *
3765 * @throws SecurityException if the caller does not have the required permission
3766 */
3767 private void enforceSendSmsPermission() {
3768 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3769 }
3770
3771 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003772 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003773 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003774 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003775 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003776 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003777 ComponentName componentName =
3778 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3779 if(componentName == null) {
3780 throw new SecurityException("Caller not current active visual voicemail package[null]");
3781 }
3782 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003783 if (!callingPackage.equals(vvmPackage)) {
3784 throw new SecurityException("Caller not current active visual voicemail package[" +
3785 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003786 }
3787 }
3788
3789 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003790 * Return the application ID for the app type.
3791 *
3792 * @param subId the subscription ID that this request applies to.
3793 * @param appType the uicc app type.
3794 * @return Application ID for specificied app type, or null if no uicc.
3795 */
3796 @Override
3797 public String getAidForAppType(int subId, int appType) {
3798 enforceReadPrivilegedPermission();
3799 Phone phone = getPhone(subId);
3800 if (phone == null) {
3801 return null;
3802 }
3803 String aid = null;
3804 try {
3805 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3806 .getApplicationByType(appType).getAid();
3807 } catch (Exception e) {
3808 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3809 }
3810 return aid;
3811 }
3812
Youhan Wang4001d252016-05-11 10:29:41 -07003813 /**
3814 * Return the Electronic Serial Number.
3815 *
3816 * @param subId the subscription ID that this request applies to.
3817 * @return ESN or null if error.
3818 */
3819 @Override
3820 public String getEsn(int subId) {
3821 enforceReadPrivilegedPermission();
3822 Phone phone = getPhone(subId);
3823 if (phone == null) {
3824 return null;
3825 }
3826 String esn = null;
3827 try {
3828 esn = phone.getEsn();
3829 } catch (Exception e) {
3830 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3831 }
3832 return esn;
3833 }
3834
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003835 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003836 * Return the Preferred Roaming List Version.
3837 *
3838 * @param subId the subscription ID that this request applies to.
3839 * @return PRLVersion or null if error.
3840 */
3841 @Override
3842 public String getCdmaPrlVersion(int subId) {
3843 enforceReadPrivilegedPermission();
3844 Phone phone = getPhone(subId);
3845 if (phone == null) {
3846 return null;
3847 }
3848 String cdmaPrlVersion = null;
3849 try {
3850 cdmaPrlVersion = phone.getCdmaPrlVersion();
3851 } catch (Exception e) {
3852 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3853 }
3854 return cdmaPrlVersion;
3855 }
3856
3857 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003858 * Get snapshot of Telephony histograms
3859 * @return List of Telephony histograms
3860 * @hide
3861 */
3862 @Override
3863 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3865 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003866 return RIL.getTelephonyRILTimingHistograms();
3867 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003868
3869 /**
3870 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003871 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003872 * Require system privileges. In the future we may add this to carrier APIs.
3873 *
3874 * @return The number of carriers set successfully, should match length of carriers
3875 */
3876 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003877 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003878 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003879
Meng Wang9b7c4e92017-02-17 11:41:27 -08003880 if (carriers == null) {
3881 throw new NullPointerException("carriers cannot be null");
3882 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003883
3884 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003885 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3886 return retVal[0];
3887 }
3888
3889 /**
3890 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003891 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003892 * Require system privileges. In the future we may add this to carrier APIs.
3893 *
3894 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3895 * means all carriers are allowed.
3896 */
3897 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003898 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003899 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003900 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003901 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3902 }
3903
fionaxu59545b42016-05-25 15:53:37 -07003904 /**
3905 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3906 * @param subId the subscription ID that this action applies to.
3907 * @param enabled control enable or disable metered apns.
3908 * {@hide}
3909 */
3910 @Override
3911 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3912 enforceModifyPermission();
3913 final Phone phone = getPhone(subId);
3914 if (phone == null) {
3915 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3916 return;
3917 }
3918 try {
3919 phone.carrierActionSetMeteredApnsEnabled(enabled);
3920 } catch (Exception e) {
3921 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3922 }
3923 }
3924
3925 /**
3926 * Action set from carrier signalling broadcast receivers to enable/disable radio
3927 * @param subId the subscription ID that this action applies to.
3928 * @param enabled control enable or disable radio.
3929 * {@hide}
3930 */
3931 @Override
3932 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3933 enforceModifyPermission();
3934 final Phone phone = getPhone(subId);
3935 if (phone == null) {
3936 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3937 return;
3938 }
3939 try {
3940 phone.carrierActionSetRadioEnabled(enabled);
3941 } catch (Exception e) {
3942 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3943 }
3944 }
3945
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003946 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003947 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3948 * network status based on which carrier apps could apply actions accordingly,
3949 * enable/disable default url handler for example.
3950 *
3951 * @param subId the subscription ID that this action applies to.
3952 * @param report control start/stop reporting the default network status.
3953 * {@hide}
3954 */
3955 @Override
3956 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3957 enforceModifyPermission();
3958 final Phone phone = getPhone(subId);
3959 if (phone == null) {
3960 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3961 return;
3962 }
3963 try {
3964 phone.carrierActionReportDefaultNetworkStatus(report);
3965 } catch (Exception e) {
3966 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3967 }
3968 }
3969
3970 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003971 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3972 * bug report is being generated.
3973 */
3974 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003975 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003976 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3977 != PackageManager.PERMISSION_GRANTED) {
3978 writer.println("Permission Denial: can't dump Phone from pid="
3979 + Binder.getCallingPid()
3980 + ", uid=" + Binder.getCallingUid()
3981 + "without permission "
3982 + android.Manifest.permission.DUMP);
3983 return;
3984 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003985 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003986 }
Jack Yueb89b242016-06-22 13:27:47 -07003987
Brad Ebingerdac2f002018-04-03 15:17:52 -07003988 @Override
3989 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
3990 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
3991 throws RemoteException {
3992 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
3993 }
3994
Jack Yueb89b242016-06-22 13:27:47 -07003995 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003996 * Get aggregated video call data usage since boot.
3997 *
3998 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3999 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004000 * {@hide}
4001 */
4002 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004003 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004004 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4005 null);
4006
Jack Yu84291ec2017-05-26 16:07:50 -07004007 // NetworkStatsService keeps tracking the active network interface and identity. It
4008 // records the delta with the corresponding network identity. We just return the total video
4009 // call data usage snapshot since boot.
4010 Phone phone = getPhone(subId);
4011 if (phone != null) {
4012 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004013 }
Jack Yu84291ec2017-05-26 16:07:50 -07004014 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004015 }
Jack Yu75ab2952016-07-08 14:29:33 -07004016
4017 /**
4018 * Policy control of data connection. Usually used when data limit is passed.
4019 * @param enabled True if enabling the data, otherwise disabling.
4020 * @param subId Subscription index
4021 * {@hide}
4022 */
4023 @Override
4024 public void setPolicyDataEnabled(boolean enabled, int subId) {
4025 enforceModifyPermission();
4026 Phone phone = getPhone(subId);
4027 if (phone != null) {
4028 phone.setPolicyDataEnabled(enabled);
4029 }
4030 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004031
4032 /**
4033 * Get Client request stats
4034 * @return List of Client Request Stats
4035 * @hide
4036 */
4037 @Override
4038 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004040 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004041 return null;
4042 }
4043
4044 Phone phone = getPhone(subId);
4045 if (phone != null) {
4046 return phone.getClientRequestStats();
4047 }
4048
4049 return null;
4050 }
4051
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004052 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004053 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004054 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004055 }
Jack Yueb4124c2017-02-16 15:32:43 -08004056
4057 /**
Grace Chen70990072017-03-24 17:21:30 -07004058 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004059 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004060 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004061 * @param state State of SIM (power down, power up, pass through)
4062 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4063 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4064 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004065 *
4066 **/
4067 @Override
Grace Chen70990072017-03-24 17:21:30 -07004068 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004069 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004070 Phone phone = PhoneFactory.getPhone(slotIndex);
4071
Jack Yueb4124c2017-02-16 15:32:43 -08004072 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004073 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004074 }
4075 }
Shuo Qiandd210312017-04-12 22:11:33 +00004076
Tyler Gunn65d45c22017-06-05 11:22:26 -07004077 private boolean isUssdApiAllowed(int subId) {
4078 CarrierConfigManager configManager =
4079 (CarrierConfigManager) mPhone.getContext().getSystemService(
4080 Context.CARRIER_CONFIG_SERVICE);
4081 if (configManager == null) {
4082 return false;
4083 }
4084 PersistableBundle pb = configManager.getConfigForSubId(subId);
4085 if (pb == null) {
4086 return false;
4087 }
4088 return pb.getBoolean(
4089 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4090 }
4091
Shuo Qiandd210312017-04-12 22:11:33 +00004092 /**
4093 * Check if phone is in emergency callback mode
4094 * @return true if phone is in emergency callback mode
4095 * @param subId sub id
4096 */
goneil9c5f4872017-12-05 14:07:56 -08004097 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004098 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004099 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004100 final Phone phone = getPhone(subId);
4101 if (phone != null) {
4102 return phone.isInEcm();
4103 } else {
4104 return false;
4105 }
4106 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004107
4108 /**
4109 * Get the current signal strength information for the given subscription.
4110 * Because this information is not updated when the device is in a low power state
4111 * it should not be relied-upon to be current.
4112 * @param subId Subscription index
4113 * @return the most recent cached signal strength info from the modem
4114 */
4115 @Override
4116 public SignalStrength getSignalStrength(int subId) {
4117 Phone p = getPhone(subId);
4118 if (p == null) {
4119 return null;
4120 }
4121
4122 return p.getSignalStrength();
4123 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004124
4125 @Override
4126 public UiccSlotInfo[] getUiccSlotsInfo() {
4127 enforceReadPrivilegedPermission();
4128
4129 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4130 if (slots == null) return null;
4131 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4132 for (int i = 0; i < slots.length; i++) {
4133 UiccSlot slot = slots[i];
4134
4135 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4136
4137 int cardState = 0;
4138 switch (slot.getCardState()) {
4139 case CARDSTATE_ABSENT:
4140 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4141 break;
4142 case CARDSTATE_PRESENT:
4143 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4144 break;
4145 case CARDSTATE_ERROR:
4146 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4147 break;
4148 case CARDSTATE_RESTRICTED:
4149 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4150 break;
4151 default:
4152 break;
4153
4154 }
4155
Qingxi Li795c5882018-01-31 13:43:27 -08004156 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004157 slot.isActive(),
4158 slot.isEuicc(),
4159 cardId,
4160 cardState,
4161 slot.getPhoneId(),
4162 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004163 }
4164 return infos;
4165 }
4166
4167 @Override
4168 public boolean switchSlots(int[] physicalSlots) {
4169 enforceModifyPermission();
4170 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4171 }
Jack Yu4c988042018-02-27 15:30:01 -08004172
4173 @Override
4174 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4175 enforceModifyPermission();
4176 final Phone phone = getPhone(subId);
4177 if (phone == null) {
4178 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4179 return;
4180 }
4181
4182 phone.setRadioIndicationUpdateMode(filters, mode);
4183 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004184
4185 /**
4186 * Returns false if the mobile data is disabled by default, otherwise return true.
4187 */
4188 private boolean getDefaultDataEnabled() {
4189 return "true".equalsIgnoreCase(
4190 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4191 }
4192
4193 /**
4194 * Returns true if the data roaming is enabled by default, i.e the system property
4195 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4196 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4197 */
4198 private boolean getDefaultDataRoamingEnabled(int subId) {
4199 final CarrierConfigManager configMgr = (CarrierConfigManager)
4200 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4201 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4202 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4203 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4204 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4205 return isDataRoamingEnabled;
4206 }
4207
4208 /**
4209 * Returns the default network type for the given {@code subId}, if the default network type is
4210 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4211 */
4212 private int getDefaultNetworkType(int subId) {
4213 return Integer.parseInt(
4214 TelephonyManager.getTelephonyProperty(
4215 mSubscriptionController.getPhoneId(subId),
4216 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4217 String.valueOf(Phone.PREFERRED_NT_MODE)));
4218 }
fionaxua13278b2018-03-21 00:08:13 -07004219
4220 @Override
4221 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4222 gid1, String gid2, String plmn, String spn) {
4223 enforceModifyPermission();
4224 final Phone phone = getPhone(subId);
4225 if (phone == null) {
4226 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4227 return;
4228 }
4229 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4230 }
4231
4232 @Override
4233 public int getCarrierIdListVersion(int subId) {
4234 enforceReadPrivilegedPermission();
4235 final Phone phone = getPhone(subId);
4236 if (phone == null) {
4237 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4238 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4239 }
4240 return phone.getCarrierIdListVersion();
4241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004242}