blob: 4933ed8ef3fc62f894f0338e5b964585c3af1870 [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 Liu1aa510f2017-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;
Brad Ebingera12246d2018-01-16 09:39:35 -080074import android.telephony.ims.aidl.IImsConfig;
75import android.telephony.ims.aidl.IImsMmTelFeature;
76import android.telephony.ims.aidl.IImsRcsFeature;
77import android.telephony.ims.aidl.IImsRegistration;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080079import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080082import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080083
Andrew Lee312e8172014-10-23 17:01:36 -070084import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080085import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070086import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070087import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070088import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070089import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080092import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010093import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070094import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070095import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080097import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070098import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070099import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700100import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700101import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700102import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800103import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700104import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700105import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.uicc.IccIoResult;
107import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800108import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700109import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800110import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.uicc.UiccController;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700113import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800114import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700115import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800116import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700117import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700118import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700120import java.io.FileDescriptor;
121import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800122import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800124import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800125import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100126import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128
129/**
130 * Implementation of the ITelephony interface.
131 */
Santos Cordon117fee72014-05-16 17:56:12 -0700132public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133 private static final String LOG_TAG = "PhoneInterfaceManager";
134 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
135 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800136 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137
138 // Message codes used with mMainThreadHandler
139 private static final int CMD_HANDLE_PIN_MMI = 1;
140 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
141 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
142 private static final int CMD_ANSWER_RINGING_CALL = 4;
143 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700144 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
145 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700146 private static final int CMD_OPEN_CHANNEL = 9;
147 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
148 private static final int CMD_CLOSE_CHANNEL = 11;
149 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800150 private static final int CMD_NV_READ_ITEM = 13;
151 private static final int EVENT_NV_READ_ITEM_DONE = 14;
152 private static final int CMD_NV_WRITE_ITEM = 15;
153 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
154 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
155 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
156 private static final int CMD_NV_RESET_CONFIG = 19;
157 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800158 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
159 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
160 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
161 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800162 private static final int CMD_SEND_ENVELOPE = 25;
163 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700164 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
165 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
166 private static final int CMD_EXCHANGE_SIM_IO = 31;
167 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800168 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
169 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700170 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
171 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700172 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
173 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700174 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
175 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
176 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
177 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700178 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
179 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
180 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
181 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700182 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800183 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
184 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000185 private static final int CMD_SWITCH_SLOTS = 50;
186 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800188 // Parameters of select command.
189 private static final int SELECT_COMMAND = 0xA4;
190 private static final int SELECT_P1 = 0x04;
191 private static final int SELECT_P2 = 0;
192 private static final int SELECT_P3 = 0x10;
193
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 /** The singleton instance. */
195 private static PhoneInterfaceManager sInstance;
196
Wink Saville3ab207e2014-11-20 13:07:20 -0800197 private PhoneGlobals mApp;
198 private Phone mPhone;
199 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700200 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800201 private AppOpsManager mAppOps;
202 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800203 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800204 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
Derek Tan97ebb422014-09-05 16:55:38 -0700206 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
207 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800208 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700209
Derek Tan740e1672017-06-27 14:56:27 -0700210 // The AID of ISD-R.
211 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
212
yinxub1bed742017-04-17 11:45:04 -0700213 private NetworkScanRequestTracker mNetworkScanRequestTracker;
214
Derek Tan89e89d42014-07-08 17:00:10 -0700215 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700216 * A request object to use for transmitting data to an ICC.
217 */
218 private static final class IccAPDUArgument {
219 public int channel, cla, command, p1, p2, p3;
220 public String data;
221
222 public IccAPDUArgument(int channel, int cla, int command,
223 int p1, int p2, int p3, String data) {
224 this.channel = channel;
225 this.cla = cla;
226 this.command = command;
227 this.p1 = p1;
228 this.p2 = p2;
229 this.p3 = p3;
230 this.data = data;
231 }
232 }
233
234 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700235 * A request object to use for transmitting data to an ICC.
236 */
237 private static final class ManualNetworkSelectionArgument {
238 public OperatorInfo operatorInfo;
239 public boolean persistSelection;
240
241 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
242 this.operatorInfo = operatorInfo;
243 this.persistSelection = persistSelection;
244 }
245 }
246
247 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
249 * request after sending. The main thread will notify the request when it is complete.
250 */
251 private static final class MainThreadRequest {
252 /** The argument to use for the request */
253 public Object argument;
254 /** The result of the request that is run on the main thread */
255 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800256 // The subscriber id that this request applies to. Defaults to
257 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
258 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259
260 public MainThreadRequest(Object argument) {
261 this.argument = argument;
262 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800263
264 public MainThreadRequest(Object argument, Integer subId) {
265 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800266 if (subId != null) {
267 this.subId = subId;
268 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 }
271
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800272 private static final class IncomingThirdPartyCallArgs {
273 public final ComponentName component;
274 public final String callId;
275 public final String callerDisplayName;
276
277 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
278 String callerDisplayName) {
279 this.component = component;
280 this.callId = callId;
281 this.callerDisplayName = callerDisplayName;
282 }
283 }
284
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285 /**
286 * A handler that processes messages on the main thread in the phone process. Since many
287 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
288 * inbound binder threads to the main thread in the phone process. The Binder thread
289 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
290 * on, which will be notified when the operation completes and will contain the result of the
291 * request.
292 *
293 * <p>If a MainThreadRequest object is provided in the msg.obj field,
294 * note that request.result must be set to something non-null for the calling thread to
295 * unblock.
296 */
297 private final class MainThreadHandler extends Handler {
298 @Override
299 public void handleMessage(Message msg) {
300 MainThreadRequest request;
301 Message onCompleted;
302 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800303 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700304 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305
306 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700307 case CMD_HANDLE_USSD_REQUEST: {
308 request = (MainThreadRequest) msg.obj;
309 final Phone phone = getPhoneFromRequest(request);
310 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
311 String ussdRequest = ussdObject.first;
312 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700313
314 if (!isUssdApiAllowed(request.subId)) {
315 // Carrier does not support use of this API, return failure.
316 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
317 UssdResponse response = new UssdResponse(ussdRequest, null);
318 Bundle returnData = new Bundle();
319 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
320 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
321
322 request.result = true;
323 synchronized (request) {
324 request.notifyAll();
325 }
326 return;
327 }
328
Tyler Gunn52dcf772017-04-26 11:30:31 -0700329 try {
330 request.result = phone != null ?
331 phone.handleUssdRequest(ussdRequest, wrappedCallback)
332 : false;
333 } catch (CallStateException cse) {
334 request.result = false;
335 }
pkanwar32d516d2016-10-14 19:37:38 -0700336 // Wake up the requesting thread
337 synchronized (request) {
338 request.notifyAll();
339 }
340 break;
341 }
342
Yorke Lee716f67e2015-06-17 15:39:16 -0700343 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700345 final Phone phone = getPhoneFromRequest(request);
346 request.result = phone != null ?
347 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
348 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 // Wake up the requesting thread
350 synchronized (request) {
351 request.notifyAll();
352 }
353 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355
356 case CMD_HANDLE_NEIGHBORING_CELL:
357 request = (MainThreadRequest) msg.obj;
358 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
359 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700360 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 break;
362
363 case EVENT_NEIGHBORING_CELL_DONE:
364 ar = (AsyncResult) msg.obj;
365 request = (MainThreadRequest) ar.userObj;
366 if (ar.exception == null && ar.result != null) {
367 request.result = ar.result;
368 } else {
369 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800370 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 }
372 // Wake up the requesting thread
373 synchronized (request) {
374 request.notifyAll();
375 }
376 break;
377
378 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700379 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800380 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700381 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 break;
383
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 case CMD_END_CALL:
385 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800386 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700387 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700388 Phone phone = getPhone(end_subId);
389 if (phone == null) {
390 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
391 break;
392 }
393 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
395 // CDMA: If the user presses the Power button we treat it as
396 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700397 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
399 // GSM: End the call as per the Phone state
400 hungUp = PhoneUtils.hangup(mCM);
401 } else {
402 throw new IllegalStateException("Unexpected phone type: " + phoneType);
403 }
404 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
405 request.result = hungUp;
406 // Wake up the requesting thread
407 synchronized (request) {
408 request.notifyAll();
409 }
410 break;
411
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700413 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800415 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700416 if (uiccCard == null) {
417 loge("iccTransmitApduLogicalChannel: No UICC");
418 request.result = new IccIoResult(0x6F, 0, (byte[])null);
419 synchronized (request) {
420 request.notifyAll();
421 }
422 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
424 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700425 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 iccArgument.channel, iccArgument.cla, iccArgument.command,
427 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 break;
431
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 ar = (AsyncResult) msg.obj;
434 request = (MainThreadRequest) ar.userObj;
435 if (ar.exception == null && ar.result != null) {
436 request.result = ar.result;
437 } else {
438 request.result = new IccIoResult(0x6F, 0, (byte[])null);
439 if (ar.result == null) {
440 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800441 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800443 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 } else {
445 loge("iccTransmitApduLogicalChannel: Unknown exception");
446 }
447 }
448 synchronized (request) {
449 request.notifyAll();
450 }
451 break;
452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
454 request = (MainThreadRequest) msg.obj;
455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduBasicChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
460 synchronized (request) {
461 request.notifyAll();
462 }
463 } else {
464 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
465 request);
466 uiccCard.iccTransmitApduBasicChannel(
467 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
468 iccArgument.p3, iccArgument.data, onCompleted);
469 }
470 break;
471
472 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
473 ar = (AsyncResult) msg.obj;
474 request = (MainThreadRequest) ar.userObj;
475 if (ar.exception == null && ar.result != null) {
476 request.result = ar.result;
477 } else {
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
479 if (ar.result == null) {
480 loge("iccTransmitApduBasicChannel: Empty response");
481 } else if (ar.exception instanceof CommandException) {
482 loge("iccTransmitApduBasicChannel: CommandException: " +
483 ar.exception);
484 } else {
485 loge("iccTransmitApduBasicChannel: Unknown exception");
486 }
487 }
488 synchronized (request) {
489 request.notifyAll();
490 }
491 break;
492
493 case CMD_EXCHANGE_SIM_IO:
494 request = (MainThreadRequest) msg.obj;
495 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800496 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 if (uiccCard == null) {
498 loge("iccExchangeSimIO: No UICC");
499 request.result = new IccIoResult(0x6F, 0, (byte[])null);
500 synchronized (request) {
501 request.notifyAll();
502 }
503 } else {
504 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
505 request);
506 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
507 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
508 iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_EXCHANGE_SIM_IO_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6f, 0, (byte[])null);
519 }
520 synchronized (request) {
521 request.notifyAll();
522 }
523 break;
524
Derek Tan4d5e5c12014-02-04 11:54:58 -0800525 case CMD_SEND_ENVELOPE:
526 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700528 if (uiccCard == null) {
529 loge("sendEnvelopeWithStatus: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
531 synchronized (request) {
532 request.notifyAll();
533 }
534 } else {
535 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
536 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
537 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 break;
539
540 case EVENT_SEND_ENVELOPE_DONE:
541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
547 if (ar.result == null) {
548 loge("sendEnvelopeWithStatus: Empty response");
549 } else if (ar.exception instanceof CommandException) {
550 loge("sendEnvelopeWithStatus: CommandException: " +
551 ar.exception);
552 } else {
553 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
554 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800555 }
556 synchronized (request) {
557 request.notifyAll();
558 }
559 break;
560
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 case CMD_OPEN_CHANNEL:
562 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800564 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800567 request.result = new IccOpenLogicalChannelResponse(-1,
568 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 synchronized (request) {
570 request.notifyAll();
571 }
572 } else {
573 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800574 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
575 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 break;
578
579 case EVENT_OPEN_CHANNEL_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 int[] result = (int[]) ar.result;
585 int channelId = result[0];
586 byte[] selectResponse = null;
587 if (result.length > 1) {
588 selectResponse = new byte[result.length - 1];
589 for (int i = 1; i < result.length; ++i) {
590 selectResponse[i - 1] = (byte) result[i];
591 }
592 }
593 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 if (ar.result == null) {
597 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 if (ar.exception != null) {
600 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
601 }
602
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700603 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700604 if (ar.exception instanceof CommandException) {
605 CommandException.Error error =
606 ((CommandException) (ar.exception)).getCommandError();
607 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700609 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 }
612 }
613 openChannelResp = new IccOpenLogicalChannelResponse(
614 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700616 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 synchronized (request) {
618 request.notifyAll();
619 }
620 break;
621
622 case CMD_CLOSE_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 if (uiccCard == null) {
626 loge("iccCloseLogicalChannel: No UICC");
627 request.result = new IccIoResult(0x6F, 0, (byte[])null);
628 synchronized (request) {
629 request.notifyAll();
630 }
631 } else {
632 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
633 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
634 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 break;
636
637 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800638 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
639 break;
640
641 case CMD_NV_READ_ITEM:
642 request = (MainThreadRequest) msg.obj;
643 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
644 mPhone.nvReadItem((Integer) request.argument, onCompleted);
645 break;
646
647 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 ar = (AsyncResult) msg.obj;
649 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800650 if (ar.exception == null && ar.result != null) {
651 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800653 request.result = "";
654 if (ar.result == null) {
655 loge("nvReadItem: Empty response");
656 } else if (ar.exception instanceof CommandException) {
657 loge("nvReadItem: CommandException: " +
658 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800660 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 }
662 }
663 synchronized (request) {
664 request.notifyAll();
665 }
666 break;
667
Jake Hambye994d462014-02-03 13:10:13 -0800668 case CMD_NV_WRITE_ITEM:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
671 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
672 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
673 break;
674
675 case EVENT_NV_WRITE_ITEM_DONE:
676 handleNullReturnEvent(msg, "nvWriteItem");
677 break;
678
679 case CMD_NV_WRITE_CDMA_PRL:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
682 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
683 break;
684
685 case EVENT_NV_WRITE_CDMA_PRL_DONE:
686 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
687 break;
688
689 case CMD_NV_RESET_CONFIG:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
692 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
693 break;
694
695 case EVENT_NV_RESET_CONFIG_DONE:
696 handleNullReturnEvent(msg, "nvResetConfig");
697 break;
698
Jake Hamby7c27be32014-03-03 13:25:59 -0800699 case CMD_GET_PREFERRED_NETWORK_TYPE:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700702 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800703 break;
704
705 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
706 ar = (AsyncResult) msg.obj;
707 request = (MainThreadRequest) ar.userObj;
708 if (ar.exception == null && ar.result != null) {
709 request.result = ar.result; // Integer
710 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800711 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800712 if (ar.result == null) {
713 loge("getPreferredNetworkType: Empty response");
714 } else if (ar.exception instanceof CommandException) {
715 loge("getPreferredNetworkType: CommandException: " +
716 ar.exception);
717 } else {
718 loge("getPreferredNetworkType: Unknown exception");
719 }
720 }
721 synchronized (request) {
722 request.notifyAll();
723 }
724 break;
725
726 case CMD_SET_PREFERRED_NETWORK_TYPE:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
729 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700730 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
734 handleNullReturnEvent(msg, "setPreferredNetworkType");
735 break;
736
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800737 case CMD_SET_VOICEMAIL_NUMBER:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
740 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800741 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
742 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800743 break;
744
745 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
746 handleNullReturnEvent(msg, "setVoicemailNumber");
747 break;
748
Stuart Scott54788802015-03-30 13:18:01 -0700749 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
752 request);
753 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
754 break;
755
756 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
757 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
758 break;
759
Shishir Agrawal302c8692015-06-19 13:49:39 -0700760 case CMD_PERFORM_NETWORK_SCAN:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
763 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
764 break;
765
766 case EVENT_PERFORM_NETWORK_SCAN_DONE:
767 ar = (AsyncResult) msg.obj;
768 request = (MainThreadRequest) ar.userObj;
769 CellNetworkScanResult cellScanResult;
770 if (ar.exception == null && ar.result != null) {
771 cellScanResult = new CellNetworkScanResult(
772 CellNetworkScanResult.STATUS_SUCCESS,
773 (List<OperatorInfo>) ar.result);
774 } else {
775 if (ar.result == null) {
776 loge("getCellNetworkScanResults: Empty response");
777 }
778 if (ar.exception != null) {
779 loge("getCellNetworkScanResults: Exception: " + ar.exception);
780 }
781 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
782 if (ar.exception instanceof CommandException) {
783 CommandException.Error error =
784 ((CommandException) (ar.exception)).getCommandError();
785 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
786 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
787 } else if (error == CommandException.Error.GENERIC_FAILURE) {
788 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
789 }
790 }
791 cellScanResult = new CellNetworkScanResult(errorCode, null);
792 }
793 request.result = cellScanResult;
794 synchronized (request) {
795 request.notifyAll();
796 }
797 break;
798
799 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
800 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700801 ManualNetworkSelectionArgument selArg =
802 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700803 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
804 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700805 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
806 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700807 break;
808
809 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
810 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
811 break;
812
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700813 case CMD_GET_MODEM_ACTIVITY_INFO:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700816 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700817 break;
818
819 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null && ar.result != null) {
823 request.result = ar.result;
824 } else {
825 if (ar.result == null) {
826 loge("queryModemActivityInfo: Empty response");
827 } else if (ar.exception instanceof CommandException) {
828 loge("queryModemActivityInfo: CommandException: " +
829 ar.exception);
830 } else {
831 loge("queryModemActivityInfo: Unknown exception");
832 }
833 }
Amit Mahajand4766222016-01-28 15:28:28 -0800834 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
835 if (request.result == null) {
836 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
837 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700838 synchronized (request) {
839 request.notifyAll();
840 }
841 break;
842
Meng Wang1a7c35a2016-05-05 20:56:15 -0700843 case CMD_SET_ALLOWED_CARRIERS:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
846 mPhone.setAllowedCarriers(
847 (List<CarrierIdentifier>) request.argument,
848 onCompleted);
849 break;
850
851 case EVENT_SET_ALLOWED_CARRIERS_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 if (ar.result == null) {
858 loge("setAllowedCarriers: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("setAllowedCarriers: CommandException: " +
861 ar.exception);
862 } else {
863 loge("setAllowedCarriers: Unknown exception");
864 }
865 }
866 // Result cannot be null. Return -1 on error.
867 if (request.result == null) {
868 request.result = new int[]{-1};
869 }
870 synchronized (request) {
871 request.notifyAll();
872 }
873 break;
874
875 case CMD_GET_ALLOWED_CARRIERS:
876 request = (MainThreadRequest) msg.obj;
877 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
878 mPhone.getAllowedCarriers(onCompleted);
879 break;
880
881 case EVENT_GET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
887 if (ar.result == null) {
888 loge("getAllowedCarriers: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("getAllowedCarriers: CommandException: " +
891 ar.exception);
892 } else {
893 loge("getAllowedCarriers: Unknown exception");
894 }
895 }
896 // Result cannot be null. Return empty list of CarrierIdentifier.
897 if (request.result == null) {
898 request.result = new ArrayList<CarrierIdentifier>(0);
899 }
900 synchronized (request) {
901 request.notifyAll();
902 }
903 break;
904
Nathan Haroldb3014052017-01-25 15:57:32 -0800905 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
906 ar = (AsyncResult) msg.obj;
907 request = (MainThreadRequest) ar.userObj;
908 if (ar.exception == null && ar.result != null) {
909 request.result = ar.result;
910 } else {
911 request.result = new IllegalArgumentException(
912 "Failed to retrieve Forbidden Plmns");
913 if (ar.result == null) {
914 loge("getForbiddenPlmns: Empty response");
915 } else {
916 loge("getForbiddenPlmns: Unknown exception");
917 }
918 }
919 synchronized (request) {
920 request.notifyAll();
921 }
922 break;
923
924 case CMD_GET_FORBIDDEN_PLMNS:
925 request = (MainThreadRequest) msg.obj;
926 uiccCard = getUiccCardFromRequest(request);
927 if (uiccCard == null) {
928 loge("getForbiddenPlmns() UiccCard is null");
929 request.result = new IllegalArgumentException(
930 "getForbiddenPlmns() UiccCard is null");
931 synchronized (request) {
932 request.notifyAll();
933 }
934 break;
935 }
936 Integer appType = (Integer) request.argument;
937 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
938 if (uiccApp == null) {
939 loge("getForbiddenPlmns() no app with specified type -- "
940 + appType);
941 request.result = new IllegalArgumentException("Failed to get UICC App");
942 synchronized (request) {
943 request.notifyAll();
944 }
945 break;
946 } else {
947 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
948 + " specified type -- " + appType);
949 }
950 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
951 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
952 onCompleted);
953 break;
954
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000955 case CMD_SWITCH_SLOTS:
956 request = (MainThreadRequest) msg.obj;
957 int[] physicalSlots = (int[]) request.argument;
958 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
959 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
960 break;
961
962 case EVENT_SWITCH_SLOTS_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 request.result = (ar.exception == null);
966 synchronized (request) {
967 request.notifyAll();
968 }
969 break;
970
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700971 default:
972 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
973 break;
974 }
975 }
Jake Hambye994d462014-02-03 13:10:13 -0800976
977 private void handleNullReturnEvent(Message msg, String command) {
978 AsyncResult ar = (AsyncResult) msg.obj;
979 MainThreadRequest request = (MainThreadRequest) ar.userObj;
980 if (ar.exception == null) {
981 request.result = true;
982 } else {
983 request.result = false;
984 if (ar.exception instanceof CommandException) {
985 loge(command + ": CommandException: " + ar.exception);
986 } else {
987 loge(command + ": Unknown exception");
988 }
989 }
990 synchronized (request) {
991 request.notifyAll();
992 }
993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700994 }
995
996 /**
997 * Posts the specified command to be executed on the main thread,
998 * waits for the request to complete, and returns the result.
999 * @see #sendRequestAsync
1000 */
1001 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001002 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001003 }
1004
1005 /**
1006 * Posts the specified command to be executed on the main thread,
1007 * waits for the request to complete, and returns the result.
1008 * @see #sendRequestAsync
1009 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001010 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001011 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1012 throw new RuntimeException("This method will deadlock if called from the main thread.");
1013 }
1014
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001015 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001016 Message msg = mMainThreadHandler.obtainMessage(command, request);
1017 msg.sendToTarget();
1018
1019 // Wait for the request to complete
1020 synchronized (request) {
1021 while (request.result == null) {
1022 try {
1023 request.wait();
1024 } catch (InterruptedException e) {
1025 // Do nothing, go back and wait until the request is complete
1026 }
1027 }
1028 }
1029 return request.result;
1030 }
1031
1032 /**
1033 * Asynchronous ("fire and forget") version of sendRequest():
1034 * Posts the specified command to be executed on the main thread, and
1035 * returns immediately.
1036 * @see #sendRequest
1037 */
1038 private void sendRequestAsync(int command) {
1039 mMainThreadHandler.sendEmptyMessage(command);
1040 }
1041
1042 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001043 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1044 * @see {@link #sendRequest(int,Object)}
1045 */
1046 private void sendRequestAsync(int command, Object argument) {
1047 MainThreadRequest request = new MainThreadRequest(argument);
1048 Message msg = mMainThreadHandler.obtainMessage(command, request);
1049 msg.sendToTarget();
1050 }
1051
1052 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001053 * Initialize the singleton PhoneInterfaceManager instance.
1054 * This is only done once, at startup, from PhoneApp.onCreate().
1055 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001056 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001057 synchronized (PhoneInterfaceManager.class) {
1058 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001059 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001060 } else {
1061 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1062 }
1063 return sInstance;
1064 }
1065 }
1066
1067 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001068 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001069 mApp = app;
1070 mPhone = phone;
1071 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001072 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001073 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1074 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001075 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001076 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001077 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001078 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001079
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001080 publish();
1081 }
1082
1083 private void publish() {
1084 if (DBG) log("publish: " + this);
1085
1086 ServiceManager.addService("phone", this);
1087 }
1088
Stuart Scott584921c2015-01-15 17:10:34 -08001089 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001090 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1091 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001092 }
1093
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001094 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1095 Phone phone = getPhoneFromRequest(request);
1096 return phone == null ? null :
1097 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1098 }
1099
Wink Saville36469e72014-06-11 15:17:00 -07001100 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001101 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001102 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001104 //
1105 // Implementation of the ITelephony interface.
1106 //
1107
1108 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001109 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001110 }
1111
Wink Savilleb564aae2014-10-23 10:18:09 -07001112 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001113 if (DBG) log("dial: " + number);
1114 // No permission check needed here: This is just a wrapper around the
1115 // ACTION_DIAL intent, which is available to any app since it puts up
1116 // the UI before it does anything.
1117
1118 String url = createTelUrl(number);
1119 if (url == null) {
1120 return;
1121 }
1122
1123 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001124 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001125 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1126 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1127 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1128 mApp.startActivity(intent);
1129 }
1130 }
1131
1132 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001133 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001134 }
1135
Wink Savilleb564aae2014-10-23 10:18:09 -07001136 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001137 if (DBG) log("call: " + number);
1138
1139 // This is just a wrapper around the ACTION_CALL intent, but we still
1140 // need to do a permission check since we're calling startActivity()
1141 // from the context of the phone app.
1142 enforceCallPermission();
1143
1144 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1145 != AppOpsManager.MODE_ALLOWED) {
1146 return;
1147 }
1148
1149 String url = createTelUrl(number);
1150 if (url == null) {
1151 return;
1152 }
1153
Wink Saville08874612014-08-31 19:19:58 -07001154 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001155 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001156 if (slist != null) {
1157 for (SubscriptionInfo subInfoRecord : slist) {
1158 if (subInfoRecord.getSubscriptionId() == subId) {
1159 isValid = true;
1160 break;
1161 }
Wink Saville08874612014-08-31 19:19:58 -07001162 }
1163 }
1164 if (isValid == false) {
1165 return;
1166 }
1167
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001169 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001170 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1171 mApp.startActivity(intent);
1172 }
1173
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 /**
1175 * End a call based on call state
1176 * @return true is a call was ended
1177 */
1178 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001179 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001180 }
1181
1182 /**
1183 * End a call based on the call state of the subId
1184 * @return true is a call was ended
1185 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001186 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001187 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001188 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189 }
1190
1191 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001192 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001193 }
1194
Wink Savilleb564aae2014-10-23 10:18:09 -07001195 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 if (DBG) log("answerRingingCall...");
1197 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1198 // but that can probably wait till the big TelephonyManager API overhaul.
1199 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1200 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001201 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 }
1203
1204 /**
1205 * Make the actual telephony calls to implement answerRingingCall().
1206 * This should only be called from the main thread of the Phone app.
1207 * @see #answerRingingCall
1208 *
1209 * TODO: it would be nice to return true if we answered the call, or
1210 * false if there wasn't actually a ringing incoming call, or some
1211 * other error occurred. (In other words, pass back the return value
1212 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1213 * But that would require calling this method via sendRequest() rather
1214 * than sendRequestAsync(), and right now we don't actually *need* that
1215 * return value, so let's just return void for now.
1216 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001217 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001218 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001220 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1221 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 if (hasActiveCall && hasHoldingCall) {
1223 // Both lines are in use!
1224 // TODO: provide a flag to let the caller specify what
1225 // policy to use if both lines are in use. (The current
1226 // behavior is hardwired to "answer incoming, end ongoing",
1227 // which is how the CALL button is specced to behave.)
1228 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1229 return;
1230 } else {
1231 // answerCall() will automatically hold the current active
1232 // call, if there is one.
1233 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1234 return;
1235 }
1236 } else {
1237 // No call was ringing.
1238 return;
1239 }
1240 }
1241
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001243 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001245 public void silenceRinger() {
1246 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 }
1248
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001249 @Override
1250 public boolean isOffhook(String callingPackage) {
1251 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001252 }
1253
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001254 @Override
1255 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1256 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1257 return false;
1258 }
1259
Sanket Padawe356d7632015-06-22 14:03:32 -07001260 final Phone phone = getPhone(subId);
1261 if (phone != null) {
1262 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1263 } else {
1264 return false;
1265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 }
1267
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001268 @Override
1269 public boolean isRinging(String callingPackage) {
1270 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001271 }
1272
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001273 @Override
1274 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1275 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1276 return false;
1277 }
1278
Sanket Padawe356d7632015-06-22 14:03:32 -07001279 final Phone phone = getPhone(subId);
1280 if (phone != null) {
1281 return (phone.getState() == PhoneConstants.State.RINGING);
1282 } else {
1283 return false;
1284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 }
1286
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001287 @Override
1288 public boolean isIdle(String callingPackage) {
1289 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001290 }
1291
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001292 @Override
1293 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1294 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1295 return false;
1296 }
1297
Sanket Padawe356d7632015-06-22 14:03:32 -07001298 final Phone phone = getPhone(subId);
1299 if (phone != null) {
1300 return (phone.getState() == PhoneConstants.State.IDLE);
1301 } else {
1302 return false;
1303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 }
1305
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001307 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001308 }
1309
Wink Savilleb564aae2014-10-23 10:18:09 -07001310 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001311 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001312 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1313 }
1314
1315 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001316 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001317 }
1318
Wink Savilleb564aae2014-10-23 10:18:09 -07001319 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001321 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1322 }
1323
1324 /** {@hide} */
1325 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001326 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001327 }
1328
Wink Savilleb564aae2014-10-23 10:18:09 -07001329 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001331 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 checkSimPin.start();
1333 return checkSimPin.unlockSim(null, pin);
1334 }
1335
Wink Saville9de0f752013-10-22 19:04:03 -07001336 /** {@hide} */
1337 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001338 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001339 }
1340
Wink Savilleb564aae2014-10-23 10:18:09 -07001341 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001343 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 checkSimPuk.start();
1345 return checkSimPuk.unlockSim(puk, pin);
1346 }
1347
1348 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001349 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 * a synchronous one.
1351 */
1352 private static class UnlockSim extends Thread {
1353
1354 private final IccCard mSimCard;
1355
1356 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001357 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1358 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359
1360 // For replies from SimCard interface
1361 private Handler mHandler;
1362
1363 // For async handler to identify request type
1364 private static final int SUPPLY_PIN_COMPLETE = 100;
1365
1366 public UnlockSim(IccCard simCard) {
1367 mSimCard = simCard;
1368 }
1369
1370 @Override
1371 public void run() {
1372 Looper.prepare();
1373 synchronized (UnlockSim.this) {
1374 mHandler = new Handler() {
1375 @Override
1376 public void handleMessage(Message msg) {
1377 AsyncResult ar = (AsyncResult) msg.obj;
1378 switch (msg.what) {
1379 case SUPPLY_PIN_COMPLETE:
1380 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1381 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001382 mRetryCount = msg.arg1;
1383 if (ar.exception != null) {
1384 if (ar.exception instanceof CommandException &&
1385 ((CommandException)(ar.exception)).getCommandError()
1386 == CommandException.Error.PASSWORD_INCORRECT) {
1387 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1388 } else {
1389 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1390 }
1391 } else {
1392 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mDone = true;
1395 UnlockSim.this.notifyAll();
1396 }
1397 break;
1398 }
1399 }
1400 };
1401 UnlockSim.this.notifyAll();
1402 }
1403 Looper.loop();
1404 }
1405
1406 /*
1407 * Use PIN or PUK to unlock SIM card
1408 *
1409 * If PUK is null, unlock SIM card with PIN
1410 *
1411 * If PUK is not null, unlock SIM card with PUK and set PIN code
1412 */
Wink Saville9de0f752013-10-22 19:04:03 -07001413 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414
1415 while (mHandler == null) {
1416 try {
1417 wait();
1418 } catch (InterruptedException e) {
1419 Thread.currentThread().interrupt();
1420 }
1421 }
1422 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1423
1424 if (puk == null) {
1425 mSimCard.supplyPin(pin, callback);
1426 } else {
1427 mSimCard.supplyPuk(puk, pin, callback);
1428 }
1429
1430 while (!mDone) {
1431 try {
1432 Log.d(LOG_TAG, "wait for done");
1433 wait();
1434 } catch (InterruptedException e) {
1435 // Restore the interrupted status
1436 Thread.currentThread().interrupt();
1437 }
1438 }
1439 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001440 int[] resultArray = new int[2];
1441 resultArray[0] = mResult;
1442 resultArray[1] = mRetryCount;
1443 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001444 }
1445 }
1446
1447 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001448 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001449
1450 }
1451
Wink Savilleb564aae2014-10-23 10:18:09 -07001452 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 // No permission check needed here: this call is harmless, and it's
1454 // needed for the ServiceState.requestStateUpdate() call (which is
1455 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001456 final Phone phone = getPhone(subId);
1457 if (phone != null) {
1458 phone.updateServiceLocation();
1459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 }
1461
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001462 @Override
1463 public boolean isRadioOn(String callingPackage) {
1464 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001465 }
1466
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001467 @Override
1468 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1469 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1470 return false;
1471 }
1472 return isRadioOnForSubscriber(subId);
1473 }
1474
1475 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001476 final Phone phone = getPhone(subId);
1477 if (phone != null) {
1478 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1479 } else {
1480 return false;
1481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483
1484 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001486
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 }
Wink Saville36469e72014-06-11 15:17:00 -07001488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001491 final Phone phone = getPhone(subId);
1492 if (phone != null) {
1493 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1494 }
Wink Saville36469e72014-06-11 15:17:00 -07001495 }
1496
1497 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001498 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001499 }
1500
Wink Savilleb564aae2014-10-23 10:18:09 -07001501 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001502 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001503 final Phone phone = getPhone(subId);
1504 if (phone == null) {
1505 return false;
1506 }
1507 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001508 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001509 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 }
1511 return true;
1512 }
Wink Saville36469e72014-06-11 15:17:00 -07001513
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001514 public boolean needMobileRadioShutdown() {
1515 /*
1516 * If any of the Radios are available, it will need to be
1517 * shutdown. So return true if any Radio is available.
1518 */
1519 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1520 Phone phone = PhoneFactory.getPhone(i);
1521 if (phone != null && phone.isRadioAvailable()) return true;
1522 }
1523 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1524 return false;
1525 }
1526
1527 public void shutdownMobileRadios() {
1528 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1529 logv("Shutting down Phone " + i);
1530 shutdownRadioUsingPhoneId(i);
1531 }
1532 }
1533
1534 private void shutdownRadioUsingPhoneId(int phoneId) {
1535 enforceModifyPermission();
1536 Phone phone = PhoneFactory.getPhone(phoneId);
1537 if (phone != null && phone.isRadioAvailable()) {
1538 phone.shutdownRadio();
1539 }
1540 }
1541
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001542 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001543 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001544 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1545 if (defaultPhone != null) {
1546 defaultPhone.setRadioPower(turnOn);
1547 return true;
1548 } else {
1549 loge("There's no default phone.");
1550 return false;
1551 }
Wink Saville36469e72014-06-11 15:17:00 -07001552 }
1553
Wink Savilleb564aae2014-10-23 10:18:09 -07001554 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001556 final Phone phone = getPhone(subId);
1557 if (phone != null) {
1558 phone.setRadioPower(turnOn);
1559 return true;
1560 } else {
1561 return false;
1562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
1564
Wink Saville36469e72014-06-11 15:17:00 -07001565 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001566 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 public boolean enableDataConnectivity() {
1568 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001569 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001572 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 return true;
1574 } else {
1575 return false;
1576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
Wink Saville36469e72014-06-11 15:17:00 -07001579 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 public boolean disableDataConnectivity() {
1582 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001583 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001584 final Phone phone = getPhone(subId);
1585 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001586 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 return true;
1588 } else {
1589 return false;
1590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 }
1592
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001594 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001595 final Phone phone = getPhone(subId);
1596 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001597 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001598 } else {
1599 return false;
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
1603 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001604 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001605 }
1606
pkanwarae03a6b2016-11-06 20:37:09 -08001607 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001608 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001609 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1610 return;
1611 }
1612 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1613 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1614 };
1615
Wink Savilleb564aae2014-10-23 10:18:09 -07001616 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1619 return false;
1620 }
Wink Saville36469e72014-06-11 15:17:00 -07001621 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
1623
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001625 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001626 }
1627
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001628 public int getCallStateForSlot(int slotIndex) {
1629 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001630 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001631 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 }
1633
Sanket Padawe356d7632015-06-22 14:03:32 -07001634 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001636 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001637 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001638 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001639 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001640 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 }
1643
Sanket Padawe356d7632015-06-22 14:03:32 -07001644 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001646 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001647 if (phone != null) {
1648 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1649 } else {
1650 return TelephonyManager.DATA_ACTIVITY_NONE;
1651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653
1654 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001655 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001656 mPhone.getContext().getSystemService(AppOpsManager.class)
1657 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001658 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001659 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001660 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 }
1662
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001663 if (DBG_LOC) log("getCellLocation: is active user");
1664 Bundle data = new Bundle();
1665 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1666 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 return null;
1668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001670 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1671 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1672 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001673 }
1674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001676 public String getNetworkCountryIsoForPhone(int phoneId) {
1677 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1678 // registered cell info, so return a NULL country instead.
1679 final long identity = Binder.clearCallingIdentity();
1680 try {
1681 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1682 if (TelephonyManager.NETWORK_TYPE_IWLAN
1683 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1684 return "";
1685 }
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
1688 }
1689 return TelephonyManager.getTelephonyProperty(
1690 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1691 }
1692
1693 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001695 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001696 }
1697
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001699 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 mApp.enforceCallingOrSelfPermission(
1701 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 final Phone phone = getPhone(subId);
1703 if (phone != null) {
1704 phone.enableLocationUpdates();
1705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 }
1707
1708 @Override
1709 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001710 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001711 }
1712
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001714 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 mApp.enforceCallingOrSelfPermission(
1716 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 final Phone phone = getPhone(subId);
1718 if (phone != null) {
1719 phone.disableLocationUpdates();
1720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 }
1722
1723 @Override
1724 @SuppressWarnings("unchecked")
1725 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001726 mPhone.getContext().getSystemService(AppOpsManager.class)
1727 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001728 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001729 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001730 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 }
1732
1733 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1734 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1735 return null;
1736 }
Svetoslav64fad262015-04-14 14:35:21 -07001737
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001738 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001740 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001742 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1743 try {
1744 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1745 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1746 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1747 } catch (RuntimeException e) {
1748 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001750 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
1752
1753
1754 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001755 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001756 mPhone.getContext().getSystemService(AppOpsManager.class)
1757 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001758 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001759 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001760 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 }
1762
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001763 if (DBG_LOC) log("getAllCellInfo: is active user");
1764 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1765 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1766 for (Phone phone : PhoneFactory.getPhones()) {
1767 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1768 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001770 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001775 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001776 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1777 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Shishir Agrawala9f32182016-04-12 12:00:16 -07001780 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001781 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001782 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1783 return null;
1784 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001785 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001786 return phone == null ? null : phone.getImei();
1787 }
1788
1789 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001790 public String getMeidForSlot(int slotIndex, String callingPackage) {
1791 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1792 return null;
1793 }
1794 Phone phone = PhoneFactory.getPhone(slotIndex);
1795 return phone == null ? null : phone.getMeid();
1796 }
1797
1798 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001799 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001800 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1801 return null;
1802 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001803 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001804 return phone == null ? null : phone.getDeviceSvn();
1805 }
1806
fionaxuf32acdf2017-11-27 22:51:16 -08001807 @Override
1808 public int getSubscriptionCarrierId(int subId) {
1809 final Phone phone = getPhone(subId);
1810 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1811 }
1812
1813 @Override
1814 public String getSubscriptionCarrierName(int subId) {
1815 final Phone phone = getPhone(subId);
1816 return phone == null ? null : phone.getCarrierName();
1817 }
1818
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 //
1820 // Internal helper methods.
1821 //
1822
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001823 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1825 *
1826 * @throws SecurityException if the caller does not have the required permission
1827 */
1828 private void enforceModifyPermission() {
1829 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1830 }
1831
1832 /**
Junda Liua2e36012014-07-09 18:30:01 -07001833 * Make sure either system app or the caller has carrier privilege.
1834 *
1835 * @throws SecurityException if the caller does not have the required permission/privilege
1836 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001837 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001838 int permission = mApp.checkCallingOrSelfPermission(
1839 android.Manifest.permission.MODIFY_PHONE_STATE);
1840 if (permission == PackageManager.PERMISSION_GRANTED) {
1841 return;
1842 }
1843
1844 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001845 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001846 }
1847
1848 /**
1849 * Make sure the caller has carrier privilege.
1850 *
1851 * @throws SecurityException if the caller does not have the required permission
1852 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001853 private void enforceCarrierPrivilege(int subId) {
1854 if (getCarrierPrivilegeStatus(subId) !=
1855 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001856 loge("No Carrier Privilege.");
1857 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001858 }
1859 }
1860
1861 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 * Make sure the caller has the CALL_PHONE permission.
1863 *
1864 * @throws SecurityException if the caller does not have the required permission
1865 */
1866 private void enforceCallPermission() {
1867 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1868 }
1869
Stuart Scott8eef64f2015-04-08 15:13:54 -07001870 private void enforceConnectivityInternalPermission() {
1871 mApp.enforceCallingOrSelfPermission(
1872 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1873 "ConnectivityService");
1874 }
1875
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 private String createTelUrl(String number) {
1877 if (TextUtils.isEmpty(number)) {
1878 return null;
1879 }
1880
Jake Hambye994d462014-02-03 13:10:13 -08001881 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 }
1883
Ihab Awadf9e92732013-12-05 18:02:52 -08001884 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1886 }
1887
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001888 private static void logv(String msg) {
1889 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1890 }
1891
Ihab Awadf9e92732013-12-05 18:02:52 -08001892 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1894 }
1895
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001896 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001898 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001902 public int getActivePhoneTypeForSlot(int slotIndex) {
1903 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 if (phone == null) {
1905 return PhoneConstants.PHONE_TYPE_NONE;
1906 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001907 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 }
1910
1911 /**
1912 * Returns the CDMA ERI icon index to display
1913 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001914 @Override
1915 public int getCdmaEriIconIndex(String callingPackage) {
1916 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001917 }
1918
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001920 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1921 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1922 return -1;
1923 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 final Phone phone = getPhone(subId);
1925 if (phone != null) {
1926 return phone.getCdmaEriIconIndex();
1927 } else {
1928 return -1;
1929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 }
1931
1932 /**
1933 * Returns the CDMA ERI icon mode,
1934 * 0 - ON
1935 * 1 - FLASHING
1936 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001937 @Override
1938 public int getCdmaEriIconMode(String callingPackage) {
1939 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001940 }
1941
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001943 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1944 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1945 return -1;
1946 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 final Phone phone = getPhone(subId);
1948 if (phone != null) {
1949 return phone.getCdmaEriIconMode();
1950 } else {
1951 return -1;
1952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
1955 /**
1956 * Returns the CDMA ERI text,
1957 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001958 @Override
1959 public String getCdmaEriText(String callingPackage) {
1960 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001961 }
1962
Sanket Padawe356d7632015-06-22 14:03:32 -07001963 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001964 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1965 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1966 return null;
1967 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001968 final Phone phone = getPhone(subId);
1969 if (phone != null) {
1970 return phone.getCdmaEriText();
1971 } else {
1972 return null;
1973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
1976 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001977 * Returns the CDMA MDN.
1978 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001980 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001981 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001982 final Phone phone = getPhone(subId);
1983 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1984 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001985 } else {
1986 return null;
1987 }
1988 }
1989
1990 /**
1991 * Returns the CDMA MIN.
1992 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001994 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001995 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 final Phone phone = getPhone(subId);
1997 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1998 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001999 } else {
2000 return null;
2001 }
2002 }
2003
2004 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 * Returns true if CDMA provisioning needs to run.
2006 */
2007 public boolean needsOtaServiceProvisioning() {
2008 return mPhone.needsOtaServiceProvisioning();
2009 }
2010
2011 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002012 * Sets the voice mail number of a given subId.
2013 */
2014 @Override
2015 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002016 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002017 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2018 new Pair<String, String>(alphaTag, number), new Integer(subId));
2019 return success;
2020 }
2021
Ta-wei Yen87c49842016-05-13 21:19:52 -07002022 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002023 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2024 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2025 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2026 if (!TextUtils.equals(callingPackage, systemDialer)) {
2027 throw new SecurityException("caller must be system dialer");
2028 }
2029 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2030 if (phoneAccountHandle == null){
2031 return null;
2032 }
2033 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2034 }
2035
2036 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002037 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002038 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2039 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2040 return null;
2041 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002042 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2043 }
2044
2045 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002046 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2047 VisualVoicemailSmsFilterSettings settings) {
2048 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002049 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002050 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2051 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002052 }
2053
2054 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002055 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2056 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002057 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002058 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002059 }
2060
2061 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002062 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2063 String callingPackage, int subId) {
2064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002065 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002066 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002067 }
2068
2069 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002070 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002071 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002072 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002073 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2074 }
2075
2076 @Override
2077 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2078 String number, int port, String text, PendingIntent sentIntent) {
2079 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002080 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002081 enforceSendSmsPermission();
2082 // Make the calls as the phone process.
2083 final long identity = Binder.clearCallingIdentity();
2084 try {
2085 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2086 if (port == 0) {
2087 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2088 sentIntent, null, false);
2089 } else {
2090 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2091 smsManager.sendDataMessageWithSelfPermissions(number, null,
2092 (short) port, data, sentIntent, null);
2093 }
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
2096 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002097 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002098 /**
fionaxu0152e512016-11-14 13:36:14 -08002099 * Sets the voice activation state of a given subId.
2100 */
2101 @Override
2102 public void setVoiceActivationState(int subId, int activationState) {
2103 enforceModifyPermissionOrCarrierPrivilege(subId);
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 phone.setVoiceActivationState(activationState);
2107 } else {
2108 loge("setVoiceActivationState fails with invalid subId: " + subId);
2109 }
2110 }
2111
2112 /**
2113 * Sets the data activation state of a given subId.
2114 */
2115 @Override
2116 public void setDataActivationState(int subId, int activationState) {
2117 enforceModifyPermissionOrCarrierPrivilege(subId);
2118 final Phone phone = getPhone(subId);
2119 if (phone != null) {
2120 phone.setDataActivationState(activationState);
2121 } else {
2122 loge("setVoiceActivationState fails with invalid subId: " + subId);
2123 }
2124 }
2125
2126 /**
2127 * Returns the voice activation state of a given subId.
2128 */
2129 @Override
2130 public int getVoiceActivationState(int subId, String callingPackage) {
2131 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2132 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2133 }
2134 final Phone phone = getPhone(subId);
2135 if (phone != null) {
2136 return phone.getVoiceActivationState();
2137 } else {
2138 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2139 }
2140 }
2141
2142 /**
2143 * Returns the data activation state of a given subId.
2144 */
2145 @Override
2146 public int getDataActivationState(int subId, String callingPackage) {
2147 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2148 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2149 }
2150 final Phone phone = getPhone(subId);
2151 if (phone != null) {
2152 return phone.getDataActivationState();
2153 } else {
2154 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2155 }
2156 }
2157
2158 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 * Returns the unread count of voicemails
2160 */
2161 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002162 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002163 }
2164
2165 /**
2166 * Returns the unread count of voicemails for a subId
2167 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002169 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002170 final Phone phone = getPhone(subId);
2171 if (phone != null) {
2172 return phone.getVoiceMessageCount();
2173 } else {
2174 return 0;
2175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 }
2177
2178 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002179 * returns true, if the device is in a state where both voice and data
2180 * are supported simultaneously. This can change based on location or network condition.
2181 */
2182 @Override
2183 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2184 final Phone phone = getPhone(subId);
2185 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2186 }
2187
2188 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002189 * Send the dialer code if called from the current default dialer or the caller has
2190 * carrier privilege.
2191 * @param inputCode The dialer code to send
2192 */
2193 @Override
2194 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2195 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2196 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2197 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2198 enforceCarrierPrivilege(getDefaultSubscription());
2199 }
2200 mPhone.sendDialerSpecialCode(inputCode);
2201 }
2202
2203 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002204 * Returns the data network type.
2205 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 *
2207 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2208 */
2209 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002210 public int getNetworkType() {
2211 final Phone phone = getPhone(getDefaultSubscription());
2212 if (phone != null) {
2213 return phone.getServiceState().getDataNetworkType();
2214 } else {
2215 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2216 }
Wink Saville36469e72014-06-11 15:17:00 -07002217 }
2218
2219 /**
2220 * Returns the network type for a subId
2221 */
2222 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002223 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2224 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2225 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2226 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002227
Sanket Padawe356d7632015-06-22 14:03:32 -07002228 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002229 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002230 return phone.getServiceState().getDataNetworkType();
2231 } else {
2232 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235
2236 /**
2237 * Returns the data network type
2238 */
2239 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002240 public int getDataNetworkType(String callingPackage) {
2241 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002242 }
2243
2244 /**
2245 * Returns the data network type for a subId
2246 */
2247 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002248 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2249 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2250 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2251 }
2252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 final Phone phone = getPhone(subId);
2254 if (phone != null) {
2255 return phone.getServiceState().getDataNetworkType();
2256 } else {
2257 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
2261 /**
Wink Saville36469e72014-06-11 15:17:00 -07002262 * Returns the Voice network type for a subId
2263 */
2264 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002265 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2266 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2267 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2268 }
2269
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 final Phone phone = getPhone(subId);
2271 if (phone != null) {
2272 return phone.getServiceState().getVoiceNetworkType();
2273 } else {
2274 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 }
2277
2278 /**
2279 * @return true if a ICC card is present
2280 */
2281 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002282 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002283 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2284 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002285 }
2286
2287 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002288 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002289 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002290 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002291 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2292 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002293 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002294 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002295 } else {
2296 return false;
2297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
2300 /**
2301 * Return if the current radio is LTE on CDMA. This
2302 * is a tri-state return value as for a period of time
2303 * the mode may be unknown.
2304 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002305 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002307 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002309 @Override
2310 public int getLteOnCdmaMode(String callingPackage) {
2311 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002312 }
2313
Sanket Padawe356d7632015-06-22 14:03:32 -07002314 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002315 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2316 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2317 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2318 }
2319
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 final Phone phone = getPhone(subId);
2321 if (phone == null) {
2322 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2323 } else {
2324 return phone.getLteOnCdmaMode();
2325 }
Wink Saville36469e72014-06-11 15:17:00 -07002326 }
2327
2328 public void setPhone(Phone phone) {
2329 mPhone = phone;
2330 }
2331
2332 /**
2333 * {@hide}
2334 * Returns Default subId, 0 in the case of single standby.
2335 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002336 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002337 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002338 }
2339
Shishir Agrawala9f32182016-04-12 12:00:16 -07002340 private int getSlotForDefaultSubscription() {
2341 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2342 }
2343
Wink Savilleb564aae2014-10-23 10:18:09 -07002344 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002345 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002347
2348 /**
2349 * @see android.telephony.TelephonyManager.WifiCallingChoices
2350 */
2351 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002352 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2353 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002354 }
2355
2356 /**
2357 * @see android.telephony.TelephonyManager.WifiCallingChoices
2358 */
2359 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002360 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2361 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2362 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002363 }
2364
Sailesh Nepald1e68152013-12-12 19:08:02 -08002365 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002366 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002367 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002368 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002369
Shishir Agrawal566b7612013-10-28 14:41:00 -07002370 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002371 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2372 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002373 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002374
Derek Tan740e1672017-06-27 14:56:27 -07002375 if (TextUtils.equals(ISDR_AID, aid)) {
2376 // Only allows LPA to open logical channel to ISD-R.
2377 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2378 ComponentInfo bestComponent =
2379 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2380 if (bestComponent == null
2381 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2382 loge("The calling package is not allowed to access ISD-R.");
2383 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2384 }
2385 }
2386
2387 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002388 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002389 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002390 if (DBG) log("iccOpenLogicalChannel: " + response);
2391 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002392 }
2393
2394 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002395 public boolean iccCloseLogicalChannel(int subId, int channel) {
2396 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002397
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002398 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002399 if (channel < 0) {
2400 return false;
2401 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002402 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002403 if (DBG) log("iccCloseLogicalChannel: " + success);
2404 return success;
2405 }
2406
2407 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002408 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002409 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002410 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002411
2412 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002413 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2414 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002415 " data=" + data);
2416 }
2417
2418 if (channel < 0) {
2419 return "";
2420 }
2421
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002422 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002423 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002424 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2425
Shishir Agrawal566b7612013-10-28 14:41:00 -07002426 // Append the returned status code to the end of the response payload.
2427 String s = Integer.toHexString(
2428 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002429 if (response.payload != null) {
2430 s = IccUtils.bytesToHexString(response.payload) + s;
2431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002432 return s;
2433 }
Jake Hambye994d462014-02-03 13:10:13 -08002434
Evan Charltonc66da362014-05-16 14:06:40 -07002435 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002436 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2437 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002438 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002439
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002440 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2441 && TextUtils.equals(ISDR_AID, data)) {
2442 // Only allows LPA to select ISD-R.
2443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2444 ComponentInfo bestComponent =
2445 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2446 if (bestComponent == null
2447 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2448 loge("The calling package is not allowed to select ISD-R.");
2449 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2450 }
2451 }
2452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002453 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002454 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2455 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002456 }
2457
2458 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002459 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002460 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002462 // Append the returned status code to the end of the response payload.
2463 String s = Integer.toHexString(
2464 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002465 if (response.payload != null) {
2466 s = IccUtils.bytesToHexString(response.payload) + s;
2467 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002468 return s;
2469 }
2470
2471 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002472 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002473 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002474 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002475
2476 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002478 p1 + " " + p2 + " " + p3 + ":" + filePath);
2479 }
2480
2481 IccIoResult response =
2482 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002483 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2484 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002485
2486 if (DBG) {
2487 log("Exchange SIM_IO [R]" + response);
2488 }
2489
2490 byte[] result = null;
2491 int length = 2;
2492 if (response.payload != null) {
2493 length = 2 + response.payload.length;
2494 result = new byte[length];
2495 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2496 } else {
2497 result = new byte[length];
2498 }
2499
2500 result[length - 1] = (byte) response.sw2;
2501 result[length - 2] = (byte) response.sw1;
2502 return result;
2503 }
2504
Nathan Haroldb3014052017-01-25 15:57:32 -08002505 /**
2506 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2507 * on a particular subscription
2508 */
2509 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002510 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2511 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002512 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2513 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2514 return null;
2515 }
2516 Object response = sendRequest(
2517 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2518 if (response instanceof String[]) {
2519 return (String[]) response;
2520 }
2521 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2522 return null;
2523 }
2524
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002525 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002526 public String sendEnvelopeWithStatus(int subId, String content) {
2527 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002528
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002529 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002530 if (response.payload == null) {
2531 return "";
2532 }
2533
2534 // Append the returned status code to the end of the response payload.
2535 String s = Integer.toHexString(
2536 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2537 s = IccUtils.bytesToHexString(response.payload) + s;
2538 return s;
2539 }
2540
Jake Hambye994d462014-02-03 13:10:13 -08002541 /**
2542 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2543 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2544 *
2545 * @param itemID the ID of the item to read
2546 * @return the NV item as a String, or null on error.
2547 */
2548 @Override
2549 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002550 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002551 if (DBG) log("nvReadItem: item " + itemID);
2552 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2553 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2554 return value;
2555 }
2556
2557 /**
2558 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2559 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2560 *
2561 * @param itemID the ID of the item to read
2562 * @param itemValue the value to write, as a String
2563 * @return true on success; false on any failure
2564 */
2565 @Override
2566 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002567 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002568 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2569 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2570 new Pair<Integer, String>(itemID, itemValue));
2571 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2572 return success;
2573 }
2574
2575 /**
2576 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2577 * Used for device configuration by some CDMA operators.
2578 *
2579 * @param preferredRoamingList byte array containing the new PRL
2580 * @return true on success; false on any failure
2581 */
2582 @Override
2583 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002584 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002585 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2586 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2587 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2588 return success;
2589 }
2590
2591 /**
2592 * Perform the specified type of NV config reset.
2593 * Used for device configuration by some CDMA operators.
2594 *
2595 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2596 * @return true on success; false on any failure
2597 */
2598 @Override
2599 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002600 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002601 if (DBG) log("nvResetConfig: type " + resetType);
2602 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2603 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2604 return success;
2605 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002606
2607 /**
Wink Saville36469e72014-06-11 15:17:00 -07002608 * {@hide}
2609 * Returns Default sim, 0 in the case of single standby.
2610 */
2611 public int getDefaultSim() {
2612 //TODO Need to get it from Telephony Devcontroller
2613 return 0;
2614 }
2615
Svet Ganovb320e182015-04-16 12:30:10 -07002616 public String[] getPcscfAddress(String apnType, String callingPackage) {
2617 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2618 return new String[0];
2619 }
2620
2621
ram87fca6f2014-07-18 18:58:44 +05302622 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002623 }
2624
Brad Ebinger51f743a2017-01-23 13:50:20 -08002625 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002626 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2627 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002628 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002629 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002630 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002631 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002632 }
2633
2634 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002635 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2636 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002637 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002638 public void disableIms(int slotId) {
2639 enforceModifyPermission();
2640 PhoneFactory.getImsResolver().disableIms(slotId);
2641 }
2642
2643 /**
2644 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2645 * feature or {@link null} if the service is not available. If the feature is available, the
2646 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2647 */
2648 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002649 IImsServiceFeatureCallback callback) {
2650 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002651 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002652 }
2653
2654 /**
2655 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2656 * feature during emergency calling or {@link null} if the service is not available. If the
2657 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2658 * listener for feature updates.
2659 */
2660 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2661 enforceModifyPermission();
2662 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002663 }
2664
Brad Ebinger7e934f52017-12-14 14:26:15 -08002665 /**
2666 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2667 * specified.
2668 */
2669 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2670 enforceModifyPermission();
2671 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2672 }
2673
Brad Ebingera12246d2018-01-16 09:39:35 -08002674 /**
2675 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2676 * specified.
2677 */
2678 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2679 enforceModifyPermission();
2680 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2681 }
2682
Wink Saville36469e72014-06-11 15:17:00 -07002683 public void setImsRegistrationState(boolean registered) {
2684 enforceModifyPermission();
2685 mPhone.setImsRegistrationState(registered);
2686 }
2687
2688 /**
Stuart Scott54788802015-03-30 13:18:01 -07002689 * Set the network selection mode to automatic.
2690 *
2691 */
2692 @Override
2693 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002694 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002695 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2696 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2697 }
2698
2699 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002700 * Set the network selection mode to manual with the selected carrier.
2701 */
2702 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002703 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002704 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002705 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002706 OperatorInfo operator = new OperatorInfo(
2707 /* operatorAlphaLong */ "",
2708 /* operatorAlphaShort */ "",
2709 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002710 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002711 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2712 persistSelection);
2713 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002714 }
2715
2716 /**
2717 * Scans for available networks.
2718 */
2719 @Override
2720 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002721 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002722 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2723 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2724 CMD_PERFORM_NETWORK_SCAN, null, subId);
2725 return result;
2726 }
2727
2728 /**
yinxub1bed742017-04-17 11:45:04 -07002729 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002730 *
yinxub1bed742017-04-17 11:45:04 -07002731 * @param subId id of the subscription
2732 * @param request contains the radio access networks with bands/channels to scan
2733 * @param messenger callback messenger for scan results or errors
2734 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002735 * @return the id of the requested scan which can be used to stop the scan.
2736 */
2737 @Override
2738 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2739 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002740 enforceModifyPermissionOrCarrierPrivilege(subId);
2741 return mNetworkScanRequestTracker.startNetworkScan(
2742 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002743 }
2744
2745 /**
2746 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002747 *
2748 * @param subId id of the subscription
2749 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002750 */
2751 @Override
2752 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002753 enforceModifyPermissionOrCarrierPrivilege(subId);
2754 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002755 }
2756
2757 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002758 * Get the calculated preferred network type.
2759 * Used for debugging incorrect network type.
2760 *
2761 * @return the preferred network type, defined in RILConstants.java.
2762 */
2763 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002764 public int getCalculatedPreferredNetworkType(String callingPackage) {
2765 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2766 return RILConstants.PREFERRED_NETWORK_MODE;
2767 }
2768
Amit Mahajan43330e02014-11-18 11:54:45 -08002769 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002770 }
2771
2772 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002773 * Get the preferred network type.
2774 * Used for device configuration by some CDMA operators.
2775 *
2776 * @return the preferred network type, defined in RILConstants.java.
2777 */
2778 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002779 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002780 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002781 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002782 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002783 int networkType = (result != null ? result[0] : -1);
2784 if (DBG) log("getPreferredNetworkType: " + networkType);
2785 return networkType;
2786 }
2787
2788 /**
2789 * Set the preferred network type.
2790 * Used for device configuration by some CDMA operators.
2791 *
2792 * @param networkType the preferred network type, defined in RILConstants.java.
2793 * @return true on success; false on any failure.
2794 */
2795 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002796 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002797 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002798 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2799 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002800 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002801 if (success) {
2802 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002803 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002804 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002805 return success;
2806 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002807
2808 /**
Junda Liu475951f2014-11-07 16:45:03 -08002809 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2810 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2811 * tethering.
2812 *
2813 * @return 0: Not required. 1: required. 2: Not set.
2814 * @hide
2815 */
2816 @Override
2817 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002818 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002819 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2820 Settings.Global.TETHER_DUN_REQUIRED, 2);
2821 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2822 // config_tether_apndata.
2823 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2824 dunRequired = 1;
2825 }
2826 return dunRequired;
2827 }
2828
2829 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002830 * Set mobile data enabled
2831 * Used by the user through settings etc to turn on/off mobile data
2832 *
2833 * @param enable {@code true} turn turn data on, else {@code false}
2834 */
2835 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002836 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002837 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002838 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002839 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002840 Phone phone = PhoneFactory.getPhone(phoneId);
2841 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002842 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2843 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002844 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002845 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002846 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002847 }
2848
2849 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002850 * Get the user enabled state of Mobile Data.
2851 *
2852 * TODO: remove and use isUserDataEnabled.
2853 * This can't be removed now because some vendor codes
2854 * calls through ITelephony directly while they should
2855 * use TelephonyManager.
2856 *
2857 * @return true on enabled
2858 */
2859 @Override
2860 public boolean getDataEnabled(int subId) {
2861 return isUserDataEnabled(subId);
2862 }
2863
2864 /**
2865 * Get whether mobile data is enabled per user setting.
2866 *
2867 * There are other factors deciding whether mobile data is actually enabled, but they are
2868 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002869 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002870 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002871 *
2872 * @return {@code true} if data is enabled else {@code false}
2873 */
2874 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002875 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002876 try {
2877 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2878 null);
2879 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002880 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002881 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002882 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002883 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002884 Phone phone = PhoneFactory.getPhone(phoneId);
2885 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002886 boolean retVal = phone.isUserDataEnabled();
2887 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002888 return retVal;
2889 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002890 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2891 return false;
2892 }
2893 }
2894
2895 /**
2896 * Get whether mobile data is enabled.
2897 *
2898 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2899 * whether mobile data is actually enabled.
2900 *
2901 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2902 *
2903 * @return {@code true} if data is enabled else {@code false}
2904 */
2905 @Override
2906 public boolean isDataEnabled(int subId) {
2907 try {
2908 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2909 null);
2910 } catch (Exception e) {
2911 enforceModifyPermissionOrCarrierPrivilege(subId);
2912 }
2913 int phoneId = mSubscriptionController.getPhoneId(subId);
2914 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2915 Phone phone = PhoneFactory.getPhone(phoneId);
2916 if (phone != null) {
2917 boolean retVal = phone.isDataEnabled();
2918 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2919 return retVal;
2920 } else {
2921 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002922 return false;
2923 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002924 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002925
2926 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002927 public int getCarrierPrivilegeStatus(int subId) {
2928 final Phone phone = getPhone(subId);
2929 if (phone == null) {
2930 loge("getCarrierPrivilegeStatus: Invalid subId");
2931 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2932 }
2933 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002934 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002935 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002936 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2937 }
2938 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002939 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002940 }
Junda Liu29340342014-07-10 15:23:27 -07002941
2942 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002943 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002944 if (TextUtils.isEmpty(pkgName))
2945 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002946 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002947 if (card == null) {
2948 loge("checkCarrierPrivilegesForPackage: No UICC");
2949 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2950 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002951 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2952 }
2953
2954 @Override
2955 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002956 if (TextUtils.isEmpty(pkgName))
2957 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002958 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2959 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2960 UiccCard card = UiccController.getInstance().getUiccCard(i);
2961 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002962 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002963 continue;
2964 }
2965
2966 result = card.getCarrierPrivilegeStatus(
2967 mPhone.getContext().getPackageManager(), pkgName);
2968 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2969 break;
2970 }
2971 }
2972
2973 return result;
Junda Liu29340342014-07-10 15:23:27 -07002974 }
Derek Tan89e89d42014-07-08 17:00:10 -07002975
2976 @Override
Junda Liue64de782015-04-16 17:19:16 -07002977 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2978 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2979 loge("phoneId " + phoneId + " is not valid.");
2980 return null;
2981 }
2982 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002983 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002984 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002985 return null ;
2986 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002987 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002988 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002989 }
2990
Amith Yamasani6e118872016-02-19 12:53:51 -08002991 @Override
2992 public List<String> getPackagesWithCarrierPrivileges() {
2993 PackageManager pm = mPhone.getContext().getPackageManager();
2994 List<String> privilegedPackages = new ArrayList<>();
2995 List<PackageInfo> packages = null;
2996 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2997 UiccCard card = UiccController.getInstance().getUiccCard(i);
2998 if (card == null) {
2999 // No UICC in that slot.
3000 continue;
3001 }
3002 if (card.hasCarrierPrivilegeRules()) {
3003 if (packages == null) {
3004 // Only check packages in user 0 for now
3005 packages = pm.getInstalledPackagesAsUser(
3006 PackageManager.MATCH_DISABLED_COMPONENTS
3007 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3008 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3009 }
3010 for (int p = packages.size() - 1; p >= 0; p--) {
3011 PackageInfo pkgInfo = packages.get(p);
3012 if (pkgInfo != null && pkgInfo.packageName != null
3013 && card.getCarrierPrivilegeStatus(pkgInfo)
3014 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3015 privilegedPackages.add(pkgInfo.packageName);
3016 }
3017 }
3018 }
3019 }
3020 return privilegedPackages;
3021 }
3022
Wink Savilleb564aae2014-10-23 10:18:09 -07003023 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003024 final Phone phone = getPhone(subId);
3025 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003026 if (card == null) {
3027 loge("getIccId: No UICC");
3028 return null;
3029 }
3030 String iccId = card.getIccId();
3031 if (TextUtils.isEmpty(iccId)) {
3032 loge("getIccId: ICC ID is null or empty.");
3033 return null;
3034 }
3035 return iccId;
3036 }
3037
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003038 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003039 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3040 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003041 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003042
Jeff Sharkey85190e62014-12-05 09:40:12 -08003043 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003044 final Phone phone = getPhone(subId);
3045 if (phone == null) {
3046 return false;
3047 }
3048 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003049
3050 if (DBG_MERGE) {
3051 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3052 + subscriberId + " to " + number);
3053 }
3054
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003055 if (TextUtils.isEmpty(iccId)) {
3056 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003057 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003058
Jeff Sharkey85190e62014-12-05 09:40:12 -08003059 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3060
3061 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003062 if (alphaTag == null) {
3063 editor.remove(alphaTagPrefKey);
3064 } else {
3065 editor.putString(alphaTagPrefKey, alphaTag);
3066 }
3067
Jeff Sharkey85190e62014-12-05 09:40:12 -08003068 // Record both the line number and IMSI for this ICCID, since we need to
3069 // track all merged IMSIs based on line number
3070 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3071 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003072 if (number == null) {
3073 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003074 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003075 } else {
3076 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003077 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003078 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003079
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003080 editor.commit();
3081 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003082 }
3083
3084 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003085 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003086 // This is open to apps with WRITE_SMS.
3087 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003088 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003089 return null;
3090 }
Derek Tan97ebb422014-09-05 16:55:38 -07003091
3092 String iccId = getIccId(subId);
3093 if (iccId != null) {
3094 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003095 if (DBG_MERGE) {
3096 log("getLine1NumberForDisplay returning " +
3097 mTelephonySharedPreferences.getString(numberPrefKey, null));
3098 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003099 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003100 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003101 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003102 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003103 }
3104
3105 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003106 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3107 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3108 return null;
3109 }
Derek Tan97ebb422014-09-05 16:55:38 -07003110
3111 String iccId = getIccId(subId);
3112 if (iccId != null) {
3113 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003114 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003115 }
Derek Tan97ebb422014-09-05 16:55:38 -07003116 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003117 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003118
3119 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003120 public String[] getMergedSubscriberIds(String callingPackage) {
3121 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3122 return null;
3123 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003124 final Context context = mPhone.getContext();
3125 final TelephonyManager tele = TelephonyManager.from(context);
3126 final SubscriptionManager sub = SubscriptionManager.from(context);
3127
3128 // Figure out what subscribers are currently active
3129 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003130 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3131 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 final int[] subIds = sub.getActiveSubscriptionIdList();
3135 for (int subId : subIds) {
3136 activeSubscriberIds.add(tele.getSubscriberId(subId));
3137 }
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003140 }
3141
3142 // First pass, find a number override for an active subscriber
3143 String mergeNumber = null;
3144 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3145 for (String key : prefs.keySet()) {
3146 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3147 final String subscriberId = (String) prefs.get(key);
3148 if (activeSubscriberIds.contains(subscriberId)) {
3149 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3150 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3151 mergeNumber = (String) prefs.get(numberKey);
3152 if (DBG_MERGE) {
3153 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3154 + " for active subscriber " + subscriberId);
3155 }
3156 if (!TextUtils.isEmpty(mergeNumber)) {
3157 break;
3158 }
3159 }
3160 }
3161 }
3162
3163 // Shortcut when no active merged subscribers
3164 if (TextUtils.isEmpty(mergeNumber)) {
3165 return null;
3166 }
3167
3168 // Second pass, find all subscribers under that line override
3169 final ArraySet<String> result = new ArraySet<>();
3170 for (String key : prefs.keySet()) {
3171 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3172 final String number = (String) prefs.get(key);
3173 if (mergeNumber.equals(number)) {
3174 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3175 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3176 final String subscriberId = (String) prefs.get(subscriberKey);
3177 if (!TextUtils.isEmpty(subscriberId)) {
3178 result.add(subscriberId);
3179 }
3180 }
3181 }
3182 }
3183
3184 final String[] resultArray = result.toArray(new String[result.size()]);
3185 Arrays.sort(resultArray);
3186 if (DBG_MERGE) {
3187 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3188 }
3189 return resultArray;
3190 }
3191
3192 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003193 public boolean setOperatorBrandOverride(int subId, String brand) {
3194 enforceCarrierPrivilege(subId);
3195 final Phone phone = getPhone(subId);
3196 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003197 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003198
3199 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003200 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003201 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3202 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003203 enforceCarrierPrivilege(subId);
3204 final Phone phone = getPhone(subId);
3205 if (phone == null) {
3206 return false;
3207 }
3208 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003209 cdmaNonRoamingList);
3210 }
3211
3212 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003213 public void setRadioCapability(RadioAccessFamily[] rafs) {
3214 try {
3215 ProxyController.getInstance().setRadioCapability(rafs);
3216 } catch (RuntimeException e) {
3217 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3218 }
3219 }
3220
3221 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003222 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3223 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3224 return RadioAccessFamily.RAF_UNKNOWN;
3225 }
3226
Wink Saville5d475dd2014-10-17 15:00:58 -07003227 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3228 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003229
3230 @Override
3231 public void enableVideoCalling(boolean enable) {
3232 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003233 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003234 }
3235
3236 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003237 public boolean isVideoCallingEnabled(String callingPackage) {
3238 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3239 return false;
3240 }
3241
Andrew Lee77527ac2014-10-21 16:57:39 -07003242 // Check the user preference and the system-level IMS setting. Even if the user has
3243 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3244 // In the long run, we may instead need to check if there exists a connection service
3245 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003246 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3247 return imsManager.isVtEnabledByPlatform()
3248 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3249 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003250 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003251
Andrew Leea1239f22015-03-02 17:44:07 -08003252 @Override
3253 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003254 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003255 }
3256
3257 @Override
3258 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003259 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003260 }
3261
Andrew Lee9431b832015-03-09 18:46:45 -07003262 @Override
3263 public boolean isTtyModeSupported() {
3264 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3265 TelephonyManager telephonyManager =
3266 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003267 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003268 }
3269
3270 @Override
3271 public boolean isHearingAidCompatibilitySupported() {
3272 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3273 }
3274
Sanket Padawe7310cc72015-01-14 09:53:20 -08003275 /**
3276 * Returns the unique device ID of phone, for example, the IMEI for
3277 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3278 *
3279 * <p>Requires Permission:
3280 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3281 */
3282 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003283 public String getDeviceId(String callingPackage) {
3284 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3285 return null;
3286 }
3287
Sanket Padawe7310cc72015-01-14 09:53:20 -08003288 final Phone phone = PhoneFactory.getPhone(0);
3289 if (phone != null) {
3290 return phone.getDeviceId();
3291 } else {
3292 return null;
3293 }
3294 }
3295
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003296 /*
3297 * {@hide}
3298 * Returns the IMS Registration Status
3299 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003300 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003301 public boolean isImsRegistered() {
3302 return mPhone.isImsRegistered();
3303 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003304
Ping Sun014fe8e2016-03-02 19:16:45 +08003305 /**
3306 * {@hide}
3307 * Returns the IMS Registration Status on a particular subid
3308 *
3309 * @param subId
3310 */
3311 public boolean isImsRegisteredForSubscriber(int subId) {
3312 Phone phone = getPhone(subId);
3313 if (phone != null) {
3314 return phone.isImsRegistered();
3315 } else {
3316 return false;
3317 }
3318 }
3319
Santos Cordon7a1885b2015-02-03 11:15:19 -08003320 @Override
3321 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3322 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3323 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003324
Nathan Haroldc55097a2015-03-11 18:14:50 -07003325 /*
3326 * {@hide}
3327 * Returns the IMS Registration Status
3328 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003329 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003330 return mPhone.isWifiCallingEnabled();
3331 }
3332
3333 /*
3334 * {@hide}
3335 * Returns the IMS Registration Status
3336 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003337 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003338 return mPhone.isVolteEnabled();
3339 }
Svet Ganovb320e182015-04-16 12:30:10 -07003340
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003341 /*
3342 * {@hide} Returns the IMS Registration Status
3343 */
3344 public boolean isVideoTelephonyAvailable() {
3345 return mPhone.isVideoEnabled();
3346 }
3347
Svet Ganovb320e182015-04-16 12:30:10 -07003348 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003349 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003350 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003351 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3352
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003353 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003354 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003355 } catch (SecurityException e) {
3356 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3357 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003358 }
Svet Ganovb320e182015-04-16 12:30:10 -07003359
3360 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3361 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3362 return false;
3363 }
3364
3365 return true;
3366 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003367
Makoto Onukifee69342015-06-29 14:44:50 -07003368 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003369 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003370 */
3371 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003372 // Default SMS app can always read it.
3373 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3374 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3375 return true;
3376 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003377
Makoto Onukie4072d12015-08-03 15:12:23 -07003378 try {
3379 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003380 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003381 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003382 // Can be read with READ_SMS too.
3383 try {
3384 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3385 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3386 if (opCode != AppOpsManager.OP_NONE) {
3387 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3388 == AppOpsManager.MODE_ALLOWED;
3389 } else {
3390 return true;
3391 }
3392 } catch (SecurityException readSmsSecurityException) {
3393 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003394 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003395 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003396 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003397 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003398 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003399 if (opCode != AppOpsManager.OP_NONE) {
3400 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3401 == AppOpsManager.MODE_ALLOWED;
3402 } else {
3403 return true;
3404 }
3405 } catch (SecurityException readPhoneNumberSecurityException) {
3406 }
3407
3408 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3409 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3410 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003411 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003412 }
3413
Stuart Scott8eef64f2015-04-08 15:13:54 -07003414 @Override
3415 public void factoryReset(int subId) {
3416 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003417 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3418 return;
3419 }
3420
Svet Ganovcc087f82015-05-12 20:35:54 -07003421 final long identity = Binder.clearCallingIdentity();
3422 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003423 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3424 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003425 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003426 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003427 // Set network selection mode to automatic
3428 setNetworkSelectionModeAutomatic(subId);
3429 // Set preferred mobile network type to the best available
3430 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3431 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003432 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003433 }
3434 } finally {
3435 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003436 }
3437 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003438
3439 @Override
3440 public String getLocaleFromDefaultSim() {
3441 // We query all subscriptions instead of just the active ones, because
3442 // this might be called early on in the provisioning flow when the
3443 // subscriptions potentially aren't active yet.
3444 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3445 if (slist == null || slist.isEmpty()) {
3446 return null;
3447 }
3448
3449 // This function may be called very early, say, from the setup wizard, at
3450 // which point we won't have a default subscription set. If that's the case
3451 // we just choose the first, which will be valid in "most cases".
3452 final int defaultSubId = getDefaultSubscription();
3453 SubscriptionInfo info = null;
3454 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3455 info = slist.get(0);
3456 } else {
3457 for (SubscriptionInfo item : slist) {
3458 if (item.getSubscriptionId() == defaultSubId) {
3459 info = item;
3460 break;
3461 }
3462 }
3463
3464 if (info == null) {
3465 return null;
3466 }
3467 }
3468
3469 // Try and fetch the locale from the carrier properties or from the SIM language
3470 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003471 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003472 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003473 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003474 if (defaultPhone != null) {
3475 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3476 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003477 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003478 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3479 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003480 } else {
3481 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003482 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003483 }
3484 }
3485
Narayan Kamath011676f2015-07-29 12:04:08 +01003486 // The SIM language preferences only store a language (e.g. fr = French), not an
3487 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3488 // the SIM and carrier preferences does not include a country we add the country
3489 // determined from the SIM MCC to provide an exact locale.
3490 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003491 if (mccLocale != null) {
3492 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3493 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003494 }
3495
Tony Hill183b2de2015-06-24 14:53:58 +01003496 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003497 return null;
3498 }
3499
3500 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3501 final long identity = Binder.clearCallingIdentity();
3502 try {
3503 return mSubscriptionController.getAllSubInfoList(
3504 mPhone.getContext().getOpPackageName());
3505 } finally {
3506 Binder.restoreCallingIdentity(identity);
3507 }
3508 }
3509
3510 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3511 final long identity = Binder.clearCallingIdentity();
3512 try {
3513 return mSubscriptionController.getActiveSubscriptionInfoList(
3514 mPhone.getContext().getOpPackageName());
3515 } finally {
3516 Binder.restoreCallingIdentity(identity);
3517 }
3518 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003519
3520 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003521 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3522 * representing the state of the modem.
3523 *
3524 * NOTE: This clears the modem state, so there should only every be one caller.
3525 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003526 */
3527 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003528 public void requestModemActivityInfo(ResultReceiver result) {
3529 enforceModifyPermission();
3530
3531 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3532 Bundle bundle = new Bundle();
3533 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3534 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003535 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003536
3537 /**
3538 * {@hide}
3539 * Returns the service state information on specified subscription.
3540 */
3541 @Override
3542 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3543
3544 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3545 return null;
3546 }
3547
3548 final Phone phone = getPhone(subId);
3549 if (phone == null) {
3550 return null;
3551 }
3552
3553 return phone.getServiceState();
3554 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003555
3556 /**
3557 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3558 *
3559 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3560 * voicemail ringtone.
3561 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3562 * PhoneAccount.
3563 */
3564 @Override
3565 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003566 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003567 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003568 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003569 }
3570
fionaxu7ed723d2017-05-30 18:58:54 -07003571 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003572 }
3573
3574 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003575 * Sets the per-account voicemail ringtone.
3576 *
3577 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3578 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3579 *
3580 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3581 * voicemail ringtone.
3582 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3583 * PhoneAccount.
3584 */
3585 @Override
3586 public void setVoicemailRingtoneUri(String callingPackage,
3587 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3589 if (!TextUtils.equals(callingPackage,
3590 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3591 enforceModifyPermissionOrCarrierPrivilege(
3592 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3593 }
3594 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3595 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003596 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003597 }
fionaxu7ed723d2017-05-30 18:58:54 -07003598 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003599 }
3600
3601 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003602 * Returns whether vibration is set for voicemail notification in Phone settings.
3603 *
3604 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3605 * voicemail vibration setting.
3606 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3607 */
3608 @Override
3609 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003610 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003611 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003612 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003613 }
3614
fionaxu7ed723d2017-05-30 18:58:54 -07003615 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003616 }
3617
Youhan Wange64578a2016-05-02 15:32:42 -07003618 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003619 * Sets the per-account voicemail vibration.
3620 *
3621 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3622 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3623 *
3624 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3625 * voicemail vibration setting.
3626 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3627 * specific PhoneAccount.
3628 */
3629 @Override
3630 public void setVoicemailVibrationEnabled(String callingPackage,
3631 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3632 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3633 if (!TextUtils.equals(callingPackage,
3634 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3635 enforceModifyPermissionOrCarrierPrivilege(
3636 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3637 }
3638
3639 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3640 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003641 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003642 }
fionaxu7ed723d2017-05-30 18:58:54 -07003643 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003644 }
3645
3646 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003647 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3648 *
3649 * @throws SecurityException if the caller does not have the required permission
3650 */
3651 private void enforceReadPrivilegedPermission() {
3652 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3653 null);
3654 }
3655
3656 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003657 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3658 * permission.
3659 *
3660 * @throws SecurityException if the caller does not have the required permission
3661 */
3662 private void enforceSendSmsPermission() {
3663 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3664 }
3665
3666 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003667 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003668 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003669 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003670 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003671 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003672 ComponentName componentName =
3673 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3674 if(componentName == null) {
3675 throw new SecurityException("Caller not current active visual voicemail package[null]");
3676 }
3677 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003678 if (!callingPackage.equals(vvmPackage)) {
3679 throw new SecurityException("Caller not current active visual voicemail package[" +
3680 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003681 }
3682 }
3683
3684 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003685 * Return the application ID for the app type.
3686 *
3687 * @param subId the subscription ID that this request applies to.
3688 * @param appType the uicc app type.
3689 * @return Application ID for specificied app type, or null if no uicc.
3690 */
3691 @Override
3692 public String getAidForAppType(int subId, int appType) {
3693 enforceReadPrivilegedPermission();
3694 Phone phone = getPhone(subId);
3695 if (phone == null) {
3696 return null;
3697 }
3698 String aid = null;
3699 try {
3700 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3701 .getApplicationByType(appType).getAid();
3702 } catch (Exception e) {
3703 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3704 }
3705 return aid;
3706 }
3707
Youhan Wang4001d252016-05-11 10:29:41 -07003708 /**
3709 * Return the Electronic Serial Number.
3710 *
3711 * @param subId the subscription ID that this request applies to.
3712 * @return ESN or null if error.
3713 */
3714 @Override
3715 public String getEsn(int subId) {
3716 enforceReadPrivilegedPermission();
3717 Phone phone = getPhone(subId);
3718 if (phone == null) {
3719 return null;
3720 }
3721 String esn = null;
3722 try {
3723 esn = phone.getEsn();
3724 } catch (Exception e) {
3725 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3726 }
3727 return esn;
3728 }
3729
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003730 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003731 * Return the Preferred Roaming List Version.
3732 *
3733 * @param subId the subscription ID that this request applies to.
3734 * @return PRLVersion or null if error.
3735 */
3736 @Override
3737 public String getCdmaPrlVersion(int subId) {
3738 enforceReadPrivilegedPermission();
3739 Phone phone = getPhone(subId);
3740 if (phone == null) {
3741 return null;
3742 }
3743 String cdmaPrlVersion = null;
3744 try {
3745 cdmaPrlVersion = phone.getCdmaPrlVersion();
3746 } catch (Exception e) {
3747 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3748 }
3749 return cdmaPrlVersion;
3750 }
3751
3752 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003753 * Get snapshot of Telephony histograms
3754 * @return List of Telephony histograms
3755 * @hide
3756 */
3757 @Override
3758 public List<TelephonyHistogram> getTelephonyHistograms() {
3759 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3760 return RIL.getTelephonyRILTimingHistograms();
3761 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003762
3763 /**
3764 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003765 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003766 * Require system privileges. In the future we may add this to carrier APIs.
3767 *
3768 * @return The number of carriers set successfully, should match length of carriers
3769 */
3770 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003771 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003772 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003773
Meng Wang9b7c4e92017-02-17 11:41:27 -08003774 if (carriers == null) {
3775 throw new NullPointerException("carriers cannot be null");
3776 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003777
3778 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003779 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3780 return retVal[0];
3781 }
3782
3783 /**
3784 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003785 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003786 * Require system privileges. In the future we may add this to carrier APIs.
3787 *
3788 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3789 * means all carriers are allowed.
3790 */
3791 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003792 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003793 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003794 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003795 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3796 }
3797
fionaxu59545b42016-05-25 15:53:37 -07003798 /**
3799 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3800 * @param subId the subscription ID that this action applies to.
3801 * @param enabled control enable or disable metered apns.
3802 * {@hide}
3803 */
3804 @Override
3805 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3806 enforceModifyPermission();
3807 final Phone phone = getPhone(subId);
3808 if (phone == null) {
3809 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3810 return;
3811 }
3812 try {
3813 phone.carrierActionSetMeteredApnsEnabled(enabled);
3814 } catch (Exception e) {
3815 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3816 }
3817 }
3818
3819 /**
3820 * Action set from carrier signalling broadcast receivers to enable/disable radio
3821 * @param subId the subscription ID that this action applies to.
3822 * @param enabled control enable or disable radio.
3823 * {@hide}
3824 */
3825 @Override
3826 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3827 enforceModifyPermission();
3828 final Phone phone = getPhone(subId);
3829 if (phone == null) {
3830 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3831 return;
3832 }
3833 try {
3834 phone.carrierActionSetRadioEnabled(enabled);
3835 } catch (Exception e) {
3836 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3837 }
3838 }
3839
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003840 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003841 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3842 * network status based on which carrier apps could apply actions accordingly,
3843 * enable/disable default url handler for example.
3844 *
3845 * @param subId the subscription ID that this action applies to.
3846 * @param report control start/stop reporting the default network status.
3847 * {@hide}
3848 */
3849 @Override
3850 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3851 enforceModifyPermission();
3852 final Phone phone = getPhone(subId);
3853 if (phone == null) {
3854 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3855 return;
3856 }
3857 try {
3858 phone.carrierActionReportDefaultNetworkStatus(report);
3859 } catch (Exception e) {
3860 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3861 }
3862 }
3863
3864 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003865 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3866 * bug report is being generated.
3867 */
3868 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003869 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003870 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3871 != PackageManager.PERMISSION_GRANTED) {
3872 writer.println("Permission Denial: can't dump Phone from pid="
3873 + Binder.getCallingPid()
3874 + ", uid=" + Binder.getCallingUid()
3875 + "without permission "
3876 + android.Manifest.permission.DUMP);
3877 return;
3878 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003879 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003880 }
Jack Yueb89b242016-06-22 13:27:47 -07003881
3882 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003883 * Get aggregated video call data usage since boot.
3884 *
3885 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3886 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003887 * {@hide}
3888 */
3889 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003890 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003891 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3892 null);
3893
Jack Yu84291ec2017-05-26 16:07:50 -07003894 // NetworkStatsService keeps tracking the active network interface and identity. It
3895 // records the delta with the corresponding network identity. We just return the total video
3896 // call data usage snapshot since boot.
3897 Phone phone = getPhone(subId);
3898 if (phone != null) {
3899 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003900 }
Jack Yu84291ec2017-05-26 16:07:50 -07003901 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003902 }
Jack Yu75ab2952016-07-08 14:29:33 -07003903
3904 /**
3905 * Policy control of data connection. Usually used when data limit is passed.
3906 * @param enabled True if enabling the data, otherwise disabling.
3907 * @param subId Subscription index
3908 * {@hide}
3909 */
3910 @Override
3911 public void setPolicyDataEnabled(boolean enabled, int subId) {
3912 enforceModifyPermission();
3913 Phone phone = getPhone(subId);
3914 if (phone != null) {
3915 phone.setPolicyDataEnabled(enabled);
3916 }
3917 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003918
3919 /**
3920 * Get Client request stats
3921 * @return List of Client Request Stats
3922 * @hide
3923 */
3924 @Override
3925 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3926 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3927 return null;
3928 }
3929
3930 Phone phone = getPhone(subId);
3931 if (phone != null) {
3932 return phone.getClientRequestStats();
3933 }
3934
3935 return null;
3936 }
3937
3938 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3939 if (workSource != null) {
3940 return workSource;
3941 }
3942
3943 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3944 workSource = new WorkSource(uid, packageName);
3945 return workSource;
3946 }
Jack Yueb4124c2017-02-16 15:32:43 -08003947
3948 /**
Grace Chen70990072017-03-24 17:21:30 -07003949 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003950 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003951 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003952 * @param state State of SIM (power down, power up, pass through)
3953 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3954 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3955 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003956 *
3957 **/
3958 @Override
Grace Chen70990072017-03-24 17:21:30 -07003959 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003960 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003961 Phone phone = PhoneFactory.getPhone(slotIndex);
3962
Jack Yueb4124c2017-02-16 15:32:43 -08003963 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003964 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003965 }
3966 }
Shuo Qiandd210312017-04-12 22:11:33 +00003967
Tyler Gunn65d45c22017-06-05 11:22:26 -07003968 private boolean isUssdApiAllowed(int subId) {
3969 CarrierConfigManager configManager =
3970 (CarrierConfigManager) mPhone.getContext().getSystemService(
3971 Context.CARRIER_CONFIG_SERVICE);
3972 if (configManager == null) {
3973 return false;
3974 }
3975 PersistableBundle pb = configManager.getConfigForSubId(subId);
3976 if (pb == null) {
3977 return false;
3978 }
3979 return pb.getBoolean(
3980 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3981 }
3982
Shuo Qiandd210312017-04-12 22:11:33 +00003983 /**
3984 * Check if phone is in emergency callback mode
3985 * @return true if phone is in emergency callback mode
3986 * @param subId sub id
3987 */
3988 public boolean getEmergencyCallbackMode(int subId) {
3989 final Phone phone = getPhone(subId);
3990 if (phone != null) {
3991 return phone.isInEcm();
3992 } else {
3993 return false;
3994 }
3995 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003996
3997 /**
3998 * Get the current signal strength information for the given subscription.
3999 * Because this information is not updated when the device is in a low power state
4000 * it should not be relied-upon to be current.
4001 * @param subId Subscription index
4002 * @return the most recent cached signal strength info from the modem
4003 */
4004 @Override
4005 public SignalStrength getSignalStrength(int subId) {
4006 Phone p = getPhone(subId);
4007 if (p == null) {
4008 return null;
4009 }
4010
4011 return p.getSignalStrength();
4012 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004013
4014 @Override
4015 public UiccSlotInfo[] getUiccSlotsInfo() {
4016 enforceReadPrivilegedPermission();
4017
4018 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4019 if (slots == null) return null;
4020 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4021 for (int i = 0; i < slots.length; i++) {
4022 UiccSlot slot = slots[i];
4023
4024 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4025
4026 int cardState = 0;
4027 switch (slot.getCardState()) {
4028 case CARDSTATE_ABSENT:
4029 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4030 break;
4031 case CARDSTATE_PRESENT:
4032 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4033 break;
4034 case CARDSTATE_ERROR:
4035 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4036 break;
4037 case CARDSTATE_RESTRICTED:
4038 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4039 break;
4040 default:
4041 break;
4042
4043 }
4044
4045 infos[i] = new UiccSlotInfo(slot.isActive(), slot.isEuicc(), cardId, cardState);
4046 }
4047 return infos;
4048 }
4049
4050 @Override
4051 public boolean switchSlots(int[] physicalSlots) {
4052 enforceModifyPermission();
4053 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004055}