blob: de4148129af1179ae4c6a06aa6f3b28124c478f9 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger7e934f52017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080058import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070059import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080060import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070061import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070062import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080065import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070066import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080067import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070069import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000071import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070072import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070073import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebingera12246d2018-01-16 09:39:35 -080074import android.telephony.ims.aidl.IImsConfig;
75import android.telephony.ims.aidl.IImsMmTelFeature;
76import android.telephony.ims.aidl.IImsRcsFeature;
77import android.telephony.ims.aidl.IImsRegistration;
Brad Ebingere21f25f2018-02-08 16:11:32 -080078import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080080import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080084
Andrew Lee312e8172014-10-23 17:01:36 -070085import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080086import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070088import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070089import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080093import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010094import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070095import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070096import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080098import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070099import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700100import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700103import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800104import com.android.internal.telephony.SubscriptionController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800105import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseri03923952017-07-19 12:22:35 -0700106import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700107import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700108import com.android.internal.telephony.uicc.IccIoResult;
109import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800110import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700111import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800112import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700113import com.android.internal.telephony.uicc.UiccController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800114import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000115import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700116import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800117import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700118import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800119import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700120import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700121import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800122
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700123import java.io.FileDescriptor;
124import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800125import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800128import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100129import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131
132/**
133 * Implementation of the ITelephony interface.
134 */
Santos Cordon117fee72014-05-16 17:56:12 -0700135public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136 private static final String LOG_TAG = "PhoneInterfaceManager";
137 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
138 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140
141 // Message codes used with mMainThreadHandler
142 private static final int CMD_HANDLE_PIN_MMI = 1;
143 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
144 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
145 private static final int CMD_ANSWER_RINGING_CALL = 4;
146 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700147 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
148 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149 private static final int CMD_OPEN_CHANNEL = 9;
150 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
151 private static final int CMD_CLOSE_CHANNEL = 11;
152 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800153 private static final int CMD_NV_READ_ITEM = 13;
154 private static final int EVENT_NV_READ_ITEM_DONE = 14;
155 private static final int CMD_NV_WRITE_ITEM = 15;
156 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
157 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
158 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
159 private static final int CMD_NV_RESET_CONFIG = 19;
160 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800161 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
162 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
163 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
164 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800165 private static final int CMD_SEND_ENVELOPE = 25;
166 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700167 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
168 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
169 private static final int CMD_EXCHANGE_SIM_IO = 31;
170 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800171 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
172 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700173 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
174 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700175 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
176 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700177 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
178 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
179 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
180 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700181 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
182 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
183 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
184 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700185 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800186 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
187 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000188 private static final int CMD_SWITCH_SLOTS = 50;
189 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800191 // Parameters of select command.
192 private static final int SELECT_COMMAND = 0xA4;
193 private static final int SELECT_P1 = 0x04;
194 private static final int SELECT_P2 = 0;
195 private static final int SELECT_P3 = 0x10;
196
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197 /** The singleton instance. */
198 private static PhoneInterfaceManager sInstance;
199
Wink Saville3ab207e2014-11-20 13:07:20 -0800200 private PhoneGlobals mApp;
201 private Phone mPhone;
202 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700203 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800204 private AppOpsManager mAppOps;
205 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800206 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800207 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208
Derek Tan97ebb422014-09-05 16:55:38 -0700209 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
210 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800211 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700212
Derek Tan740e1672017-06-27 14:56:27 -0700213 // The AID of ISD-R.
214 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
215
yinxub1bed742017-04-17 11:45:04 -0700216 private NetworkScanRequestTracker mNetworkScanRequestTracker;
217
Derek Tan89e89d42014-07-08 17:00:10 -0700218 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700219 * A request object to use for transmitting data to an ICC.
220 */
221 private static final class IccAPDUArgument {
222 public int channel, cla, command, p1, p2, p3;
223 public String data;
224
225 public IccAPDUArgument(int channel, int cla, int command,
226 int p1, int p2, int p3, String data) {
227 this.channel = channel;
228 this.cla = cla;
229 this.command = command;
230 this.p1 = p1;
231 this.p2 = p2;
232 this.p3 = p3;
233 this.data = data;
234 }
235 }
236
237 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700238 * A request object to use for transmitting data to an ICC.
239 */
240 private static final class ManualNetworkSelectionArgument {
241 public OperatorInfo operatorInfo;
242 public boolean persistSelection;
243
244 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
245 this.operatorInfo = operatorInfo;
246 this.persistSelection = persistSelection;
247 }
248 }
249
250 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
252 * request after sending. The main thread will notify the request when it is complete.
253 */
254 private static final class MainThreadRequest {
255 /** The argument to use for the request */
256 public Object argument;
257 /** The result of the request that is run on the main thread */
258 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800259 // The subscriber id that this request applies to. Defaults to
260 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
261 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262
263 public MainThreadRequest(Object argument) {
264 this.argument = argument;
265 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800266
267 public MainThreadRequest(Object argument, Integer subId) {
268 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800269 if (subId != null) {
270 this.subId = subId;
271 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 }
274
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800275 private static final class IncomingThirdPartyCallArgs {
276 public final ComponentName component;
277 public final String callId;
278 public final String callerDisplayName;
279
280 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
281 String callerDisplayName) {
282 this.component = component;
283 this.callId = callId;
284 this.callerDisplayName = callerDisplayName;
285 }
286 }
287
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 /**
289 * A handler that processes messages on the main thread in the phone process. Since many
290 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
291 * inbound binder threads to the main thread in the phone process. The Binder thread
292 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
293 * on, which will be notified when the operation completes and will contain the result of the
294 * request.
295 *
296 * <p>If a MainThreadRequest object is provided in the msg.obj field,
297 * note that request.result must be set to something non-null for the calling thread to
298 * unblock.
299 */
300 private final class MainThreadHandler extends Handler {
301 @Override
302 public void handleMessage(Message msg) {
303 MainThreadRequest request;
304 Message onCompleted;
305 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800306 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700307 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308
309 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700310 case CMD_HANDLE_USSD_REQUEST: {
311 request = (MainThreadRequest) msg.obj;
312 final Phone phone = getPhoneFromRequest(request);
313 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
314 String ussdRequest = ussdObject.first;
315 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700316
317 if (!isUssdApiAllowed(request.subId)) {
318 // Carrier does not support use of this API, return failure.
319 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
320 UssdResponse response = new UssdResponse(ussdRequest, null);
321 Bundle returnData = new Bundle();
322 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
323 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
324
325 request.result = true;
326 synchronized (request) {
327 request.notifyAll();
328 }
329 return;
330 }
331
Tyler Gunn52dcf772017-04-26 11:30:31 -0700332 try {
333 request.result = phone != null ?
334 phone.handleUssdRequest(ussdRequest, wrappedCallback)
335 : false;
336 } catch (CallStateException cse) {
337 request.result = false;
338 }
pkanwar32d516d2016-10-14 19:37:38 -0700339 // Wake up the requesting thread
340 synchronized (request) {
341 request.notifyAll();
342 }
343 break;
344 }
345
Yorke Lee716f67e2015-06-17 15:39:16 -0700346 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700348 final Phone phone = getPhoneFromRequest(request);
349 request.result = phone != null ?
350 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
351 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 // Wake up the requesting thread
353 synchronized (request) {
354 request.notifyAll();
355 }
356 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
359 case CMD_HANDLE_NEIGHBORING_CELL:
360 request = (MainThreadRequest) msg.obj;
361 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
362 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700363 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 break;
365
366 case EVENT_NEIGHBORING_CELL_DONE:
367 ar = (AsyncResult) msg.obj;
368 request = (MainThreadRequest) ar.userObj;
369 if (ar.exception == null && ar.result != null) {
370 request.result = ar.result;
371 } else {
372 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800373 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 }
375 // Wake up the requesting thread
376 synchronized (request) {
377 request.notifyAll();
378 }
379 break;
380
381 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700382 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800383 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700384 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 break;
386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 case CMD_END_CALL:
388 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800389 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700390 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700391 Phone phone = getPhone(end_subId);
392 if (phone == null) {
393 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
394 break;
395 }
396 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
398 // CDMA: If the user presses the Power button we treat it as
399 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700400 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
402 // GSM: End the call as per the Phone state
403 hungUp = PhoneUtils.hangup(mCM);
404 } else {
405 throw new IllegalStateException("Unexpected phone type: " + phoneType);
406 }
407 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
408 request.result = hungUp;
409 // Wake up the requesting thread
410 synchronized (request) {
411 request.notifyAll();
412 }
413 break;
414
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800418 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700419 if (uiccCard == null) {
420 loge("iccTransmitApduLogicalChannel: No UICC");
421 request.result = new IccIoResult(0x6F, 0, (byte[])null);
422 synchronized (request) {
423 request.notifyAll();
424 }
425 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
427 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700428 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 iccArgument.channel, iccArgument.cla, iccArgument.command,
430 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700432 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 break;
434
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 ar = (AsyncResult) msg.obj;
437 request = (MainThreadRequest) ar.userObj;
438 if (ar.exception == null && ar.result != null) {
439 request.result = ar.result;
440 } else {
441 request.result = new IccIoResult(0x6F, 0, (byte[])null);
442 if (ar.result == null) {
443 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800444 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800446 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 } else {
448 loge("iccTransmitApduLogicalChannel: Unknown exception");
449 }
450 }
451 synchronized (request) {
452 request.notifyAll();
453 }
454 break;
455
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
457 request = (MainThreadRequest) msg.obj;
458 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800459 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 if (uiccCard == null) {
461 loge("iccTransmitApduBasicChannel: No UICC");
462 request.result = new IccIoResult(0x6F, 0, (byte[])null);
463 synchronized (request) {
464 request.notifyAll();
465 }
466 } else {
467 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
468 request);
469 uiccCard.iccTransmitApduBasicChannel(
470 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
471 iccArgument.p3, iccArgument.data, onCompleted);
472 }
473 break;
474
475 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
476 ar = (AsyncResult) msg.obj;
477 request = (MainThreadRequest) ar.userObj;
478 if (ar.exception == null && ar.result != null) {
479 request.result = ar.result;
480 } else {
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
482 if (ar.result == null) {
483 loge("iccTransmitApduBasicChannel: Empty response");
484 } else if (ar.exception instanceof CommandException) {
485 loge("iccTransmitApduBasicChannel: CommandException: " +
486 ar.exception);
487 } else {
488 loge("iccTransmitApduBasicChannel: Unknown exception");
489 }
490 }
491 synchronized (request) {
492 request.notifyAll();
493 }
494 break;
495
496 case CMD_EXCHANGE_SIM_IO:
497 request = (MainThreadRequest) msg.obj;
498 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 if (uiccCard == null) {
501 loge("iccExchangeSimIO: No UICC");
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
503 synchronized (request) {
504 request.notifyAll();
505 }
506 } else {
507 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
508 request);
509 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
510 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
511 iccArgument.data, onCompleted);
512 }
513 break;
514
515 case EVENT_EXCHANGE_SIM_IO_DONE:
516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
520 } else {
521 request.result = new IccIoResult(0x6f, 0, (byte[])null);
522 }
523 synchronized (request) {
524 request.notifyAll();
525 }
526 break;
527
Derek Tan4d5e5c12014-02-04 11:54:58 -0800528 case CMD_SEND_ENVELOPE:
529 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800530 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700531 if (uiccCard == null) {
532 loge("sendEnvelopeWithStatus: No UICC");
533 request.result = new IccIoResult(0x6F, 0, (byte[])null);
534 synchronized (request) {
535 request.notifyAll();
536 }
537 } else {
538 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
539 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
540 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800541 break;
542
543 case EVENT_SEND_ENVELOPE_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("sendEnvelopeWithStatus: Empty response");
552 } else if (ar.exception instanceof CommandException) {
553 loge("sendEnvelopeWithStatus: CommandException: " +
554 ar.exception);
555 } else {
556 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
557 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 }
559 synchronized (request) {
560 request.notifyAll();
561 }
562 break;
563
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 case CMD_OPEN_CHANNEL:
565 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800566 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800567 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 if (uiccCard == null) {
569 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800570 request.result = new IccOpenLogicalChannelResponse(-1,
571 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700572 synchronized (request) {
573 request.notifyAll();
574 }
575 } else {
576 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800577 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
578 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 break;
581
582 case EVENT_OPEN_CHANNEL_DONE:
583 ar = (AsyncResult) msg.obj;
584 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 int[] result = (int[]) ar.result;
588 int channelId = result[0];
589 byte[] selectResponse = null;
590 if (result.length > 1) {
591 selectResponse = new byte[result.length - 1];
592 for (int i = 1; i < result.length; ++i) {
593 selectResponse[i - 1] = (byte) result[i];
594 }
595 }
596 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700597 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 if (ar.result == null) {
600 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 if (ar.exception != null) {
603 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
604 }
605
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700607 if (ar.exception instanceof CommandException) {
608 CommandException.Error error =
609 ((CommandException) (ar.exception)).getCommandError();
610 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700612 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 }
615 }
616 openChannelResp = new IccOpenLogicalChannelResponse(
617 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700619 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 synchronized (request) {
621 request.notifyAll();
622 }
623 break;
624
625 case CMD_CLOSE_CHANNEL:
626 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800627 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 if (uiccCard == null) {
629 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900630 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 synchronized (request) {
632 request.notifyAll();
633 }
634 } else {
635 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
636 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
637 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 break;
639
640 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800641 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
642 break;
643
644 case CMD_NV_READ_ITEM:
645 request = (MainThreadRequest) msg.obj;
646 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
647 mPhone.nvReadItem((Integer) request.argument, onCompleted);
648 break;
649
650 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 ar = (AsyncResult) msg.obj;
652 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800653 if (ar.exception == null && ar.result != null) {
654 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800656 request.result = "";
657 if (ar.result == null) {
658 loge("nvReadItem: Empty response");
659 } else if (ar.exception instanceof CommandException) {
660 loge("nvReadItem: CommandException: " +
661 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800663 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 }
665 }
666 synchronized (request) {
667 request.notifyAll();
668 }
669 break;
670
Jake Hambye994d462014-02-03 13:10:13 -0800671 case CMD_NV_WRITE_ITEM:
672 request = (MainThreadRequest) msg.obj;
673 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
674 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
675 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
676 break;
677
678 case EVENT_NV_WRITE_ITEM_DONE:
679 handleNullReturnEvent(msg, "nvWriteItem");
680 break;
681
682 case CMD_NV_WRITE_CDMA_PRL:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
685 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
686 break;
687
688 case EVENT_NV_WRITE_CDMA_PRL_DONE:
689 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
690 break;
691
692 case CMD_NV_RESET_CONFIG:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
695 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
696 break;
697
698 case EVENT_NV_RESET_CONFIG_DONE:
699 handleNullReturnEvent(msg, "nvResetConfig");
700 break;
701
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 case CMD_GET_PREFERRED_NETWORK_TYPE:
703 request = (MainThreadRequest) msg.obj;
704 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700705 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 break;
707
708 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
709 ar = (AsyncResult) msg.obj;
710 request = (MainThreadRequest) ar.userObj;
711 if (ar.exception == null && ar.result != null) {
712 request.result = ar.result; // Integer
713 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800714 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 if (ar.result == null) {
716 loge("getPreferredNetworkType: Empty response");
717 } else if (ar.exception instanceof CommandException) {
718 loge("getPreferredNetworkType: CommandException: " +
719 ar.exception);
720 } else {
721 loge("getPreferredNetworkType: Unknown exception");
722 }
723 }
724 synchronized (request) {
725 request.notifyAll();
726 }
727 break;
728
729 case CMD_SET_PREFERRED_NETWORK_TYPE:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
732 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700733 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 break;
735
736 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
737 handleNullReturnEvent(msg, "setPreferredNetworkType");
738 break;
739
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800740 case CMD_SET_VOICEMAIL_NUMBER:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
743 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800744 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
745 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800746 break;
747
748 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
749 handleNullReturnEvent(msg, "setVoicemailNumber");
750 break;
751
Stuart Scott54788802015-03-30 13:18:01 -0700752 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
755 request);
756 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
757 break;
758
759 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
760 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
761 break;
762
Shishir Agrawal302c8692015-06-19 13:49:39 -0700763 case CMD_PERFORM_NETWORK_SCAN:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
766 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
767 break;
768
769 case EVENT_PERFORM_NETWORK_SCAN_DONE:
770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
772 CellNetworkScanResult cellScanResult;
773 if (ar.exception == null && ar.result != null) {
774 cellScanResult = new CellNetworkScanResult(
775 CellNetworkScanResult.STATUS_SUCCESS,
776 (List<OperatorInfo>) ar.result);
777 } else {
778 if (ar.result == null) {
779 loge("getCellNetworkScanResults: Empty response");
780 }
781 if (ar.exception != null) {
782 loge("getCellNetworkScanResults: Exception: " + ar.exception);
783 }
784 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
785 if (ar.exception instanceof CommandException) {
786 CommandException.Error error =
787 ((CommandException) (ar.exception)).getCommandError();
788 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
789 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
790 } else if (error == CommandException.Error.GENERIC_FAILURE) {
791 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
792 }
793 }
794 cellScanResult = new CellNetworkScanResult(errorCode, null);
795 }
796 request.result = cellScanResult;
797 synchronized (request) {
798 request.notifyAll();
799 }
800 break;
801
802 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
803 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700804 ManualNetworkSelectionArgument selArg =
805 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700806 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
807 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700808 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
809 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 break;
811
812 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
813 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
814 break;
815
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700816 case CMD_GET_MODEM_ACTIVITY_INFO:
817 request = (MainThreadRequest) msg.obj;
818 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700819 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700820 break;
821
822 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null && ar.result != null) {
826 request.result = ar.result;
827 } else {
828 if (ar.result == null) {
829 loge("queryModemActivityInfo: Empty response");
830 } else if (ar.exception instanceof CommandException) {
831 loge("queryModemActivityInfo: CommandException: " +
832 ar.exception);
833 } else {
834 loge("queryModemActivityInfo: Unknown exception");
835 }
836 }
Amit Mahajand4766222016-01-28 15:28:28 -0800837 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
838 if (request.result == null) {
839 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
840 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700841 synchronized (request) {
842 request.notifyAll();
843 }
844 break;
845
Meng Wang1a7c35a2016-05-05 20:56:15 -0700846 case CMD_SET_ALLOWED_CARRIERS:
847 request = (MainThreadRequest) msg.obj;
848 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
849 mPhone.setAllowedCarriers(
850 (List<CarrierIdentifier>) request.argument,
851 onCompleted);
852 break;
853
854 case EVENT_SET_ALLOWED_CARRIERS_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
860 if (ar.result == null) {
861 loge("setAllowedCarriers: Empty response");
862 } else if (ar.exception instanceof CommandException) {
863 loge("setAllowedCarriers: CommandException: " +
864 ar.exception);
865 } else {
866 loge("setAllowedCarriers: Unknown exception");
867 }
868 }
869 // Result cannot be null. Return -1 on error.
870 if (request.result == null) {
871 request.result = new int[]{-1};
872 }
873 synchronized (request) {
874 request.notifyAll();
875 }
876 break;
877
878 case CMD_GET_ALLOWED_CARRIERS:
879 request = (MainThreadRequest) msg.obj;
880 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
881 mPhone.getAllowedCarriers(onCompleted);
882 break;
883
884 case EVENT_GET_ALLOWED_CARRIERS_DONE:
885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null && ar.result != null) {
888 request.result = ar.result;
889 } else {
890 if (ar.result == null) {
891 loge("getAllowedCarriers: Empty response");
892 } else if (ar.exception instanceof CommandException) {
893 loge("getAllowedCarriers: CommandException: " +
894 ar.exception);
895 } else {
896 loge("getAllowedCarriers: Unknown exception");
897 }
898 }
899 // Result cannot be null. Return empty list of CarrierIdentifier.
900 if (request.result == null) {
901 request.result = new ArrayList<CarrierIdentifier>(0);
902 }
903 synchronized (request) {
904 request.notifyAll();
905 }
906 break;
907
Nathan Haroldb3014052017-01-25 15:57:32 -0800908 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
914 request.result = new IllegalArgumentException(
915 "Failed to retrieve Forbidden Plmns");
916 if (ar.result == null) {
917 loge("getForbiddenPlmns: Empty response");
918 } else {
919 loge("getForbiddenPlmns: Unknown exception");
920 }
921 }
922 synchronized (request) {
923 request.notifyAll();
924 }
925 break;
926
927 case CMD_GET_FORBIDDEN_PLMNS:
928 request = (MainThreadRequest) msg.obj;
929 uiccCard = getUiccCardFromRequest(request);
930 if (uiccCard == null) {
931 loge("getForbiddenPlmns() UiccCard is null");
932 request.result = new IllegalArgumentException(
933 "getForbiddenPlmns() UiccCard is null");
934 synchronized (request) {
935 request.notifyAll();
936 }
937 break;
938 }
939 Integer appType = (Integer) request.argument;
940 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
941 if (uiccApp == null) {
942 loge("getForbiddenPlmns() no app with specified type -- "
943 + appType);
944 request.result = new IllegalArgumentException("Failed to get UICC App");
945 synchronized (request) {
946 request.notifyAll();
947 }
948 break;
949 } else {
950 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
951 + " specified type -- " + appType);
952 }
953 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
954 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
955 onCompleted);
956 break;
957
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000958 case CMD_SWITCH_SLOTS:
959 request = (MainThreadRequest) msg.obj;
960 int[] physicalSlots = (int[]) request.argument;
961 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
962 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
963 break;
964
965 case EVENT_SWITCH_SLOTS_DONE:
966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
968 request.result = (ar.exception == null);
969 synchronized (request) {
970 request.notifyAll();
971 }
972 break;
973
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700974 default:
975 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
976 break;
977 }
978 }
Jake Hambye994d462014-02-03 13:10:13 -0800979
980 private void handleNullReturnEvent(Message msg, String command) {
981 AsyncResult ar = (AsyncResult) msg.obj;
982 MainThreadRequest request = (MainThreadRequest) ar.userObj;
983 if (ar.exception == null) {
984 request.result = true;
985 } else {
986 request.result = false;
987 if (ar.exception instanceof CommandException) {
988 loge(command + ": CommandException: " + ar.exception);
989 } else {
990 loge(command + ": Unknown exception");
991 }
992 }
993 synchronized (request) {
994 request.notifyAll();
995 }
996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700997 }
998
999 /**
1000 * Posts the specified command to be executed on the main thread,
1001 * waits for the request to complete, and returns the result.
1002 * @see #sendRequestAsync
1003 */
1004 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001005 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001006 }
1007
1008 /**
1009 * Posts the specified command to be executed on the main thread,
1010 * waits for the request to complete, and returns the result.
1011 * @see #sendRequestAsync
1012 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001013 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001014 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1015 throw new RuntimeException("This method will deadlock if called from the main thread.");
1016 }
1017
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001018 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001019 Message msg = mMainThreadHandler.obtainMessage(command, request);
1020 msg.sendToTarget();
1021
1022 // Wait for the request to complete
1023 synchronized (request) {
1024 while (request.result == null) {
1025 try {
1026 request.wait();
1027 } catch (InterruptedException e) {
1028 // Do nothing, go back and wait until the request is complete
1029 }
1030 }
1031 }
1032 return request.result;
1033 }
1034
1035 /**
1036 * Asynchronous ("fire and forget") version of sendRequest():
1037 * Posts the specified command to be executed on the main thread, and
1038 * returns immediately.
1039 * @see #sendRequest
1040 */
1041 private void sendRequestAsync(int command) {
1042 mMainThreadHandler.sendEmptyMessage(command);
1043 }
1044
1045 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001046 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1047 * @see {@link #sendRequest(int,Object)}
1048 */
1049 private void sendRequestAsync(int command, Object argument) {
1050 MainThreadRequest request = new MainThreadRequest(argument);
1051 Message msg = mMainThreadHandler.obtainMessage(command, request);
1052 msg.sendToTarget();
1053 }
1054
1055 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001056 * Initialize the singleton PhoneInterfaceManager instance.
1057 * This is only done once, at startup, from PhoneApp.onCreate().
1058 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001059 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001060 synchronized (PhoneInterfaceManager.class) {
1061 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001062 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001063 } else {
1064 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1065 }
1066 return sInstance;
1067 }
1068 }
1069
1070 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001071 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001072 mApp = app;
1073 mPhone = phone;
1074 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001075 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001076 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1077 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001078 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001079 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001080 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001081 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001082
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 publish();
1084 }
1085
1086 private void publish() {
1087 if (DBG) log("publish: " + this);
1088
1089 ServiceManager.addService("phone", this);
1090 }
1091
Stuart Scott584921c2015-01-15 17:10:34 -08001092 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001093 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1094 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001095 }
1096
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001097 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1098 Phone phone = getPhoneFromRequest(request);
1099 return phone == null ? null :
1100 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1101 }
1102
Wink Saville36469e72014-06-11 15:17:00 -07001103 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001104 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001105 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001107 //
1108 // Implementation of the ITelephony interface.
1109 //
1110
1111 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001112 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001113 }
1114
Wink Savilleb564aae2014-10-23 10:18:09 -07001115 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001116 if (DBG) log("dial: " + number);
1117 // No permission check needed here: This is just a wrapper around the
1118 // ACTION_DIAL intent, which is available to any app since it puts up
1119 // the UI before it does anything.
1120
1121 String url = createTelUrl(number);
1122 if (url == null) {
1123 return;
1124 }
1125
1126 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001127 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001128 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1129 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1130 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1131 mApp.startActivity(intent);
1132 }
1133 }
1134
1135 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001136 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001137 }
1138
Wink Savilleb564aae2014-10-23 10:18:09 -07001139 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 if (DBG) log("call: " + number);
1141
1142 // This is just a wrapper around the ACTION_CALL intent, but we still
1143 // need to do a permission check since we're calling startActivity()
1144 // from the context of the phone app.
1145 enforceCallPermission();
1146
1147 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1148 != AppOpsManager.MODE_ALLOWED) {
1149 return;
1150 }
1151
1152 String url = createTelUrl(number);
1153 if (url == null) {
1154 return;
1155 }
1156
Wink Saville08874612014-08-31 19:19:58 -07001157 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001158 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001159 if (slist != null) {
1160 for (SubscriptionInfo subInfoRecord : slist) {
1161 if (subInfoRecord.getSubscriptionId() == subId) {
1162 isValid = true;
1163 break;
1164 }
Wink Saville08874612014-08-31 19:19:58 -07001165 }
1166 }
1167 if (isValid == false) {
1168 return;
1169 }
1170
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001172 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1174 mApp.startActivity(intent);
1175 }
1176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001177 /**
1178 * End a call based on call state
1179 * @return true is a call was ended
1180 */
1181 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001182 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001183 }
1184
1185 /**
1186 * End a call based on the call state of the subId
1187 * @return true is a call was ended
1188 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001189 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001191 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 }
1193
1194 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001195 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001196 }
1197
Wink Savilleb564aae2014-10-23 10:18:09 -07001198 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 if (DBG) log("answerRingingCall...");
1200 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1201 // but that can probably wait till the big TelephonyManager API overhaul.
1202 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1203 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001204 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 }
1206
1207 /**
1208 * Make the actual telephony calls to implement answerRingingCall().
1209 * This should only be called from the main thread of the Phone app.
1210 * @see #answerRingingCall
1211 *
1212 * TODO: it would be nice to return true if we answered the call, or
1213 * false if there wasn't actually a ringing incoming call, or some
1214 * other error occurred. (In other words, pass back the return value
1215 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1216 * But that would require calling this method via sendRequest() rather
1217 * than sendRequestAsync(), and right now we don't actually *need* that
1218 * return value, so let's just return void for now.
1219 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001220 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001221 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001223 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1224 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225 if (hasActiveCall && hasHoldingCall) {
1226 // Both lines are in use!
1227 // TODO: provide a flag to let the caller specify what
1228 // policy to use if both lines are in use. (The current
1229 // behavior is hardwired to "answer incoming, end ongoing",
1230 // which is how the CALL button is specced to behave.)
1231 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1232 return;
1233 } else {
1234 // answerCall() will automatically hold the current active
1235 // call, if there is one.
1236 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1237 return;
1238 }
1239 } else {
1240 // No call was ringing.
1241 return;
1242 }
1243 }
1244
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001246 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001248 public void silenceRinger() {
1249 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 }
1251
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001252 @Override
1253 public boolean isOffhook(String callingPackage) {
1254 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001255 }
1256
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001257 @Override
1258 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001260 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001261 return false;
1262 }
1263
Sanket Padawe356d7632015-06-22 14:03:32 -07001264 final Phone phone = getPhone(subId);
1265 if (phone != null) {
1266 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1267 } else {
1268 return false;
1269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 }
1271
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001272 @Override
1273 public boolean isRinging(String callingPackage) {
1274 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001275 }
1276
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001277 @Override
1278 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001280 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001281 return false;
1282 }
1283
Sanket Padawe356d7632015-06-22 14:03:32 -07001284 final Phone phone = getPhone(subId);
1285 if (phone != null) {
1286 return (phone.getState() == PhoneConstants.State.RINGING);
1287 } else {
1288 return false;
1289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 }
1291
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001292 @Override
1293 public boolean isIdle(String callingPackage) {
1294 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001295 }
1296
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001297 @Override
1298 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001300 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001301 return false;
1302 }
1303
Sanket Padawe356d7632015-06-22 14:03:32 -07001304 final Phone phone = getPhone(subId);
1305 if (phone != null) {
1306 return (phone.getState() == PhoneConstants.State.IDLE);
1307 } else {
1308 return false;
1309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 }
1311
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001313 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Wink Savilleb564aae2014-10-23 10:18:09 -07001316 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001317 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001318 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1319 }
1320
1321 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001322 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001323 }
1324
Wink Savilleb564aae2014-10-23 10:18:09 -07001325 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001326 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001327 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1328 }
1329
1330 /** {@hide} */
1331 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001332 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001333 }
1334
Wink Savilleb564aae2014-10-23 10:18:09 -07001335 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001337 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001338 checkSimPin.start();
1339 return checkSimPin.unlockSim(null, pin);
1340 }
1341
Wink Saville9de0f752013-10-22 19:04:03 -07001342 /** {@hide} */
1343 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001344 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001345 }
1346
Wink Savilleb564aae2014-10-23 10:18:09 -07001347 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001349 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 checkSimPuk.start();
1351 return checkSimPuk.unlockSim(puk, pin);
1352 }
1353
1354 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001355 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 * a synchronous one.
1357 */
1358 private static class UnlockSim extends Thread {
1359
1360 private final IccCard mSimCard;
1361
1362 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001363 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1364 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365
1366 // For replies from SimCard interface
1367 private Handler mHandler;
1368
1369 // For async handler to identify request type
1370 private static final int SUPPLY_PIN_COMPLETE = 100;
1371
1372 public UnlockSim(IccCard simCard) {
1373 mSimCard = simCard;
1374 }
1375
1376 @Override
1377 public void run() {
1378 Looper.prepare();
1379 synchronized (UnlockSim.this) {
1380 mHandler = new Handler() {
1381 @Override
1382 public void handleMessage(Message msg) {
1383 AsyncResult ar = (AsyncResult) msg.obj;
1384 switch (msg.what) {
1385 case SUPPLY_PIN_COMPLETE:
1386 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1387 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001388 mRetryCount = msg.arg1;
1389 if (ar.exception != null) {
1390 if (ar.exception instanceof CommandException &&
1391 ((CommandException)(ar.exception)).getCommandError()
1392 == CommandException.Error.PASSWORD_INCORRECT) {
1393 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1394 } else {
1395 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1396 }
1397 } else {
1398 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 mDone = true;
1401 UnlockSim.this.notifyAll();
1402 }
1403 break;
1404 }
1405 }
1406 };
1407 UnlockSim.this.notifyAll();
1408 }
1409 Looper.loop();
1410 }
1411
1412 /*
1413 * Use PIN or PUK to unlock SIM card
1414 *
1415 * If PUK is null, unlock SIM card with PIN
1416 *
1417 * If PUK is not null, unlock SIM card with PUK and set PIN code
1418 */
Wink Saville9de0f752013-10-22 19:04:03 -07001419 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420
1421 while (mHandler == null) {
1422 try {
1423 wait();
1424 } catch (InterruptedException e) {
1425 Thread.currentThread().interrupt();
1426 }
1427 }
1428 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1429
1430 if (puk == null) {
1431 mSimCard.supplyPin(pin, callback);
1432 } else {
1433 mSimCard.supplyPuk(puk, pin, callback);
1434 }
1435
1436 while (!mDone) {
1437 try {
1438 Log.d(LOG_TAG, "wait for done");
1439 wait();
1440 } catch (InterruptedException e) {
1441 // Restore the interrupted status
1442 Thread.currentThread().interrupt();
1443 }
1444 }
1445 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001446 int[] resultArray = new int[2];
1447 resultArray[0] = mResult;
1448 resultArray[1] = mRetryCount;
1449 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 }
1451 }
1452
1453 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001455
1456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 // No permission check needed here: this call is harmless, and it's
1460 // needed for the ServiceState.requestStateUpdate() call (which is
1461 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001462 final Phone phone = getPhone(subId);
1463 if (phone != null) {
1464 phone.updateServiceLocation();
1465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 }
1467
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001468 @Override
1469 public boolean isRadioOn(String callingPackage) {
1470 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001471 }
1472
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001473 @Override
1474 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001476 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001477 return false;
1478 }
1479 return isRadioOnForSubscriber(subId);
1480 }
1481
1482 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001483 final Phone phone = getPhone(subId);
1484 if (phone != null) {
1485 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1486 } else {
1487 return false;
1488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 }
1490
1491 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001492 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001493
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 }
Wink Saville36469e72014-06-11 15:17:00 -07001495
Wink Savilleb564aae2014-10-23 10:18:09 -07001496 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001498 final Phone phone = getPhone(subId);
1499 if (phone != null) {
1500 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1501 }
Wink Saville36469e72014-06-11 15:17:00 -07001502 }
1503
1504 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001505 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001506 }
1507
Wink Savilleb564aae2014-10-23 10:18:09 -07001508 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001509 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001510 final Phone phone = getPhone(subId);
1511 if (phone == null) {
1512 return false;
1513 }
1514 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001515 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001516 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001517 }
1518 return true;
1519 }
Wink Saville36469e72014-06-11 15:17:00 -07001520
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001521 public boolean needMobileRadioShutdown() {
1522 /*
1523 * If any of the Radios are available, it will need to be
1524 * shutdown. So return true if any Radio is available.
1525 */
1526 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1527 Phone phone = PhoneFactory.getPhone(i);
1528 if (phone != null && phone.isRadioAvailable()) return true;
1529 }
1530 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1531 return false;
1532 }
1533
1534 public void shutdownMobileRadios() {
1535 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1536 logv("Shutting down Phone " + i);
1537 shutdownRadioUsingPhoneId(i);
1538 }
1539 }
1540
1541 private void shutdownRadioUsingPhoneId(int phoneId) {
1542 enforceModifyPermission();
1543 Phone phone = PhoneFactory.getPhone(phoneId);
1544 if (phone != null && phone.isRadioAvailable()) {
1545 phone.shutdownRadio();
1546 }
1547 }
1548
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001550 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001551 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1552 if (defaultPhone != null) {
1553 defaultPhone.setRadioPower(turnOn);
1554 return true;
1555 } else {
1556 loge("There's no default phone.");
1557 return false;
1558 }
Wink Saville36469e72014-06-11 15:17:00 -07001559 }
1560
Wink Savilleb564aae2014-10-23 10:18:09 -07001561 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 final Phone phone = getPhone(subId);
1564 if (phone != null) {
1565 phone.setRadioPower(turnOn);
1566 return true;
1567 } else {
1568 return false;
1569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
Wink Saville36469e72014-06-11 15:17:00 -07001572 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 public boolean enableDataConnectivity() {
1575 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001576 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001577 final Phone phone = getPhone(subId);
1578 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001579 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 return true;
1581 } else {
1582 return false;
1583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 }
1585
Wink Saville36469e72014-06-11 15:17:00 -07001586 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 public boolean disableDataConnectivity() {
1589 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001590 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001591 final Phone phone = getPhone(subId);
1592 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001593 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 return true;
1595 } else {
1596 return false;
1597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 }
1599
Sanket Padawe356d7632015-06-22 14:03:32 -07001600 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001601 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001602 final Phone phone = getPhone(subId);
1603 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001604 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001605 } else {
1606 return false;
1607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 }
1609
1610 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001611 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001612 }
1613
pkanwarae03a6b2016-11-06 20:37:09 -08001614 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001615 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001616 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1617 return;
1618 }
1619 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1620 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1621 };
1622
Wink Savilleb564aae2014-10-23 10:18:09 -07001623 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1626 return false;
1627 }
Wink Saville36469e72014-06-11 15:17:00 -07001628 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
1630
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001632 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001633 }
1634
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001635 public int getCallStateForSlot(int slotIndex) {
1636 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001637 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001638 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 }
1640
Sanket Padawe356d7632015-06-22 14:03:32 -07001641 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001643 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001644 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001645 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001646 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001647 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 }
1650
Sanket Padawe356d7632015-06-22 14:03:32 -07001651 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001653 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 if (phone != null) {
1655 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1656 } else {
1657 return TelephonyManager.DATA_ACTIVITY_NONE;
1658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
1660
1661 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001662 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001663 mPhone.getContext().getSystemService(AppOpsManager.class)
1664 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001665 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001666 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001667 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 }
1669
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001670 if (DBG_LOC) log("getCellLocation: is active user");
1671 Bundle data = new Bundle();
1672 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1673 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 return null;
1675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001677 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1678 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1679 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001680 }
1681
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001683 public String getNetworkCountryIsoForPhone(int phoneId) {
1684 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1685 // registered cell info, so return a NULL country instead.
1686 final long identity = Binder.clearCallingIdentity();
1687 try {
1688 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1689 if (TelephonyManager.NETWORK_TYPE_IWLAN
1690 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1691 return "";
1692 }
1693 } finally {
1694 Binder.restoreCallingIdentity(identity);
1695 }
1696 return TelephonyManager.getTelephonyProperty(
1697 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1698 }
1699
1700 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001702 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001703 }
1704
Sanket Padawe356d7632015-06-22 14:03:32 -07001705 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001706 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 mApp.enforceCallingOrSelfPermission(
1708 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 final Phone phone = getPhone(subId);
1710 if (phone != null) {
1711 phone.enableLocationUpdates();
1712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 }
1714
1715 @Override
1716 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001717 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001718 }
1719
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001721 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001722 mApp.enforceCallingOrSelfPermission(
1723 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 final Phone phone = getPhone(subId);
1725 if (phone != null) {
1726 phone.disableLocationUpdates();
1727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 }
1729
1730 @Override
1731 @SuppressWarnings("unchecked")
1732 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001733 mPhone.getContext().getSystemService(AppOpsManager.class)
1734 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001735 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001736 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001737 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
1739
1740 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1741 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1742 return null;
1743 }
Svetoslav64fad262015-04-14 14:35:21 -07001744
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001745 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001747 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001749 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1750 try {
1751 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1752 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1753 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1754 } catch (RuntimeException e) {
1755 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759
1760
1761 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001762 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001763 mPhone.getContext().getSystemService(AppOpsManager.class)
1764 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001765 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001766 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001767 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001770 if (DBG_LOC) log("getAllCellInfo: is active user");
1771 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1772 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1773 for (Phone phone : PhoneFactory.getPhones()) {
1774 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1775 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001777 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001780 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001782 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001783 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1784 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Shishir Agrawala9f32182016-04-12 12:00:16 -07001787 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001788 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001789 Phone phone = PhoneFactory.getPhone(slotIndex);
1790 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001791 return null;
1792 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001793 int subId = phone.getSubId();
1794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1795 mApp, subId, callingPackage, "getImeiForSlot")) {
1796 return null;
1797 }
1798 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001799 }
1800
1801 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001802 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001803 Phone phone = PhoneFactory.getPhone(slotIndex);
1804 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001805 return null;
1806 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001807 int subId = phone.getSubId();
1808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1809 mApp, subId, callingPackage, "getMeidForSlot")) {
1810 return null;
1811 }
1812 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001813 }
1814
1815 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001816 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001817 Phone phone = PhoneFactory.getPhone(slotIndex);
1818 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001819 return null;
1820 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001821 int subId = phone.getSubId();
1822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1823 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1824 return null;
1825 }
1826 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001827 }
1828
fionaxuf32acdf2017-11-27 22:51:16 -08001829 @Override
1830 public int getSubscriptionCarrierId(int subId) {
1831 final Phone phone = getPhone(subId);
1832 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1833 }
1834
1835 @Override
1836 public String getSubscriptionCarrierName(int subId) {
1837 final Phone phone = getPhone(subId);
1838 return phone == null ? null : phone.getCarrierName();
1839 }
1840
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 //
1842 // Internal helper methods.
1843 //
1844
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001845 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1847 *
1848 * @throws SecurityException if the caller does not have the required permission
1849 */
1850 private void enforceModifyPermission() {
1851 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1852 }
1853
1854 /**
1855 * Make sure the caller has the CALL_PHONE permission.
1856 *
1857 * @throws SecurityException if the caller does not have the required permission
1858 */
1859 private void enforceCallPermission() {
1860 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1861 }
1862
Stuart Scott8eef64f2015-04-08 15:13:54 -07001863 private void enforceConnectivityInternalPermission() {
1864 mApp.enforceCallingOrSelfPermission(
1865 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1866 "ConnectivityService");
1867 }
1868
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 private String createTelUrl(String number) {
1870 if (TextUtils.isEmpty(number)) {
1871 return null;
1872 }
1873
Jake Hambye994d462014-02-03 13:10:13 -08001874 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 }
1876
Ihab Awadf9e92732013-12-05 18:02:52 -08001877 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1879 }
1880
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001881 private static void logv(String msg) {
1882 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1883 }
1884
Ihab Awadf9e92732013-12-05 18:02:52 -08001885 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1887 }
1888
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001891 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001895 public int getActivePhoneTypeForSlot(int slotIndex) {
1896 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001897 if (phone == null) {
1898 return PhoneConstants.PHONE_TYPE_NONE;
1899 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001900 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
1904 /**
1905 * Returns the CDMA ERI icon index to display
1906 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001907 @Override
1908 public int getCdmaEriIconIndex(String callingPackage) {
1909 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001910 }
1911
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001913 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001915 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001916 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) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001939 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001940 return -1;
1941 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 final Phone phone = getPhone(subId);
1943 if (phone != null) {
1944 return phone.getCdmaEriIconMode();
1945 } else {
1946 return -1;
1947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 }
1949
1950 /**
1951 * Returns the CDMA ERI text,
1952 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001953 @Override
1954 public String getCdmaEriText(String callingPackage) {
1955 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001956 }
1957
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001959 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001961 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001962 return null;
1963 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001964 final Phone phone = getPhone(subId);
1965 if (phone != null) {
1966 return phone.getCdmaEriText();
1967 } else {
1968 return null;
1969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971
1972 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001973 * Returns the CDMA MDN.
1974 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001976 public String getCdmaMdn(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1978 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 final Phone phone = getPhone(subId);
1980 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1981 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001982 } else {
1983 return null;
1984 }
1985 }
1986
1987 /**
1988 * Returns the CDMA MIN.
1989 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001991 public String getCdmaMin(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1993 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 final Phone phone = getPhone(subId);
1995 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1996 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001997 } else {
1998 return null;
1999 }
2000 }
2001
2002 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 * Returns true if CDMA provisioning needs to run.
2004 */
2005 public boolean needsOtaServiceProvisioning() {
2006 return mPhone.needsOtaServiceProvisioning();
2007 }
2008
2009 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002010 * Sets the voice mail number of a given subId.
2011 */
2012 @Override
2013 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002014 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002015 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2016 new Pair<String, String>(alphaTag, number), new Integer(subId));
2017 return success;
2018 }
2019
Ta-wei Yen87c49842016-05-13 21:19:52 -07002020 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002021 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2022 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2023 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2024 if (!TextUtils.equals(callingPackage, systemDialer)) {
2025 throw new SecurityException("caller must be system dialer");
2026 }
2027 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2028 if (phoneAccountHandle == null){
2029 return null;
2030 }
2031 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2032 }
2033
2034 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002035 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002038 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002039 return null;
2040 }
Jeff Davidson87b3c102018-03-15 17:16:18 -07002041 final long identity = Binder.clearCallingIdentity();
2042 try {
2043 return RemoteVvmTaskManager
2044 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
2047 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002048 }
2049
2050 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002051 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2052 VisualVoicemailSmsFilterSettings settings) {
2053 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002054 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002055 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2056 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002057 }
2058
2059 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002060 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2061 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002062 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002063 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002064 }
2065
2066 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002067 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2068 String callingPackage, int subId) {
2069 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002070 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002071 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002072 }
2073
2074 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002075 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002076 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002077 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002078 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2079 }
2080
2081 @Override
2082 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2083 String number, int port, String text, PendingIntent sentIntent) {
2084 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002085 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002086 enforceSendSmsPermission();
2087 // Make the calls as the phone process.
2088 final long identity = Binder.clearCallingIdentity();
2089 try {
2090 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2091 if (port == 0) {
2092 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2093 sentIntent, null, false);
2094 } else {
2095 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2096 smsManager.sendDataMessageWithSelfPermissions(number, null,
2097 (short) port, data, sentIntent, null);
2098 }
2099 } finally {
2100 Binder.restoreCallingIdentity(identity);
2101 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002102 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002103 /**
fionaxu0152e512016-11-14 13:36:14 -08002104 * Sets the voice activation state of a given subId.
2105 */
2106 @Override
2107 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2109 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002110 final Phone phone = getPhone(subId);
2111 if (phone != null) {
2112 phone.setVoiceActivationState(activationState);
2113 } else {
2114 loge("setVoiceActivationState fails with invalid subId: " + subId);
2115 }
2116 }
2117
2118 /**
2119 * Sets the data activation state of a given subId.
2120 */
2121 @Override
2122 public void setDataActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2124 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002125 final Phone phone = getPhone(subId);
2126 if (phone != null) {
2127 phone.setDataActivationState(activationState);
2128 } else {
2129 loge("setVoiceActivationState fails with invalid subId: " + subId);
2130 }
2131 }
2132
2133 /**
2134 * Returns the voice activation state of a given subId.
2135 */
2136 @Override
2137 public int getVoiceActivationState(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002138 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002139 mApp, subId, callingPackage, "getVoiceActivationStateForSubscriber")) {
fionaxu0152e512016-11-14 13:36:14 -08002140 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2141 }
2142 final Phone phone = getPhone(subId);
2143 if (phone != null) {
2144 return phone.getVoiceActivationState();
2145 } else {
2146 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2147 }
2148 }
2149
2150 /**
2151 * Returns the data activation state of a given subId.
2152 */
2153 @Override
2154 public int getDataActivationState(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002155 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002156 mApp, subId, callingPackage, "getDataActivationStateForSubscriber")) {
fionaxu0152e512016-11-14 13:36:14 -08002157 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2158 }
2159 final Phone phone = getPhone(subId);
2160 if (phone != null) {
2161 return phone.getDataActivationState();
2162 } else {
2163 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2164 }
2165 }
2166
2167 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 * Returns the unread count of voicemails
2169 */
2170 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002171 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002172 }
2173
2174 /**
2175 * Returns the unread count of voicemails for a subId
2176 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002177 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002178 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002179 final Phone phone = getPhone(subId);
2180 if (phone != null) {
2181 return phone.getVoiceMessageCount();
2182 } else {
2183 return 0;
2184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
2187 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002188 * returns true, if the device is in a state where both voice and data
2189 * are supported simultaneously. This can change based on location or network condition.
2190 */
2191 @Override
2192 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2193 final Phone phone = getPhone(subId);
2194 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2195 }
2196
2197 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002198 * Send the dialer code if called from the current default dialer or the caller has
2199 * carrier privilege.
2200 * @param inputCode The dialer code to send
2201 */
2202 @Override
2203 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2204 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2205 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2206 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002207 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2208 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002209 }
2210 mPhone.sendDialerSpecialCode(inputCode);
2211 }
2212
2213 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002214 * Returns the data network type.
2215 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 *
2217 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2218 */
2219 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002220 public int getNetworkType() {
2221 final Phone phone = getPhone(getDefaultSubscription());
2222 if (phone != null) {
2223 return phone.getServiceState().getDataNetworkType();
2224 } else {
2225 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2226 }
Wink Saville36469e72014-06-11 15:17:00 -07002227 }
2228
2229 /**
2230 * Returns the network type for a subId
2231 */
2232 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002235 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002236 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2237 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002238
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002240 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002241 return phone.getServiceState().getDataNetworkType();
2242 } else {
2243 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
2247 /**
2248 * Returns the data network type
2249 */
2250 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002251 public int getDataNetworkType(String callingPackage) {
2252 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002253 }
2254
2255 /**
2256 * Returns the data network type for a subId
2257 */
2258 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002261 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2263 }
2264
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 final Phone phone = getPhone(subId);
2266 if (phone != null) {
2267 return phone.getServiceState().getDataNetworkType();
2268 } else {
2269 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
2273 /**
Wink Saville36469e72014-06-11 15:17:00 -07002274 * Returns the Voice network type for a subId
2275 */
2276 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002277 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002279 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002280 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2281 }
2282
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 final Phone phone = getPhone(subId);
2284 if (phone != null) {
2285 return phone.getServiceState().getVoiceNetworkType();
2286 } else {
2287 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
2291 /**
2292 * @return true if a ICC card is present
2293 */
2294 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002295 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002296 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2297 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002298 }
2299
2300 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002301 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002302 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002303 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002304 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2305 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002306 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002308 } else {
2309 return false;
2310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 }
2312
2313 /**
2314 * Return if the current radio is LTE on CDMA. This
2315 * is a tri-state return value as for a period of time
2316 * the mode may be unknown.
2317 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002318 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002320 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 @Override
2323 public int getLteOnCdmaMode(String callingPackage) {
2324 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002325 }
2326
Sanket Padawe356d7632015-06-22 14:03:32 -07002327 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002328 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002330 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002331 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2332 }
2333
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 final Phone phone = getPhone(subId);
2335 if (phone == null) {
2336 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2337 } else {
2338 return phone.getLteOnCdmaMode();
2339 }
Wink Saville36469e72014-06-11 15:17:00 -07002340 }
2341
2342 public void setPhone(Phone phone) {
2343 mPhone = phone;
2344 }
2345
2346 /**
2347 * {@hide}
2348 * Returns Default subId, 0 in the case of single standby.
2349 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002350 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002351 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002352 }
2353
Shishir Agrawala9f32182016-04-12 12:00:16 -07002354 private int getSlotForDefaultSubscription() {
2355 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2356 }
2357
Wink Savilleb564aae2014-10-23 10:18:09 -07002358 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002359 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002361
2362 /**
2363 * @see android.telephony.TelephonyManager.WifiCallingChoices
2364 */
2365 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002366 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2367 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002368 }
2369
2370 /**
2371 * @see android.telephony.TelephonyManager.WifiCallingChoices
2372 */
2373 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002374 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2375 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2376 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002377 }
2378
Sailesh Nepald1e68152013-12-12 19:08:02 -08002379 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002380 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002381 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002382 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002383
Shishir Agrawal566b7612013-10-28 14:41:00 -07002384 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002385 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2386 int subId, String callingPackage, String aid, int p2) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2388 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389
Derek Tan740e1672017-06-27 14:56:27 -07002390 if (TextUtils.equals(ISDR_AID, aid)) {
2391 // Only allows LPA to open logical channel to ISD-R.
2392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2393 ComponentInfo bestComponent =
2394 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2395 if (bestComponent == null
2396 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2397 loge("The calling package is not allowed to access ISD-R.");
2398 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2399 }
2400 }
2401
2402 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002403 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002404 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002405 if (DBG) log("iccOpenLogicalChannel: " + response);
2406 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002407 }
2408
2409 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002410 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2412 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002413
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002414 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002415 if (channel < 0) {
2416 return false;
2417 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002418 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002419 if (DBG) log("iccCloseLogicalChannel: " + success);
2420 return success;
2421 }
2422
2423 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002425 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2427 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002428
2429 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002430 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2431 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002432 " data=" + data);
2433 }
2434
2435 if (channel < 0) {
2436 return "";
2437 }
2438
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002439 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002440 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002441 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2442
Shishir Agrawal566b7612013-10-28 14:41:00 -07002443 // Append the returned status code to the end of the response payload.
2444 String s = Integer.toHexString(
2445 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002446 if (response.payload != null) {
2447 s = IccUtils.bytesToHexString(response.payload) + s;
2448 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002449 return s;
2450 }
Jake Hambye994d462014-02-03 13:10:13 -08002451
Evan Charltonc66da362014-05-16 14:06:40 -07002452 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002453 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2454 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2456 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002457
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002458 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2459 && TextUtils.equals(ISDR_AID, data)) {
2460 // Only allows LPA to select ISD-R.
2461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2462 ComponentInfo bestComponent =
2463 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2464 if (bestComponent == null
2465 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2466 loge("The calling package is not allowed to select ISD-R.");
2467 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2468 }
2469 }
2470
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002471 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002472 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2473 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474 }
2475
2476 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002478 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002480 // Append the returned status code to the end of the response payload.
2481 String s = Integer.toHexString(
2482 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002483 if (response.payload != null) {
2484 s = IccUtils.bytesToHexString(response.payload) + s;
2485 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002486 return s;
2487 }
2488
2489 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002490 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002491 String filePath) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2493 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002494
2495 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002496 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002497 p1 + " " + p2 + " " + p3 + ":" + filePath);
2498 }
2499
2500 IccIoResult response =
2501 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002502 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2503 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002504
2505 if (DBG) {
2506 log("Exchange SIM_IO [R]" + response);
2507 }
2508
2509 byte[] result = null;
2510 int length = 2;
2511 if (response.payload != null) {
2512 length = 2 + response.payload.length;
2513 result = new byte[length];
2514 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2515 } else {
2516 result = new byte[length];
2517 }
2518
2519 result[length - 1] = (byte) response.sw2;
2520 result[length - 2] = (byte) response.sw1;
2521 return result;
2522 }
2523
Nathan Haroldb3014052017-01-25 15:57:32 -08002524 /**
2525 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2526 * on a particular subscription
2527 */
2528 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002529 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002530 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2531 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002532 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2533 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2534 return null;
2535 }
2536 Object response = sendRequest(
2537 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2538 if (response instanceof String[]) {
2539 return (String[]) response;
2540 }
2541 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2542 return null;
2543 }
2544
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002545 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002546 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2548 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002549
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002550 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002551 if (response.payload == null) {
2552 return "";
2553 }
2554
2555 // Append the returned status code to the end of the response payload.
2556 String s = Integer.toHexString(
2557 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2558 s = IccUtils.bytesToHexString(response.payload) + s;
2559 return s;
2560 }
2561
Jake Hambye994d462014-02-03 13:10:13 -08002562 /**
2563 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2564 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2565 *
2566 * @param itemID the ID of the item to read
2567 * @return the NV item as a String, or null on error.
2568 */
2569 @Override
2570 public String nvReadItem(int itemID) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2572 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002573 if (DBG) log("nvReadItem: item " + itemID);
2574 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2575 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2576 return value;
2577 }
2578
2579 /**
2580 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2581 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2582 *
2583 * @param itemID the ID of the item to read
2584 * @param itemValue the value to write, as a String
2585 * @return true on success; false on any failure
2586 */
2587 @Override
2588 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2590 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002591 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2592 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2593 new Pair<Integer, String>(itemID, itemValue));
2594 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2595 return success;
2596 }
2597
2598 /**
2599 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2600 * Used for device configuration by some CDMA operators.
2601 *
2602 * @param preferredRoamingList byte array containing the new PRL
2603 * @return true on success; false on any failure
2604 */
2605 @Override
2606 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2608 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002609 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2610 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2611 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2612 return success;
2613 }
2614
2615 /**
2616 * Perform the specified type of NV config reset.
2617 * Used for device configuration by some CDMA operators.
2618 *
2619 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2620 * @return true on success; false on any failure
2621 */
2622 @Override
2623 public boolean nvResetConfig(int resetType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2625 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002626 if (DBG) log("nvResetConfig: type " + resetType);
2627 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2628 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2629 return success;
2630 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002631
Svet Ganovb320e182015-04-16 12:30:10 -07002632 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002634 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002635 return new String[0];
2636 }
2637
2638
ram87fca6f2014-07-18 18:58:44 +05302639 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002640 }
2641
Brad Ebinger51f743a2017-01-23 13:50:20 -08002642 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002643 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2644 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002645 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002646 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002647 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002648 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002649 }
2650
2651 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002652 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2653 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002654 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002655 public void disableIms(int slotId) {
2656 enforceModifyPermission();
2657 PhoneFactory.getImsResolver().disableIms(slotId);
2658 }
2659
2660 /**
2661 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2662 * feature or {@link null} if the service is not available. If the feature is available, the
2663 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2664 */
2665 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002666 IImsServiceFeatureCallback callback) {
2667 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002668 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002669 }
2670
2671 /**
2672 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2673 * feature during emergency calling or {@link null} if the service is not available. If the
2674 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2675 * listener for feature updates.
2676 */
2677 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2678 enforceModifyPermission();
2679 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002680 }
2681
Brad Ebinger7e934f52017-12-14 14:26:15 -08002682 /**
2683 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2684 * specified.
2685 */
2686 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2687 enforceModifyPermission();
2688 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2689 }
2690
Brad Ebingera12246d2018-01-16 09:39:35 -08002691 /**
2692 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2693 * specified.
2694 */
2695 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2696 enforceModifyPermission();
2697 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2698 }
2699
Brad Ebinger884c07b2018-02-15 16:17:40 -08002700 /**
Brad Ebinger67801702018-03-02 13:43:36 -08002701 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2702 * available, false if the IMS resolver is idle.
2703 */
2704 public boolean isResolvingImsBinding() {
2705 enforceModifyPermission();
2706 return PhoneFactory.getImsResolver().isResolvingBinding();
2707 }
2708
Wink Saville36469e72014-06-11 15:17:00 -07002709 public void setImsRegistrationState(boolean registered) {
2710 enforceModifyPermission();
2711 mPhone.setImsRegistrationState(registered);
2712 }
2713
2714 /**
Stuart Scott54788802015-03-30 13:18:01 -07002715 * Set the network selection mode to automatic.
2716 *
2717 */
2718 @Override
2719 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2721 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002722 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2723 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2724 }
2725
2726 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002727 * Set the network selection mode to manual with the selected carrier.
2728 */
2729 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002730 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002731 boolean persistSelection) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2733 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002734 OperatorInfo operator = new OperatorInfo(
2735 /* operatorAlphaLong */ "",
2736 /* operatorAlphaShort */ "",
2737 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002738 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002739 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2740 persistSelection);
2741 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002742 }
2743
2744 /**
2745 * Scans for available networks.
2746 */
2747 @Override
2748 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2750 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002751 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2752 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2753 CMD_PERFORM_NETWORK_SCAN, null, subId);
2754 return result;
2755 }
2756
2757 /**
yinxub1bed742017-04-17 11:45:04 -07002758 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002759 *
yinxub1bed742017-04-17 11:45:04 -07002760 * @param subId id of the subscription
2761 * @param request contains the radio access networks with bands/channels to scan
2762 * @param messenger callback messenger for scan results or errors
2763 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002764 * @return the id of the requested scan which can be used to stop the scan.
2765 */
2766 @Override
2767 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2768 IBinder binder) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2770 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002771 return mNetworkScanRequestTracker.startNetworkScan(
2772 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002773 }
2774
2775 /**
2776 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002777 *
2778 * @param subId id of the subscription
2779 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002780 */
2781 @Override
2782 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2784 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002785 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002786 }
2787
2788 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002789 * Get the calculated preferred network type.
2790 * Used for debugging incorrect network type.
2791 *
2792 * @return the preferred network type, defined in RILConstants.java.
2793 */
2794 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002795 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002796 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002797 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002798 return RILConstants.PREFERRED_NETWORK_MODE;
2799 }
2800
Amit Mahajan43330e02014-11-18 11:54:45 -08002801 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002802 }
2803
2804 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002805 * Get the preferred network type.
2806 * Used for device configuration by some CDMA operators.
2807 *
2808 * @return the preferred network type, defined in RILConstants.java.
2809 */
2810 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002811 public int getPreferredNetworkType(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2813 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002814 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002815 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002816 int networkType = (result != null ? result[0] : -1);
2817 if (DBG) log("getPreferredNetworkType: " + networkType);
2818 return networkType;
2819 }
2820
2821 /**
2822 * Set the preferred network type.
2823 * Used for device configuration by some CDMA operators.
2824 *
2825 * @param networkType the preferred network type, defined in RILConstants.java.
2826 * @return true on success; false on any failure.
2827 */
2828 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002829 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2831 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002832 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2833 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002834 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002835 if (success) {
2836 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002837 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002838 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002839 return success;
2840 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002841
2842 /**
Junda Liu475951f2014-11-07 16:45:03 -08002843 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2844 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2845 * tethering.
2846 *
2847 * @return 0: Not required. 1: required. 2: Not set.
2848 * @hide
2849 */
2850 @Override
2851 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002852 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002853 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2854 Settings.Global.TETHER_DUN_REQUIRED, 2);
2855 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2856 // config_tether_apndata.
2857 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2858 dunRequired = 1;
2859 }
2860 return dunRequired;
2861 }
2862
2863 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002864 * Set mobile data enabled
2865 * Used by the user through settings etc to turn on/off mobile data
2866 *
2867 * @param enable {@code true} turn turn data on, else {@code false}
2868 */
2869 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002870 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2872 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002873 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002874 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002875 Phone phone = PhoneFactory.getPhone(phoneId);
2876 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002877 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2878 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002879 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002880 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002881 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002882 }
2883
2884 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002885 * Get the user enabled state of Mobile Data.
2886 *
2887 * TODO: remove and use isUserDataEnabled.
2888 * This can't be removed now because some vendor codes
2889 * calls through ITelephony directly while they should
2890 * use TelephonyManager.
2891 *
2892 * @return true on enabled
2893 */
2894 @Override
2895 public boolean getDataEnabled(int subId) {
2896 return isUserDataEnabled(subId);
2897 }
2898
2899 /**
2900 * Get whether mobile data is enabled per user setting.
2901 *
2902 * There are other factors deciding whether mobile data is actually enabled, but they are
2903 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002904 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002905 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002906 *
2907 * @return {@code true} if data is enabled else {@code false}
2908 */
2909 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002910 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002911 try {
2912 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2913 null);
2914 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2916 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002917 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002918 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002919 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002920 Phone phone = PhoneFactory.getPhone(phoneId);
2921 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002922 boolean retVal = phone.isUserDataEnabled();
2923 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002924 return retVal;
2925 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002926 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2927 return false;
2928 }
2929 }
2930
2931 /**
2932 * Get whether mobile data is enabled.
2933 *
2934 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2935 * whether mobile data is actually enabled.
2936 *
2937 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2938 *
2939 * @return {@code true} if data is enabled else {@code false}
2940 */
2941 @Override
2942 public boolean isDataEnabled(int subId) {
2943 try {
2944 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2945 null);
2946 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2948 mApp, subId, "isDataEnabled");
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002949 }
2950 int phoneId = mSubscriptionController.getPhoneId(subId);
2951 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2952 Phone phone = PhoneFactory.getPhone(phoneId);
2953 if (phone != null) {
2954 boolean retVal = phone.isDataEnabled();
2955 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2956 return retVal;
2957 } else {
2958 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002959 return false;
2960 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002961 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002962
2963 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002964 public int getCarrierPrivilegeStatus(int subId) {
2965 final Phone phone = getPhone(subId);
2966 if (phone == null) {
2967 loge("getCarrierPrivilegeStatus: Invalid subId");
2968 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2969 }
2970 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002971 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002972 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002973 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2974 }
2975 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002976 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002977 }
Junda Liu29340342014-07-10 15:23:27 -07002978
2979 @Override
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002980 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2981 final Phone phone = getPhone(subId);
2982 if (phone == null) {
2983 loge("getCarrierPrivilegeStatus: Invalid subId");
2984 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2985 }
2986 UiccProfile profile =
2987 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
2988 if (profile == null) {
2989 loge("getCarrierPrivilegeStatus: No UICC");
2990 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2991 }
2992 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
2993 }
2994
2995 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002996 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002997 if (TextUtils.isEmpty(pkgName))
2998 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002999 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003000 if (card == null) {
3001 loge("checkCarrierPrivilegesForPackage: No UICC");
3002 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3003 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003004 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3005 }
3006
3007 @Override
3008 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003009 if (TextUtils.isEmpty(pkgName))
3010 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003011 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3012 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3013 UiccCard card = UiccController.getInstance().getUiccCard(i);
3014 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003015 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003016 continue;
3017 }
3018
3019 result = card.getCarrierPrivilegeStatus(
3020 mPhone.getContext().getPackageManager(), pkgName);
3021 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3022 break;
3023 }
3024 }
3025
3026 return result;
Junda Liu29340342014-07-10 15:23:27 -07003027 }
Derek Tan89e89d42014-07-08 17:00:10 -07003028
3029 @Override
Junda Liue64de782015-04-16 17:19:16 -07003030 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3031 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3032 loge("phoneId " + phoneId + " is not valid.");
3033 return null;
3034 }
3035 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003036 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003037 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003038 return null ;
3039 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003040 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003041 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003042 }
3043
Amith Yamasani6e118872016-02-19 12:53:51 -08003044 @Override
3045 public List<String> getPackagesWithCarrierPrivileges() {
3046 PackageManager pm = mPhone.getContext().getPackageManager();
3047 List<String> privilegedPackages = new ArrayList<>();
3048 List<PackageInfo> packages = null;
3049 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3050 UiccCard card = UiccController.getInstance().getUiccCard(i);
3051 if (card == null) {
3052 // No UICC in that slot.
3053 continue;
3054 }
3055 if (card.hasCarrierPrivilegeRules()) {
3056 if (packages == null) {
3057 // Only check packages in user 0 for now
3058 packages = pm.getInstalledPackagesAsUser(
3059 PackageManager.MATCH_DISABLED_COMPONENTS
3060 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3061 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3062 }
3063 for (int p = packages.size() - 1; p >= 0; p--) {
3064 PackageInfo pkgInfo = packages.get(p);
3065 if (pkgInfo != null && pkgInfo.packageName != null
3066 && card.getCarrierPrivilegeStatus(pkgInfo)
3067 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3068 privilegedPackages.add(pkgInfo.packageName);
3069 }
3070 }
3071 }
3072 }
3073 return privilegedPackages;
3074 }
3075
Wink Savilleb564aae2014-10-23 10:18:09 -07003076 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003077 final Phone phone = getPhone(subId);
3078 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003079 if (card == null) {
3080 loge("getIccId: No UICC");
3081 return null;
3082 }
3083 String iccId = card.getIccId();
3084 if (TextUtils.isEmpty(iccId)) {
3085 loge("getIccId: ICC ID is null or empty.");
3086 return null;
3087 }
3088 return iccId;
3089 }
3090
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003091 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003092 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3093 String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003094 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3095 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003096
Jeff Sharkey85190e62014-12-05 09:40:12 -08003097 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003098 final Phone phone = getPhone(subId);
3099 if (phone == null) {
3100 return false;
3101 }
3102 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003103
3104 if (DBG_MERGE) {
3105 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3106 + subscriberId + " to " + number);
3107 }
3108
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003109 if (TextUtils.isEmpty(iccId)) {
3110 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003111 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003112
Jeff Sharkey85190e62014-12-05 09:40:12 -08003113 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3114
3115 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003116 if (alphaTag == null) {
3117 editor.remove(alphaTagPrefKey);
3118 } else {
3119 editor.putString(alphaTagPrefKey, alphaTag);
3120 }
3121
Jeff Sharkey85190e62014-12-05 09:40:12 -08003122 // Record both the line number and IMSI for this ICCID, since we need to
3123 // track all merged IMSIs based on line number
3124 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3125 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003126 if (number == null) {
3127 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003128 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003129 } else {
3130 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003131 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003132 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003133
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003134 editor.commit();
3135 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003136 }
3137
3138 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003139 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003140 // This is open to apps with WRITE_SMS.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003142 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003143 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003144 return null;
3145 }
Derek Tan97ebb422014-09-05 16:55:38 -07003146
3147 String iccId = getIccId(subId);
3148 if (iccId != null) {
3149 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003150 if (DBG_MERGE) {
3151 log("getLine1NumberForDisplay returning " +
3152 mTelephonySharedPreferences.getString(numberPrefKey, null));
3153 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003154 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003155 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003156 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003157 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003158 }
3159
3160 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003161 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003162 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003163 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003164 return null;
3165 }
Derek Tan97ebb422014-09-05 16:55:38 -07003166
3167 String iccId = getIccId(subId);
3168 if (iccId != null) {
3169 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003170 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003171 }
Derek Tan97ebb422014-09-05 16:55:38 -07003172 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003173 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003174
3175 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003176 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003177 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3178 // about carrier-privileged callers not having access.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003180 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3181 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003182 return null;
3183 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003184 final Context context = mPhone.getContext();
3185 final TelephonyManager tele = TelephonyManager.from(context);
3186 final SubscriptionManager sub = SubscriptionManager.from(context);
3187
3188 // Figure out what subscribers are currently active
3189 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003190 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3191 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 final int[] subIds = sub.getActiveSubscriptionIdList();
3195 for (int subId : subIds) {
3196 activeSubscriberIds.add(tele.getSubscriberId(subId));
3197 }
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003200 }
3201
3202 // First pass, find a number override for an active subscriber
3203 String mergeNumber = null;
3204 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3205 for (String key : prefs.keySet()) {
3206 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3207 final String subscriberId = (String) prefs.get(key);
3208 if (activeSubscriberIds.contains(subscriberId)) {
3209 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3210 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3211 mergeNumber = (String) prefs.get(numberKey);
3212 if (DBG_MERGE) {
3213 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3214 + " for active subscriber " + subscriberId);
3215 }
3216 if (!TextUtils.isEmpty(mergeNumber)) {
3217 break;
3218 }
3219 }
3220 }
3221 }
3222
3223 // Shortcut when no active merged subscribers
3224 if (TextUtils.isEmpty(mergeNumber)) {
3225 return null;
3226 }
3227
3228 // Second pass, find all subscribers under that line override
3229 final ArraySet<String> result = new ArraySet<>();
3230 for (String key : prefs.keySet()) {
3231 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3232 final String number = (String) prefs.get(key);
3233 if (mergeNumber.equals(number)) {
3234 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3235 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3236 final String subscriberId = (String) prefs.get(subscriberKey);
3237 if (!TextUtils.isEmpty(subscriberId)) {
3238 result.add(subscriberId);
3239 }
3240 }
3241 }
3242 }
3243
3244 final String[] resultArray = result.toArray(new String[result.size()]);
3245 Arrays.sort(resultArray);
3246 if (DBG_MERGE) {
3247 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3248 }
3249 return resultArray;
3250 }
3251
3252 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003253 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003254 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3255 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003256 final Phone phone = getPhone(subId);
3257 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003258 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003259
3260 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003261 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003262 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3263 List<String> cdmaNonRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003264 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003265 final Phone phone = getPhone(subId);
3266 if (phone == null) {
3267 return false;
3268 }
3269 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003270 cdmaNonRoamingList);
3271 }
3272
3273 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003274 public void setRadioCapability(RadioAccessFamily[] rafs) {
3275 try {
3276 ProxyController.getInstance().setRadioCapability(rafs);
3277 } catch (RuntimeException e) {
3278 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3279 }
3280 }
3281
3282 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003283 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003284 Phone phone = PhoneFactory.getPhone(phoneId);
3285 if (phone == null) {
3286 return RadioAccessFamily.RAF_UNKNOWN;
3287 }
3288 int subId = phone.getSubId();
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003290 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003291 return RadioAccessFamily.RAF_UNKNOWN;
3292 }
3293
Wink Saville5d475dd2014-10-17 15:00:58 -07003294 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3295 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003296
3297 @Override
3298 public void enableVideoCalling(boolean enable) {
3299 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003300 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003301 }
3302
3303 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003304 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003306 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003307 return false;
3308 }
3309
Andrew Lee77527ac2014-10-21 16:57:39 -07003310 // Check the user preference and the system-level IMS setting. Even if the user has
3311 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3312 // In the long run, we may instead need to check if there exists a connection service
3313 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003314 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3315 return imsManager.isVtEnabledByPlatform()
3316 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3317 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003318 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003319
Andrew Leea1239f22015-03-02 17:44:07 -08003320 @Override
3321 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003322 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003323 }
3324
3325 @Override
3326 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003327 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003328 }
3329
Andrew Lee9431b832015-03-09 18:46:45 -07003330 @Override
3331 public boolean isTtyModeSupported() {
3332 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3333 TelephonyManager telephonyManager =
3334 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003335 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003336 }
3337
3338 @Override
3339 public boolean isHearingAidCompatibilitySupported() {
3340 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3341 }
3342
Hall Liu73714012018-01-22 19:15:32 -08003343 public boolean isRttSupported() {
3344 boolean isCarrierSupported =
3345 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3346 boolean isDeviceSupported =
3347 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3348 return isCarrierSupported && isDeviceSupported;
3349 }
3350
Sanket Padawe7310cc72015-01-14 09:53:20 -08003351 /**
3352 * Returns the unique device ID of phone, for example, the IMEI for
3353 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3354 *
3355 * <p>Requires Permission:
3356 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3357 */
3358 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003359 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003360 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003361 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003362 return null;
3363 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003364 int subId = phone.getSubId();
3365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3366 mApp, subId, callingPackage, "getDeviceId")) {
3367 return null;
3368 }
3369 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003370 }
3371
Ping Sun014fe8e2016-03-02 19:16:45 +08003372 /**
3373 * {@hide}
3374 * Returns the IMS Registration Status on a particular subid
3375 *
3376 * @param subId
3377 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003378 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08003379 Phone phone = getPhone(subId);
3380 if (phone != null) {
3381 return phone.isImsRegistered();
3382 } else {
3383 return false;
3384 }
3385 }
3386
Santos Cordon7a1885b2015-02-03 11:15:19 -08003387 @Override
3388 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3389 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3390 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003391
Brad Ebingere21f25f2018-02-08 16:11:32 -08003392 /**
3393 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003394 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003395 public boolean isWifiCallingAvailable(int subId) {
3396 Phone phone = getPhone(subId);
3397 if (phone != null) {
3398 return phone.isWifiCallingEnabled();
3399 } else {
3400 return false;
3401 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003402 }
3403
Brad Ebingere21f25f2018-02-08 16:11:32 -08003404 /**
3405 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003406 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003407 public boolean isVolteAvailable(int subId) {
3408 Phone phone = getPhone(subId);
3409 if (phone != null) {
3410 return phone.isVolteEnabled();
3411 } else {
3412 return false;
3413 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003414 }
Svet Ganovb320e182015-04-16 12:30:10 -07003415
Brad Ebingere21f25f2018-02-08 16:11:32 -08003416 /**
3417 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003418 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003419 public boolean isVideoTelephonyAvailable(int subId) {
3420 Phone phone = getPhone(subId);
3421 if (phone != null) {
3422 return phone.isVideoEnabled();
3423 } else {
3424 return false;
3425 }
3426 }
3427
3428 /**
3429 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3430 * defined in {@link ImsRegistrationImplBase}.
3431 */
3432 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3433 Phone phone = getPhone(subId);
3434 if (phone != null) {
3435 return phone.getImsRegistrationTech();
3436 } else {
3437 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3438 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003439 }
3440
Stuart Scott8eef64f2015-04-08 15:13:54 -07003441 @Override
3442 public void factoryReset(int subId) {
3443 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003444 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3445 return;
3446 }
3447
Svet Ganovcc087f82015-05-12 20:35:54 -07003448 final long identity = Binder.clearCallingIdentity();
3449 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003450 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3451 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003452 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003453 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003454 // Set network selection mode to automatic
3455 setNetworkSelectionModeAutomatic(subId);
3456 // Set preferred mobile network type to the best available
Kitta Koutarouab8a69b2018-03-05 14:16:45 +09003457 String defaultNetwork = TelephonyManager.getTelephonyProperty(
3458 mSubscriptionController.getPhoneId(subId),
3459 "ro.telephony.default_network",
3460 null);
3461 int networkType = !TextUtils.isEmpty(defaultNetwork)
3462 ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
3463 setPreferredNetworkType(subId, networkType);
Svet Ganovcc087f82015-05-12 20:35:54 -07003464 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003465 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003466 }
3467 } finally {
3468 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003469 }
3470 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003471
3472 @Override
3473 public String getLocaleFromDefaultSim() {
3474 // We query all subscriptions instead of just the active ones, because
3475 // this might be called early on in the provisioning flow when the
3476 // subscriptions potentially aren't active yet.
3477 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3478 if (slist == null || slist.isEmpty()) {
3479 return null;
3480 }
3481
3482 // This function may be called very early, say, from the setup wizard, at
3483 // which point we won't have a default subscription set. If that's the case
3484 // we just choose the first, which will be valid in "most cases".
3485 final int defaultSubId = getDefaultSubscription();
3486 SubscriptionInfo info = null;
3487 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3488 info = slist.get(0);
3489 } else {
3490 for (SubscriptionInfo item : slist) {
3491 if (item.getSubscriptionId() == defaultSubId) {
3492 info = item;
3493 break;
3494 }
3495 }
3496
3497 if (info == null) {
3498 return null;
3499 }
3500 }
3501
3502 // Try and fetch the locale from the carrier properties or from the SIM language
3503 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003504 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003505 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003506 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003507 if (defaultPhone != null) {
3508 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3509 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003510 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003511 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3512 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003513 } else {
3514 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003515 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003516 }
3517 }
3518
Narayan Kamath011676f2015-07-29 12:04:08 +01003519 // The SIM language preferences only store a language (e.g. fr = French), not an
3520 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3521 // the SIM and carrier preferences does not include a country we add the country
3522 // determined from the SIM MCC to provide an exact locale.
3523 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003524 if (mccLocale != null) {
3525 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3526 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003527 }
3528
Tony Hill183b2de2015-06-24 14:53:58 +01003529 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003530 return null;
3531 }
3532
3533 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 return mSubscriptionController.getAllSubInfoList(
3537 mPhone.getContext().getOpPackageName());
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
3541 }
3542
3543 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 return mSubscriptionController.getActiveSubscriptionInfoList(
3547 mPhone.getContext().getOpPackageName());
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
3551 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003552
3553 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003554 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3555 * representing the state of the modem.
3556 *
3557 * NOTE: This clears the modem state, so there should only every be one caller.
3558 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003559 */
3560 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003561 public void requestModemActivityInfo(ResultReceiver result) {
3562 enforceModifyPermission();
3563
3564 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3565 Bundle bundle = new Bundle();
3566 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3567 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003568 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003569
3570 /**
3571 * {@hide}
3572 * Returns the service state information on specified subscription.
3573 */
3574 @Override
3575 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3576
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003578 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003579 return null;
3580 }
3581
3582 final Phone phone = getPhone(subId);
3583 if (phone == null) {
3584 return null;
3585 }
3586
3587 return phone.getServiceState();
3588 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003589
3590 /**
3591 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3592 *
3593 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3594 * voicemail ringtone.
3595 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3596 * PhoneAccount.
3597 */
3598 @Override
3599 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003600 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003601 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003602 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003603 }
3604
fionaxu7ed723d2017-05-30 18:58:54 -07003605 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003606 }
3607
3608 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003609 * Sets the per-account voicemail ringtone.
3610 *
3611 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3612 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3613 *
3614 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3615 * voicemail ringtone.
3616 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3617 * PhoneAccount.
3618 */
3619 @Override
3620 public void setVoicemailRingtoneUri(String callingPackage,
3621 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3622 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3623 if (!TextUtils.equals(callingPackage,
3624 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3626 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3627 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003628 }
3629 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3630 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003631 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003632 }
fionaxu7ed723d2017-05-30 18:58:54 -07003633 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003634 }
3635
3636 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003637 * Returns whether vibration is set for voicemail notification in Phone settings.
3638 *
3639 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3640 * voicemail vibration setting.
3641 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3642 */
3643 @Override
3644 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003645 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003646 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003647 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003648 }
3649
fionaxu7ed723d2017-05-30 18:58:54 -07003650 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003651 }
3652
Youhan Wange64578a2016-05-02 15:32:42 -07003653 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003654 * Sets the per-account voicemail vibration.
3655 *
3656 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3657 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3658 *
3659 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3660 * voicemail vibration setting.
3661 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3662 * specific PhoneAccount.
3663 */
3664 @Override
3665 public void setVoicemailVibrationEnabled(String callingPackage,
3666 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3668 if (!TextUtils.equals(callingPackage,
3669 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3671 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3672 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003673 }
3674
3675 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3676 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003677 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003678 }
fionaxu7ed723d2017-05-30 18:58:54 -07003679 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003680 }
3681
3682 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003683 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3684 *
3685 * @throws SecurityException if the caller does not have the required permission
3686 */
3687 private void enforceReadPrivilegedPermission() {
3688 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3689 null);
3690 }
3691
3692 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003693 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3694 * permission.
3695 *
3696 * @throws SecurityException if the caller does not have the required permission
3697 */
3698 private void enforceSendSmsPermission() {
3699 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3700 }
3701
3702 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003703 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003704 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003705 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003706 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003707 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003708 ComponentName componentName =
3709 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3710 if(componentName == null) {
3711 throw new SecurityException("Caller not current active visual voicemail package[null]");
3712 }
3713 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003714 if (!callingPackage.equals(vvmPackage)) {
3715 throw new SecurityException("Caller not current active visual voicemail package[" +
3716 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003717 }
3718 }
3719
3720 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003721 * Return the application ID for the app type.
3722 *
3723 * @param subId the subscription ID that this request applies to.
3724 * @param appType the uicc app type.
3725 * @return Application ID for specificied app type, or null if no uicc.
3726 */
3727 @Override
3728 public String getAidForAppType(int subId, int appType) {
3729 enforceReadPrivilegedPermission();
3730 Phone phone = getPhone(subId);
3731 if (phone == null) {
3732 return null;
3733 }
3734 String aid = null;
3735 try {
3736 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3737 .getApplicationByType(appType).getAid();
3738 } catch (Exception e) {
3739 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3740 }
3741 return aid;
3742 }
3743
Youhan Wang4001d252016-05-11 10:29:41 -07003744 /**
3745 * Return the Electronic Serial Number.
3746 *
3747 * @param subId the subscription ID that this request applies to.
3748 * @return ESN or null if error.
3749 */
3750 @Override
3751 public String getEsn(int subId) {
3752 enforceReadPrivilegedPermission();
3753 Phone phone = getPhone(subId);
3754 if (phone == null) {
3755 return null;
3756 }
3757 String esn = null;
3758 try {
3759 esn = phone.getEsn();
3760 } catch (Exception e) {
3761 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3762 }
3763 return esn;
3764 }
3765
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003766 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003767 * Return the Preferred Roaming List Version.
3768 *
3769 * @param subId the subscription ID that this request applies to.
3770 * @return PRLVersion or null if error.
3771 */
3772 @Override
3773 public String getCdmaPrlVersion(int subId) {
3774 enforceReadPrivilegedPermission();
3775 Phone phone = getPhone(subId);
3776 if (phone == null) {
3777 return null;
3778 }
3779 String cdmaPrlVersion = null;
3780 try {
3781 cdmaPrlVersion = phone.getCdmaPrlVersion();
3782 } catch (Exception e) {
3783 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3784 }
3785 return cdmaPrlVersion;
3786 }
3787
3788 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003789 * Get snapshot of Telephony histograms
3790 * @return List of Telephony histograms
3791 * @hide
3792 */
3793 @Override
3794 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3796 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003797 return RIL.getTelephonyRILTimingHistograms();
3798 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003799
3800 /**
3801 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003802 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003803 * Require system privileges. In the future we may add this to carrier APIs.
3804 *
3805 * @return The number of carriers set successfully, should match length of carriers
3806 */
3807 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003808 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003809 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003810
Meng Wang9b7c4e92017-02-17 11:41:27 -08003811 if (carriers == null) {
3812 throw new NullPointerException("carriers cannot be null");
3813 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003814
3815 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003816 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3817 return retVal[0];
3818 }
3819
3820 /**
3821 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003822 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003823 * Require system privileges. In the future we may add this to carrier APIs.
3824 *
3825 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3826 * means all carriers are allowed.
3827 */
3828 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003829 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003830 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003831 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003832 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3833 }
3834
fionaxu59545b42016-05-25 15:53:37 -07003835 /**
3836 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3837 * @param subId the subscription ID that this action applies to.
3838 * @param enabled control enable or disable metered apns.
3839 * {@hide}
3840 */
3841 @Override
3842 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3843 enforceModifyPermission();
3844 final Phone phone = getPhone(subId);
3845 if (phone == null) {
3846 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3847 return;
3848 }
3849 try {
3850 phone.carrierActionSetMeteredApnsEnabled(enabled);
3851 } catch (Exception e) {
3852 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3853 }
3854 }
3855
3856 /**
3857 * Action set from carrier signalling broadcast receivers to enable/disable radio
3858 * @param subId the subscription ID that this action applies to.
3859 * @param enabled control enable or disable radio.
3860 * {@hide}
3861 */
3862 @Override
3863 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3864 enforceModifyPermission();
3865 final Phone phone = getPhone(subId);
3866 if (phone == null) {
3867 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3868 return;
3869 }
3870 try {
3871 phone.carrierActionSetRadioEnabled(enabled);
3872 } catch (Exception e) {
3873 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3874 }
3875 }
3876
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003877 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003878 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3879 * network status based on which carrier apps could apply actions accordingly,
3880 * enable/disable default url handler for example.
3881 *
3882 * @param subId the subscription ID that this action applies to.
3883 * @param report control start/stop reporting the default network status.
3884 * {@hide}
3885 */
3886 @Override
3887 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3888 enforceModifyPermission();
3889 final Phone phone = getPhone(subId);
3890 if (phone == null) {
3891 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3892 return;
3893 }
3894 try {
3895 phone.carrierActionReportDefaultNetworkStatus(report);
3896 } catch (Exception e) {
3897 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3898 }
3899 }
3900
3901 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003902 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3903 * bug report is being generated.
3904 */
3905 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003906 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003907 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3908 != PackageManager.PERMISSION_GRANTED) {
3909 writer.println("Permission Denial: can't dump Phone from pid="
3910 + Binder.getCallingPid()
3911 + ", uid=" + Binder.getCallingUid()
3912 + "without permission "
3913 + android.Manifest.permission.DUMP);
3914 return;
3915 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003916 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003917 }
Jack Yueb89b242016-06-22 13:27:47 -07003918
3919 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003920 * Get aggregated video call data usage since boot.
3921 *
3922 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3923 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003924 * {@hide}
3925 */
3926 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003927 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003928 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3929 null);
3930
Jack Yu84291ec2017-05-26 16:07:50 -07003931 // NetworkStatsService keeps tracking the active network interface and identity. It
3932 // records the delta with the corresponding network identity. We just return the total video
3933 // call data usage snapshot since boot.
3934 Phone phone = getPhone(subId);
3935 if (phone != null) {
3936 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003937 }
Jack Yu84291ec2017-05-26 16:07:50 -07003938 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003939 }
Jack Yu75ab2952016-07-08 14:29:33 -07003940
3941 /**
3942 * Policy control of data connection. Usually used when data limit is passed.
3943 * @param enabled True if enabling the data, otherwise disabling.
3944 * @param subId Subscription index
3945 * {@hide}
3946 */
3947 @Override
3948 public void setPolicyDataEnabled(boolean enabled, int subId) {
3949 enforceModifyPermission();
3950 Phone phone = getPhone(subId);
3951 if (phone != null) {
3952 phone.setPolicyDataEnabled(enabled);
3953 }
3954 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003955
3956 /**
3957 * Get Client request stats
3958 * @return List of Client Request Stats
3959 * @hide
3960 */
3961 @Override
3962 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003963 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003964 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003965 return null;
3966 }
3967
3968 Phone phone = getPhone(subId);
3969 if (phone != null) {
3970 return phone.getClientRequestStats();
3971 }
3972
3973 return null;
3974 }
3975
3976 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3977 if (workSource != null) {
3978 return workSource;
3979 }
3980
3981 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3982 workSource = new WorkSource(uid, packageName);
3983 return workSource;
3984 }
Jack Yueb4124c2017-02-16 15:32:43 -08003985
3986 /**
Grace Chen70990072017-03-24 17:21:30 -07003987 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003988 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003989 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003990 * @param state State of SIM (power down, power up, pass through)
3991 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3992 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3993 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003994 *
3995 **/
3996 @Override
Grace Chen70990072017-03-24 17:21:30 -07003997 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003998 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003999 Phone phone = PhoneFactory.getPhone(slotIndex);
4000
Jack Yueb4124c2017-02-16 15:32:43 -08004001 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004002 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004003 }
4004 }
Shuo Qiandd210312017-04-12 22:11:33 +00004005
Tyler Gunn65d45c22017-06-05 11:22:26 -07004006 private boolean isUssdApiAllowed(int subId) {
4007 CarrierConfigManager configManager =
4008 (CarrierConfigManager) mPhone.getContext().getSystemService(
4009 Context.CARRIER_CONFIG_SERVICE);
4010 if (configManager == null) {
4011 return false;
4012 }
4013 PersistableBundle pb = configManager.getConfigForSubId(subId);
4014 if (pb == null) {
4015 return false;
4016 }
4017 return pb.getBoolean(
4018 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4019 }
4020
Shuo Qiandd210312017-04-12 22:11:33 +00004021 /**
4022 * Check if phone is in emergency callback mode
4023 * @return true if phone is in emergency callback mode
4024 * @param subId sub id
4025 */
4026 public boolean getEmergencyCallbackMode(int subId) {
4027 final Phone phone = getPhone(subId);
4028 if (phone != null) {
4029 return phone.isInEcm();
4030 } else {
4031 return false;
4032 }
4033 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004034
4035 /**
4036 * Get the current signal strength information for the given subscription.
4037 * Because this information is not updated when the device is in a low power state
4038 * it should not be relied-upon to be current.
4039 * @param subId Subscription index
4040 * @return the most recent cached signal strength info from the modem
4041 */
4042 @Override
4043 public SignalStrength getSignalStrength(int subId) {
4044 Phone p = getPhone(subId);
4045 if (p == null) {
4046 return null;
4047 }
4048
4049 return p.getSignalStrength();
4050 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004051
4052 @Override
4053 public UiccSlotInfo[] getUiccSlotsInfo() {
4054 enforceReadPrivilegedPermission();
4055
4056 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4057 if (slots == null) return null;
4058 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4059 for (int i = 0; i < slots.length; i++) {
4060 UiccSlot slot = slots[i];
4061
4062 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4063
4064 int cardState = 0;
4065 switch (slot.getCardState()) {
4066 case CARDSTATE_ABSENT:
4067 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4068 break;
4069 case CARDSTATE_PRESENT:
4070 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4071 break;
4072 case CARDSTATE_ERROR:
4073 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4074 break;
4075 case CARDSTATE_RESTRICTED:
4076 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4077 break;
4078 default:
4079 break;
4080
4081 }
4082
Qingxi Li63668902018-01-31 13:43:27 -08004083 infos[i] = new UiccSlotInfo(
Qingxi Li0ae57f72018-03-07 10:52:26 -08004084 slot.isActive(),
4085 slot.isEuicc(),
4086 cardId,
4087 cardState,
4088 slot.getPhoneId(),
4089 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004090 }
4091 return infos;
4092 }
4093
4094 @Override
4095 public boolean switchSlots(int[] physicalSlots) {
4096 enforceModifyPermission();
4097 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4098 }
Jack Yue6146032018-02-27 15:30:01 -08004099
4100 @Override
4101 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4102 enforceModifyPermission();
4103 final Phone phone = getPhone(subId);
4104 if (phone == null) {
4105 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4106 return;
4107 }
4108
4109 phone.setRadioIndicationUpdateMode(filters, mode);
4110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004111}