blob: e7f28d7c03e34228715a607c7f29601f06dbccc1 [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) {
goneil9e8ba382017-12-13 12:57:23 -08002138 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002139 final Phone phone = getPhone(subId);
2140 if (phone != null) {
2141 return phone.getVoiceActivationState();
2142 } else {
2143 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2144 }
2145 }
2146
2147 /**
2148 * Returns the data activation state of a given subId.
2149 */
2150 @Override
2151 public int getDataActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002152 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002153 final Phone phone = getPhone(subId);
2154 if (phone != null) {
2155 return phone.getDataActivationState();
2156 } else {
2157 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2158 }
2159 }
2160
2161 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 * Returns the unread count of voicemails
2163 */
2164 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002165 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
2167
2168 /**
2169 * Returns the unread count of voicemails for a subId
2170 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002171 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002172 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002173 final Phone phone = getPhone(subId);
2174 if (phone != null) {
2175 return phone.getVoiceMessageCount();
2176 } else {
2177 return 0;
2178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 }
2180
2181 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002182 * returns true, if the device is in a state where both voice and data
2183 * are supported simultaneously. This can change based on location or network condition.
2184 */
2185 @Override
2186 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2187 final Phone phone = getPhone(subId);
2188 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2189 }
2190
2191 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002192 * Send the dialer code if called from the current default dialer or the caller has
2193 * carrier privilege.
2194 * @param inputCode The dialer code to send
2195 */
2196 @Override
2197 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2198 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2199 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2200 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002201 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2202 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002203 }
2204 mPhone.sendDialerSpecialCode(inputCode);
2205 }
2206
2207 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002208 * Returns the data network type.
2209 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 *
2211 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2212 */
2213 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002214 public int getNetworkType() {
2215 final Phone phone = getPhone(getDefaultSubscription());
2216 if (phone != null) {
2217 return phone.getServiceState().getDataNetworkType();
2218 } else {
2219 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2220 }
Wink Saville36469e72014-06-11 15:17:00 -07002221 }
2222
2223 /**
2224 * Returns the network type for a subId
2225 */
2226 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002227 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002229 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2231 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002232
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002234 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002235 return phone.getServiceState().getDataNetworkType();
2236 } else {
2237 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
2241 /**
2242 * Returns the data network type
2243 */
2244 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 public int getDataNetworkType(String callingPackage) {
2246 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002247 }
2248
2249 /**
2250 * Returns the data network type for a subId
2251 */
2252 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002253 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002255 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002256 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2257 }
2258
Sanket Padawe356d7632015-06-22 14:03:32 -07002259 final Phone phone = getPhone(subId);
2260 if (phone != null) {
2261 return phone.getServiceState().getDataNetworkType();
2262 } else {
2263 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 }
2266
2267 /**
Wink Saville36469e72014-06-11 15:17:00 -07002268 * Returns the Voice network type for a subId
2269 */
2270 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002271 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002273 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002274 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2275 }
2276
Sanket Padawe356d7632015-06-22 14:03:32 -07002277 final Phone phone = getPhone(subId);
2278 if (phone != null) {
2279 return phone.getServiceState().getVoiceNetworkType();
2280 } else {
2281 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 }
2284
2285 /**
2286 * @return true if a ICC card is present
2287 */
2288 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002289 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002290 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2291 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002292 }
2293
2294 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002295 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002296 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002297 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002298 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2299 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002300 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002301 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002302 } else {
2303 return false;
2304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 }
2306
2307 /**
2308 * Return if the current radio is LTE on CDMA. This
2309 * is a tri-state return value as for a period of time
2310 * the mode may be unknown.
2311 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002312 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002314 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002316 @Override
2317 public int getLteOnCdmaMode(String callingPackage) {
2318 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002319 }
2320
Sanket Padawe356d7632015-06-22 14:03:32 -07002321 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002324 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002325 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2326 }
2327
Sanket Padawe356d7632015-06-22 14:03:32 -07002328 final Phone phone = getPhone(subId);
2329 if (phone == null) {
2330 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2331 } else {
2332 return phone.getLteOnCdmaMode();
2333 }
Wink Saville36469e72014-06-11 15:17:00 -07002334 }
2335
2336 public void setPhone(Phone phone) {
2337 mPhone = phone;
2338 }
2339
2340 /**
2341 * {@hide}
2342 * Returns Default subId, 0 in the case of single standby.
2343 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002344 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002345 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002346 }
2347
Shishir Agrawala9f32182016-04-12 12:00:16 -07002348 private int getSlotForDefaultSubscription() {
2349 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2350 }
2351
Wink Savilleb564aae2014-10-23 10:18:09 -07002352 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002353 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002355
2356 /**
2357 * @see android.telephony.TelephonyManager.WifiCallingChoices
2358 */
2359 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002360 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2361 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002362 }
2363
2364 /**
2365 * @see android.telephony.TelephonyManager.WifiCallingChoices
2366 */
2367 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002368 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2369 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2370 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002371 }
2372
Sailesh Nepald1e68152013-12-12 19:08:02 -08002373 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002374 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002375 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002376 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002377
Shishir Agrawal566b7612013-10-28 14:41:00 -07002378 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002379 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2380 int subId, String callingPackage, String aid, int p2) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2382 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002383
Derek Tan740e1672017-06-27 14:56:27 -07002384 if (TextUtils.equals(ISDR_AID, aid)) {
2385 // Only allows LPA to open logical channel to ISD-R.
2386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2387 ComponentInfo bestComponent =
2388 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2389 if (bestComponent == null
2390 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2391 loge("The calling package is not allowed to access ISD-R.");
2392 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2393 }
2394 }
2395
2396 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002397 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002398 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002399 if (DBG) log("iccOpenLogicalChannel: " + response);
2400 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002401 }
2402
2403 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002404 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2406 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002407
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002408 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002409 if (channel < 0) {
2410 return false;
2411 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002412 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002413 if (DBG) log("iccCloseLogicalChannel: " + success);
2414 return success;
2415 }
2416
2417 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002418 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002419 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2421 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002422
2423 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2425 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002426 " data=" + data);
2427 }
2428
2429 if (channel < 0) {
2430 return "";
2431 }
2432
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002433 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002434 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002435 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2436
Shishir Agrawal566b7612013-10-28 14:41:00 -07002437 // Append the returned status code to the end of the response payload.
2438 String s = Integer.toHexString(
2439 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002440 if (response.payload != null) {
2441 s = IccUtils.bytesToHexString(response.payload) + s;
2442 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002443 return s;
2444 }
Jake Hambye994d462014-02-03 13:10:13 -08002445
Evan Charltonc66da362014-05-16 14:06:40 -07002446 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002447 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2448 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2450 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002451
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002452 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2453 && TextUtils.equals(ISDR_AID, data)) {
2454 // Only allows LPA to select ISD-R.
2455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2456 ComponentInfo bestComponent =
2457 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2458 if (bestComponent == null
2459 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2460 loge("The calling package is not allowed to select ISD-R.");
2461 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2462 }
2463 }
2464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002465 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002466 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2467 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002468 }
2469
2470 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002471 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002472 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2473
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474 // Append the returned status code to the end of the response payload.
2475 String s = Integer.toHexString(
2476 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002477 if (response.payload != null) {
2478 s = IccUtils.bytesToHexString(response.payload) + s;
2479 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002480 return s;
2481 }
2482
2483 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002484 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002485 String filePath) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2487 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002488
2489 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002490 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002491 p1 + " " + p2 + " " + p3 + ":" + filePath);
2492 }
2493
2494 IccIoResult response =
2495 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002496 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2497 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002498
2499 if (DBG) {
2500 log("Exchange SIM_IO [R]" + response);
2501 }
2502
2503 byte[] result = null;
2504 int length = 2;
2505 if (response.payload != null) {
2506 length = 2 + response.payload.length;
2507 result = new byte[length];
2508 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2509 } else {
2510 result = new byte[length];
2511 }
2512
2513 result[length - 1] = (byte) response.sw2;
2514 result[length - 2] = (byte) response.sw1;
2515 return result;
2516 }
2517
Nathan Haroldb3014052017-01-25 15:57:32 -08002518 /**
2519 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2520 * on a particular subscription
2521 */
2522 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002523 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002524 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2525 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002526 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2527 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2528 return null;
2529 }
2530 Object response = sendRequest(
2531 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2532 if (response instanceof String[]) {
2533 return (String[]) response;
2534 }
2535 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2536 return null;
2537 }
2538
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002539 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002540 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2542 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002543
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002544 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002545 if (response.payload == null) {
2546 return "";
2547 }
2548
2549 // Append the returned status code to the end of the response payload.
2550 String s = Integer.toHexString(
2551 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2552 s = IccUtils.bytesToHexString(response.payload) + s;
2553 return s;
2554 }
2555
Jake Hambye994d462014-02-03 13:10:13 -08002556 /**
2557 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2558 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2559 *
2560 * @param itemID the ID of the item to read
2561 * @return the NV item as a String, or null on error.
2562 */
2563 @Override
2564 public String nvReadItem(int itemID) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2566 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002567 if (DBG) log("nvReadItem: item " + itemID);
2568 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2569 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2570 return value;
2571 }
2572
2573 /**
2574 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2575 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2576 *
2577 * @param itemID the ID of the item to read
2578 * @param itemValue the value to write, as a String
2579 * @return true on success; false on any failure
2580 */
2581 @Override
2582 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2584 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002585 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2586 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2587 new Pair<Integer, String>(itemID, itemValue));
2588 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2589 return success;
2590 }
2591
2592 /**
2593 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2594 * Used for device configuration by some CDMA operators.
2595 *
2596 * @param preferredRoamingList byte array containing the new PRL
2597 * @return true on success; false on any failure
2598 */
2599 @Override
2600 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2602 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002603 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2604 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2605 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2606 return success;
2607 }
2608
2609 /**
2610 * Perform the specified type of NV config reset.
2611 * Used for device configuration by some CDMA operators.
2612 *
2613 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2614 * @return true on success; false on any failure
2615 */
2616 @Override
2617 public boolean nvResetConfig(int resetType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2619 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002620 if (DBG) log("nvResetConfig: type " + resetType);
2621 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2622 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2623 return success;
2624 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002625
Svet Ganovb320e182015-04-16 12:30:10 -07002626 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002628 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002629 return new String[0];
2630 }
2631
2632
ram87fca6f2014-07-18 18:58:44 +05302633 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002634 }
2635
Brad Ebinger51f743a2017-01-23 13:50:20 -08002636 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002637 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2638 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002639 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002640 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002641 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002642 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002643 }
2644
2645 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002646 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2647 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002648 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002649 public void disableIms(int slotId) {
2650 enforceModifyPermission();
2651 PhoneFactory.getImsResolver().disableIms(slotId);
2652 }
2653
2654 /**
2655 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2656 * feature or {@link null} if the service is not available. If the feature is available, the
2657 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2658 */
2659 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002660 IImsServiceFeatureCallback callback) {
2661 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002662 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002663 }
2664
2665 /**
2666 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2667 * feature during emergency calling or {@link null} if the service is not available. If the
2668 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2669 * listener for feature updates.
2670 */
2671 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2672 enforceModifyPermission();
2673 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002674 }
2675
Brad Ebinger7e934f52017-12-14 14:26:15 -08002676 /**
2677 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2678 * specified.
2679 */
2680 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2681 enforceModifyPermission();
2682 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2683 }
2684
Brad Ebingera12246d2018-01-16 09:39:35 -08002685 /**
2686 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2687 * specified.
2688 */
2689 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2690 enforceModifyPermission();
2691 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2692 }
2693
Brad Ebinger884c07b2018-02-15 16:17:40 -08002694 /**
Brad Ebinger67801702018-03-02 13:43:36 -08002695 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2696 * available, false if the IMS resolver is idle.
2697 */
2698 public boolean isResolvingImsBinding() {
2699 enforceModifyPermission();
2700 return PhoneFactory.getImsResolver().isResolvingBinding();
2701 }
2702
Wink Saville36469e72014-06-11 15:17:00 -07002703 public void setImsRegistrationState(boolean registered) {
2704 enforceModifyPermission();
2705 mPhone.setImsRegistrationState(registered);
2706 }
2707
2708 /**
Stuart Scott54788802015-03-30 13:18:01 -07002709 * Set the network selection mode to automatic.
2710 *
2711 */
2712 @Override
2713 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2715 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002716 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2717 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2718 }
2719
2720 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002721 * Set the network selection mode to manual with the selected carrier.
2722 */
2723 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002724 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002725 boolean persistSelection) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2727 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002728 OperatorInfo operator = new OperatorInfo(
2729 /* operatorAlphaLong */ "",
2730 /* operatorAlphaShort */ "",
2731 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002732 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002733 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2734 persistSelection);
2735 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002736 }
2737
2738 /**
2739 * Scans for available networks.
2740 */
2741 @Override
2742 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2744 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002745 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2746 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2747 CMD_PERFORM_NETWORK_SCAN, null, subId);
2748 return result;
2749 }
2750
2751 /**
yinxub1bed742017-04-17 11:45:04 -07002752 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002753 *
yinxub1bed742017-04-17 11:45:04 -07002754 * @param subId id of the subscription
2755 * @param request contains the radio access networks with bands/channels to scan
2756 * @param messenger callback messenger for scan results or errors
2757 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002758 * @return the id of the requested scan which can be used to stop the scan.
2759 */
2760 @Override
2761 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2762 IBinder binder) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2764 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002765 return mNetworkScanRequestTracker.startNetworkScan(
2766 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002767 }
2768
2769 /**
2770 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002771 *
2772 * @param subId id of the subscription
2773 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002774 */
2775 @Override
2776 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2778 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002779 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002780 }
2781
2782 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002783 * Get the calculated preferred network type.
2784 * Used for debugging incorrect network type.
2785 *
2786 * @return the preferred network type, defined in RILConstants.java.
2787 */
2788 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002789 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002791 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002792 return RILConstants.PREFERRED_NETWORK_MODE;
2793 }
2794
Amit Mahajan43330e02014-11-18 11:54:45 -08002795 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002796 }
2797
2798 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002799 * Get the preferred network type.
2800 * Used for device configuration by some CDMA operators.
2801 *
2802 * @return the preferred network type, defined in RILConstants.java.
2803 */
2804 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002805 public int getPreferredNetworkType(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2807 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002808 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002809 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002810 int networkType = (result != null ? result[0] : -1);
2811 if (DBG) log("getPreferredNetworkType: " + networkType);
2812 return networkType;
2813 }
2814
2815 /**
2816 * Set the preferred network type.
2817 * Used for device configuration by some CDMA operators.
2818 *
2819 * @param networkType the preferred network type, defined in RILConstants.java.
2820 * @return true on success; false on any failure.
2821 */
2822 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002823 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2825 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002826 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2827 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002828 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002829 if (success) {
2830 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002831 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002832 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002833 return success;
2834 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002835
2836 /**
Junda Liu475951f2014-11-07 16:45:03 -08002837 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2838 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2839 * tethering.
2840 *
2841 * @return 0: Not required. 1: required. 2: Not set.
2842 * @hide
2843 */
2844 @Override
2845 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002846 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002847 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2848 Settings.Global.TETHER_DUN_REQUIRED, 2);
2849 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2850 // config_tether_apndata.
2851 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2852 dunRequired = 1;
2853 }
2854 return dunRequired;
2855 }
2856
2857 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002858 * Set mobile data enabled
2859 * Used by the user through settings etc to turn on/off mobile data
2860 *
2861 * @param enable {@code true} turn turn data on, else {@code false}
2862 */
2863 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002864 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2866 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002867 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002868 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002869 Phone phone = PhoneFactory.getPhone(phoneId);
2870 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002871 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2872 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002873 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002874 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002875 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002876 }
2877
2878 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002879 * Get the user enabled state of Mobile Data.
2880 *
2881 * TODO: remove and use isUserDataEnabled.
2882 * This can't be removed now because some vendor codes
2883 * calls through ITelephony directly while they should
2884 * use TelephonyManager.
2885 *
2886 * @return true on enabled
2887 */
2888 @Override
2889 public boolean getDataEnabled(int subId) {
2890 return isUserDataEnabled(subId);
2891 }
2892
2893 /**
2894 * Get whether mobile data is enabled per user setting.
2895 *
2896 * There are other factors deciding whether mobile data is actually enabled, but they are
2897 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002898 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002899 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002900 *
2901 * @return {@code true} if data is enabled else {@code false}
2902 */
2903 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002904 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002905 try {
2906 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2907 null);
2908 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2910 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002911 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002912 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002913 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002914 Phone phone = PhoneFactory.getPhone(phoneId);
2915 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002916 boolean retVal = phone.isUserDataEnabled();
2917 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002918 return retVal;
2919 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002920 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2921 return false;
2922 }
2923 }
2924
2925 /**
2926 * Get whether mobile data is enabled.
2927 *
2928 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2929 * whether mobile data is actually enabled.
2930 *
2931 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2932 *
2933 * @return {@code true} if data is enabled else {@code false}
2934 */
2935 @Override
2936 public boolean isDataEnabled(int subId) {
2937 try {
2938 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2939 null);
2940 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2942 mApp, subId, "isDataEnabled");
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002943 }
2944 int phoneId = mSubscriptionController.getPhoneId(subId);
2945 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2946 Phone phone = PhoneFactory.getPhone(phoneId);
2947 if (phone != null) {
2948 boolean retVal = phone.isDataEnabled();
2949 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2950 return retVal;
2951 } else {
2952 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002953 return false;
2954 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002955 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002956
2957 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002958 public int getCarrierPrivilegeStatus(int subId) {
2959 final Phone phone = getPhone(subId);
2960 if (phone == null) {
2961 loge("getCarrierPrivilegeStatus: Invalid subId");
2962 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2963 }
2964 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002965 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002966 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002967 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2968 }
2969 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002970 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002971 }
Junda Liu29340342014-07-10 15:23:27 -07002972
2973 @Override
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002974 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2975 final Phone phone = getPhone(subId);
2976 if (phone == null) {
2977 loge("getCarrierPrivilegeStatus: Invalid subId");
2978 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2979 }
2980 UiccProfile profile =
2981 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
2982 if (profile == null) {
2983 loge("getCarrierPrivilegeStatus: No UICC");
2984 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2985 }
2986 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
2987 }
2988
2989 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002990 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002991 if (TextUtils.isEmpty(pkgName))
2992 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002993 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002994 if (card == null) {
2995 loge("checkCarrierPrivilegesForPackage: No UICC");
2996 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2997 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002998 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2999 }
3000
3001 @Override
3002 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003003 if (TextUtils.isEmpty(pkgName))
3004 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003005 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3006 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3007 UiccCard card = UiccController.getInstance().getUiccCard(i);
3008 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003009 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003010 continue;
3011 }
3012
3013 result = card.getCarrierPrivilegeStatus(
3014 mPhone.getContext().getPackageManager(), pkgName);
3015 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3016 break;
3017 }
3018 }
3019
3020 return result;
Junda Liu29340342014-07-10 15:23:27 -07003021 }
Derek Tan89e89d42014-07-08 17:00:10 -07003022
3023 @Override
Junda Liue64de782015-04-16 17:19:16 -07003024 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3025 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3026 loge("phoneId " + phoneId + " is not valid.");
3027 return null;
3028 }
3029 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003030 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003031 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003032 return null ;
3033 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003034 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003035 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003036 }
3037
Amith Yamasani6e118872016-02-19 12:53:51 -08003038 @Override
3039 public List<String> getPackagesWithCarrierPrivileges() {
3040 PackageManager pm = mPhone.getContext().getPackageManager();
3041 List<String> privilegedPackages = new ArrayList<>();
3042 List<PackageInfo> packages = null;
3043 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3044 UiccCard card = UiccController.getInstance().getUiccCard(i);
3045 if (card == null) {
3046 // No UICC in that slot.
3047 continue;
3048 }
3049 if (card.hasCarrierPrivilegeRules()) {
3050 if (packages == null) {
3051 // Only check packages in user 0 for now
3052 packages = pm.getInstalledPackagesAsUser(
3053 PackageManager.MATCH_DISABLED_COMPONENTS
3054 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3055 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3056 }
3057 for (int p = packages.size() - 1; p >= 0; p--) {
3058 PackageInfo pkgInfo = packages.get(p);
3059 if (pkgInfo != null && pkgInfo.packageName != null
3060 && card.getCarrierPrivilegeStatus(pkgInfo)
3061 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3062 privilegedPackages.add(pkgInfo.packageName);
3063 }
3064 }
3065 }
3066 }
3067 return privilegedPackages;
3068 }
3069
Wink Savilleb564aae2014-10-23 10:18:09 -07003070 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003071 final Phone phone = getPhone(subId);
3072 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003073 if (card == null) {
3074 loge("getIccId: No UICC");
3075 return null;
3076 }
3077 String iccId = card.getIccId();
3078 if (TextUtils.isEmpty(iccId)) {
3079 loge("getIccId: ICC ID is null or empty.");
3080 return null;
3081 }
3082 return iccId;
3083 }
3084
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003085 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003086 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3087 String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003088 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3089 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003090
Jeff Sharkey85190e62014-12-05 09:40:12 -08003091 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003092 final Phone phone = getPhone(subId);
3093 if (phone == null) {
3094 return false;
3095 }
3096 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003097
3098 if (DBG_MERGE) {
3099 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3100 + subscriberId + " to " + number);
3101 }
3102
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003103 if (TextUtils.isEmpty(iccId)) {
3104 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003105 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003106
Jeff Sharkey85190e62014-12-05 09:40:12 -08003107 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3108
3109 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003110 if (alphaTag == null) {
3111 editor.remove(alphaTagPrefKey);
3112 } else {
3113 editor.putString(alphaTagPrefKey, alphaTag);
3114 }
3115
Jeff Sharkey85190e62014-12-05 09:40:12 -08003116 // Record both the line number and IMSI for this ICCID, since we need to
3117 // track all merged IMSIs based on line number
3118 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3119 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003120 if (number == null) {
3121 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003122 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003123 } else {
3124 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003125 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003126 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003127
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003128 editor.commit();
3129 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003130 }
3131
3132 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003133 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003134 // This is open to apps with WRITE_SMS.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003136 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003137 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003138 return null;
3139 }
Derek Tan97ebb422014-09-05 16:55:38 -07003140
3141 String iccId = getIccId(subId);
3142 if (iccId != null) {
3143 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003144 if (DBG_MERGE) {
3145 log("getLine1NumberForDisplay returning " +
3146 mTelephonySharedPreferences.getString(numberPrefKey, null));
3147 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003148 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003149 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003150 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003151 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003152 }
3153
3154 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003155 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003157 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003158 return null;
3159 }
Derek Tan97ebb422014-09-05 16:55:38 -07003160
3161 String iccId = getIccId(subId);
3162 if (iccId != null) {
3163 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003164 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003165 }
Derek Tan97ebb422014-09-05 16:55:38 -07003166 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003167 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003168
3169 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003170 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003171 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3172 // about carrier-privileged callers not having access.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003174 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3175 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003176 return null;
3177 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003178 final Context context = mPhone.getContext();
3179 final TelephonyManager tele = TelephonyManager.from(context);
3180 final SubscriptionManager sub = SubscriptionManager.from(context);
3181
3182 // Figure out what subscribers are currently active
3183 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003184 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3185 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 final int[] subIds = sub.getActiveSubscriptionIdList();
3189 for (int subId : subIds) {
3190 activeSubscriberIds.add(tele.getSubscriberId(subId));
3191 }
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003194 }
3195
3196 // First pass, find a number override for an active subscriber
3197 String mergeNumber = null;
3198 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3199 for (String key : prefs.keySet()) {
3200 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3201 final String subscriberId = (String) prefs.get(key);
3202 if (activeSubscriberIds.contains(subscriberId)) {
3203 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3204 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3205 mergeNumber = (String) prefs.get(numberKey);
3206 if (DBG_MERGE) {
3207 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3208 + " for active subscriber " + subscriberId);
3209 }
3210 if (!TextUtils.isEmpty(mergeNumber)) {
3211 break;
3212 }
3213 }
3214 }
3215 }
3216
3217 // Shortcut when no active merged subscribers
3218 if (TextUtils.isEmpty(mergeNumber)) {
3219 return null;
3220 }
3221
3222 // Second pass, find all subscribers under that line override
3223 final ArraySet<String> result = new ArraySet<>();
3224 for (String key : prefs.keySet()) {
3225 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3226 final String number = (String) prefs.get(key);
3227 if (mergeNumber.equals(number)) {
3228 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3229 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3230 final String subscriberId = (String) prefs.get(subscriberKey);
3231 if (!TextUtils.isEmpty(subscriberId)) {
3232 result.add(subscriberId);
3233 }
3234 }
3235 }
3236 }
3237
3238 final String[] resultArray = result.toArray(new String[result.size()]);
3239 Arrays.sort(resultArray);
3240 if (DBG_MERGE) {
3241 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3242 }
3243 return resultArray;
3244 }
3245
3246 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003247 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003248 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3249 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003250 final Phone phone = getPhone(subId);
3251 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003252 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003253
3254 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003255 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003256 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3257 List<String> cdmaNonRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003258 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003259 final Phone phone = getPhone(subId);
3260 if (phone == null) {
3261 return false;
3262 }
3263 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003264 cdmaNonRoamingList);
3265 }
3266
3267 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003268 public void setRadioCapability(RadioAccessFamily[] rafs) {
3269 try {
3270 ProxyController.getInstance().setRadioCapability(rafs);
3271 } catch (RuntimeException e) {
3272 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3273 }
3274 }
3275
3276 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003277 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003278 Phone phone = PhoneFactory.getPhone(phoneId);
3279 if (phone == null) {
3280 return RadioAccessFamily.RAF_UNKNOWN;
3281 }
3282 int subId = phone.getSubId();
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003284 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003285 return RadioAccessFamily.RAF_UNKNOWN;
3286 }
3287
Wink Saville5d475dd2014-10-17 15:00:58 -07003288 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3289 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003290
3291 @Override
3292 public void enableVideoCalling(boolean enable) {
3293 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003294 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003295 }
3296
3297 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003298 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003300 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003301 return false;
3302 }
3303
Andrew Lee77527ac2014-10-21 16:57:39 -07003304 // Check the user preference and the system-level IMS setting. Even if the user has
3305 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3306 // In the long run, we may instead need to check if there exists a connection service
3307 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003308 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3309 return imsManager.isVtEnabledByPlatform()
3310 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3311 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003312 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003313
Andrew Leea1239f22015-03-02 17:44:07 -08003314 @Override
3315 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003316 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003317 }
3318
3319 @Override
3320 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003321 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003322 }
3323
Andrew Lee9431b832015-03-09 18:46:45 -07003324 @Override
3325 public boolean isTtyModeSupported() {
3326 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3327 TelephonyManager telephonyManager =
3328 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003329 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003330 }
3331
3332 @Override
3333 public boolean isHearingAidCompatibilitySupported() {
3334 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3335 }
3336
Hall Liu73714012018-01-22 19:15:32 -08003337 public boolean isRttSupported() {
3338 boolean isCarrierSupported =
3339 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3340 boolean isDeviceSupported =
3341 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3342 return isCarrierSupported && isDeviceSupported;
3343 }
3344
Sanket Padawe7310cc72015-01-14 09:53:20 -08003345 /**
3346 * Returns the unique device ID of phone, for example, the IMEI for
3347 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3348 *
3349 * <p>Requires Permission:
3350 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3351 */
3352 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003353 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003354 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003355 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003356 return null;
3357 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003358 int subId = phone.getSubId();
3359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3360 mApp, subId, callingPackage, "getDeviceId")) {
3361 return null;
3362 }
3363 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003364 }
3365
Ping Sun014fe8e2016-03-02 19:16:45 +08003366 /**
3367 * {@hide}
3368 * Returns the IMS Registration Status on a particular subid
3369 *
3370 * @param subId
3371 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003372 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08003373 Phone phone = getPhone(subId);
3374 if (phone != null) {
3375 return phone.isImsRegistered();
3376 } else {
3377 return false;
3378 }
3379 }
3380
Santos Cordon7a1885b2015-02-03 11:15:19 -08003381 @Override
3382 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3383 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3384 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003385
Brad Ebingere21f25f2018-02-08 16:11:32 -08003386 /**
3387 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003388 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003389 public boolean isWifiCallingAvailable(int subId) {
3390 Phone phone = getPhone(subId);
3391 if (phone != null) {
3392 return phone.isWifiCallingEnabled();
3393 } else {
3394 return false;
3395 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003396 }
3397
Brad Ebingere21f25f2018-02-08 16:11:32 -08003398 /**
3399 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003400 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003401 public boolean isVolteAvailable(int subId) {
3402 Phone phone = getPhone(subId);
3403 if (phone != null) {
3404 return phone.isVolteEnabled();
3405 } else {
3406 return false;
3407 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003408 }
Svet Ganovb320e182015-04-16 12:30:10 -07003409
Brad Ebingere21f25f2018-02-08 16:11:32 -08003410 /**
3411 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003412 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003413 public boolean isVideoTelephonyAvailable(int subId) {
3414 Phone phone = getPhone(subId);
3415 if (phone != null) {
3416 return phone.isVideoEnabled();
3417 } else {
3418 return false;
3419 }
3420 }
3421
3422 /**
3423 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3424 * defined in {@link ImsRegistrationImplBase}.
3425 */
3426 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3427 Phone phone = getPhone(subId);
3428 if (phone != null) {
3429 return phone.getImsRegistrationTech();
3430 } else {
3431 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3432 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003433 }
3434
Stuart Scott8eef64f2015-04-08 15:13:54 -07003435 @Override
3436 public void factoryReset(int subId) {
3437 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003438 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3439 return;
3440 }
3441
Svet Ganovcc087f82015-05-12 20:35:54 -07003442 final long identity = Binder.clearCallingIdentity();
3443 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003444 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3445 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003446 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003447 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003448 // Set network selection mode to automatic
3449 setNetworkSelectionModeAutomatic(subId);
3450 // Set preferred mobile network type to the best available
Kitta Koutarouab8a69b2018-03-05 14:16:45 +09003451 String defaultNetwork = TelephonyManager.getTelephonyProperty(
3452 mSubscriptionController.getPhoneId(subId),
3453 "ro.telephony.default_network",
3454 null);
3455 int networkType = !TextUtils.isEmpty(defaultNetwork)
3456 ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
3457 setPreferredNetworkType(subId, networkType);
Svet Ganovcc087f82015-05-12 20:35:54 -07003458 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003459 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003460 }
3461 } finally {
3462 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003463 }
3464 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003465
3466 @Override
3467 public String getLocaleFromDefaultSim() {
3468 // We query all subscriptions instead of just the active ones, because
3469 // this might be called early on in the provisioning flow when the
3470 // subscriptions potentially aren't active yet.
3471 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3472 if (slist == null || slist.isEmpty()) {
3473 return null;
3474 }
3475
3476 // This function may be called very early, say, from the setup wizard, at
3477 // which point we won't have a default subscription set. If that's the case
3478 // we just choose the first, which will be valid in "most cases".
3479 final int defaultSubId = getDefaultSubscription();
3480 SubscriptionInfo info = null;
3481 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3482 info = slist.get(0);
3483 } else {
3484 for (SubscriptionInfo item : slist) {
3485 if (item.getSubscriptionId() == defaultSubId) {
3486 info = item;
3487 break;
3488 }
3489 }
3490
3491 if (info == null) {
3492 return null;
3493 }
3494 }
3495
3496 // Try and fetch the locale from the carrier properties or from the SIM language
3497 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003498 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003499 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003500 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003501 if (defaultPhone != null) {
3502 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3503 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003504 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003505 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3506 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003507 } else {
3508 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003509 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003510 }
3511 }
3512
Narayan Kamath011676f2015-07-29 12:04:08 +01003513 // The SIM language preferences only store a language (e.g. fr = French), not an
3514 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3515 // the SIM and carrier preferences does not include a country we add the country
3516 // determined from the SIM MCC to provide an exact locale.
3517 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003518 if (mccLocale != null) {
3519 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3520 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003521 }
3522
Tony Hill183b2de2015-06-24 14:53:58 +01003523 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003524 return null;
3525 }
3526
3527 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 return mSubscriptionController.getAllSubInfoList(
3531 mPhone.getContext().getOpPackageName());
3532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
3535 }
3536
3537 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 return mSubscriptionController.getActiveSubscriptionInfoList(
3541 mPhone.getContext().getOpPackageName());
3542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
3545 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003546
3547 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003548 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3549 * representing the state of the modem.
3550 *
3551 * NOTE: This clears the modem state, so there should only every be one caller.
3552 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003553 */
3554 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003555 public void requestModemActivityInfo(ResultReceiver result) {
3556 enforceModifyPermission();
3557
3558 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3559 Bundle bundle = new Bundle();
3560 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3561 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003562 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003563
3564 /**
3565 * {@hide}
3566 * Returns the service state information on specified subscription.
3567 */
3568 @Override
3569 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3570
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003572 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003573 return null;
3574 }
3575
3576 final Phone phone = getPhone(subId);
3577 if (phone == null) {
3578 return null;
3579 }
3580
3581 return phone.getServiceState();
3582 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003583
3584 /**
3585 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3586 *
3587 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3588 * voicemail ringtone.
3589 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3590 * PhoneAccount.
3591 */
3592 @Override
3593 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003594 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003595 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003596 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003597 }
3598
fionaxu7ed723d2017-05-30 18:58:54 -07003599 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003600 }
3601
3602 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003603 * Sets the per-account voicemail ringtone.
3604 *
3605 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3606 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3607 *
3608 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3609 * voicemail ringtone.
3610 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3611 * PhoneAccount.
3612 */
3613 @Override
3614 public void setVoicemailRingtoneUri(String callingPackage,
3615 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3617 if (!TextUtils.equals(callingPackage,
3618 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3620 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3621 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003622 }
3623 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3624 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003625 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003626 }
fionaxu7ed723d2017-05-30 18:58:54 -07003627 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003628 }
3629
3630 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003631 * Returns whether vibration is set for voicemail notification in Phone settings.
3632 *
3633 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3634 * voicemail vibration setting.
3635 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3636 */
3637 @Override
3638 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003639 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003640 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003641 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003642 }
3643
fionaxu7ed723d2017-05-30 18:58:54 -07003644 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003645 }
3646
Youhan Wange64578a2016-05-02 15:32:42 -07003647 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003648 * Sets the per-account voicemail vibration.
3649 *
3650 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3651 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3652 *
3653 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3654 * voicemail vibration setting.
3655 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3656 * specific PhoneAccount.
3657 */
3658 @Override
3659 public void setVoicemailVibrationEnabled(String callingPackage,
3660 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3662 if (!TextUtils.equals(callingPackage,
3663 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3665 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3666 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003667 }
3668
3669 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3670 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003671 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003672 }
fionaxu7ed723d2017-05-30 18:58:54 -07003673 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003674 }
3675
3676 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003677 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3678 *
3679 * @throws SecurityException if the caller does not have the required permission
3680 */
3681 private void enforceReadPrivilegedPermission() {
3682 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3683 null);
3684 }
3685
3686 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003687 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3688 * permission.
3689 *
3690 * @throws SecurityException if the caller does not have the required permission
3691 */
3692 private void enforceSendSmsPermission() {
3693 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3694 }
3695
3696 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003697 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003698 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003699 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003700 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003701 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003702 ComponentName componentName =
3703 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3704 if(componentName == null) {
3705 throw new SecurityException("Caller not current active visual voicemail package[null]");
3706 }
3707 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003708 if (!callingPackage.equals(vvmPackage)) {
3709 throw new SecurityException("Caller not current active visual voicemail package[" +
3710 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003711 }
3712 }
3713
3714 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003715 * Return the application ID for the app type.
3716 *
3717 * @param subId the subscription ID that this request applies to.
3718 * @param appType the uicc app type.
3719 * @return Application ID for specificied app type, or null if no uicc.
3720 */
3721 @Override
3722 public String getAidForAppType(int subId, int appType) {
3723 enforceReadPrivilegedPermission();
3724 Phone phone = getPhone(subId);
3725 if (phone == null) {
3726 return null;
3727 }
3728 String aid = null;
3729 try {
3730 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3731 .getApplicationByType(appType).getAid();
3732 } catch (Exception e) {
3733 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3734 }
3735 return aid;
3736 }
3737
Youhan Wang4001d252016-05-11 10:29:41 -07003738 /**
3739 * Return the Electronic Serial Number.
3740 *
3741 * @param subId the subscription ID that this request applies to.
3742 * @return ESN or null if error.
3743 */
3744 @Override
3745 public String getEsn(int subId) {
3746 enforceReadPrivilegedPermission();
3747 Phone phone = getPhone(subId);
3748 if (phone == null) {
3749 return null;
3750 }
3751 String esn = null;
3752 try {
3753 esn = phone.getEsn();
3754 } catch (Exception e) {
3755 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3756 }
3757 return esn;
3758 }
3759
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003760 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003761 * Return the Preferred Roaming List Version.
3762 *
3763 * @param subId the subscription ID that this request applies to.
3764 * @return PRLVersion or null if error.
3765 */
3766 @Override
3767 public String getCdmaPrlVersion(int subId) {
3768 enforceReadPrivilegedPermission();
3769 Phone phone = getPhone(subId);
3770 if (phone == null) {
3771 return null;
3772 }
3773 String cdmaPrlVersion = null;
3774 try {
3775 cdmaPrlVersion = phone.getCdmaPrlVersion();
3776 } catch (Exception e) {
3777 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3778 }
3779 return cdmaPrlVersion;
3780 }
3781
3782 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003783 * Get snapshot of Telephony histograms
3784 * @return List of Telephony histograms
3785 * @hide
3786 */
3787 @Override
3788 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3790 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003791 return RIL.getTelephonyRILTimingHistograms();
3792 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003793
3794 /**
3795 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003796 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003797 * Require system privileges. In the future we may add this to carrier APIs.
3798 *
3799 * @return The number of carriers set successfully, should match length of carriers
3800 */
3801 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003802 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003803 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003804
Meng Wang9b7c4e92017-02-17 11:41:27 -08003805 if (carriers == null) {
3806 throw new NullPointerException("carriers cannot be null");
3807 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003808
3809 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003810 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3811 return retVal[0];
3812 }
3813
3814 /**
3815 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003816 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003817 * Require system privileges. In the future we may add this to carrier APIs.
3818 *
3819 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3820 * means all carriers are allowed.
3821 */
3822 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003823 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003824 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003825 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003826 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3827 }
3828
fionaxu59545b42016-05-25 15:53:37 -07003829 /**
3830 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3831 * @param subId the subscription ID that this action applies to.
3832 * @param enabled control enable or disable metered apns.
3833 * {@hide}
3834 */
3835 @Override
3836 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3837 enforceModifyPermission();
3838 final Phone phone = getPhone(subId);
3839 if (phone == null) {
3840 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3841 return;
3842 }
3843 try {
3844 phone.carrierActionSetMeteredApnsEnabled(enabled);
3845 } catch (Exception e) {
3846 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3847 }
3848 }
3849
3850 /**
3851 * Action set from carrier signalling broadcast receivers to enable/disable radio
3852 * @param subId the subscription ID that this action applies to.
3853 * @param enabled control enable or disable radio.
3854 * {@hide}
3855 */
3856 @Override
3857 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3858 enforceModifyPermission();
3859 final Phone phone = getPhone(subId);
3860 if (phone == null) {
3861 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3862 return;
3863 }
3864 try {
3865 phone.carrierActionSetRadioEnabled(enabled);
3866 } catch (Exception e) {
3867 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3868 }
3869 }
3870
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003871 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003872 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3873 * network status based on which carrier apps could apply actions accordingly,
3874 * enable/disable default url handler for example.
3875 *
3876 * @param subId the subscription ID that this action applies to.
3877 * @param report control start/stop reporting the default network status.
3878 * {@hide}
3879 */
3880 @Override
3881 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3882 enforceModifyPermission();
3883 final Phone phone = getPhone(subId);
3884 if (phone == null) {
3885 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3886 return;
3887 }
3888 try {
3889 phone.carrierActionReportDefaultNetworkStatus(report);
3890 } catch (Exception e) {
3891 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3892 }
3893 }
3894
3895 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003896 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3897 * bug report is being generated.
3898 */
3899 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003900 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003901 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3902 != PackageManager.PERMISSION_GRANTED) {
3903 writer.println("Permission Denial: can't dump Phone from pid="
3904 + Binder.getCallingPid()
3905 + ", uid=" + Binder.getCallingUid()
3906 + "without permission "
3907 + android.Manifest.permission.DUMP);
3908 return;
3909 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003910 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003911 }
Jack Yueb89b242016-06-22 13:27:47 -07003912
3913 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003914 * Get aggregated video call data usage since boot.
3915 *
3916 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3917 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003918 * {@hide}
3919 */
3920 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003921 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003922 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3923 null);
3924
Jack Yu84291ec2017-05-26 16:07:50 -07003925 // NetworkStatsService keeps tracking the active network interface and identity. It
3926 // records the delta with the corresponding network identity. We just return the total video
3927 // call data usage snapshot since boot.
3928 Phone phone = getPhone(subId);
3929 if (phone != null) {
3930 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003931 }
Jack Yu84291ec2017-05-26 16:07:50 -07003932 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003933 }
Jack Yu75ab2952016-07-08 14:29:33 -07003934
3935 /**
3936 * Policy control of data connection. Usually used when data limit is passed.
3937 * @param enabled True if enabling the data, otherwise disabling.
3938 * @param subId Subscription index
3939 * {@hide}
3940 */
3941 @Override
3942 public void setPolicyDataEnabled(boolean enabled, int subId) {
3943 enforceModifyPermission();
3944 Phone phone = getPhone(subId);
3945 if (phone != null) {
3946 phone.setPolicyDataEnabled(enabled);
3947 }
3948 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003949
3950 /**
3951 * Get Client request stats
3952 * @return List of Client Request Stats
3953 * @hide
3954 */
3955 @Override
3956 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003958 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003959 return null;
3960 }
3961
3962 Phone phone = getPhone(subId);
3963 if (phone != null) {
3964 return phone.getClientRequestStats();
3965 }
3966
3967 return null;
3968 }
3969
3970 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3971 if (workSource != null) {
3972 return workSource;
3973 }
3974
3975 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3976 workSource = new WorkSource(uid, packageName);
3977 return workSource;
3978 }
Jack Yueb4124c2017-02-16 15:32:43 -08003979
3980 /**
Grace Chen70990072017-03-24 17:21:30 -07003981 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003982 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003983 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003984 * @param state State of SIM (power down, power up, pass through)
3985 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3986 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3987 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003988 *
3989 **/
3990 @Override
Grace Chen70990072017-03-24 17:21:30 -07003991 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003992 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003993 Phone phone = PhoneFactory.getPhone(slotIndex);
3994
Jack Yueb4124c2017-02-16 15:32:43 -08003995 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003996 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003997 }
3998 }
Shuo Qiandd210312017-04-12 22:11:33 +00003999
Tyler Gunn65d45c22017-06-05 11:22:26 -07004000 private boolean isUssdApiAllowed(int subId) {
4001 CarrierConfigManager configManager =
4002 (CarrierConfigManager) mPhone.getContext().getSystemService(
4003 Context.CARRIER_CONFIG_SERVICE);
4004 if (configManager == null) {
4005 return false;
4006 }
4007 PersistableBundle pb = configManager.getConfigForSubId(subId);
4008 if (pb == null) {
4009 return false;
4010 }
4011 return pb.getBoolean(
4012 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4013 }
4014
Shuo Qiandd210312017-04-12 22:11:33 +00004015 /**
4016 * Check if phone is in emergency callback mode
4017 * @return true if phone is in emergency callback mode
4018 * @param subId sub id
4019 */
4020 public boolean getEmergencyCallbackMode(int subId) {
4021 final Phone phone = getPhone(subId);
4022 if (phone != null) {
4023 return phone.isInEcm();
4024 } else {
4025 return false;
4026 }
4027 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004028
4029 /**
4030 * Get the current signal strength information for the given subscription.
4031 * Because this information is not updated when the device is in a low power state
4032 * it should not be relied-upon to be current.
4033 * @param subId Subscription index
4034 * @return the most recent cached signal strength info from the modem
4035 */
4036 @Override
4037 public SignalStrength getSignalStrength(int subId) {
4038 Phone p = getPhone(subId);
4039 if (p == null) {
4040 return null;
4041 }
4042
4043 return p.getSignalStrength();
4044 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004045
4046 @Override
4047 public UiccSlotInfo[] getUiccSlotsInfo() {
4048 enforceReadPrivilegedPermission();
4049
4050 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4051 if (slots == null) return null;
4052 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4053 for (int i = 0; i < slots.length; i++) {
4054 UiccSlot slot = slots[i];
4055
4056 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4057
4058 int cardState = 0;
4059 switch (slot.getCardState()) {
4060 case CARDSTATE_ABSENT:
4061 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4062 break;
4063 case CARDSTATE_PRESENT:
4064 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4065 break;
4066 case CARDSTATE_ERROR:
4067 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4068 break;
4069 case CARDSTATE_RESTRICTED:
4070 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4071 break;
4072 default:
4073 break;
4074
4075 }
4076
Qingxi Li63668902018-01-31 13:43:27 -08004077 infos[i] = new UiccSlotInfo(
Qingxi Li0ae57f72018-03-07 10:52:26 -08004078 slot.isActive(),
4079 slot.isEuicc(),
4080 cardId,
4081 cardState,
4082 slot.getPhoneId(),
4083 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004084 }
4085 return infos;
4086 }
4087
4088 @Override
4089 public boolean switchSlots(int[] physicalSlots) {
4090 enforceModifyPermission();
4091 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4092 }
Jack Yue6146032018-02-27 15:30:01 -08004093
4094 @Override
4095 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4096 enforceModifyPermission();
4097 final Phone phone = getPhone(subId);
4098 if (phone == null) {
4099 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4100 return;
4101 }
4102
4103 phone.setRadioIndicationUpdateMode(filters, mode);
4104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004105}