blob: 433567fe17c6f693f6c139832912577c88a6e8d7 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
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;
Ta-wei Yen87c49842016-05-13 21:19:52 -070058import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080059import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070060import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070061import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080064import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070065import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080066import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080067import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070068import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070069import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000070import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070071import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080073import android.telephony.ims.aidl.IImsConfig;
74import android.telephony.ims.aidl.IImsMmTelFeature;
75import android.telephony.ims.aidl.IImsRcsFeature;
76import android.telephony.ims.aidl.IImsRegistration;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080081import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080082
Andrew Lee312e8172014-10-23 17:01:36 -070083import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080084import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070085import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070086import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070087import com.android.internal.telephony.CarrierInfoManager;
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 Basseribf5362b2017-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 Chen964682d2017-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 Chen964682d2017-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) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001656 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001657 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001658 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
1660
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001661 if (DBG_LOC) log("getCellLocation: is active user");
1662 Bundle data = new Bundle();
1663 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1664 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 return null;
1666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001668 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001669 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1670 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001671 }
1672
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001674 public String getNetworkCountryIsoForPhone(int phoneId) {
1675 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1676 // registered cell info, so return a NULL country instead.
1677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1680 if (TelephonyManager.NETWORK_TYPE_IWLAN
1681 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1682 return "";
1683 }
1684 } finally {
1685 Binder.restoreCallingIdentity(identity);
1686 }
1687 return TelephonyManager.getTelephonyProperty(
1688 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1689 }
1690
1691 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001693 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001694 }
1695
Sanket Padawe356d7632015-06-22 14:03:32 -07001696 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001697 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 mApp.enforceCallingOrSelfPermission(
1699 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 final Phone phone = getPhone(subId);
1701 if (phone != null) {
1702 phone.enableLocationUpdates();
1703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
1706 @Override
1707 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001708 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001709 }
1710
Sanket Padawe356d7632015-06-22 14:03:32 -07001711 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001712 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 mApp.enforceCallingOrSelfPermission(
1714 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001715 final Phone phone = getPhone(subId);
1716 if (phone != null) {
1717 phone.disableLocationUpdates();
1718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 }
1720
1721 @Override
1722 @SuppressWarnings("unchecked")
1723 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001724 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001725 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001726 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 }
1728
1729 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1730 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1731 return null;
1732 }
Svetoslav64fad262015-04-14 14:35:21 -07001733
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001734 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001736 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001738 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001739 try {
1740 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1741 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1742 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1743 } catch (RuntimeException e) {
1744 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001746 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
1748
1749
1750 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001751 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001752 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001753 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001754 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 }
1756
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001758 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001759 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1760 for (Phone phone : PhoneFactory.getPhones()) {
1761 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1762 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001764 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 }
1766
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001767 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001769 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001770 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001771 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
Shishir Agrawala9f32182016-04-12 12:00:16 -07001774 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001775 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001776 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1777 return null;
1778 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001779 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001780 return phone == null ? null : phone.getImei();
1781 }
1782
1783 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001784 public String getMeidForSlot(int slotIndex, String callingPackage) {
1785 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1786 return null;
1787 }
1788 Phone phone = PhoneFactory.getPhone(slotIndex);
1789 return phone == null ? null : phone.getMeid();
1790 }
1791
1792 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001793 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001794 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1795 return null;
1796 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001797 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001798 return phone == null ? null : phone.getDeviceSvn();
1799 }
1800
fionaxu43304da2017-11-27 22:51:16 -08001801 @Override
1802 public int getSubscriptionCarrierId(int subId) {
1803 final Phone phone = getPhone(subId);
1804 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1805 }
1806
1807 @Override
1808 public String getSubscriptionCarrierName(int subId) {
1809 final Phone phone = getPhone(subId);
1810 return phone == null ? null : phone.getCarrierName();
1811 }
1812
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 //
1814 // Internal helper methods.
1815 //
1816
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001817 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1819 *
1820 * @throws SecurityException if the caller does not have the required permission
1821 */
1822 private void enforceModifyPermission() {
1823 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1824 }
1825
1826 /**
Junda Liua2e36012014-07-09 18:30:01 -07001827 * Make sure either system app or the caller has carrier privilege.
1828 *
1829 * @throws SecurityException if the caller does not have the required permission/privilege
1830 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001831 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001832 int permission = mApp.checkCallingOrSelfPermission(
1833 android.Manifest.permission.MODIFY_PHONE_STATE);
1834 if (permission == PackageManager.PERMISSION_GRANTED) {
1835 return;
1836 }
1837
1838 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001839 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001840 }
1841
1842 /**
1843 * Make sure the caller has carrier privilege.
1844 *
1845 * @throws SecurityException if the caller does not have the required permission
1846 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001847 private void enforceCarrierPrivilege(int subId) {
1848 if (getCarrierPrivilegeStatus(subId) !=
1849 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001850 loge("No Carrier Privilege.");
1851 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001852 }
1853 }
1854
1855 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 * Make sure the caller has the CALL_PHONE permission.
1857 *
1858 * @throws SecurityException if the caller does not have the required permission
1859 */
1860 private void enforceCallPermission() {
1861 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1862 }
1863
Stuart Scott8eef64f2015-04-08 15:13:54 -07001864 private void enforceConnectivityInternalPermission() {
1865 mApp.enforceCallingOrSelfPermission(
1866 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1867 "ConnectivityService");
1868 }
1869
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 private String createTelUrl(String number) {
1871 if (TextUtils.isEmpty(number)) {
1872 return null;
1873 }
1874
Jake Hambye994d462014-02-03 13:10:13 -08001875 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 }
1877
Ihab Awadf9e92732013-12-05 18:02:52 -08001878 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1880 }
1881
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001882 private static void logv(String msg) {
1883 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1884 }
1885
Ihab Awadf9e92732013-12-05 18:02:52 -08001886 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1888 }
1889
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001890 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001892 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001896 public int getActivePhoneTypeForSlot(int slotIndex) {
1897 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 if (phone == null) {
1899 return PhoneConstants.PHONE_TYPE_NONE;
1900 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001901 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905 /**
1906 * Returns the CDMA ERI icon index to display
1907 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001908 @Override
1909 public int getCdmaEriIconIndex(String callingPackage) {
1910 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001911 }
1912
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001914 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1915 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1916 return -1;
1917 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001918 final Phone phone = getPhone(subId);
1919 if (phone != null) {
1920 return phone.getCdmaEriIconIndex();
1921 } else {
1922 return -1;
1923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 }
1925
1926 /**
1927 * Returns the CDMA ERI icon mode,
1928 * 0 - ON
1929 * 1 - FLASHING
1930 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001931 @Override
1932 public int getCdmaEriIconMode(String callingPackage) {
1933 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001934 }
1935
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001937 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1938 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1939 return -1;
1940 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 final Phone phone = getPhone(subId);
1942 if (phone != null) {
1943 return phone.getCdmaEriIconMode();
1944 } else {
1945 return -1;
1946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948
1949 /**
1950 * Returns the CDMA ERI text,
1951 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001952 @Override
1953 public String getCdmaEriText(String callingPackage) {
1954 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001955 }
1956
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001958 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1959 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1960 return null;
1961 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001962 final Phone phone = getPhone(subId);
1963 if (phone != null) {
1964 return phone.getCdmaEriText();
1965 } else {
1966 return null;
1967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
1970 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001971 * Returns the CDMA MDN.
1972 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001974 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001975 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 final Phone phone = getPhone(subId);
1977 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1978 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001979 } else {
1980 return null;
1981 }
1982 }
1983
1984 /**
1985 * Returns the CDMA MIN.
1986 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001988 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001989 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 final Phone phone = getPhone(subId);
1991 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1992 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001993 } else {
1994 return null;
1995 }
1996 }
1997
1998 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 * Returns true if CDMA provisioning needs to run.
2000 */
2001 public boolean needsOtaServiceProvisioning() {
2002 return mPhone.needsOtaServiceProvisioning();
2003 }
2004
2005 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002006 * Sets the voice mail number of a given subId.
2007 */
2008 @Override
2009 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002010 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002011 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2012 new Pair<String, String>(alphaTag, number), new Integer(subId));
2013 return success;
2014 }
2015
Ta-wei Yen87c49842016-05-13 21:19:52 -07002016 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002017 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2018 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2019 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2020 if (!TextUtils.equals(callingPackage, systemDialer)) {
2021 throw new SecurityException("caller must be system dialer");
2022 }
2023 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2024 if (phoneAccountHandle == null){
2025 return null;
2026 }
2027 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2028 }
2029
2030 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002031 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2033 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2034 return null;
2035 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002036 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2037 }
2038
2039 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002040 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2041 VisualVoicemailSmsFilterSettings settings) {
2042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002043 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002044 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2045 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002046 }
2047
2048 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002049 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2050 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002051 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002052 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002053 }
2054
2055 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002056 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2057 String callingPackage, int subId) {
2058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002059 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002060 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002061 }
2062
2063 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002064 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002065 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002066 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002067 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2068 }
2069
2070 @Override
2071 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2072 String number, int port, String text, PendingIntent sentIntent) {
2073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002074 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002075 enforceSendSmsPermission();
2076 // Make the calls as the phone process.
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2080 if (port == 0) {
2081 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2082 sentIntent, null, false);
2083 } else {
2084 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2085 smsManager.sendDataMessageWithSelfPermissions(number, null,
2086 (short) port, data, sentIntent, null);
2087 }
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
2090 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002091 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002092 /**
fionaxu0152e512016-11-14 13:36:14 -08002093 * Sets the voice activation state of a given subId.
2094 */
2095 @Override
2096 public void setVoiceActivationState(int subId, int activationState) {
2097 enforceModifyPermissionOrCarrierPrivilege(subId);
2098 final Phone phone = getPhone(subId);
2099 if (phone != null) {
2100 phone.setVoiceActivationState(activationState);
2101 } else {
2102 loge("setVoiceActivationState fails with invalid subId: " + subId);
2103 }
2104 }
2105
2106 /**
2107 * Sets the data activation state of a given subId.
2108 */
2109 @Override
2110 public void setDataActivationState(int subId, int activationState) {
2111 enforceModifyPermissionOrCarrierPrivilege(subId);
2112 final Phone phone = getPhone(subId);
2113 if (phone != null) {
2114 phone.setDataActivationState(activationState);
2115 } else {
2116 loge("setVoiceActivationState fails with invalid subId: " + subId);
2117 }
2118 }
2119
2120 /**
2121 * Returns the voice activation state of a given subId.
2122 */
2123 @Override
2124 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002125 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002126 final Phone phone = getPhone(subId);
2127 if (phone != null) {
2128 return phone.getVoiceActivationState();
2129 } else {
2130 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2131 }
2132 }
2133
2134 /**
2135 * Returns the data activation state of a given subId.
2136 */
2137 @Override
2138 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002139 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002140 final Phone phone = getPhone(subId);
2141 if (phone != null) {
2142 return phone.getDataActivationState();
2143 } else {
2144 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2145 }
2146 }
2147
2148 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 * Returns the unread count of voicemails
2150 */
2151 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002152 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002153 }
2154
2155 /**
2156 * Returns the unread count of voicemails for a subId
2157 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002158 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002159 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 final Phone phone = getPhone(subId);
2161 if (phone != null) {
2162 return phone.getVoiceMessageCount();
2163 } else {
2164 return 0;
2165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
2167
2168 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002169 * returns true, if the device is in a state where both voice and data
2170 * are supported simultaneously. This can change based on location or network condition.
2171 */
2172 @Override
2173 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2174 final Phone phone = getPhone(subId);
2175 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2176 }
2177
2178 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002179 * Send the dialer code if called from the current default dialer or the caller has
2180 * carrier privilege.
2181 * @param inputCode The dialer code to send
2182 */
2183 @Override
2184 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2185 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2186 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2187 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2188 enforceCarrierPrivilege(getDefaultSubscription());
2189 }
2190 mPhone.sendDialerSpecialCode(inputCode);
2191 }
2192
2193 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002194 * Returns the data network type.
2195 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 *
2197 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2198 */
2199 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002200 public int getNetworkType() {
2201 final Phone phone = getPhone(getDefaultSubscription());
2202 if (phone != null) {
2203 return phone.getServiceState().getDataNetworkType();
2204 } else {
2205 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2206 }
Wink Saville36469e72014-06-11 15:17:00 -07002207 }
2208
2209 /**
2210 * Returns the network type for a subId
2211 */
2212 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002213 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2214 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2215 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2216 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002217
Sanket Padawe356d7632015-06-22 14:03:32 -07002218 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002219 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002220 return phone.getServiceState().getDataNetworkType();
2221 } else {
2222 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 }
2225
2226 /**
2227 * Returns the data network type
2228 */
2229 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 public int getDataNetworkType(String callingPackage) {
2231 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002232 }
2233
2234 /**
2235 * Returns the data network type for a subId
2236 */
2237 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002238 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2239 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2240 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2241 }
2242
Sanket Padawe356d7632015-06-22 14:03:32 -07002243 final Phone phone = getPhone(subId);
2244 if (phone != null) {
2245 return phone.getServiceState().getDataNetworkType();
2246 } else {
2247 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 }
2250
2251 /**
Wink Saville36469e72014-06-11 15:17:00 -07002252 * Returns the Voice network type for a subId
2253 */
2254 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002255 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2256 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2257 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2258 }
2259
Sanket Padawe356d7632015-06-22 14:03:32 -07002260 final Phone phone = getPhone(subId);
2261 if (phone != null) {
2262 return phone.getServiceState().getVoiceNetworkType();
2263 } else {
2264 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
2268 /**
2269 * @return true if a ICC card is present
2270 */
2271 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002272 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002273 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2274 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002275 }
2276
2277 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002278 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002279 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002281 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2282 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002283 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002284 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002285 } else {
2286 return false;
2287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
2289
2290 /**
2291 * Return if the current radio is LTE on CDMA. This
2292 * is a tri-state return value as for a period of time
2293 * the mode may be unknown.
2294 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002295 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002297 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002299 @Override
2300 public int getLteOnCdmaMode(String callingPackage) {
2301 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002302 }
2303
Sanket Padawe356d7632015-06-22 14:03:32 -07002304 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002305 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2306 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2307 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2308 }
2309
Sanket Padawe356d7632015-06-22 14:03:32 -07002310 final Phone phone = getPhone(subId);
2311 if (phone == null) {
2312 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2313 } else {
2314 return phone.getLteOnCdmaMode();
2315 }
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
2318 public void setPhone(Phone phone) {
2319 mPhone = phone;
2320 }
2321
2322 /**
2323 * {@hide}
2324 * Returns Default subId, 0 in the case of single standby.
2325 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002326 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002327 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
2329
Shishir Agrawala9f32182016-04-12 12:00:16 -07002330 private int getSlotForDefaultSubscription() {
2331 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2332 }
2333
Wink Savilleb564aae2014-10-23 10:18:09 -07002334 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002335 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002337
2338 /**
2339 * @see android.telephony.TelephonyManager.WifiCallingChoices
2340 */
2341 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002342 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2343 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002344 }
2345
2346 /**
2347 * @see android.telephony.TelephonyManager.WifiCallingChoices
2348 */
2349 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002350 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2351 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2352 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002353 }
2354
Sailesh Nepald1e68152013-12-12 19:08:02 -08002355 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002356 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002357 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002358 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002359
Shishir Agrawal566b7612013-10-28 14:41:00 -07002360 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002361 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2362 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002363 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002364
Derek Tan740e1672017-06-27 14:56:27 -07002365 if (TextUtils.equals(ISDR_AID, aid)) {
2366 // Only allows LPA to open logical channel to ISD-R.
2367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2368 ComponentInfo bestComponent =
2369 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2370 if (bestComponent == null
2371 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2372 loge("The calling package is not allowed to access ISD-R.");
2373 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2374 }
2375 }
2376
2377 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002378 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002379 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002380 if (DBG) log("iccOpenLogicalChannel: " + response);
2381 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002382 }
2383
2384 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002385 public boolean iccCloseLogicalChannel(int subId, int channel) {
2386 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002387
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002388 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389 if (channel < 0) {
2390 return false;
2391 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002392 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002393 if (DBG) log("iccCloseLogicalChannel: " + success);
2394 return success;
2395 }
2396
2397 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002398 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002399 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002400 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002401
2402 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002403 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2404 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002405 " data=" + data);
2406 }
2407
2408 if (channel < 0) {
2409 return "";
2410 }
2411
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002412 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002413 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002414 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2415
Shishir Agrawal566b7612013-10-28 14:41:00 -07002416 // Append the returned status code to the end of the response payload.
2417 String s = Integer.toHexString(
2418 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002419 if (response.payload != null) {
2420 s = IccUtils.bytesToHexString(response.payload) + s;
2421 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002422 return s;
2423 }
Jake Hambye994d462014-02-03 13:10:13 -08002424
Evan Charltonc66da362014-05-16 14:06:40 -07002425 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002426 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2427 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002428 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002429
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002430 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2431 && TextUtils.equals(ISDR_AID, data)) {
2432 // Only allows LPA to select ISD-R.
2433 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2434 ComponentInfo bestComponent =
2435 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2436 if (bestComponent == null
2437 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2438 loge("The calling package is not allowed to select ISD-R.");
2439 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2440 }
2441 }
2442
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002443 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002444 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2445 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002446 }
2447
2448 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002449 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002450 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2451
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002452 // Append the returned status code to the end of the response payload.
2453 String s = Integer.toHexString(
2454 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002455 if (response.payload != null) {
2456 s = IccUtils.bytesToHexString(response.payload) + s;
2457 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002458 return s;
2459 }
2460
2461 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002462 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002463 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002464 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002465
2466 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002467 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002468 p1 + " " + p2 + " " + p3 + ":" + filePath);
2469 }
2470
2471 IccIoResult response =
2472 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002473 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2474 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002475
2476 if (DBG) {
2477 log("Exchange SIM_IO [R]" + response);
2478 }
2479
2480 byte[] result = null;
2481 int length = 2;
2482 if (response.payload != null) {
2483 length = 2 + response.payload.length;
2484 result = new byte[length];
2485 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2486 } else {
2487 result = new byte[length];
2488 }
2489
2490 result[length - 1] = (byte) response.sw2;
2491 result[length - 2] = (byte) response.sw1;
2492 return result;
2493 }
2494
Nathan Haroldb3014052017-01-25 15:57:32 -08002495 /**
2496 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2497 * on a particular subscription
2498 */
2499 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002500 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2501 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002502 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2503 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2504 return null;
2505 }
2506 Object response = sendRequest(
2507 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2508 if (response instanceof String[]) {
2509 return (String[]) response;
2510 }
2511 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2512 return null;
2513 }
2514
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002515 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002516 public String sendEnvelopeWithStatus(int subId, String content) {
2517 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002518
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002520 if (response.payload == null) {
2521 return "";
2522 }
2523
2524 // Append the returned status code to the end of the response payload.
2525 String s = Integer.toHexString(
2526 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2527 s = IccUtils.bytesToHexString(response.payload) + s;
2528 return s;
2529 }
2530
Jake Hambye994d462014-02-03 13:10:13 -08002531 /**
2532 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2533 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2534 *
2535 * @param itemID the ID of the item to read
2536 * @return the NV item as a String, or null on error.
2537 */
2538 @Override
2539 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002540 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002541 if (DBG) log("nvReadItem: item " + itemID);
2542 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2543 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2544 return value;
2545 }
2546
2547 /**
2548 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2549 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2550 *
2551 * @param itemID the ID of the item to read
2552 * @param itemValue the value to write, as a String
2553 * @return true on success; false on any failure
2554 */
2555 @Override
2556 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002558 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2559 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2560 new Pair<Integer, String>(itemID, itemValue));
2561 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2562 return success;
2563 }
2564
2565 /**
2566 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2567 * Used for device configuration by some CDMA operators.
2568 *
2569 * @param preferredRoamingList byte array containing the new PRL
2570 * @return true on success; false on any failure
2571 */
2572 @Override
2573 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002574 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002575 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2576 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2577 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2578 return success;
2579 }
2580
2581 /**
2582 * Perform the specified type of NV config reset.
2583 * Used for device configuration by some CDMA operators.
2584 *
2585 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2586 * @return true on success; false on any failure
2587 */
2588 @Override
2589 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002590 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002591 if (DBG) log("nvResetConfig: type " + resetType);
2592 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2593 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2594 return success;
2595 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002596
2597 /**
Wink Saville36469e72014-06-11 15:17:00 -07002598 * {@hide}
2599 * Returns Default sim, 0 in the case of single standby.
2600 */
2601 public int getDefaultSim() {
2602 //TODO Need to get it from Telephony Devcontroller
2603 return 0;
2604 }
2605
Svet Ganovb320e182015-04-16 12:30:10 -07002606 public String[] getPcscfAddress(String apnType, String callingPackage) {
2607 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2608 return new String[0];
2609 }
2610
2611
ram87fca6f2014-07-18 18:58:44 +05302612 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002613 }
2614
Brad Ebinger51f743a2017-01-23 13:50:20 -08002615 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002616 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2617 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002618 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002619 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002620 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002621 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002622 }
2623
2624 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002625 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2626 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002627 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002628 public void disableIms(int slotId) {
2629 enforceModifyPermission();
2630 PhoneFactory.getImsResolver().disableIms(slotId);
2631 }
2632
2633 /**
2634 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2635 * feature or {@link null} if the service is not available. If the feature is available, the
2636 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2637 */
2638 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002639 IImsServiceFeatureCallback callback) {
2640 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002641 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002642 }
2643
2644 /**
2645 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2646 * feature during emergency calling or {@link null} if the service is not available. If the
2647 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2648 * listener for feature updates.
2649 */
2650 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2651 enforceModifyPermission();
2652 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002653 }
2654
Brad Ebinger5f64b052017-12-14 14:26:15 -08002655 /**
2656 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2657 * specified.
2658 */
2659 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2660 enforceModifyPermission();
2661 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2662 }
2663
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002664 /**
2665 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2666 * specified.
2667 */
2668 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2669 enforceModifyPermission();
2670 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2671 }
2672
Wink Saville36469e72014-06-11 15:17:00 -07002673 public void setImsRegistrationState(boolean registered) {
2674 enforceModifyPermission();
2675 mPhone.setImsRegistrationState(registered);
2676 }
2677
2678 /**
Stuart Scott54788802015-03-30 13:18:01 -07002679 * Set the network selection mode to automatic.
2680 *
2681 */
2682 @Override
2683 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002684 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002685 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2686 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2687 }
2688
2689 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002690 * Set the network selection mode to manual with the selected carrier.
2691 */
2692 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002693 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002694 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002695 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002696 OperatorInfo operator = new OperatorInfo(
2697 /* operatorAlphaLong */ "",
2698 /* operatorAlphaShort */ "",
2699 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002700 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002701 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2702 persistSelection);
2703 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002704 }
2705
2706 /**
2707 * Scans for available networks.
2708 */
2709 @Override
2710 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002711 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002712 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2713 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2714 CMD_PERFORM_NETWORK_SCAN, null, subId);
2715 return result;
2716 }
2717
2718 /**
yinxub1bed742017-04-17 11:45:04 -07002719 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002720 *
yinxub1bed742017-04-17 11:45:04 -07002721 * @param subId id of the subscription
2722 * @param request contains the radio access networks with bands/channels to scan
2723 * @param messenger callback messenger for scan results or errors
2724 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002725 * @return the id of the requested scan which can be used to stop the scan.
2726 */
2727 @Override
2728 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2729 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002730 enforceModifyPermissionOrCarrierPrivilege(subId);
2731 return mNetworkScanRequestTracker.startNetworkScan(
2732 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002733 }
2734
2735 /**
2736 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002737 *
2738 * @param subId id of the subscription
2739 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002740 */
2741 @Override
2742 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002743 enforceModifyPermissionOrCarrierPrivilege(subId);
2744 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002745 }
2746
2747 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002748 * Get the calculated preferred network type.
2749 * Used for debugging incorrect network type.
2750 *
2751 * @return the preferred network type, defined in RILConstants.java.
2752 */
2753 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002754 public int getCalculatedPreferredNetworkType(String callingPackage) {
2755 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2756 return RILConstants.PREFERRED_NETWORK_MODE;
2757 }
2758
Amit Mahajan43330e02014-11-18 11:54:45 -08002759 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002760 }
2761
2762 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002763 * Get the preferred network type.
2764 * Used for device configuration by some CDMA operators.
2765 *
2766 * @return the preferred network type, defined in RILConstants.java.
2767 */
2768 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002769 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002770 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002771 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002772 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002773 int networkType = (result != null ? result[0] : -1);
2774 if (DBG) log("getPreferredNetworkType: " + networkType);
2775 return networkType;
2776 }
2777
2778 /**
2779 * Set the preferred network type.
2780 * Used for device configuration by some CDMA operators.
2781 *
2782 * @param networkType the preferred network type, defined in RILConstants.java.
2783 * @return true on success; false on any failure.
2784 */
2785 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002786 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002787 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002788 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2789 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002790 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002791 if (success) {
2792 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002793 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002794 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002795 return success;
2796 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002797
2798 /**
Junda Liu475951f2014-11-07 16:45:03 -08002799 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2800 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2801 * tethering.
2802 *
2803 * @return 0: Not required. 1: required. 2: Not set.
2804 * @hide
2805 */
2806 @Override
2807 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002808 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002809 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2810 Settings.Global.TETHER_DUN_REQUIRED, 2);
2811 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2812 // config_tether_apndata.
2813 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2814 dunRequired = 1;
2815 }
2816 return dunRequired;
2817 }
2818
2819 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002820 * Set mobile data enabled
2821 * Used by the user through settings etc to turn on/off mobile data
2822 *
2823 * @param enable {@code true} turn turn data on, else {@code false}
2824 */
2825 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002826 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002827 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002828 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002829 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002830 Phone phone = PhoneFactory.getPhone(phoneId);
2831 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002832 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2833 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002834 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002835 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002836 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002837 }
2838
2839 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002840 * Get the user enabled state of Mobile Data.
2841 *
2842 * TODO: remove and use isUserDataEnabled.
2843 * This can't be removed now because some vendor codes
2844 * calls through ITelephony directly while they should
2845 * use TelephonyManager.
2846 *
2847 * @return true on enabled
2848 */
2849 @Override
2850 public boolean getDataEnabled(int subId) {
2851 return isUserDataEnabled(subId);
2852 }
2853
2854 /**
2855 * Get whether mobile data is enabled per user setting.
2856 *
2857 * There are other factors deciding whether mobile data is actually enabled, but they are
2858 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002859 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002860 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002861 *
2862 * @return {@code true} if data is enabled else {@code false}
2863 */
2864 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002865 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002866 try {
2867 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2868 null);
2869 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002870 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002871 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002872 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002873 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002874 Phone phone = PhoneFactory.getPhone(phoneId);
2875 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002876 boolean retVal = phone.isUserDataEnabled();
2877 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002878 return retVal;
2879 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002880 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2881 return false;
2882 }
2883 }
2884
2885 /**
2886 * Get whether mobile data is enabled.
2887 *
2888 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2889 * whether mobile data is actually enabled.
2890 *
2891 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2892 *
2893 * @return {@code true} if data is enabled else {@code false}
2894 */
2895 @Override
2896 public boolean isDataEnabled(int subId) {
2897 try {
2898 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2899 null);
2900 } catch (Exception e) {
2901 enforceModifyPermissionOrCarrierPrivilege(subId);
2902 }
2903 int phoneId = mSubscriptionController.getPhoneId(subId);
2904 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2905 Phone phone = PhoneFactory.getPhone(phoneId);
2906 if (phone != null) {
2907 boolean retVal = phone.isDataEnabled();
2908 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2909 return retVal;
2910 } else {
2911 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002912 return false;
2913 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002914 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002915
2916 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002917 public int getCarrierPrivilegeStatus(int subId) {
2918 final Phone phone = getPhone(subId);
2919 if (phone == null) {
2920 loge("getCarrierPrivilegeStatus: Invalid subId");
2921 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2922 }
2923 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002924 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002925 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002926 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2927 }
2928 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002929 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002930 }
Junda Liu29340342014-07-10 15:23:27 -07002931
2932 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002933 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002934 if (TextUtils.isEmpty(pkgName))
2935 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002936 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002937 if (card == null) {
2938 loge("checkCarrierPrivilegesForPackage: No UICC");
2939 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2940 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002941 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2942 }
2943
2944 @Override
2945 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002946 if (TextUtils.isEmpty(pkgName))
2947 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002948 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2949 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2950 UiccCard card = UiccController.getInstance().getUiccCard(i);
2951 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002952 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002953 continue;
2954 }
2955
2956 result = card.getCarrierPrivilegeStatus(
2957 mPhone.getContext().getPackageManager(), pkgName);
2958 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2959 break;
2960 }
2961 }
2962
2963 return result;
Junda Liu29340342014-07-10 15:23:27 -07002964 }
Derek Tan89e89d42014-07-08 17:00:10 -07002965
2966 @Override
Junda Liue64de782015-04-16 17:19:16 -07002967 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2968 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2969 loge("phoneId " + phoneId + " is not valid.");
2970 return null;
2971 }
2972 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002973 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002974 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002975 return null ;
2976 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002977 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002978 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002979 }
2980
Amith Yamasani6e118872016-02-19 12:53:51 -08002981 @Override
2982 public List<String> getPackagesWithCarrierPrivileges() {
2983 PackageManager pm = mPhone.getContext().getPackageManager();
2984 List<String> privilegedPackages = new ArrayList<>();
2985 List<PackageInfo> packages = null;
2986 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2987 UiccCard card = UiccController.getInstance().getUiccCard(i);
2988 if (card == null) {
2989 // No UICC in that slot.
2990 continue;
2991 }
2992 if (card.hasCarrierPrivilegeRules()) {
2993 if (packages == null) {
2994 // Only check packages in user 0 for now
2995 packages = pm.getInstalledPackagesAsUser(
2996 PackageManager.MATCH_DISABLED_COMPONENTS
2997 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2998 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2999 }
3000 for (int p = packages.size() - 1; p >= 0; p--) {
3001 PackageInfo pkgInfo = packages.get(p);
3002 if (pkgInfo != null && pkgInfo.packageName != null
3003 && card.getCarrierPrivilegeStatus(pkgInfo)
3004 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3005 privilegedPackages.add(pkgInfo.packageName);
3006 }
3007 }
3008 }
3009 }
3010 return privilegedPackages;
3011 }
3012
Wink Savilleb564aae2014-10-23 10:18:09 -07003013 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003014 final Phone phone = getPhone(subId);
3015 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003016 if (card == null) {
3017 loge("getIccId: No UICC");
3018 return null;
3019 }
3020 String iccId = card.getIccId();
3021 if (TextUtils.isEmpty(iccId)) {
3022 loge("getIccId: ICC ID is null or empty.");
3023 return null;
3024 }
3025 return iccId;
3026 }
3027
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003028 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003029 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3030 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003031 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003032
Jeff Sharkey85190e62014-12-05 09:40:12 -08003033 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003034 final Phone phone = getPhone(subId);
3035 if (phone == null) {
3036 return false;
3037 }
3038 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003039
3040 if (DBG_MERGE) {
3041 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3042 + subscriberId + " to " + number);
3043 }
3044
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003045 if (TextUtils.isEmpty(iccId)) {
3046 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003047 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003048
Jeff Sharkey85190e62014-12-05 09:40:12 -08003049 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3050
3051 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003052 if (alphaTag == null) {
3053 editor.remove(alphaTagPrefKey);
3054 } else {
3055 editor.putString(alphaTagPrefKey, alphaTag);
3056 }
3057
Jeff Sharkey85190e62014-12-05 09:40:12 -08003058 // Record both the line number and IMSI for this ICCID, since we need to
3059 // track all merged IMSIs based on line number
3060 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3061 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003062 if (number == null) {
3063 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003064 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003065 } else {
3066 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003067 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003068 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003069
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003070 editor.commit();
3071 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003072 }
3073
3074 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003075 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003076 // This is open to apps with WRITE_SMS.
3077 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003078 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003079 return null;
3080 }
Derek Tan97ebb422014-09-05 16:55:38 -07003081
3082 String iccId = getIccId(subId);
3083 if (iccId != null) {
3084 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003085 if (DBG_MERGE) {
3086 log("getLine1NumberForDisplay returning " +
3087 mTelephonySharedPreferences.getString(numberPrefKey, null));
3088 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003089 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003090 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003091 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003092 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003093 }
3094
3095 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003096 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3097 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3098 return null;
3099 }
Derek Tan97ebb422014-09-05 16:55:38 -07003100
3101 String iccId = getIccId(subId);
3102 if (iccId != null) {
3103 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003104 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003105 }
Derek Tan97ebb422014-09-05 16:55:38 -07003106 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003107 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003108
3109 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003110 public String[] getMergedSubscriberIds(String callingPackage) {
3111 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3112 return null;
3113 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003114 final Context context = mPhone.getContext();
3115 final TelephonyManager tele = TelephonyManager.from(context);
3116 final SubscriptionManager sub = SubscriptionManager.from(context);
3117
3118 // Figure out what subscribers are currently active
3119 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003120 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3121 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 final int[] subIds = sub.getActiveSubscriptionIdList();
3125 for (int subId : subIds) {
3126 activeSubscriberIds.add(tele.getSubscriberId(subId));
3127 }
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003130 }
3131
3132 // First pass, find a number override for an active subscriber
3133 String mergeNumber = null;
3134 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3135 for (String key : prefs.keySet()) {
3136 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3137 final String subscriberId = (String) prefs.get(key);
3138 if (activeSubscriberIds.contains(subscriberId)) {
3139 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3140 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3141 mergeNumber = (String) prefs.get(numberKey);
3142 if (DBG_MERGE) {
3143 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3144 + " for active subscriber " + subscriberId);
3145 }
3146 if (!TextUtils.isEmpty(mergeNumber)) {
3147 break;
3148 }
3149 }
3150 }
3151 }
3152
3153 // Shortcut when no active merged subscribers
3154 if (TextUtils.isEmpty(mergeNumber)) {
3155 return null;
3156 }
3157
3158 // Second pass, find all subscribers under that line override
3159 final ArraySet<String> result = new ArraySet<>();
3160 for (String key : prefs.keySet()) {
3161 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3162 final String number = (String) prefs.get(key);
3163 if (mergeNumber.equals(number)) {
3164 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3165 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3166 final String subscriberId = (String) prefs.get(subscriberKey);
3167 if (!TextUtils.isEmpty(subscriberId)) {
3168 result.add(subscriberId);
3169 }
3170 }
3171 }
3172 }
3173
3174 final String[] resultArray = result.toArray(new String[result.size()]);
3175 Arrays.sort(resultArray);
3176 if (DBG_MERGE) {
3177 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3178 }
3179 return resultArray;
3180 }
3181
3182 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003183 public boolean setOperatorBrandOverride(int subId, String brand) {
3184 enforceCarrierPrivilege(subId);
3185 final Phone phone = getPhone(subId);
3186 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003187 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003188
3189 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003190 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003191 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3192 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003193 enforceCarrierPrivilege(subId);
3194 final Phone phone = getPhone(subId);
3195 if (phone == null) {
3196 return false;
3197 }
3198 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003199 cdmaNonRoamingList);
3200 }
3201
3202 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003203 public void setRadioCapability(RadioAccessFamily[] rafs) {
3204 try {
3205 ProxyController.getInstance().setRadioCapability(rafs);
3206 } catch (RuntimeException e) {
3207 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3208 }
3209 }
3210
3211 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003212 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3213 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3214 return RadioAccessFamily.RAF_UNKNOWN;
3215 }
3216
Wink Saville5d475dd2014-10-17 15:00:58 -07003217 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3218 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003219
3220 @Override
3221 public void enableVideoCalling(boolean enable) {
3222 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003223 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003224 }
3225
3226 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003227 public boolean isVideoCallingEnabled(String callingPackage) {
3228 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3229 return false;
3230 }
3231
Andrew Lee77527ac2014-10-21 16:57:39 -07003232 // Check the user preference and the system-level IMS setting. Even if the user has
3233 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3234 // In the long run, we may instead need to check if there exists a connection service
3235 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003236 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3237 return imsManager.isVtEnabledByPlatform()
3238 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3239 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003240 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003241
Andrew Leea1239f22015-03-02 17:44:07 -08003242 @Override
3243 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003244 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003245 }
3246
3247 @Override
3248 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003249 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003250 }
3251
Andrew Lee9431b832015-03-09 18:46:45 -07003252 @Override
3253 public boolean isTtyModeSupported() {
3254 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3255 TelephonyManager telephonyManager =
3256 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003257 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003258 }
3259
3260 @Override
3261 public boolean isHearingAidCompatibilitySupported() {
3262 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3263 }
3264
Sanket Padawe7310cc72015-01-14 09:53:20 -08003265 /**
3266 * Returns the unique device ID of phone, for example, the IMEI for
3267 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3268 *
3269 * <p>Requires Permission:
3270 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3271 */
3272 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003273 public String getDeviceId(String callingPackage) {
3274 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3275 return null;
3276 }
3277
Sanket Padawe7310cc72015-01-14 09:53:20 -08003278 final Phone phone = PhoneFactory.getPhone(0);
3279 if (phone != null) {
3280 return phone.getDeviceId();
3281 } else {
3282 return null;
3283 }
3284 }
3285
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003286 /*
3287 * {@hide}
3288 * Returns the IMS Registration Status
3289 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003290 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003291 public boolean isImsRegistered() {
3292 return mPhone.isImsRegistered();
3293 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003294
Ping Sunc67b7c22016-03-02 19:16:45 +08003295 /**
3296 * {@hide}
3297 * Returns the IMS Registration Status on a particular subid
3298 *
3299 * @param subId
3300 */
3301 public boolean isImsRegisteredForSubscriber(int subId) {
3302 Phone phone = getPhone(subId);
3303 if (phone != null) {
3304 return phone.isImsRegistered();
3305 } else {
3306 return false;
3307 }
3308 }
3309
Santos Cordon7a1885b2015-02-03 11:15:19 -08003310 @Override
3311 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3312 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3313 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003314
Nathan Haroldc55097a2015-03-11 18:14:50 -07003315 /*
3316 * {@hide}
3317 * Returns the IMS Registration Status
3318 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003319 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003320 return mPhone.isWifiCallingEnabled();
3321 }
3322
3323 /*
3324 * {@hide}
3325 * Returns the IMS Registration Status
3326 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003327 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003328 return mPhone.isVolteEnabled();
3329 }
Svet Ganovb320e182015-04-16 12:30:10 -07003330
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003331 /*
3332 * {@hide} Returns the IMS Registration Status
3333 */
3334 public boolean isVideoTelephonyAvailable() {
3335 return mPhone.isVideoEnabled();
3336 }
3337
Svet Ganovb320e182015-04-16 12:30:10 -07003338 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003339 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003340 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003341 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3342
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003343 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003344 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003345 } catch (SecurityException e) {
3346 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3347 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003348 }
Svet Ganovb320e182015-04-16 12:30:10 -07003349
3350 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3351 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3352 return false;
3353 }
3354
3355 return true;
3356 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003357
Makoto Onukifee69342015-06-29 14:44:50 -07003358 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003359 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003360 */
3361 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003362 // Default SMS app can always read it.
3363 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3364 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3365 return true;
3366 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003367
Makoto Onukie4072d12015-08-03 15:12:23 -07003368 try {
3369 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003370 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003371 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003372 // Can be read with READ_SMS too.
3373 try {
3374 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3375 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3376 if (opCode != AppOpsManager.OP_NONE) {
3377 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3378 == AppOpsManager.MODE_ALLOWED;
3379 } else {
3380 return true;
3381 }
3382 } catch (SecurityException readSmsSecurityException) {
3383 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003384 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003385 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003386 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003387 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003388 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003389 if (opCode != AppOpsManager.OP_NONE) {
3390 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3391 == AppOpsManager.MODE_ALLOWED;
3392 } else {
3393 return true;
3394 }
3395 } catch (SecurityException readPhoneNumberSecurityException) {
3396 }
3397
3398 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3399 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3400 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003401 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003402 }
3403
Stuart Scott8eef64f2015-04-08 15:13:54 -07003404 @Override
3405 public void factoryReset(int subId) {
3406 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003407 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3408 return;
3409 }
3410
Svet Ganovcc087f82015-05-12 20:35:54 -07003411 final long identity = Binder.clearCallingIdentity();
3412 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003413 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3414 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003415 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003416 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003417 // Set network selection mode to automatic
3418 setNetworkSelectionModeAutomatic(subId);
3419 // Set preferred mobile network type to the best available
3420 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3421 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003422 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003423 // Remove IMSI encryption keys from Carrier DB.
3424 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003425 }
3426 } finally {
3427 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003428 }
3429 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003430
3431 @Override
3432 public String getLocaleFromDefaultSim() {
3433 // We query all subscriptions instead of just the active ones, because
3434 // this might be called early on in the provisioning flow when the
3435 // subscriptions potentially aren't active yet.
3436 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3437 if (slist == null || slist.isEmpty()) {
3438 return null;
3439 }
3440
3441 // This function may be called very early, say, from the setup wizard, at
3442 // which point we won't have a default subscription set. If that's the case
3443 // we just choose the first, which will be valid in "most cases".
3444 final int defaultSubId = getDefaultSubscription();
3445 SubscriptionInfo info = null;
3446 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3447 info = slist.get(0);
3448 } else {
3449 for (SubscriptionInfo item : slist) {
3450 if (item.getSubscriptionId() == defaultSubId) {
3451 info = item;
3452 break;
3453 }
3454 }
3455
3456 if (info == null) {
3457 return null;
3458 }
3459 }
3460
3461 // Try and fetch the locale from the carrier properties or from the SIM language
3462 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003463 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003464 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003465 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003466 if (defaultPhone != null) {
3467 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3468 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003469 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003470 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3471 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003472 } else {
3473 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003474 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003475 }
3476 }
3477
Narayan Kamath011676f2015-07-29 12:04:08 +01003478 // The SIM language preferences only store a language (e.g. fr = French), not an
3479 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3480 // the SIM and carrier preferences does not include a country we add the country
3481 // determined from the SIM MCC to provide an exact locale.
3482 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003483 if (mccLocale != null) {
3484 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3485 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003486 }
3487
Tony Hill183b2de2015-06-24 14:53:58 +01003488 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003489 return null;
3490 }
3491
3492 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 return mSubscriptionController.getAllSubInfoList(
3496 mPhone.getContext().getOpPackageName());
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
3500 }
3501
3502 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3503 final long identity = Binder.clearCallingIdentity();
3504 try {
3505 return mSubscriptionController.getActiveSubscriptionInfoList(
3506 mPhone.getContext().getOpPackageName());
3507 } finally {
3508 Binder.restoreCallingIdentity(identity);
3509 }
3510 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003511
Chenjie Yu1ba97252018-01-11 18:16:20 -08003512 private final ModemActivityInfo mLastModemActivityInfo =
3513 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3514
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003515 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003516 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3517 * representing the state of the modem.
3518 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003519 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3520 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003521 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003522 */
3523 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003524 public void requestModemActivityInfo(ResultReceiver result) {
3525 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003526 ModemActivityInfo ret = null;
3527 synchronized (mLastModemActivityInfo) {
3528 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3529 null);
3530 if (info != null) {
3531 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3532 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3533 mergedTxTimeMs[i] =
3534 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3535 }
3536 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3537 mLastModemActivityInfo.setSleepTimeMillis(
3538 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3539 mLastModemActivityInfo.setIdleTimeMillis(
3540 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3541 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3542 mLastModemActivityInfo.setRxTimeMillis(
3543 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3544 mLastModemActivityInfo.setEnergyUsed(
3545 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3546 }
3547 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3548 mLastModemActivityInfo.getSleepTimeMillis(),
3549 mLastModemActivityInfo.getIdleTimeMillis(),
3550 mLastModemActivityInfo.getTxTimeMillis(),
3551 mLastModemActivityInfo.getRxTimeMillis(),
3552 mLastModemActivityInfo.getEnergyUsed());
3553 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003554 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003555 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003556 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003557 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003558
3559 /**
3560 * {@hide}
3561 * Returns the service state information on specified subscription.
3562 */
3563 @Override
3564 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3565
3566 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3567 return null;
3568 }
3569
3570 final Phone phone = getPhone(subId);
3571 if (phone == null) {
3572 return null;
3573 }
3574
3575 return phone.getServiceState();
3576 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003577
3578 /**
3579 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3580 *
3581 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3582 * voicemail ringtone.
3583 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3584 * PhoneAccount.
3585 */
3586 @Override
3587 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003588 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003589 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003590 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003591 }
3592
fionaxu7ed723d2017-05-30 18:58:54 -07003593 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003594 }
3595
3596 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003597 * Sets the per-account voicemail ringtone.
3598 *
3599 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3600 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3601 *
3602 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3603 * voicemail ringtone.
3604 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3605 * PhoneAccount.
3606 */
3607 @Override
3608 public void setVoicemailRingtoneUri(String callingPackage,
3609 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3611 if (!TextUtils.equals(callingPackage,
3612 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3613 enforceModifyPermissionOrCarrierPrivilege(
3614 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3615 }
3616 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3617 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003618 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003619 }
fionaxu7ed723d2017-05-30 18:58:54 -07003620 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003621 }
3622
3623 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003624 * Returns whether vibration is set for voicemail notification in Phone settings.
3625 *
3626 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3627 * voicemail vibration setting.
3628 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3629 */
3630 @Override
3631 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003632 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003633 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003634 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003635 }
3636
fionaxu7ed723d2017-05-30 18:58:54 -07003637 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003638 }
3639
Youhan Wange64578a2016-05-02 15:32:42 -07003640 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003641 * Sets the per-account voicemail vibration.
3642 *
3643 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3644 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3645 *
3646 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3647 * voicemail vibration setting.
3648 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3649 * specific PhoneAccount.
3650 */
3651 @Override
3652 public void setVoicemailVibrationEnabled(String callingPackage,
3653 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3654 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3655 if (!TextUtils.equals(callingPackage,
3656 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3657 enforceModifyPermissionOrCarrierPrivilege(
3658 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3659 }
3660
3661 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3662 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003663 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003664 }
fionaxu7ed723d2017-05-30 18:58:54 -07003665 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003666 }
3667
3668 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003669 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3670 *
3671 * @throws SecurityException if the caller does not have the required permission
3672 */
3673 private void enforceReadPrivilegedPermission() {
3674 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3675 null);
3676 }
3677
3678 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003679 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3680 * permission.
3681 *
3682 * @throws SecurityException if the caller does not have the required permission
3683 */
3684 private void enforceSendSmsPermission() {
3685 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3686 }
3687
3688 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003689 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003690 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003691 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003692 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003693 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003694 ComponentName componentName =
3695 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3696 if(componentName == null) {
3697 throw new SecurityException("Caller not current active visual voicemail package[null]");
3698 }
3699 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003700 if (!callingPackage.equals(vvmPackage)) {
3701 throw new SecurityException("Caller not current active visual voicemail package[" +
3702 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003703 }
3704 }
3705
3706 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003707 * Return the application ID for the app type.
3708 *
3709 * @param subId the subscription ID that this request applies to.
3710 * @param appType the uicc app type.
3711 * @return Application ID for specificied app type, or null if no uicc.
3712 */
3713 @Override
3714 public String getAidForAppType(int subId, int appType) {
3715 enforceReadPrivilegedPermission();
3716 Phone phone = getPhone(subId);
3717 if (phone == null) {
3718 return null;
3719 }
3720 String aid = null;
3721 try {
3722 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3723 .getApplicationByType(appType).getAid();
3724 } catch (Exception e) {
3725 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3726 }
3727 return aid;
3728 }
3729
Youhan Wang4001d252016-05-11 10:29:41 -07003730 /**
3731 * Return the Electronic Serial Number.
3732 *
3733 * @param subId the subscription ID that this request applies to.
3734 * @return ESN or null if error.
3735 */
3736 @Override
3737 public String getEsn(int subId) {
3738 enforceReadPrivilegedPermission();
3739 Phone phone = getPhone(subId);
3740 if (phone == null) {
3741 return null;
3742 }
3743 String esn = null;
3744 try {
3745 esn = phone.getEsn();
3746 } catch (Exception e) {
3747 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3748 }
3749 return esn;
3750 }
3751
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003752 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003753 * Return the Preferred Roaming List Version.
3754 *
3755 * @param subId the subscription ID that this request applies to.
3756 * @return PRLVersion or null if error.
3757 */
3758 @Override
3759 public String getCdmaPrlVersion(int subId) {
3760 enforceReadPrivilegedPermission();
3761 Phone phone = getPhone(subId);
3762 if (phone == null) {
3763 return null;
3764 }
3765 String cdmaPrlVersion = null;
3766 try {
3767 cdmaPrlVersion = phone.getCdmaPrlVersion();
3768 } catch (Exception e) {
3769 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3770 }
3771 return cdmaPrlVersion;
3772 }
3773
3774 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003775 * Get snapshot of Telephony histograms
3776 * @return List of Telephony histograms
3777 * @hide
3778 */
3779 @Override
3780 public List<TelephonyHistogram> getTelephonyHistograms() {
3781 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3782 return RIL.getTelephonyRILTimingHistograms();
3783 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003784
3785 /**
3786 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003787 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003788 * Require system privileges. In the future we may add this to carrier APIs.
3789 *
3790 * @return The number of carriers set successfully, should match length of carriers
3791 */
3792 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003793 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003794 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003795
Meng Wang9b7c4e92017-02-17 11:41:27 -08003796 if (carriers == null) {
3797 throw new NullPointerException("carriers cannot be null");
3798 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003799
3800 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003801 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3802 return retVal[0];
3803 }
3804
3805 /**
3806 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003807 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003808 * Require system privileges. In the future we may add this to carrier APIs.
3809 *
3810 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3811 * means all carriers are allowed.
3812 */
3813 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003814 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003815 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003816 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003817 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3818 }
3819
fionaxu59545b42016-05-25 15:53:37 -07003820 /**
3821 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3822 * @param subId the subscription ID that this action applies to.
3823 * @param enabled control enable or disable metered apns.
3824 * {@hide}
3825 */
3826 @Override
3827 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3828 enforceModifyPermission();
3829 final Phone phone = getPhone(subId);
3830 if (phone == null) {
3831 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3832 return;
3833 }
3834 try {
3835 phone.carrierActionSetMeteredApnsEnabled(enabled);
3836 } catch (Exception e) {
3837 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3838 }
3839 }
3840
3841 /**
3842 * Action set from carrier signalling broadcast receivers to enable/disable radio
3843 * @param subId the subscription ID that this action applies to.
3844 * @param enabled control enable or disable radio.
3845 * {@hide}
3846 */
3847 @Override
3848 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3849 enforceModifyPermission();
3850 final Phone phone = getPhone(subId);
3851 if (phone == null) {
3852 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3853 return;
3854 }
3855 try {
3856 phone.carrierActionSetRadioEnabled(enabled);
3857 } catch (Exception e) {
3858 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3859 }
3860 }
3861
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003862 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003863 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3864 * network status based on which carrier apps could apply actions accordingly,
3865 * enable/disable default url handler for example.
3866 *
3867 * @param subId the subscription ID that this action applies to.
3868 * @param report control start/stop reporting the default network status.
3869 * {@hide}
3870 */
3871 @Override
3872 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3873 enforceModifyPermission();
3874 final Phone phone = getPhone(subId);
3875 if (phone == null) {
3876 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3877 return;
3878 }
3879 try {
3880 phone.carrierActionReportDefaultNetworkStatus(report);
3881 } catch (Exception e) {
3882 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3883 }
3884 }
3885
3886 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003887 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3888 * bug report is being generated.
3889 */
3890 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003891 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003892 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3893 != PackageManager.PERMISSION_GRANTED) {
3894 writer.println("Permission Denial: can't dump Phone from pid="
3895 + Binder.getCallingPid()
3896 + ", uid=" + Binder.getCallingUid()
3897 + "without permission "
3898 + android.Manifest.permission.DUMP);
3899 return;
3900 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003901 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003902 }
Jack Yueb89b242016-06-22 13:27:47 -07003903
3904 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003905 * Get aggregated video call data usage since boot.
3906 *
3907 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3908 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003909 * {@hide}
3910 */
3911 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003912 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003913 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3914 null);
3915
Jack Yu84291ec2017-05-26 16:07:50 -07003916 // NetworkStatsService keeps tracking the active network interface and identity. It
3917 // records the delta with the corresponding network identity. We just return the total video
3918 // call data usage snapshot since boot.
3919 Phone phone = getPhone(subId);
3920 if (phone != null) {
3921 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003922 }
Jack Yu84291ec2017-05-26 16:07:50 -07003923 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003924 }
Jack Yu75ab2952016-07-08 14:29:33 -07003925
3926 /**
3927 * Policy control of data connection. Usually used when data limit is passed.
3928 * @param enabled True if enabling the data, otherwise disabling.
3929 * @param subId Subscription index
3930 * {@hide}
3931 */
3932 @Override
3933 public void setPolicyDataEnabled(boolean enabled, int subId) {
3934 enforceModifyPermission();
3935 Phone phone = getPhone(subId);
3936 if (phone != null) {
3937 phone.setPolicyDataEnabled(enabled);
3938 }
3939 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003940
3941 /**
3942 * Get Client request stats
3943 * @return List of Client Request Stats
3944 * @hide
3945 */
3946 @Override
3947 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3948 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3949 return null;
3950 }
3951
3952 Phone phone = getPhone(subId);
3953 if (phone != null) {
3954 return phone.getClientRequestStats();
3955 }
3956
3957 return null;
3958 }
3959
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003960 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003961 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003962 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003963 }
Jack Yueb4124c2017-02-16 15:32:43 -08003964
3965 /**
Grace Chen70990072017-03-24 17:21:30 -07003966 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003967 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003968 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003969 * @param state State of SIM (power down, power up, pass through)
3970 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3971 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3972 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003973 *
3974 **/
3975 @Override
Grace Chen70990072017-03-24 17:21:30 -07003976 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003977 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003978 Phone phone = PhoneFactory.getPhone(slotIndex);
3979
Jack Yueb4124c2017-02-16 15:32:43 -08003980 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003981 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003982 }
3983 }
Shuo Qiandd210312017-04-12 22:11:33 +00003984
Tyler Gunn65d45c22017-06-05 11:22:26 -07003985 private boolean isUssdApiAllowed(int subId) {
3986 CarrierConfigManager configManager =
3987 (CarrierConfigManager) mPhone.getContext().getSystemService(
3988 Context.CARRIER_CONFIG_SERVICE);
3989 if (configManager == null) {
3990 return false;
3991 }
3992 PersistableBundle pb = configManager.getConfigForSubId(subId);
3993 if (pb == null) {
3994 return false;
3995 }
3996 return pb.getBoolean(
3997 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3998 }
3999
Shuo Qiandd210312017-04-12 22:11:33 +00004000 /**
4001 * Check if phone is in emergency callback mode
4002 * @return true if phone is in emergency callback mode
4003 * @param subId sub id
4004 */
goneil9c5f4872017-12-05 14:07:56 -08004005 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004006 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004007 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004008 final Phone phone = getPhone(subId);
4009 if (phone != null) {
4010 return phone.isInEcm();
4011 } else {
4012 return false;
4013 }
4014 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004015
4016 /**
4017 * Get the current signal strength information for the given subscription.
4018 * Because this information is not updated when the device is in a low power state
4019 * it should not be relied-upon to be current.
4020 * @param subId Subscription index
4021 * @return the most recent cached signal strength info from the modem
4022 */
4023 @Override
4024 public SignalStrength getSignalStrength(int subId) {
4025 Phone p = getPhone(subId);
4026 if (p == null) {
4027 return null;
4028 }
4029
4030 return p.getSignalStrength();
4031 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004032
4033 @Override
4034 public UiccSlotInfo[] getUiccSlotsInfo() {
4035 enforceReadPrivilegedPermission();
4036
4037 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4038 if (slots == null) return null;
4039 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4040 for (int i = 0; i < slots.length; i++) {
4041 UiccSlot slot = slots[i];
4042
4043 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4044
4045 int cardState = 0;
4046 switch (slot.getCardState()) {
4047 case CARDSTATE_ABSENT:
4048 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4049 break;
4050 case CARDSTATE_PRESENT:
4051 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4052 break;
4053 case CARDSTATE_ERROR:
4054 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4055 break;
4056 case CARDSTATE_RESTRICTED:
4057 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4058 break;
4059 default:
4060 break;
4061
4062 }
4063
Qingxi Li795c5882018-01-31 13:43:27 -08004064 infos[i] = new UiccSlotInfo(
4065 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004066 }
4067 return infos;
4068 }
4069
4070 @Override
4071 public boolean switchSlots(int[] physicalSlots) {
4072 enforceModifyPermission();
4073 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004075}