blob: e1e430374d8813242acd1d5bb174c6f3874d0a2a [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 Ebinger7e934f52017-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;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Hall Liubefa7332017-11-22 17:40:08 -080058import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070059import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080060import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070061import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070062import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080065import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070066import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080067import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070069import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000071import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070072import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070073import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080077import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080079
Andrew Lee312e8172014-10-23 17:01:36 -070080import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080081import com.android.ims.internal.IImsMMTelFeature;
82import com.android.ims.internal.IImsRcsFeature;
Brad Ebinger7e934f52017-12-14 14:26:15 -080083import com.android.ims.internal.IImsRegistration;
Brad Ebinger34bef922017-11-09 10:27:08 -080084import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070085import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070086import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070087import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070088import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080091import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010092import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070093import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070094import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080096import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070097import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070098import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070099import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700100import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700101import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800102import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700103import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700104import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700105import com.android.internal.telephony.uicc.IccIoResult;
106import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800107import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700108import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800109import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700110import com.android.internal.telephony.uicc.UiccController;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000111import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700112import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800113import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700114import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800115import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700116import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700117import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800118
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700119import java.io.FileDescriptor;
120import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800123import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800124import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100125import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127
128/**
129 * Implementation of the ITelephony interface.
130 */
Santos Cordon117fee72014-05-16 17:56:12 -0700131public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132 private static final String LOG_TAG = "PhoneInterfaceManager";
133 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
134 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800135 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136
137 // Message codes used with mMainThreadHandler
138 private static final int CMD_HANDLE_PIN_MMI = 1;
139 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
140 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
141 private static final int CMD_ANSWER_RINGING_CALL = 4;
142 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700143 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
144 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145 private static final int CMD_OPEN_CHANNEL = 9;
146 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
147 private static final int CMD_CLOSE_CHANNEL = 11;
148 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800149 private static final int CMD_NV_READ_ITEM = 13;
150 private static final int EVENT_NV_READ_ITEM_DONE = 14;
151 private static final int CMD_NV_WRITE_ITEM = 15;
152 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
153 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
154 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
155 private static final int CMD_NV_RESET_CONFIG = 19;
156 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800157 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
158 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
159 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
160 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800161 private static final int CMD_SEND_ENVELOPE = 25;
162 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700163 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
164 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
165 private static final int CMD_EXCHANGE_SIM_IO = 31;
166 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800167 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
168 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700169 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
170 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700171 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
172 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
174 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
175 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
176 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700177 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
178 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
179 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
180 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700181 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800182 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
183 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000184 private static final int CMD_SWITCH_SLOTS = 50;
185 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800187 // Parameters of select command.
188 private static final int SELECT_COMMAND = 0xA4;
189 private static final int SELECT_P1 = 0x04;
190 private static final int SELECT_P2 = 0;
191 private static final int SELECT_P3 = 0x10;
192
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 /** The singleton instance. */
194 private static PhoneInterfaceManager sInstance;
195
Wink Saville3ab207e2014-11-20 13:07:20 -0800196 private PhoneGlobals mApp;
197 private Phone mPhone;
198 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700199 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800200 private AppOpsManager mAppOps;
201 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800202 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800203 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
Derek Tan97ebb422014-09-05 16:55:38 -0700205 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
206 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700208
Derek Tan740e1672017-06-27 14:56:27 -0700209 // The AID of ISD-R.
210 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
211
yinxub1bed742017-04-17 11:45:04 -0700212 private NetworkScanRequestTracker mNetworkScanRequestTracker;
213
Derek Tan89e89d42014-07-08 17:00:10 -0700214 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700215 * A request object to use for transmitting data to an ICC.
216 */
217 private static final class IccAPDUArgument {
218 public int channel, cla, command, p1, p2, p3;
219 public String data;
220
221 public IccAPDUArgument(int channel, int cla, int command,
222 int p1, int p2, int p3, String data) {
223 this.channel = channel;
224 this.cla = cla;
225 this.command = command;
226 this.p1 = p1;
227 this.p2 = p2;
228 this.p3 = p3;
229 this.data = data;
230 }
231 }
232
233 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700234 * A request object to use for transmitting data to an ICC.
235 */
236 private static final class ManualNetworkSelectionArgument {
237 public OperatorInfo operatorInfo;
238 public boolean persistSelection;
239
240 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
241 this.operatorInfo = operatorInfo;
242 this.persistSelection = persistSelection;
243 }
244 }
245
246 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
248 * request after sending. The main thread will notify the request when it is complete.
249 */
250 private static final class MainThreadRequest {
251 /** The argument to use for the request */
252 public Object argument;
253 /** The result of the request that is run on the main thread */
254 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800255 // The subscriber id that this request applies to. Defaults to
256 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
257 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258
259 public MainThreadRequest(Object argument) {
260 this.argument = argument;
261 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800262
263 public MainThreadRequest(Object argument, Integer subId) {
264 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800265 if (subId != null) {
266 this.subId = subId;
267 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800268 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 }
270
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800271 private static final class IncomingThirdPartyCallArgs {
272 public final ComponentName component;
273 public final String callId;
274 public final String callerDisplayName;
275
276 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
277 String callerDisplayName) {
278 this.component = component;
279 this.callId = callId;
280 this.callerDisplayName = callerDisplayName;
281 }
282 }
283
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284 /**
285 * A handler that processes messages on the main thread in the phone process. Since many
286 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
287 * inbound binder threads to the main thread in the phone process. The Binder thread
288 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
289 * on, which will be notified when the operation completes and will contain the result of the
290 * request.
291 *
292 * <p>If a MainThreadRequest object is provided in the msg.obj field,
293 * note that request.result must be set to something non-null for the calling thread to
294 * unblock.
295 */
296 private final class MainThreadHandler extends Handler {
297 @Override
298 public void handleMessage(Message msg) {
299 MainThreadRequest request;
300 Message onCompleted;
301 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800302 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700303 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304
305 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700306 case CMD_HANDLE_USSD_REQUEST: {
307 request = (MainThreadRequest) msg.obj;
308 final Phone phone = getPhoneFromRequest(request);
309 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
310 String ussdRequest = ussdObject.first;
311 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700312
313 if (!isUssdApiAllowed(request.subId)) {
314 // Carrier does not support use of this API, return failure.
315 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
316 UssdResponse response = new UssdResponse(ussdRequest, null);
317 Bundle returnData = new Bundle();
318 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
319 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
320
321 request.result = true;
322 synchronized (request) {
323 request.notifyAll();
324 }
325 return;
326 }
327
Tyler Gunn52dcf772017-04-26 11:30:31 -0700328 try {
329 request.result = phone != null ?
330 phone.handleUssdRequest(ussdRequest, wrappedCallback)
331 : false;
332 } catch (CallStateException cse) {
333 request.result = false;
334 }
pkanwar32d516d2016-10-14 19:37:38 -0700335 // Wake up the requesting thread
336 synchronized (request) {
337 request.notifyAll();
338 }
339 break;
340 }
341
Yorke Lee716f67e2015-06-17 15:39:16 -0700342 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700344 final Phone phone = getPhoneFromRequest(request);
345 request.result = phone != null ?
346 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
347 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 // Wake up the requesting thread
349 synchronized (request) {
350 request.notifyAll();
351 }
352 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
355 case CMD_HANDLE_NEIGHBORING_CELL:
356 request = (MainThreadRequest) msg.obj;
357 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
358 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700359 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 break;
361
362 case EVENT_NEIGHBORING_CELL_DONE:
363 ar = (AsyncResult) msg.obj;
364 request = (MainThreadRequest) ar.userObj;
365 if (ar.exception == null && ar.result != null) {
366 request.result = ar.result;
367 } else {
368 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800369 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 }
371 // Wake up the requesting thread
372 synchronized (request) {
373 request.notifyAll();
374 }
375 break;
376
377 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700378 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800379 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700380 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 break;
382
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 case CMD_END_CALL:
384 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800385 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700386 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700387 Phone phone = getPhone(end_subId);
388 if (phone == null) {
389 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
390 break;
391 }
392 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
394 // CDMA: If the user presses the Power button we treat it as
395 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700396 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
398 // GSM: End the call as per the Phone state
399 hungUp = PhoneUtils.hangup(mCM);
400 } else {
401 throw new IllegalStateException("Unexpected phone type: " + phoneType);
402 }
403 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
404 request.result = hungUp;
405 // Wake up the requesting thread
406 synchronized (request) {
407 request.notifyAll();
408 }
409 break;
410
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700412 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800414 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700415 if (uiccCard == null) {
416 loge("iccTransmitApduLogicalChannel: No UICC");
417 request.result = new IccIoResult(0x6F, 0, (byte[])null);
418 synchronized (request) {
419 request.notifyAll();
420 }
421 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
423 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700424 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 iccArgument.channel, iccArgument.cla, iccArgument.command,
426 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700427 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700428 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 break;
430
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 ar = (AsyncResult) msg.obj;
433 request = (MainThreadRequest) ar.userObj;
434 if (ar.exception == null && ar.result != null) {
435 request.result = ar.result;
436 } else {
437 request.result = new IccIoResult(0x6F, 0, (byte[])null);
438 if (ar.result == null) {
439 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800440 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700441 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800442 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 } else {
444 loge("iccTransmitApduLogicalChannel: Unknown exception");
445 }
446 }
447 synchronized (request) {
448 request.notifyAll();
449 }
450 break;
451
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
453 request = (MainThreadRequest) msg.obj;
454 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800455 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 if (uiccCard == null) {
457 loge("iccTransmitApduBasicChannel: No UICC");
458 request.result = new IccIoResult(0x6F, 0, (byte[])null);
459 synchronized (request) {
460 request.notifyAll();
461 }
462 } else {
463 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
464 request);
465 uiccCard.iccTransmitApduBasicChannel(
466 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
467 iccArgument.p3, iccArgument.data, onCompleted);
468 }
469 break;
470
471 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
472 ar = (AsyncResult) msg.obj;
473 request = (MainThreadRequest) ar.userObj;
474 if (ar.exception == null && ar.result != null) {
475 request.result = ar.result;
476 } else {
477 request.result = new IccIoResult(0x6F, 0, (byte[])null);
478 if (ar.result == null) {
479 loge("iccTransmitApduBasicChannel: Empty response");
480 } else if (ar.exception instanceof CommandException) {
481 loge("iccTransmitApduBasicChannel: CommandException: " +
482 ar.exception);
483 } else {
484 loge("iccTransmitApduBasicChannel: Unknown exception");
485 }
486 }
487 synchronized (request) {
488 request.notifyAll();
489 }
490 break;
491
492 case CMD_EXCHANGE_SIM_IO:
493 request = (MainThreadRequest) msg.obj;
494 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800495 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 if (uiccCard == null) {
497 loge("iccExchangeSimIO: No UICC");
498 request.result = new IccIoResult(0x6F, 0, (byte[])null);
499 synchronized (request) {
500 request.notifyAll();
501 }
502 } else {
503 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
504 request);
505 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
506 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
507 iccArgument.data, onCompleted);
508 }
509 break;
510
511 case EVENT_EXCHANGE_SIM_IO_DONE:
512 ar = (AsyncResult) msg.obj;
513 request = (MainThreadRequest) ar.userObj;
514 if (ar.exception == null && ar.result != null) {
515 request.result = ar.result;
516 } else {
517 request.result = new IccIoResult(0x6f, 0, (byte[])null);
518 }
519 synchronized (request) {
520 request.notifyAll();
521 }
522 break;
523
Derek Tan4d5e5c12014-02-04 11:54:58 -0800524 case CMD_SEND_ENVELOPE:
525 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800526 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700527 if (uiccCard == null) {
528 loge("sendEnvelopeWithStatus: No UICC");
529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
530 synchronized (request) {
531 request.notifyAll();
532 }
533 } else {
534 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
535 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
536 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 break;
538
539 case EVENT_SEND_ENVELOPE_DONE:
540 ar = (AsyncResult) msg.obj;
541 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700542 if (ar.exception == null && ar.result != null) {
543 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
546 if (ar.result == null) {
547 loge("sendEnvelopeWithStatus: Empty response");
548 } else if (ar.exception instanceof CommandException) {
549 loge("sendEnvelopeWithStatus: CommandException: " +
550 ar.exception);
551 } else {
552 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
553 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 }
555 synchronized (request) {
556 request.notifyAll();
557 }
558 break;
559
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 case CMD_OPEN_CHANNEL:
561 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800563 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 if (uiccCard == null) {
565 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800566 request.result = new IccOpenLogicalChannelResponse(-1,
567 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 synchronized (request) {
569 request.notifyAll();
570 }
571 } else {
572 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800573 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
574 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700575 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 break;
577
578 case EVENT_OPEN_CHANNEL_DONE:
579 ar = (AsyncResult) msg.obj;
580 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 int[] result = (int[]) ar.result;
584 int channelId = result[0];
585 byte[] selectResponse = null;
586 if (result.length > 1) {
587 selectResponse = new byte[result.length - 1];
588 for (int i = 1; i < result.length; ++i) {
589 selectResponse[i - 1] = (byte) result[i];
590 }
591 }
592 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700593 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 if (ar.result == null) {
596 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 if (ar.exception != null) {
599 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
600 }
601
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700602 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700603 if (ar.exception instanceof CommandException) {
604 CommandException.Error error =
605 ((CommandException) (ar.exception)).getCommandError();
606 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700607 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700608 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 }
611 }
612 openChannelResp = new IccOpenLogicalChannelResponse(
613 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700615 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 synchronized (request) {
617 request.notifyAll();
618 }
619 break;
620
621 case CMD_CLOSE_CHANNEL:
622 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800623 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 if (uiccCard == null) {
625 loge("iccCloseLogicalChannel: No UICC");
626 request.result = new IccIoResult(0x6F, 0, (byte[])null);
627 synchronized (request) {
628 request.notifyAll();
629 }
630 } else {
631 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
632 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800637 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
638 break;
639
640 case CMD_NV_READ_ITEM:
641 request = (MainThreadRequest) msg.obj;
642 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
643 mPhone.nvReadItem((Integer) request.argument, onCompleted);
644 break;
645
646 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 ar = (AsyncResult) msg.obj;
648 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800649 if (ar.exception == null && ar.result != null) {
650 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800652 request.result = "";
653 if (ar.result == null) {
654 loge("nvReadItem: Empty response");
655 } else if (ar.exception instanceof CommandException) {
656 loge("nvReadItem: CommandException: " +
657 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800659 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 }
661 }
662 synchronized (request) {
663 request.notifyAll();
664 }
665 break;
666
Jake Hambye994d462014-02-03 13:10:13 -0800667 case CMD_NV_WRITE_ITEM:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
670 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
671 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
672 break;
673
674 case EVENT_NV_WRITE_ITEM_DONE:
675 handleNullReturnEvent(msg, "nvWriteItem");
676 break;
677
678 case CMD_NV_WRITE_CDMA_PRL:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
681 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
682 break;
683
684 case EVENT_NV_WRITE_CDMA_PRL_DONE:
685 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
686 break;
687
688 case CMD_NV_RESET_CONFIG:
689 request = (MainThreadRequest) msg.obj;
690 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
691 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
692 break;
693
694 case EVENT_NV_RESET_CONFIG_DONE:
695 handleNullReturnEvent(msg, "nvResetConfig");
696 break;
697
Jake Hamby7c27be32014-03-03 13:25:59 -0800698 case CMD_GET_PREFERRED_NETWORK_TYPE:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700701 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 break;
703
704 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
705 ar = (AsyncResult) msg.obj;
706 request = (MainThreadRequest) ar.userObj;
707 if (ar.exception == null && ar.result != null) {
708 request.result = ar.result; // Integer
709 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800710 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 if (ar.result == null) {
712 loge("getPreferredNetworkType: Empty response");
713 } else if (ar.exception instanceof CommandException) {
714 loge("getPreferredNetworkType: CommandException: " +
715 ar.exception);
716 } else {
717 loge("getPreferredNetworkType: Unknown exception");
718 }
719 }
720 synchronized (request) {
721 request.notifyAll();
722 }
723 break;
724
725 case CMD_SET_PREFERRED_NETWORK_TYPE:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
728 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700729 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
733 handleNullReturnEvent(msg, "setPreferredNetworkType");
734 break;
735
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800736 case CMD_SET_VOICEMAIL_NUMBER:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
739 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800740 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
741 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800742 break;
743
744 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
745 handleNullReturnEvent(msg, "setVoicemailNumber");
746 break;
747
Stuart Scott54788802015-03-30 13:18:01 -0700748 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
751 request);
752 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
753 break;
754
755 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
756 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
757 break;
758
Shishir Agrawal302c8692015-06-19 13:49:39 -0700759 case CMD_PERFORM_NETWORK_SCAN:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
762 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
763 break;
764
765 case EVENT_PERFORM_NETWORK_SCAN_DONE:
766 ar = (AsyncResult) msg.obj;
767 request = (MainThreadRequest) ar.userObj;
768 CellNetworkScanResult cellScanResult;
769 if (ar.exception == null && ar.result != null) {
770 cellScanResult = new CellNetworkScanResult(
771 CellNetworkScanResult.STATUS_SUCCESS,
772 (List<OperatorInfo>) ar.result);
773 } else {
774 if (ar.result == null) {
775 loge("getCellNetworkScanResults: Empty response");
776 }
777 if (ar.exception != null) {
778 loge("getCellNetworkScanResults: Exception: " + ar.exception);
779 }
780 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
781 if (ar.exception instanceof CommandException) {
782 CommandException.Error error =
783 ((CommandException) (ar.exception)).getCommandError();
784 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
785 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
786 } else if (error == CommandException.Error.GENERIC_FAILURE) {
787 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
788 }
789 }
790 cellScanResult = new CellNetworkScanResult(errorCode, null);
791 }
792 request.result = cellScanResult;
793 synchronized (request) {
794 request.notifyAll();
795 }
796 break;
797
798 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
799 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700800 ManualNetworkSelectionArgument selArg =
801 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700802 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
803 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700804 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
805 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700806 break;
807
808 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
809 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
810 break;
811
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700812 case CMD_GET_MODEM_ACTIVITY_INFO:
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700815 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700816 break;
817
818 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
819 ar = (AsyncResult) msg.obj;
820 request = (MainThreadRequest) ar.userObj;
821 if (ar.exception == null && ar.result != null) {
822 request.result = ar.result;
823 } else {
824 if (ar.result == null) {
825 loge("queryModemActivityInfo: Empty response");
826 } else if (ar.exception instanceof CommandException) {
827 loge("queryModemActivityInfo: CommandException: " +
828 ar.exception);
829 } else {
830 loge("queryModemActivityInfo: Unknown exception");
831 }
832 }
Amit Mahajand4766222016-01-28 15:28:28 -0800833 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
834 if (request.result == null) {
835 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
836 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700837 synchronized (request) {
838 request.notifyAll();
839 }
840 break;
841
Meng Wang1a7c35a2016-05-05 20:56:15 -0700842 case CMD_SET_ALLOWED_CARRIERS:
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
845 mPhone.setAllowedCarriers(
846 (List<CarrierIdentifier>) request.argument,
847 onCompleted);
848 break;
849
850 case EVENT_SET_ALLOWED_CARRIERS_DONE:
851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null && ar.result != null) {
854 request.result = ar.result;
855 } else {
856 if (ar.result == null) {
857 loge("setAllowedCarriers: Empty response");
858 } else if (ar.exception instanceof CommandException) {
859 loge("setAllowedCarriers: CommandException: " +
860 ar.exception);
861 } else {
862 loge("setAllowedCarriers: Unknown exception");
863 }
864 }
865 // Result cannot be null. Return -1 on error.
866 if (request.result == null) {
867 request.result = new int[]{-1};
868 }
869 synchronized (request) {
870 request.notifyAll();
871 }
872 break;
873
874 case CMD_GET_ALLOWED_CARRIERS:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
877 mPhone.getAllowedCarriers(onCompleted);
878 break;
879
880 case EVENT_GET_ALLOWED_CARRIERS_DONE:
881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result;
885 } else {
886 if (ar.result == null) {
887 loge("getAllowedCarriers: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("getAllowedCarriers: CommandException: " +
890 ar.exception);
891 } else {
892 loge("getAllowedCarriers: Unknown exception");
893 }
894 }
895 // Result cannot be null. Return empty list of CarrierIdentifier.
896 if (request.result == null) {
897 request.result = new ArrayList<CarrierIdentifier>(0);
898 }
899 synchronized (request) {
900 request.notifyAll();
901 }
902 break;
903
Nathan Haroldb3014052017-01-25 15:57:32 -0800904 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
905 ar = (AsyncResult) msg.obj;
906 request = (MainThreadRequest) ar.userObj;
907 if (ar.exception == null && ar.result != null) {
908 request.result = ar.result;
909 } else {
910 request.result = new IllegalArgumentException(
911 "Failed to retrieve Forbidden Plmns");
912 if (ar.result == null) {
913 loge("getForbiddenPlmns: Empty response");
914 } else {
915 loge("getForbiddenPlmns: Unknown exception");
916 }
917 }
918 synchronized (request) {
919 request.notifyAll();
920 }
921 break;
922
923 case CMD_GET_FORBIDDEN_PLMNS:
924 request = (MainThreadRequest) msg.obj;
925 uiccCard = getUiccCardFromRequest(request);
926 if (uiccCard == null) {
927 loge("getForbiddenPlmns() UiccCard is null");
928 request.result = new IllegalArgumentException(
929 "getForbiddenPlmns() UiccCard is null");
930 synchronized (request) {
931 request.notifyAll();
932 }
933 break;
934 }
935 Integer appType = (Integer) request.argument;
936 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
937 if (uiccApp == null) {
938 loge("getForbiddenPlmns() no app with specified type -- "
939 + appType);
940 request.result = new IllegalArgumentException("Failed to get UICC App");
941 synchronized (request) {
942 request.notifyAll();
943 }
944 break;
945 } else {
946 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
947 + " specified type -- " + appType);
948 }
949 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
950 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
951 onCompleted);
952 break;
953
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000954 case CMD_SWITCH_SLOTS:
955 request = (MainThreadRequest) msg.obj;
956 int[] physicalSlots = (int[]) request.argument;
957 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
958 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
959 break;
960
961 case EVENT_SWITCH_SLOTS_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 request.result = (ar.exception == null);
965 synchronized (request) {
966 request.notifyAll();
967 }
968 break;
969
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700970 default:
971 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
972 break;
973 }
974 }
Jake Hambye994d462014-02-03 13:10:13 -0800975
976 private void handleNullReturnEvent(Message msg, String command) {
977 AsyncResult ar = (AsyncResult) msg.obj;
978 MainThreadRequest request = (MainThreadRequest) ar.userObj;
979 if (ar.exception == null) {
980 request.result = true;
981 } else {
982 request.result = false;
983 if (ar.exception instanceof CommandException) {
984 loge(command + ": CommandException: " + ar.exception);
985 } else {
986 loge(command + ": Unknown exception");
987 }
988 }
989 synchronized (request) {
990 request.notifyAll();
991 }
992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700993 }
994
995 /**
996 * Posts the specified command to be executed on the main thread,
997 * waits for the request to complete, and returns the result.
998 * @see #sendRequestAsync
999 */
1000 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001001 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001002 }
1003
1004 /**
1005 * Posts the specified command to be executed on the main thread,
1006 * waits for the request to complete, and returns the result.
1007 * @see #sendRequestAsync
1008 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001009 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001010 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1011 throw new RuntimeException("This method will deadlock if called from the main thread.");
1012 }
1013
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001014 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001015 Message msg = mMainThreadHandler.obtainMessage(command, request);
1016 msg.sendToTarget();
1017
1018 // Wait for the request to complete
1019 synchronized (request) {
1020 while (request.result == null) {
1021 try {
1022 request.wait();
1023 } catch (InterruptedException e) {
1024 // Do nothing, go back and wait until the request is complete
1025 }
1026 }
1027 }
1028 return request.result;
1029 }
1030
1031 /**
1032 * Asynchronous ("fire and forget") version of sendRequest():
1033 * Posts the specified command to be executed on the main thread, and
1034 * returns immediately.
1035 * @see #sendRequest
1036 */
1037 private void sendRequestAsync(int command) {
1038 mMainThreadHandler.sendEmptyMessage(command);
1039 }
1040
1041 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001042 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1043 * @see {@link #sendRequest(int,Object)}
1044 */
1045 private void sendRequestAsync(int command, Object argument) {
1046 MainThreadRequest request = new MainThreadRequest(argument);
1047 Message msg = mMainThreadHandler.obtainMessage(command, request);
1048 msg.sendToTarget();
1049 }
1050
1051 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001052 * Initialize the singleton PhoneInterfaceManager instance.
1053 * This is only done once, at startup, from PhoneApp.onCreate().
1054 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001055 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001056 synchronized (PhoneInterfaceManager.class) {
1057 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001058 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001059 } else {
1060 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1061 }
1062 return sInstance;
1063 }
1064 }
1065
1066 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001067 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001068 mApp = app;
1069 mPhone = phone;
1070 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001071 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001072 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1073 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001074 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001075 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001076 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001077 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001078
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001079 publish();
1080 }
1081
1082 private void publish() {
1083 if (DBG) log("publish: " + this);
1084
1085 ServiceManager.addService("phone", this);
1086 }
1087
Stuart Scott584921c2015-01-15 17:10:34 -08001088 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001089 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1090 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001091 }
1092
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001093 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1094 Phone phone = getPhoneFromRequest(request);
1095 return phone == null ? null :
1096 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1097 }
1098
Wink Saville36469e72014-06-11 15:17:00 -07001099 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001100 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001101 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001102 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 //
1104 // Implementation of the ITelephony interface.
1105 //
1106
1107 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001108 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001109 }
1110
Wink Savilleb564aae2014-10-23 10:18:09 -07001111 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001112 if (DBG) log("dial: " + number);
1113 // No permission check needed here: This is just a wrapper around the
1114 // ACTION_DIAL intent, which is available to any app since it puts up
1115 // the UI before it does anything.
1116
1117 String url = createTelUrl(number);
1118 if (url == null) {
1119 return;
1120 }
1121
1122 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001123 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001124 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1125 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1126 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1127 mApp.startActivity(intent);
1128 }
1129 }
1130
1131 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001132 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001133 }
1134
Wink Savilleb564aae2014-10-23 10:18:09 -07001135 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 if (DBG) log("call: " + number);
1137
1138 // This is just a wrapper around the ACTION_CALL intent, but we still
1139 // need to do a permission check since we're calling startActivity()
1140 // from the context of the phone app.
1141 enforceCallPermission();
1142
1143 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1144 != AppOpsManager.MODE_ALLOWED) {
1145 return;
1146 }
1147
1148 String url = createTelUrl(number);
1149 if (url == null) {
1150 return;
1151 }
1152
Wink Saville08874612014-08-31 19:19:58 -07001153 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001154 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001155 if (slist != null) {
1156 for (SubscriptionInfo subInfoRecord : slist) {
1157 if (subInfoRecord.getSubscriptionId() == subId) {
1158 isValid = true;
1159 break;
1160 }
Wink Saville08874612014-08-31 19:19:58 -07001161 }
1162 }
1163 if (isValid == false) {
1164 return;
1165 }
1166
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001167 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001168 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1170 mApp.startActivity(intent);
1171 }
1172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173 /**
1174 * End a call based on call state
1175 * @return true is a call was ended
1176 */
1177 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001178 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001179 }
1180
1181 /**
1182 * End a call based on the call state of the subId
1183 * @return true is a call was ended
1184 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001185 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001186 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001187 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 }
1189
1190 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001191 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001192 }
1193
Wink Savilleb564aae2014-10-23 10:18:09 -07001194 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 if (DBG) log("answerRingingCall...");
1196 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1197 // but that can probably wait till the big TelephonyManager API overhaul.
1198 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1199 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001200 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001201 }
1202
1203 /**
1204 * Make the actual telephony calls to implement answerRingingCall().
1205 * This should only be called from the main thread of the Phone app.
1206 * @see #answerRingingCall
1207 *
1208 * TODO: it would be nice to return true if we answered the call, or
1209 * false if there wasn't actually a ringing incoming call, or some
1210 * other error occurred. (In other words, pass back the return value
1211 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1212 * But that would require calling this method via sendRequest() rather
1213 * than sendRequestAsync(), and right now we don't actually *need* that
1214 * return value, so let's just return void for now.
1215 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001216 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001217 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001219 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1220 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 if (hasActiveCall && hasHoldingCall) {
1222 // Both lines are in use!
1223 // TODO: provide a flag to let the caller specify what
1224 // policy to use if both lines are in use. (The current
1225 // behavior is hardwired to "answer incoming, end ongoing",
1226 // which is how the CALL button is specced to behave.)
1227 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1228 return;
1229 } else {
1230 // answerCall() will automatically hold the current active
1231 // call, if there is one.
1232 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1233 return;
1234 }
1235 } else {
1236 // No call was ringing.
1237 return;
1238 }
1239 }
1240
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001242 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001244 public void silenceRinger() {
1245 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 }
1247
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001248 @Override
1249 public boolean isOffhook(String callingPackage) {
1250 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001251 }
1252
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001253 @Override
1254 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1255 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1256 return false;
1257 }
1258
Sanket Padawe356d7632015-06-22 14:03:32 -07001259 final Phone phone = getPhone(subId);
1260 if (phone != null) {
1261 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1262 } else {
1263 return false;
1264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 }
1266
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001267 @Override
1268 public boolean isRinging(String callingPackage) {
1269 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001270 }
1271
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001272 @Override
1273 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1274 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1275 return false;
1276 }
1277
Sanket Padawe356d7632015-06-22 14:03:32 -07001278 final Phone phone = getPhone(subId);
1279 if (phone != null) {
1280 return (phone.getState() == PhoneConstants.State.RINGING);
1281 } else {
1282 return false;
1283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 }
1285
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001286 @Override
1287 public boolean isIdle(String callingPackage) {
1288 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001289 }
1290
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001291 @Override
1292 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1293 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1294 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.IDLE);
1300 } else {
1301 return false;
1302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 }
1304
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001306 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001307 }
1308
Wink Savilleb564aae2014-10-23 10:18:09 -07001309 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001310 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001311 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1312 }
1313
1314 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001315 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001316 }
1317
Wink Savilleb564aae2014-10-23 10:18:09 -07001318 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001319 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001320 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1321 }
1322
1323 /** {@hide} */
1324 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001325 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
1327
Wink Savilleb564aae2014-10-23 10:18:09 -07001328 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001330 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 checkSimPin.start();
1332 return checkSimPin.unlockSim(null, pin);
1333 }
1334
Wink Saville9de0f752013-10-22 19:04:03 -07001335 /** {@hide} */
1336 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001337 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001338 }
1339
Wink Savilleb564aae2014-10-23 10:18:09 -07001340 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001342 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 checkSimPuk.start();
1344 return checkSimPuk.unlockSim(puk, pin);
1345 }
1346
1347 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001348 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 * a synchronous one.
1350 */
1351 private static class UnlockSim extends Thread {
1352
1353 private final IccCard mSimCard;
1354
1355 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001356 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1357 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358
1359 // For replies from SimCard interface
1360 private Handler mHandler;
1361
1362 // For async handler to identify request type
1363 private static final int SUPPLY_PIN_COMPLETE = 100;
1364
1365 public UnlockSim(IccCard simCard) {
1366 mSimCard = simCard;
1367 }
1368
1369 @Override
1370 public void run() {
1371 Looper.prepare();
1372 synchronized (UnlockSim.this) {
1373 mHandler = new Handler() {
1374 @Override
1375 public void handleMessage(Message msg) {
1376 AsyncResult ar = (AsyncResult) msg.obj;
1377 switch (msg.what) {
1378 case SUPPLY_PIN_COMPLETE:
1379 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1380 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001381 mRetryCount = msg.arg1;
1382 if (ar.exception != null) {
1383 if (ar.exception instanceof CommandException &&
1384 ((CommandException)(ar.exception)).getCommandError()
1385 == CommandException.Error.PASSWORD_INCORRECT) {
1386 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1387 } else {
1388 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1389 }
1390 } else {
1391 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mDone = true;
1394 UnlockSim.this.notifyAll();
1395 }
1396 break;
1397 }
1398 }
1399 };
1400 UnlockSim.this.notifyAll();
1401 }
1402 Looper.loop();
1403 }
1404
1405 /*
1406 * Use PIN or PUK to unlock SIM card
1407 *
1408 * If PUK is null, unlock SIM card with PIN
1409 *
1410 * If PUK is not null, unlock SIM card with PUK and set PIN code
1411 */
Wink Saville9de0f752013-10-22 19:04:03 -07001412 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413
1414 while (mHandler == null) {
1415 try {
1416 wait();
1417 } catch (InterruptedException e) {
1418 Thread.currentThread().interrupt();
1419 }
1420 }
1421 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1422
1423 if (puk == null) {
1424 mSimCard.supplyPin(pin, callback);
1425 } else {
1426 mSimCard.supplyPuk(puk, pin, callback);
1427 }
1428
1429 while (!mDone) {
1430 try {
1431 Log.d(LOG_TAG, "wait for done");
1432 wait();
1433 } catch (InterruptedException e) {
1434 // Restore the interrupted status
1435 Thread.currentThread().interrupt();
1436 }
1437 }
1438 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001439 int[] resultArray = new int[2];
1440 resultArray[0] = mResult;
1441 resultArray[1] = mRetryCount;
1442 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 }
1444 }
1445
1446 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001447 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001448
1449 }
1450
Wink Savilleb564aae2014-10-23 10:18:09 -07001451 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 // No permission check needed here: this call is harmless, and it's
1453 // needed for the ServiceState.requestStateUpdate() call (which is
1454 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001455 final Phone phone = getPhone(subId);
1456 if (phone != null) {
1457 phone.updateServiceLocation();
1458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 }
1460
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001461 @Override
1462 public boolean isRadioOn(String callingPackage) {
1463 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001464 }
1465
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001466 @Override
1467 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1468 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1469 return false;
1470 }
1471 return isRadioOnForSubscriber(subId);
1472 }
1473
1474 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001475 final Phone phone = getPhone(subId);
1476 if (phone != null) {
1477 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1478 } else {
1479 return false;
1480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482
1483 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001484 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001485
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 }
Wink Saville36469e72014-06-11 15:17:00 -07001487
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001490 final Phone phone = getPhone(subId);
1491 if (phone != null) {
1492 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1493 }
Wink Saville36469e72014-06-11 15:17:00 -07001494 }
1495
1496 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001497 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001498 }
1499
Wink Savilleb564aae2014-10-23 10:18:09 -07001500 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001501 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001502 final Phone phone = getPhone(subId);
1503 if (phone == null) {
1504 return false;
1505 }
1506 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001507 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001508 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 }
1510 return true;
1511 }
Wink Saville36469e72014-06-11 15:17:00 -07001512
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001513 public boolean needMobileRadioShutdown() {
1514 /*
1515 * If any of the Radios are available, it will need to be
1516 * shutdown. So return true if any Radio is available.
1517 */
1518 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1519 Phone phone = PhoneFactory.getPhone(i);
1520 if (phone != null && phone.isRadioAvailable()) return true;
1521 }
1522 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1523 return false;
1524 }
1525
1526 public void shutdownMobileRadios() {
1527 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1528 logv("Shutting down Phone " + i);
1529 shutdownRadioUsingPhoneId(i);
1530 }
1531 }
1532
1533 private void shutdownRadioUsingPhoneId(int phoneId) {
1534 enforceModifyPermission();
1535 Phone phone = PhoneFactory.getPhone(phoneId);
1536 if (phone != null && phone.isRadioAvailable()) {
1537 phone.shutdownRadio();
1538 }
1539 }
1540
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001542 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001543 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1544 if (defaultPhone != null) {
1545 defaultPhone.setRadioPower(turnOn);
1546 return true;
1547 } else {
1548 loge("There's no default phone.");
1549 return false;
1550 }
Wink Saville36469e72014-06-11 15:17:00 -07001551 }
1552
Wink Savilleb564aae2014-10-23 10:18:09 -07001553 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001555 final Phone phone = getPhone(subId);
1556 if (phone != null) {
1557 phone.setRadioPower(turnOn);
1558 return true;
1559 } else {
1560 return false;
1561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 }
1563
Wink Saville36469e72014-06-11 15:17:00 -07001564 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001565 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 public boolean enableDataConnectivity() {
1567 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001568 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001569 final Phone phone = getPhone(subId);
1570 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001571 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001572 return true;
1573 } else {
1574 return false;
1575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001576 }
1577
Wink Saville36469e72014-06-11 15:17:00 -07001578 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001579 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 public boolean disableDataConnectivity() {
1581 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001582 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001583 final Phone phone = getPhone(subId);
1584 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001585 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 return true;
1587 } else {
1588 return false;
1589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 }
1591
Sanket Padawe356d7632015-06-22 14:03:32 -07001592 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001593 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 final Phone phone = getPhone(subId);
1595 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001596 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001597 } else {
1598 return false;
1599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
1601
1602 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001603 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001604 }
1605
pkanwarae03a6b2016-11-06 20:37:09 -08001606 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001607 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1609 return;
1610 }
1611 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1612 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1613 };
1614
Wink Savilleb564aae2014-10-23 10:18:09 -07001615 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1618 return false;
1619 }
Wink Saville36469e72014-06-11 15:17:00 -07001620 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001624 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001625 }
1626
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001627 public int getCallStateForSlot(int slotIndex) {
1628 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001629 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001630 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 }
1632
Sanket Padawe356d7632015-06-22 14:03:32 -07001633 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001635 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001636 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001637 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001639 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 }
1642
Sanket Padawe356d7632015-06-22 14:03:32 -07001643 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001645 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001646 if (phone != null) {
1647 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1648 } else {
1649 return TelephonyManager.DATA_ACTIVITY_NONE;
1650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652
1653 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001654 public Bundle getCellLocation(String callingPackage) {
Hall Liubefa7332017-11-22 17:40:08 -08001655 mPhone.getContext().getSystemService(AppOpsManager.class)
1656 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001657 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liubefa7332017-11-22 17:40:08 -08001658 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001659 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 }
1661
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001662 if (DBG_LOC) log("getCellLocation: is active user");
1663 Bundle data = new Bundle();
1664 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1665 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 return null;
1667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001669 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1670 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1671 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001672 }
1673
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001675 public String getNetworkCountryIsoForPhone(int phoneId) {
1676 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1677 // registered cell info, so return a NULL country instead.
1678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1681 if (TelephonyManager.NETWORK_TYPE_IWLAN
1682 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1683 return "";
1684 }
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
1687 }
1688 return TelephonyManager.getTelephonyProperty(
1689 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1690 }
1691
1692 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001694 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001695 }
1696
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001698 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 mApp.enforceCallingOrSelfPermission(
1700 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 final Phone phone = getPhone(subId);
1702 if (phone != null) {
1703 phone.enableLocationUpdates();
1704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
1707 @Override
1708 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001709 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001710 }
1711
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001713 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 mApp.enforceCallingOrSelfPermission(
1715 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.disableLocationUpdates();
1719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 }
1721
1722 @Override
1723 @SuppressWarnings("unchecked")
1724 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liubefa7332017-11-22 17:40:08 -08001725 mPhone.getContext().getSystemService(AppOpsManager.class)
1726 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001727 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liubefa7332017-11-22 17:40:08 -08001728 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001729 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 }
1731
1732 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1733 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1734 return null;
1735 }
Svetoslav64fad262015-04-14 14:35:21 -07001736
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001737 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001739 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001741 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1742 try {
1743 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1744 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1745 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1746 } catch (RuntimeException e) {
1747 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001749 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
1751
1752
1753 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001754 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liubefa7332017-11-22 17:40:08 -08001755 mPhone.getContext().getSystemService(AppOpsManager.class)
1756 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liubefa7332017-11-22 17:40:08 -08001758 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001759 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 }
1761
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001762 if (DBG_LOC) log("getAllCellInfo: is active user");
1763 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1764 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1765 for (Phone phone : PhoneFactory.getPhones()) {
1766 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1767 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001769 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001772 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001774 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001775 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1776 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
1778
Shishir Agrawala9f32182016-04-12 12:00:16 -07001779 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001780 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001781 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1782 return null;
1783 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001784 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001785 return phone == null ? null : phone.getImei();
1786 }
1787
1788 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001789 public String getMeidForSlot(int slotIndex, String callingPackage) {
1790 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1791 return null;
1792 }
1793 Phone phone = PhoneFactory.getPhone(slotIndex);
1794 return phone == null ? null : phone.getMeid();
1795 }
1796
1797 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001798 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001799 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1800 return null;
1801 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001802 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001803 return phone == null ? null : phone.getDeviceSvn();
1804 }
1805
fionaxuf32acdf2017-11-27 22:51:16 -08001806 @Override
1807 public int getSubscriptionCarrierId(int subId) {
1808 final Phone phone = getPhone(subId);
1809 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1810 }
1811
1812 @Override
1813 public String getSubscriptionCarrierName(int subId) {
1814 final Phone phone = getPhone(subId);
1815 return phone == null ? null : phone.getCarrierName();
1816 }
1817
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 //
1819 // Internal helper methods.
1820 //
1821
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001822 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1824 *
1825 * @throws SecurityException if the caller does not have the required permission
1826 */
1827 private void enforceModifyPermission() {
1828 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1829 }
1830
1831 /**
Junda Liua2e36012014-07-09 18:30:01 -07001832 * Make sure either system app or the caller has carrier privilege.
1833 *
1834 * @throws SecurityException if the caller does not have the required permission/privilege
1835 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001836 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001837 int permission = mApp.checkCallingOrSelfPermission(
1838 android.Manifest.permission.MODIFY_PHONE_STATE);
1839 if (permission == PackageManager.PERMISSION_GRANTED) {
1840 return;
1841 }
1842
1843 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001844 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001845 }
1846
1847 /**
1848 * Make sure the caller has carrier privilege.
1849 *
1850 * @throws SecurityException if the caller does not have the required permission
1851 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001852 private void enforceCarrierPrivilege(int subId) {
1853 if (getCarrierPrivilegeStatus(subId) !=
1854 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001855 loge("No Carrier Privilege.");
1856 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001857 }
1858 }
1859
1860 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 * Make sure the caller has the CALL_PHONE permission.
1862 *
1863 * @throws SecurityException if the caller does not have the required permission
1864 */
1865 private void enforceCallPermission() {
1866 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1867 }
1868
Stuart Scott8eef64f2015-04-08 15:13:54 -07001869 private void enforceConnectivityInternalPermission() {
1870 mApp.enforceCallingOrSelfPermission(
1871 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1872 "ConnectivityService");
1873 }
1874
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 private String createTelUrl(String number) {
1876 if (TextUtils.isEmpty(number)) {
1877 return null;
1878 }
1879
Jake Hambye994d462014-02-03 13:10:13 -08001880 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 }
1882
Ihab Awadf9e92732013-12-05 18:02:52 -08001883 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1885 }
1886
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001887 private static void logv(String msg) {
1888 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1889 }
1890
Ihab Awadf9e92732013-12-05 18:02:52 -08001891 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1893 }
1894
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001895 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001897 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001898 }
1899
Sanket Padawe356d7632015-06-22 14:03:32 -07001900 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001901 public int getActivePhoneTypeForSlot(int slotIndex) {
1902 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 if (phone == null) {
1904 return PhoneConstants.PHONE_TYPE_NONE;
1905 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001906 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909
1910 /**
1911 * Returns the CDMA ERI icon index to display
1912 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001913 @Override
1914 public int getCdmaEriIconIndex(String callingPackage) {
1915 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001916 }
1917
Sanket Padawe356d7632015-06-22 14:03:32 -07001918 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001919 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1920 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1921 return -1;
1922 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001923 final Phone phone = getPhone(subId);
1924 if (phone != null) {
1925 return phone.getCdmaEriIconIndex();
1926 } else {
1927 return -1;
1928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 }
1930
1931 /**
1932 * Returns the CDMA ERI icon mode,
1933 * 0 - ON
1934 * 1 - FLASHING
1935 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001936 @Override
1937 public int getCdmaEriIconMode(String callingPackage) {
1938 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001939 }
1940
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001942 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1943 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1944 return -1;
1945 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 final Phone phone = getPhone(subId);
1947 if (phone != null) {
1948 return phone.getCdmaEriIconMode();
1949 } else {
1950 return -1;
1951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
1954 /**
1955 * Returns the CDMA ERI text,
1956 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001957 @Override
1958 public String getCdmaEriText(String callingPackage) {
1959 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001960 }
1961
Sanket Padawe356d7632015-06-22 14:03:32 -07001962 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001963 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1964 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1965 return null;
1966 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001967 final Phone phone = getPhone(subId);
1968 if (phone != null) {
1969 return phone.getCdmaEriText();
1970 } else {
1971 return null;
1972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 }
1974
1975 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001976 * Returns the CDMA MDN.
1977 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001979 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001980 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001981 final Phone phone = getPhone(subId);
1982 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1983 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001984 } else {
1985 return null;
1986 }
1987 }
1988
1989 /**
1990 * Returns the CDMA MIN.
1991 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001992 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001993 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001994 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 final Phone phone = getPhone(subId);
1996 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1997 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001998 } else {
1999 return null;
2000 }
2001 }
2002
2003 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004 * Returns true if CDMA provisioning needs to run.
2005 */
2006 public boolean needsOtaServiceProvisioning() {
2007 return mPhone.needsOtaServiceProvisioning();
2008 }
2009
2010 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002011 * Sets the voice mail number of a given subId.
2012 */
2013 @Override
2014 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002015 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002016 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2017 new Pair<String, String>(alphaTag, number), new Integer(subId));
2018 return success;
2019 }
2020
Ta-wei Yen87c49842016-05-13 21:19:52 -07002021 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002022 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2023 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2024 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2025 if (!TextUtils.equals(callingPackage, systemDialer)) {
2026 throw new SecurityException("caller must be system dialer");
2027 }
2028 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2029 if (phoneAccountHandle == null){
2030 return null;
2031 }
2032 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2033 }
2034
2035 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002036 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2038 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2039 return null;
2040 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002041 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2042 }
2043
2044 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002045 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2046 VisualVoicemailSmsFilterSettings settings) {
2047 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002048 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002049 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2050 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002051 }
2052
2053 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002054 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2055 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002056 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002057 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002058 }
2059
2060 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002061 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2062 String callingPackage, int subId) {
2063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002064 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002065 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002066 }
2067
2068 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002069 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002070 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002071 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002072 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2073 }
2074
2075 @Override
2076 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2077 String number, int port, String text, PendingIntent sentIntent) {
2078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002079 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002080 enforceSendSmsPermission();
2081 // Make the calls as the phone process.
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2085 if (port == 0) {
2086 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2087 sentIntent, null, false);
2088 } else {
2089 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2090 smsManager.sendDataMessageWithSelfPermissions(number, null,
2091 (short) port, data, sentIntent, null);
2092 }
2093 } finally {
2094 Binder.restoreCallingIdentity(identity);
2095 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002096 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002097 /**
fionaxu0152e512016-11-14 13:36:14 -08002098 * Sets the voice activation state of a given subId.
2099 */
2100 @Override
2101 public void setVoiceActivationState(int subId, int activationState) {
2102 enforceModifyPermissionOrCarrierPrivilege(subId);
2103 final Phone phone = getPhone(subId);
2104 if (phone != null) {
2105 phone.setVoiceActivationState(activationState);
2106 } else {
2107 loge("setVoiceActivationState fails with invalid subId: " + subId);
2108 }
2109 }
2110
2111 /**
2112 * Sets the data activation state of a given subId.
2113 */
2114 @Override
2115 public void setDataActivationState(int subId, int activationState) {
2116 enforceModifyPermissionOrCarrierPrivilege(subId);
2117 final Phone phone = getPhone(subId);
2118 if (phone != null) {
2119 phone.setDataActivationState(activationState);
2120 } else {
2121 loge("setVoiceActivationState fails with invalid subId: " + subId);
2122 }
2123 }
2124
2125 /**
2126 * Returns the voice activation state of a given subId.
2127 */
2128 @Override
2129 public int getVoiceActivationState(int subId, String callingPackage) {
2130 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2131 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2132 }
2133 final Phone phone = getPhone(subId);
2134 if (phone != null) {
2135 return phone.getVoiceActivationState();
2136 } else {
2137 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2138 }
2139 }
2140
2141 /**
2142 * Returns the data activation state of a given subId.
2143 */
2144 @Override
2145 public int getDataActivationState(int subId, String callingPackage) {
2146 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2147 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2148 }
2149 final Phone phone = getPhone(subId);
2150 if (phone != null) {
2151 return phone.getDataActivationState();
2152 } else {
2153 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2154 }
2155 }
2156
2157 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 * Returns the unread count of voicemails
2159 */
2160 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002161 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002162 }
2163
2164 /**
2165 * Returns the unread count of voicemails for a subId
2166 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002167 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002168 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002169 final Phone phone = getPhone(subId);
2170 if (phone != null) {
2171 return phone.getVoiceMessageCount();
2172 } else {
2173 return 0;
2174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 }
2176
2177 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002178 * returns true, if the device is in a state where both voice and data
2179 * are supported simultaneously. This can change based on location or network condition.
2180 */
2181 @Override
2182 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2183 final Phone phone = getPhone(subId);
2184 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2185 }
2186
2187 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002188 * Send the dialer code if called from the current default dialer or the caller has
2189 * carrier privilege.
2190 * @param inputCode The dialer code to send
2191 */
2192 @Override
2193 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2194 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2195 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2196 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2197 enforceCarrierPrivilege(getDefaultSubscription());
2198 }
2199 mPhone.sendDialerSpecialCode(inputCode);
2200 }
2201
2202 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002203 * Returns the data network type.
2204 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 *
2206 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2207 */
2208 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002209 public int getNetworkType() {
2210 final Phone phone = getPhone(getDefaultSubscription());
2211 if (phone != null) {
2212 return phone.getServiceState().getDataNetworkType();
2213 } else {
2214 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2215 }
Wink Saville36469e72014-06-11 15:17:00 -07002216 }
2217
2218 /**
2219 * Returns the network type for a subId
2220 */
2221 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002222 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2223 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2224 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2225 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002226
Sanket Padawe356d7632015-06-22 14:03:32 -07002227 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002228 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002229 return phone.getServiceState().getDataNetworkType();
2230 } else {
2231 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 }
2234
2235 /**
2236 * Returns the data network type
2237 */
2238 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002239 public int getDataNetworkType(String callingPackage) {
2240 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002241 }
2242
2243 /**
2244 * Returns the data network type for a subId
2245 */
2246 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002247 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2248 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2249 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2250 }
2251
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 final Phone phone = getPhone(subId);
2253 if (phone != null) {
2254 return phone.getServiceState().getDataNetworkType();
2255 } else {
2256 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259
2260 /**
Wink Saville36469e72014-06-11 15:17:00 -07002261 * Returns the Voice network type for a subId
2262 */
2263 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002264 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2265 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2266 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2267 }
2268
Sanket Padawe356d7632015-06-22 14:03:32 -07002269 final Phone phone = getPhone(subId);
2270 if (phone != null) {
2271 return phone.getServiceState().getVoiceNetworkType();
2272 } else {
2273 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
2276
2277 /**
2278 * @return true if a ICC card is present
2279 */
2280 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002281 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002282 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2283 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002284 }
2285
2286 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002287 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002288 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002290 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2291 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002292 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002293 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002294 } else {
2295 return false;
2296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
2299 /**
2300 * Return if the current radio is LTE on CDMA. This
2301 * is a tri-state return value as for a period of time
2302 * the mode may be unknown.
2303 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002304 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002306 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002308 @Override
2309 public int getLteOnCdmaMode(String callingPackage) {
2310 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002311 }
2312
Sanket Padawe356d7632015-06-22 14:03:32 -07002313 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2315 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2316 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2317 }
2318
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 final Phone phone = getPhone(subId);
2320 if (phone == null) {
2321 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2322 } else {
2323 return phone.getLteOnCdmaMode();
2324 }
Wink Saville36469e72014-06-11 15:17:00 -07002325 }
2326
2327 public void setPhone(Phone phone) {
2328 mPhone = phone;
2329 }
2330
2331 /**
2332 * {@hide}
2333 * Returns Default subId, 0 in the case of single standby.
2334 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002335 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002336 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002337 }
2338
Shishir Agrawala9f32182016-04-12 12:00:16 -07002339 private int getSlotForDefaultSubscription() {
2340 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2341 }
2342
Wink Savilleb564aae2014-10-23 10:18:09 -07002343 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002344 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002346
2347 /**
2348 * @see android.telephony.TelephonyManager.WifiCallingChoices
2349 */
2350 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002351 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2352 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002353 }
2354
2355 /**
2356 * @see android.telephony.TelephonyManager.WifiCallingChoices
2357 */
2358 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002359 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2360 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2361 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002362 }
2363
Sailesh Nepald1e68152013-12-12 19:08:02 -08002364 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002365 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002366 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002367 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002368
Shishir Agrawal566b7612013-10-28 14:41:00 -07002369 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002370 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2371 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002372 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002373
Derek Tan740e1672017-06-27 14:56:27 -07002374 if (TextUtils.equals(ISDR_AID, aid)) {
2375 // Only allows LPA to open logical channel to ISD-R.
2376 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2377 ComponentInfo bestComponent =
2378 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2379 if (bestComponent == null
2380 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2381 loge("The calling package is not allowed to access ISD-R.");
2382 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2383 }
2384 }
2385
2386 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002387 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002388 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002389 if (DBG) log("iccOpenLogicalChannel: " + response);
2390 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002391 }
2392
2393 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002394 public boolean iccCloseLogicalChannel(int subId, int channel) {
2395 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002396
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002397 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002398 if (channel < 0) {
2399 return false;
2400 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002401 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002402 if (DBG) log("iccCloseLogicalChannel: " + success);
2403 return success;
2404 }
2405
2406 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002407 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002408 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002409 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002410
2411 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002412 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2413 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002414 " data=" + data);
2415 }
2416
2417 if (channel < 0) {
2418 return "";
2419 }
2420
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002421 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002422 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002423 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2424
Shishir Agrawal566b7612013-10-28 14:41:00 -07002425 // Append the returned status code to the end of the response payload.
2426 String s = Integer.toHexString(
2427 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002428 if (response.payload != null) {
2429 s = IccUtils.bytesToHexString(response.payload) + s;
2430 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002431 return s;
2432 }
Jake Hambye994d462014-02-03 13:10:13 -08002433
Evan Charltonc66da362014-05-16 14:06:40 -07002434 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002435 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2436 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002437 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002438
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002439 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2440 && TextUtils.equals(ISDR_AID, data)) {
2441 // Only allows LPA to select ISD-R.
2442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2443 ComponentInfo bestComponent =
2444 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2445 if (bestComponent == null
2446 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2447 loge("The calling package is not allowed to select ISD-R.");
2448 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2449 }
2450 }
2451
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002452 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002453 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2454 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002455 }
2456
2457 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002458 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002459 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2460
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002461 // Append the returned status code to the end of the response payload.
2462 String s = Integer.toHexString(
2463 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002464 if (response.payload != null) {
2465 s = IccUtils.bytesToHexString(response.payload) + s;
2466 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002467 return s;
2468 }
2469
2470 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002471 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002472 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002473 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474
2475 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002476 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002477 p1 + " " + p2 + " " + p3 + ":" + filePath);
2478 }
2479
2480 IccIoResult response =
2481 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002482 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2483 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002484
2485 if (DBG) {
2486 log("Exchange SIM_IO [R]" + response);
2487 }
2488
2489 byte[] result = null;
2490 int length = 2;
2491 if (response.payload != null) {
2492 length = 2 + response.payload.length;
2493 result = new byte[length];
2494 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2495 } else {
2496 result = new byte[length];
2497 }
2498
2499 result[length - 1] = (byte) response.sw2;
2500 result[length - 2] = (byte) response.sw1;
2501 return result;
2502 }
2503
Nathan Haroldb3014052017-01-25 15:57:32 -08002504 /**
2505 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2506 * on a particular subscription
2507 */
2508 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002509 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2510 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002511 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2512 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2513 return null;
2514 }
2515 Object response = sendRequest(
2516 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2517 if (response instanceof String[]) {
2518 return (String[]) response;
2519 }
2520 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2521 return null;
2522 }
2523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002524 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002525 public String sendEnvelopeWithStatus(int subId, String content) {
2526 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002527
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002528 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002529 if (response.payload == null) {
2530 return "";
2531 }
2532
2533 // Append the returned status code to the end of the response payload.
2534 String s = Integer.toHexString(
2535 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2536 s = IccUtils.bytesToHexString(response.payload) + s;
2537 return s;
2538 }
2539
Jake Hambye994d462014-02-03 13:10:13 -08002540 /**
2541 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2542 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2543 *
2544 * @param itemID the ID of the item to read
2545 * @return the NV item as a String, or null on error.
2546 */
2547 @Override
2548 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002549 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002550 if (DBG) log("nvReadItem: item " + itemID);
2551 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2552 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2553 return value;
2554 }
2555
2556 /**
2557 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2558 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2559 *
2560 * @param itemID the ID of the item to read
2561 * @param itemValue the value to write, as a String
2562 * @return true on success; false on any failure
2563 */
2564 @Override
2565 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002566 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002567 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2568 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2569 new Pair<Integer, String>(itemID, itemValue));
2570 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2571 return success;
2572 }
2573
2574 /**
2575 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2576 * Used for device configuration by some CDMA operators.
2577 *
2578 * @param preferredRoamingList byte array containing the new PRL
2579 * @return true on success; false on any failure
2580 */
2581 @Override
2582 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002583 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002584 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2585 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2586 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2587 return success;
2588 }
2589
2590 /**
2591 * Perform the specified type of NV config reset.
2592 * Used for device configuration by some CDMA operators.
2593 *
2594 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2595 * @return true on success; false on any failure
2596 */
2597 @Override
2598 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002599 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002600 if (DBG) log("nvResetConfig: type " + resetType);
2601 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2602 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2603 return success;
2604 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002605
2606 /**
Wink Saville36469e72014-06-11 15:17:00 -07002607 * {@hide}
2608 * Returns Default sim, 0 in the case of single standby.
2609 */
2610 public int getDefaultSim() {
2611 //TODO Need to get it from Telephony Devcontroller
2612 return 0;
2613 }
2614
Svet Ganovb320e182015-04-16 12:30:10 -07002615 public String[] getPcscfAddress(String apnType, String callingPackage) {
2616 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2617 return new String[0];
2618 }
2619
2620
ram87fca6f2014-07-18 18:58:44 +05302621 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002622 }
2623
Brad Ebinger51f743a2017-01-23 13:50:20 -08002624 /**
Brad Ebinger34bef922017-11-09 10:27:08 -08002625 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2626 * feature or {@link null} if the service is not available. If the feature is available, the
2627 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002628 */
Brad Ebinger34bef922017-11-09 10:27:08 -08002629 public IImsMMTelFeature getMMTelFeatureAndListen(int slotId,
2630 IImsServiceFeatureCallback callback) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002631 enforceModifyPermission();
Brad Ebinger34bef922017-11-09 10:27:08 -08002632 return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback);
2633 }
2634
2635 /**
2636 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2637 * feature during emergency calling or {@link null} if the service is not available. If the
2638 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2639 * listener for feature updates.
2640 */
2641 public IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId,
2642 IImsServiceFeatureCallback callback) {
2643 enforceModifyPermission();
2644 return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback);
2645 }
2646
2647 /**
2648 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2649 * feature during emergency calling or {@link null} if the service is not available. If the
2650 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2651 * listener for feature updates.
2652 */
2653 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2654 enforceModifyPermission();
2655 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002656 }
2657
Brad Ebinger7e934f52017-12-14 14:26:15 -08002658 /**
2659 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2660 * specified.
2661 */
2662 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2663 enforceModifyPermission();
2664 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2665 }
2666
Wink Saville36469e72014-06-11 15:17:00 -07002667 public void setImsRegistrationState(boolean registered) {
2668 enforceModifyPermission();
2669 mPhone.setImsRegistrationState(registered);
2670 }
2671
2672 /**
Stuart Scott54788802015-03-30 13:18:01 -07002673 * Set the network selection mode to automatic.
2674 *
2675 */
2676 @Override
2677 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002678 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002679 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2680 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2681 }
2682
2683 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002684 * Set the network selection mode to manual with the selected carrier.
2685 */
2686 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002687 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002688 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002689 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002690 OperatorInfo operator = new OperatorInfo(
2691 /* operatorAlphaLong */ "",
2692 /* operatorAlphaShort */ "",
2693 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002694 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002695 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2696 persistSelection);
2697 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002698 }
2699
2700 /**
2701 * Scans for available networks.
2702 */
2703 @Override
2704 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002705 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002706 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2707 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2708 CMD_PERFORM_NETWORK_SCAN, null, subId);
2709 return result;
2710 }
2711
2712 /**
yinxub1bed742017-04-17 11:45:04 -07002713 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002714 *
yinxub1bed742017-04-17 11:45:04 -07002715 * @param subId id of the subscription
2716 * @param request contains the radio access networks with bands/channels to scan
2717 * @param messenger callback messenger for scan results or errors
2718 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002719 * @return the id of the requested scan which can be used to stop the scan.
2720 */
2721 @Override
2722 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2723 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002724 enforceModifyPermissionOrCarrierPrivilege(subId);
2725 return mNetworkScanRequestTracker.startNetworkScan(
2726 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002727 }
2728
2729 /**
2730 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002731 *
2732 * @param subId id of the subscription
2733 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002734 */
2735 @Override
2736 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002737 enforceModifyPermissionOrCarrierPrivilege(subId);
2738 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002739 }
2740
2741 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002742 * Get the calculated preferred network type.
2743 * Used for debugging incorrect network type.
2744 *
2745 * @return the preferred network type, defined in RILConstants.java.
2746 */
2747 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002748 public int getCalculatedPreferredNetworkType(String callingPackage) {
2749 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2750 return RILConstants.PREFERRED_NETWORK_MODE;
2751 }
2752
Amit Mahajan43330e02014-11-18 11:54:45 -08002753 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002754 }
2755
2756 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002757 * Get the preferred network type.
2758 * Used for device configuration by some CDMA operators.
2759 *
2760 * @return the preferred network type, defined in RILConstants.java.
2761 */
2762 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002763 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002764 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002765 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002766 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002767 int networkType = (result != null ? result[0] : -1);
2768 if (DBG) log("getPreferredNetworkType: " + networkType);
2769 return networkType;
2770 }
2771
2772 /**
2773 * Set the preferred network type.
2774 * Used for device configuration by some CDMA operators.
2775 *
2776 * @param networkType the preferred network type, defined in RILConstants.java.
2777 * @return true on success; false on any failure.
2778 */
2779 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002780 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002781 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002782 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2783 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002784 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002785 if (success) {
2786 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002787 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002788 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002789 return success;
2790 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002791
2792 /**
Junda Liu475951f2014-11-07 16:45:03 -08002793 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2794 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2795 * tethering.
2796 *
2797 * @return 0: Not required. 1: required. 2: Not set.
2798 * @hide
2799 */
2800 @Override
2801 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002802 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002803 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2804 Settings.Global.TETHER_DUN_REQUIRED, 2);
2805 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2806 // config_tether_apndata.
2807 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2808 dunRequired = 1;
2809 }
2810 return dunRequired;
2811 }
2812
2813 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002814 * Set mobile data enabled
2815 * Used by the user through settings etc to turn on/off mobile data
2816 *
2817 * @param enable {@code true} turn turn data on, else {@code false}
2818 */
2819 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002820 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002821 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002822 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002823 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002824 Phone phone = PhoneFactory.getPhone(phoneId);
2825 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002826 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2827 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002828 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002829 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002830 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002831 }
2832
2833 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002834 * Get the user enabled state of Mobile Data.
2835 *
2836 * TODO: remove and use isUserDataEnabled.
2837 * This can't be removed now because some vendor codes
2838 * calls through ITelephony directly while they should
2839 * use TelephonyManager.
2840 *
2841 * @return true on enabled
2842 */
2843 @Override
2844 public boolean getDataEnabled(int subId) {
2845 return isUserDataEnabled(subId);
2846 }
2847
2848 /**
2849 * Get whether mobile data is enabled per user setting.
2850 *
2851 * There are other factors deciding whether mobile data is actually enabled, but they are
2852 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002853 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002854 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002855 *
2856 * @return {@code true} if data is enabled else {@code false}
2857 */
2858 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002859 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002860 try {
2861 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2862 null);
2863 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002864 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002865 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002866 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002867 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002868 Phone phone = PhoneFactory.getPhone(phoneId);
2869 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002870 boolean retVal = phone.isUserDataEnabled();
2871 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002872 return retVal;
2873 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002874 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2875 return false;
2876 }
2877 }
2878
2879 /**
2880 * Get whether mobile data is enabled.
2881 *
2882 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2883 * whether mobile data is actually enabled.
2884 *
2885 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2886 *
2887 * @return {@code true} if data is enabled else {@code false}
2888 */
2889 @Override
2890 public boolean isDataEnabled(int subId) {
2891 try {
2892 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2893 null);
2894 } catch (Exception e) {
2895 enforceModifyPermissionOrCarrierPrivilege(subId);
2896 }
2897 int phoneId = mSubscriptionController.getPhoneId(subId);
2898 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2899 Phone phone = PhoneFactory.getPhone(phoneId);
2900 if (phone != null) {
2901 boolean retVal = phone.isDataEnabled();
2902 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2903 return retVal;
2904 } else {
2905 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002906 return false;
2907 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002908 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002909
2910 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002911 public int getCarrierPrivilegeStatus(int subId) {
2912 final Phone phone = getPhone(subId);
2913 if (phone == null) {
2914 loge("getCarrierPrivilegeStatus: Invalid subId");
2915 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2916 }
2917 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002918 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002919 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002920 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2921 }
2922 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002923 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002924 }
Junda Liu29340342014-07-10 15:23:27 -07002925
2926 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002927 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002928 if (TextUtils.isEmpty(pkgName))
2929 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002930 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002931 if (card == null) {
2932 loge("checkCarrierPrivilegesForPackage: No UICC");
2933 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2934 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002935 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2936 }
2937
2938 @Override
2939 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002940 if (TextUtils.isEmpty(pkgName))
2941 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002942 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2943 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2944 UiccCard card = UiccController.getInstance().getUiccCard(i);
2945 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002946 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002947 continue;
2948 }
2949
2950 result = card.getCarrierPrivilegeStatus(
2951 mPhone.getContext().getPackageManager(), pkgName);
2952 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2953 break;
2954 }
2955 }
2956
2957 return result;
Junda Liu29340342014-07-10 15:23:27 -07002958 }
Derek Tan89e89d42014-07-08 17:00:10 -07002959
2960 @Override
Junda Liue64de782015-04-16 17:19:16 -07002961 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2962 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2963 loge("phoneId " + phoneId + " is not valid.");
2964 return null;
2965 }
2966 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002967 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002968 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002969 return null ;
2970 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002971 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002972 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002973 }
2974
Amith Yamasani6e118872016-02-19 12:53:51 -08002975 @Override
2976 public List<String> getPackagesWithCarrierPrivileges() {
2977 PackageManager pm = mPhone.getContext().getPackageManager();
2978 List<String> privilegedPackages = new ArrayList<>();
2979 List<PackageInfo> packages = null;
2980 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2981 UiccCard card = UiccController.getInstance().getUiccCard(i);
2982 if (card == null) {
2983 // No UICC in that slot.
2984 continue;
2985 }
2986 if (card.hasCarrierPrivilegeRules()) {
2987 if (packages == null) {
2988 // Only check packages in user 0 for now
2989 packages = pm.getInstalledPackagesAsUser(
2990 PackageManager.MATCH_DISABLED_COMPONENTS
2991 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2992 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2993 }
2994 for (int p = packages.size() - 1; p >= 0; p--) {
2995 PackageInfo pkgInfo = packages.get(p);
2996 if (pkgInfo != null && pkgInfo.packageName != null
2997 && card.getCarrierPrivilegeStatus(pkgInfo)
2998 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2999 privilegedPackages.add(pkgInfo.packageName);
3000 }
3001 }
3002 }
3003 }
3004 return privilegedPackages;
3005 }
3006
Wink Savilleb564aae2014-10-23 10:18:09 -07003007 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003008 final Phone phone = getPhone(subId);
3009 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003010 if (card == null) {
3011 loge("getIccId: No UICC");
3012 return null;
3013 }
3014 String iccId = card.getIccId();
3015 if (TextUtils.isEmpty(iccId)) {
3016 loge("getIccId: ICC ID is null or empty.");
3017 return null;
3018 }
3019 return iccId;
3020 }
3021
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003022 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003023 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3024 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003025 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003026
Jeff Sharkey85190e62014-12-05 09:40:12 -08003027 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003028 final Phone phone = getPhone(subId);
3029 if (phone == null) {
3030 return false;
3031 }
3032 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003033
3034 if (DBG_MERGE) {
3035 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3036 + subscriberId + " to " + number);
3037 }
3038
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003039 if (TextUtils.isEmpty(iccId)) {
3040 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003041 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003042
Jeff Sharkey85190e62014-12-05 09:40:12 -08003043 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3044
3045 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003046 if (alphaTag == null) {
3047 editor.remove(alphaTagPrefKey);
3048 } else {
3049 editor.putString(alphaTagPrefKey, alphaTag);
3050 }
3051
Jeff Sharkey85190e62014-12-05 09:40:12 -08003052 // Record both the line number and IMSI for this ICCID, since we need to
3053 // track all merged IMSIs based on line number
3054 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3055 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003056 if (number == null) {
3057 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003058 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003059 } else {
3060 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003061 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003062 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003063
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003064 editor.commit();
3065 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003066 }
3067
3068 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003069 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003070 // This is open to apps with WRITE_SMS.
3071 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003072 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003073 return null;
3074 }
Derek Tan97ebb422014-09-05 16:55:38 -07003075
3076 String iccId = getIccId(subId);
3077 if (iccId != null) {
3078 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003079 if (DBG_MERGE) {
3080 log("getLine1NumberForDisplay returning " +
3081 mTelephonySharedPreferences.getString(numberPrefKey, null));
3082 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003083 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003084 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003085 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003086 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003087 }
3088
3089 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003090 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3091 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3092 return null;
3093 }
Derek Tan97ebb422014-09-05 16:55:38 -07003094
3095 String iccId = getIccId(subId);
3096 if (iccId != null) {
3097 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003098 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003099 }
Derek Tan97ebb422014-09-05 16:55:38 -07003100 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003101 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003102
3103 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003104 public String[] getMergedSubscriberIds(String callingPackage) {
3105 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3106 return null;
3107 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003108 final Context context = mPhone.getContext();
3109 final TelephonyManager tele = TelephonyManager.from(context);
3110 final SubscriptionManager sub = SubscriptionManager.from(context);
3111
3112 // Figure out what subscribers are currently active
3113 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003114 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3115 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 final int[] subIds = sub.getActiveSubscriptionIdList();
3119 for (int subId : subIds) {
3120 activeSubscriberIds.add(tele.getSubscriberId(subId));
3121 }
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003124 }
3125
3126 // First pass, find a number override for an active subscriber
3127 String mergeNumber = null;
3128 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3129 for (String key : prefs.keySet()) {
3130 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3131 final String subscriberId = (String) prefs.get(key);
3132 if (activeSubscriberIds.contains(subscriberId)) {
3133 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3134 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3135 mergeNumber = (String) prefs.get(numberKey);
3136 if (DBG_MERGE) {
3137 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3138 + " for active subscriber " + subscriberId);
3139 }
3140 if (!TextUtils.isEmpty(mergeNumber)) {
3141 break;
3142 }
3143 }
3144 }
3145 }
3146
3147 // Shortcut when no active merged subscribers
3148 if (TextUtils.isEmpty(mergeNumber)) {
3149 return null;
3150 }
3151
3152 // Second pass, find all subscribers under that line override
3153 final ArraySet<String> result = new ArraySet<>();
3154 for (String key : prefs.keySet()) {
3155 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3156 final String number = (String) prefs.get(key);
3157 if (mergeNumber.equals(number)) {
3158 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3159 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3160 final String subscriberId = (String) prefs.get(subscriberKey);
3161 if (!TextUtils.isEmpty(subscriberId)) {
3162 result.add(subscriberId);
3163 }
3164 }
3165 }
3166 }
3167
3168 final String[] resultArray = result.toArray(new String[result.size()]);
3169 Arrays.sort(resultArray);
3170 if (DBG_MERGE) {
3171 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3172 }
3173 return resultArray;
3174 }
3175
3176 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003177 public boolean setOperatorBrandOverride(int subId, String brand) {
3178 enforceCarrierPrivilege(subId);
3179 final Phone phone = getPhone(subId);
3180 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003181 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003182
3183 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003184 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003185 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3186 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003187 enforceCarrierPrivilege(subId);
3188 final Phone phone = getPhone(subId);
3189 if (phone == null) {
3190 return false;
3191 }
3192 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003193 cdmaNonRoamingList);
3194 }
3195
3196 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003197 public void setRadioCapability(RadioAccessFamily[] rafs) {
3198 try {
3199 ProxyController.getInstance().setRadioCapability(rafs);
3200 } catch (RuntimeException e) {
3201 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3202 }
3203 }
3204
3205 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003206 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3207 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3208 return RadioAccessFamily.RAF_UNKNOWN;
3209 }
3210
Wink Saville5d475dd2014-10-17 15:00:58 -07003211 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3212 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003213
3214 @Override
3215 public void enableVideoCalling(boolean enable) {
3216 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003217 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003218 }
3219
3220 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003221 public boolean isVideoCallingEnabled(String callingPackage) {
3222 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3223 return false;
3224 }
3225
Andrew Lee77527ac2014-10-21 16:57:39 -07003226 // Check the user preference and the system-level IMS setting. Even if the user has
3227 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3228 // In the long run, we may instead need to check if there exists a connection service
3229 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003230 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3231 return imsManager.isVtEnabledByPlatform()
3232 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3233 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003234 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003235
Andrew Leea1239f22015-03-02 17:44:07 -08003236 @Override
3237 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003238 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003239 }
3240
3241 @Override
3242 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003243 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003244 }
3245
Andrew Lee9431b832015-03-09 18:46:45 -07003246 @Override
3247 public boolean isTtyModeSupported() {
3248 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3249 TelephonyManager telephonyManager =
3250 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003251 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003252 }
3253
3254 @Override
3255 public boolean isHearingAidCompatibilitySupported() {
3256 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3257 }
3258
Sanket Padawe7310cc72015-01-14 09:53:20 -08003259 /**
3260 * Returns the unique device ID of phone, for example, the IMEI for
3261 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3262 *
3263 * <p>Requires Permission:
3264 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3265 */
3266 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003267 public String getDeviceId(String callingPackage) {
3268 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3269 return null;
3270 }
3271
Sanket Padawe7310cc72015-01-14 09:53:20 -08003272 final Phone phone = PhoneFactory.getPhone(0);
3273 if (phone != null) {
3274 return phone.getDeviceId();
3275 } else {
3276 return null;
3277 }
3278 }
3279
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003280 /*
3281 * {@hide}
3282 * Returns the IMS Registration Status
3283 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003284 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003285 public boolean isImsRegistered() {
3286 return mPhone.isImsRegistered();
3287 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003288
Ping Sun014fe8e2016-03-02 19:16:45 +08003289 /**
3290 * {@hide}
3291 * Returns the IMS Registration Status on a particular subid
3292 *
3293 * @param subId
3294 */
3295 public boolean isImsRegisteredForSubscriber(int subId) {
3296 Phone phone = getPhone(subId);
3297 if (phone != null) {
3298 return phone.isImsRegistered();
3299 } else {
3300 return false;
3301 }
3302 }
3303
Santos Cordon7a1885b2015-02-03 11:15:19 -08003304 @Override
3305 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3306 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3307 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003308
Nathan Haroldc55097a2015-03-11 18:14:50 -07003309 /*
3310 * {@hide}
3311 * Returns the IMS Registration Status
3312 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003313 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003314 return mPhone.isWifiCallingEnabled();
3315 }
3316
3317 /*
3318 * {@hide}
3319 * Returns the IMS Registration Status
3320 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003321 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003322 return mPhone.isVolteEnabled();
3323 }
Svet Ganovb320e182015-04-16 12:30:10 -07003324
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003325 /*
3326 * {@hide} Returns the IMS Registration Status
3327 */
3328 public boolean isVideoTelephonyAvailable() {
3329 return mPhone.isVideoEnabled();
3330 }
3331
Svet Ganovb320e182015-04-16 12:30:10 -07003332 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003333 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003334 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003335 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3336
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003337 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003338 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003339 } catch (SecurityException e) {
3340 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3341 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003342 }
Svet Ganovb320e182015-04-16 12:30:10 -07003343
3344 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3345 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3346 return false;
3347 }
3348
3349 return true;
3350 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003351
Makoto Onukifee69342015-06-29 14:44:50 -07003352 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003353 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003354 */
3355 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003356 // Default SMS app can always read it.
3357 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3358 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3359 return true;
3360 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003361
Makoto Onukie4072d12015-08-03 15:12:23 -07003362 try {
3363 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003364 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003365 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003366 // Can be read with READ_SMS too.
3367 try {
3368 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3369 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3370 if (opCode != AppOpsManager.OP_NONE) {
3371 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3372 == AppOpsManager.MODE_ALLOWED;
3373 } else {
3374 return true;
3375 }
3376 } catch (SecurityException readSmsSecurityException) {
3377 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003378 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003379 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003380 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003381 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003382 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003383 if (opCode != AppOpsManager.OP_NONE) {
3384 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3385 == AppOpsManager.MODE_ALLOWED;
3386 } else {
3387 return true;
3388 }
3389 } catch (SecurityException readPhoneNumberSecurityException) {
3390 }
3391
3392 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3393 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3394 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003395 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003396 }
3397
Stuart Scott8eef64f2015-04-08 15:13:54 -07003398 @Override
3399 public void factoryReset(int subId) {
3400 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003401 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3402 return;
3403 }
3404
Svet Ganovcc087f82015-05-12 20:35:54 -07003405 final long identity = Binder.clearCallingIdentity();
3406 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003407 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3408 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003409 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003410 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003411 // Set network selection mode to automatic
3412 setNetworkSelectionModeAutomatic(subId);
3413 // Set preferred mobile network type to the best available
3414 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3415 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003416 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003417 }
3418 } finally {
3419 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003420 }
3421 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003422
3423 @Override
3424 public String getLocaleFromDefaultSim() {
3425 // We query all subscriptions instead of just the active ones, because
3426 // this might be called early on in the provisioning flow when the
3427 // subscriptions potentially aren't active yet.
3428 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3429 if (slist == null || slist.isEmpty()) {
3430 return null;
3431 }
3432
3433 // This function may be called very early, say, from the setup wizard, at
3434 // which point we won't have a default subscription set. If that's the case
3435 // we just choose the first, which will be valid in "most cases".
3436 final int defaultSubId = getDefaultSubscription();
3437 SubscriptionInfo info = null;
3438 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3439 info = slist.get(0);
3440 } else {
3441 for (SubscriptionInfo item : slist) {
3442 if (item.getSubscriptionId() == defaultSubId) {
3443 info = item;
3444 break;
3445 }
3446 }
3447
3448 if (info == null) {
3449 return null;
3450 }
3451 }
3452
3453 // Try and fetch the locale from the carrier properties or from the SIM language
3454 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003455 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003456 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003457 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003458 if (defaultPhone != null) {
3459 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3460 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003461 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003462 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3463 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003464 } else {
3465 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003466 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003467 }
3468 }
3469
Narayan Kamath011676f2015-07-29 12:04:08 +01003470 // The SIM language preferences only store a language (e.g. fr = French), not an
3471 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3472 // the SIM and carrier preferences does not include a country we add the country
3473 // determined from the SIM MCC to provide an exact locale.
3474 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003475 if (mccLocale != null) {
3476 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3477 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003478 }
3479
Tony Hill183b2de2015-06-24 14:53:58 +01003480 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003481 return null;
3482 }
3483
3484 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 return mSubscriptionController.getAllSubInfoList(
3488 mPhone.getContext().getOpPackageName());
3489 } finally {
3490 Binder.restoreCallingIdentity(identity);
3491 }
3492 }
3493
3494 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 return mSubscriptionController.getActiveSubscriptionInfoList(
3498 mPhone.getContext().getOpPackageName());
3499 } finally {
3500 Binder.restoreCallingIdentity(identity);
3501 }
3502 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003503
3504 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003505 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3506 * representing the state of the modem.
3507 *
3508 * NOTE: This clears the modem state, so there should only every be one caller.
3509 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003510 */
3511 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003512 public void requestModemActivityInfo(ResultReceiver result) {
3513 enforceModifyPermission();
3514
3515 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3516 Bundle bundle = new Bundle();
3517 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3518 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003519 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003520
3521 /**
3522 * {@hide}
3523 * Returns the service state information on specified subscription.
3524 */
3525 @Override
3526 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3527
3528 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3529 return null;
3530 }
3531
3532 final Phone phone = getPhone(subId);
3533 if (phone == null) {
3534 return null;
3535 }
3536
3537 return phone.getServiceState();
3538 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003539
3540 /**
3541 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3542 *
3543 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3544 * voicemail ringtone.
3545 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3546 * PhoneAccount.
3547 */
3548 @Override
3549 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003550 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003551 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003552 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003553 }
3554
fionaxu7ed723d2017-05-30 18:58:54 -07003555 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003556 }
3557
3558 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003559 * Sets the per-account voicemail ringtone.
3560 *
3561 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3562 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3563 *
3564 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3565 * voicemail ringtone.
3566 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3567 * PhoneAccount.
3568 */
3569 @Override
3570 public void setVoicemailRingtoneUri(String callingPackage,
3571 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3572 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3573 if (!TextUtils.equals(callingPackage,
3574 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3575 enforceModifyPermissionOrCarrierPrivilege(
3576 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3577 }
3578 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3579 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003580 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003581 }
fionaxu7ed723d2017-05-30 18:58:54 -07003582 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003583 }
3584
3585 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003586 * Returns whether vibration is set for voicemail notification in Phone settings.
3587 *
3588 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3589 * voicemail vibration setting.
3590 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3591 */
3592 @Override
3593 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003594 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003595 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003596 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003597 }
3598
fionaxu7ed723d2017-05-30 18:58:54 -07003599 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003600 }
3601
Youhan Wange64578a2016-05-02 15:32:42 -07003602 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003603 * Sets the per-account voicemail vibration.
3604 *
3605 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3606 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3607 *
3608 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3609 * voicemail vibration setting.
3610 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3611 * specific PhoneAccount.
3612 */
3613 @Override
3614 public void setVoicemailVibrationEnabled(String callingPackage,
3615 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3617 if (!TextUtils.equals(callingPackage,
3618 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3619 enforceModifyPermissionOrCarrierPrivilege(
3620 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3621 }
3622
3623 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3624 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003625 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003626 }
fionaxu7ed723d2017-05-30 18:58:54 -07003627 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003628 }
3629
3630 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003631 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3632 *
3633 * @throws SecurityException if the caller does not have the required permission
3634 */
3635 private void enforceReadPrivilegedPermission() {
3636 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3637 null);
3638 }
3639
3640 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003641 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3642 * permission.
3643 *
3644 * @throws SecurityException if the caller does not have the required permission
3645 */
3646 private void enforceSendSmsPermission() {
3647 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3648 }
3649
3650 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003651 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003652 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003653 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003654 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003655 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003656 ComponentName componentName =
3657 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3658 if(componentName == null) {
3659 throw new SecurityException("Caller not current active visual voicemail package[null]");
3660 }
3661 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003662 if (!callingPackage.equals(vvmPackage)) {
3663 throw new SecurityException("Caller not current active visual voicemail package[" +
3664 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003665 }
3666 }
3667
3668 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003669 * Return the application ID for the app type.
3670 *
3671 * @param subId the subscription ID that this request applies to.
3672 * @param appType the uicc app type.
3673 * @return Application ID for specificied app type, or null if no uicc.
3674 */
3675 @Override
3676 public String getAidForAppType(int subId, int appType) {
3677 enforceReadPrivilegedPermission();
3678 Phone phone = getPhone(subId);
3679 if (phone == null) {
3680 return null;
3681 }
3682 String aid = null;
3683 try {
3684 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3685 .getApplicationByType(appType).getAid();
3686 } catch (Exception e) {
3687 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3688 }
3689 return aid;
3690 }
3691
Youhan Wang4001d252016-05-11 10:29:41 -07003692 /**
3693 * Return the Electronic Serial Number.
3694 *
3695 * @param subId the subscription ID that this request applies to.
3696 * @return ESN or null if error.
3697 */
3698 @Override
3699 public String getEsn(int subId) {
3700 enforceReadPrivilegedPermission();
3701 Phone phone = getPhone(subId);
3702 if (phone == null) {
3703 return null;
3704 }
3705 String esn = null;
3706 try {
3707 esn = phone.getEsn();
3708 } catch (Exception e) {
3709 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3710 }
3711 return esn;
3712 }
3713
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003714 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003715 * Return the Preferred Roaming List Version.
3716 *
3717 * @param subId the subscription ID that this request applies to.
3718 * @return PRLVersion or null if error.
3719 */
3720 @Override
3721 public String getCdmaPrlVersion(int subId) {
3722 enforceReadPrivilegedPermission();
3723 Phone phone = getPhone(subId);
3724 if (phone == null) {
3725 return null;
3726 }
3727 String cdmaPrlVersion = null;
3728 try {
3729 cdmaPrlVersion = phone.getCdmaPrlVersion();
3730 } catch (Exception e) {
3731 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3732 }
3733 return cdmaPrlVersion;
3734 }
3735
3736 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003737 * Get snapshot of Telephony histograms
3738 * @return List of Telephony histograms
3739 * @hide
3740 */
3741 @Override
3742 public List<TelephonyHistogram> getTelephonyHistograms() {
3743 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3744 return RIL.getTelephonyRILTimingHistograms();
3745 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003746
3747 /**
3748 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003749 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003750 * Require system privileges. In the future we may add this to carrier APIs.
3751 *
3752 * @return The number of carriers set successfully, should match length of carriers
3753 */
3754 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003755 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003756 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003757
Meng Wang9b7c4e92017-02-17 11:41:27 -08003758 if (carriers == null) {
3759 throw new NullPointerException("carriers cannot be null");
3760 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003761
3762 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003763 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3764 return retVal[0];
3765 }
3766
3767 /**
3768 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003769 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003770 * Require system privileges. In the future we may add this to carrier APIs.
3771 *
3772 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3773 * means all carriers are allowed.
3774 */
3775 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003776 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003777 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003778 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003779 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3780 }
3781
fionaxu59545b42016-05-25 15:53:37 -07003782 /**
3783 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3784 * @param subId the subscription ID that this action applies to.
3785 * @param enabled control enable or disable metered apns.
3786 * {@hide}
3787 */
3788 @Override
3789 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3790 enforceModifyPermission();
3791 final Phone phone = getPhone(subId);
3792 if (phone == null) {
3793 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3794 return;
3795 }
3796 try {
3797 phone.carrierActionSetMeteredApnsEnabled(enabled);
3798 } catch (Exception e) {
3799 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3800 }
3801 }
3802
3803 /**
3804 * Action set from carrier signalling broadcast receivers to enable/disable radio
3805 * @param subId the subscription ID that this action applies to.
3806 * @param enabled control enable or disable radio.
3807 * {@hide}
3808 */
3809 @Override
3810 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3811 enforceModifyPermission();
3812 final Phone phone = getPhone(subId);
3813 if (phone == null) {
3814 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3815 return;
3816 }
3817 try {
3818 phone.carrierActionSetRadioEnabled(enabled);
3819 } catch (Exception e) {
3820 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3821 }
3822 }
3823
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003824 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003825 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3826 * network status based on which carrier apps could apply actions accordingly,
3827 * enable/disable default url handler for example.
3828 *
3829 * @param subId the subscription ID that this action applies to.
3830 * @param report control start/stop reporting the default network status.
3831 * {@hide}
3832 */
3833 @Override
3834 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3835 enforceModifyPermission();
3836 final Phone phone = getPhone(subId);
3837 if (phone == null) {
3838 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3839 return;
3840 }
3841 try {
3842 phone.carrierActionReportDefaultNetworkStatus(report);
3843 } catch (Exception e) {
3844 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3845 }
3846 }
3847
3848 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003849 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3850 * bug report is being generated.
3851 */
3852 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003853 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003854 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3855 != PackageManager.PERMISSION_GRANTED) {
3856 writer.println("Permission Denial: can't dump Phone from pid="
3857 + Binder.getCallingPid()
3858 + ", uid=" + Binder.getCallingUid()
3859 + "without permission "
3860 + android.Manifest.permission.DUMP);
3861 return;
3862 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003863 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003864 }
Jack Yueb89b242016-06-22 13:27:47 -07003865
3866 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003867 * Get aggregated video call data usage since boot.
3868 *
3869 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3870 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003871 * {@hide}
3872 */
3873 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003874 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003875 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3876 null);
3877
Jack Yu84291ec2017-05-26 16:07:50 -07003878 // NetworkStatsService keeps tracking the active network interface and identity. It
3879 // records the delta with the corresponding network identity. We just return the total video
3880 // call data usage snapshot since boot.
3881 Phone phone = getPhone(subId);
3882 if (phone != null) {
3883 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003884 }
Jack Yu84291ec2017-05-26 16:07:50 -07003885 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003886 }
Jack Yu75ab2952016-07-08 14:29:33 -07003887
3888 /**
3889 * Policy control of data connection. Usually used when data limit is passed.
3890 * @param enabled True if enabling the data, otherwise disabling.
3891 * @param subId Subscription index
3892 * {@hide}
3893 */
3894 @Override
3895 public void setPolicyDataEnabled(boolean enabled, int subId) {
3896 enforceModifyPermission();
3897 Phone phone = getPhone(subId);
3898 if (phone != null) {
3899 phone.setPolicyDataEnabled(enabled);
3900 }
3901 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003902
3903 /**
3904 * Get Client request stats
3905 * @return List of Client Request Stats
3906 * @hide
3907 */
3908 @Override
3909 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3910 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3911 return null;
3912 }
3913
3914 Phone phone = getPhone(subId);
3915 if (phone != null) {
3916 return phone.getClientRequestStats();
3917 }
3918
3919 return null;
3920 }
3921
3922 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3923 if (workSource != null) {
3924 return workSource;
3925 }
3926
3927 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3928 workSource = new WorkSource(uid, packageName);
3929 return workSource;
3930 }
Jack Yueb4124c2017-02-16 15:32:43 -08003931
3932 /**
Grace Chen70990072017-03-24 17:21:30 -07003933 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003934 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003935 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003936 * @param state State of SIM (power down, power up, pass through)
3937 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3938 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3939 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003940 *
3941 **/
3942 @Override
Grace Chen70990072017-03-24 17:21:30 -07003943 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003944 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003945 Phone phone = PhoneFactory.getPhone(slotIndex);
3946
Jack Yueb4124c2017-02-16 15:32:43 -08003947 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003948 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003949 }
3950 }
Shuo Qiandd210312017-04-12 22:11:33 +00003951
Tyler Gunn65d45c22017-06-05 11:22:26 -07003952 private boolean isUssdApiAllowed(int subId) {
3953 CarrierConfigManager configManager =
3954 (CarrierConfigManager) mPhone.getContext().getSystemService(
3955 Context.CARRIER_CONFIG_SERVICE);
3956 if (configManager == null) {
3957 return false;
3958 }
3959 PersistableBundle pb = configManager.getConfigForSubId(subId);
3960 if (pb == null) {
3961 return false;
3962 }
3963 return pb.getBoolean(
3964 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3965 }
3966
Shuo Qiandd210312017-04-12 22:11:33 +00003967 /**
3968 * Check if phone is in emergency callback mode
3969 * @return true if phone is in emergency callback mode
3970 * @param subId sub id
3971 */
3972 public boolean getEmergencyCallbackMode(int subId) {
3973 final Phone phone = getPhone(subId);
3974 if (phone != null) {
3975 return phone.isInEcm();
3976 } else {
3977 return false;
3978 }
3979 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003980
3981 /**
3982 * Get the current signal strength information for the given subscription.
3983 * Because this information is not updated when the device is in a low power state
3984 * it should not be relied-upon to be current.
3985 * @param subId Subscription index
3986 * @return the most recent cached signal strength info from the modem
3987 */
3988 @Override
3989 public SignalStrength getSignalStrength(int subId) {
3990 Phone p = getPhone(subId);
3991 if (p == null) {
3992 return null;
3993 }
3994
3995 return p.getSignalStrength();
3996 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00003997
3998 @Override
3999 public UiccSlotInfo[] getUiccSlotsInfo() {
4000 enforceReadPrivilegedPermission();
4001
4002 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4003 if (slots == null) return null;
4004 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4005 for (int i = 0; i < slots.length; i++) {
4006 UiccSlot slot = slots[i];
4007
4008 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4009
4010 int cardState = 0;
4011 switch (slot.getCardState()) {
4012 case CARDSTATE_ABSENT:
4013 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4014 break;
4015 case CARDSTATE_PRESENT:
4016 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4017 break;
4018 case CARDSTATE_ERROR:
4019 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4020 break;
4021 case CARDSTATE_RESTRICTED:
4022 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4023 break;
4024 default:
4025 break;
4026
4027 }
4028
4029 infos[i] = new UiccSlotInfo(slot.isActive(), slot.isEuicc(), cardId, cardState);
4030 }
4031 return infos;
4032 }
4033
4034 @Override
4035 public boolean switchSlots(int[] physicalSlots) {
4036 enforceModifyPermission();
4037 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4038 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004039}