blob: f993452657a494d8869d91aa742a6dfe4ced0678 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
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 Ebinger22bc3e42018-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 Ebinger1f2b5082018-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;
Tyler Gunn67073572018-02-14 14:19:42 -080081import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080083import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080085
Andrew Lee312e8172014-10-23 17:01:36 -070086import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080087import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070088import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070089import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070090import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070091import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070092import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080095import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010096import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070097import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070098import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800100import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700101import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700102import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700103import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700104import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700105import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800106import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800107import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700108import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700109import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700110import com.android.internal.telephony.uicc.IccIoResult;
111import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800112import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700113import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800114import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700115import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800116import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000117import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700118import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800119import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700120import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800121import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700122import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700123import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800124
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700125import java.io.FileDescriptor;
126import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800127import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800129import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800130import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100131import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133
134/**
135 * Implementation of the ITelephony interface.
136 */
Santos Cordon117fee72014-05-16 17:56:12 -0700137public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138 private static final String LOG_TAG = "PhoneInterfaceManager";
139 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
140 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142
143 // Message codes used with mMainThreadHandler
144 private static final int CMD_HANDLE_PIN_MMI = 1;
145 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
146 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
147 private static final int CMD_ANSWER_RINGING_CALL = 4;
148 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700149 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
150 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151 private static final int CMD_OPEN_CHANNEL = 9;
152 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
153 private static final int CMD_CLOSE_CHANNEL = 11;
154 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800155 private static final int CMD_NV_READ_ITEM = 13;
156 private static final int EVENT_NV_READ_ITEM_DONE = 14;
157 private static final int CMD_NV_WRITE_ITEM = 15;
158 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
159 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
160 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
161 private static final int CMD_NV_RESET_CONFIG = 19;
162 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800163 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
164 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
165 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
166 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800167 private static final int CMD_SEND_ENVELOPE = 25;
168 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700169 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
170 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
171 private static final int CMD_EXCHANGE_SIM_IO = 31;
172 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800173 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
174 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700175 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
176 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700177 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
178 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700179 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
180 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
181 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
182 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700183 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
184 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
185 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
186 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700187 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
189 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000190 private static final int CMD_SWITCH_SLOTS = 50;
191 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800193 // Parameters of select command.
194 private static final int SELECT_COMMAND = 0xA4;
195 private static final int SELECT_P1 = 0x04;
196 private static final int SELECT_P2 = 0;
197 private static final int SELECT_P3 = 0x10;
198
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199 /** The singleton instance. */
200 private static PhoneInterfaceManager sInstance;
201
Wink Saville3ab207e2014-11-20 13:07:20 -0800202 private PhoneGlobals mApp;
203 private Phone mPhone;
204 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700205 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800206 private AppOpsManager mAppOps;
207 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800208 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800209 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700210
Derek Tan97ebb422014-09-05 16:55:38 -0700211 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
212 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800213 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700214
Derek Tan740e1672017-06-27 14:56:27 -0700215 // The AID of ISD-R.
216 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
217
yinxub1bed742017-04-17 11:45:04 -0700218 private NetworkScanRequestTracker mNetworkScanRequestTracker;
219
Derek Tan89e89d42014-07-08 17:00:10 -0700220 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700221 * A request object to use for transmitting data to an ICC.
222 */
223 private static final class IccAPDUArgument {
224 public int channel, cla, command, p1, p2, p3;
225 public String data;
226
227 public IccAPDUArgument(int channel, int cla, int command,
228 int p1, int p2, int p3, String data) {
229 this.channel = channel;
230 this.cla = cla;
231 this.command = command;
232 this.p1 = p1;
233 this.p2 = p2;
234 this.p3 = p3;
235 this.data = data;
236 }
237 }
238
239 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700240 * A request object to use for transmitting data to an ICC.
241 */
242 private static final class ManualNetworkSelectionArgument {
243 public OperatorInfo operatorInfo;
244 public boolean persistSelection;
245
246 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
247 this.operatorInfo = operatorInfo;
248 this.persistSelection = persistSelection;
249 }
250 }
251
252 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
254 * request after sending. The main thread will notify the request when it is complete.
255 */
256 private static final class MainThreadRequest {
257 /** The argument to use for the request */
258 public Object argument;
259 /** The result of the request that is run on the main thread */
260 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800261 // The subscriber id that this request applies to. Defaults to
262 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
263 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700264
265 public MainThreadRequest(Object argument) {
266 this.argument = argument;
267 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800268
269 public MainThreadRequest(Object argument, Integer subId) {
270 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800271 if (subId != null) {
272 this.subId = subId;
273 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 }
276
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800277 private static final class IncomingThirdPartyCallArgs {
278 public final ComponentName component;
279 public final String callId;
280 public final String callerDisplayName;
281
282 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
283 String callerDisplayName) {
284 this.component = component;
285 this.callId = callId;
286 this.callerDisplayName = callerDisplayName;
287 }
288 }
289
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290 /**
291 * A handler that processes messages on the main thread in the phone process. Since many
292 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
293 * inbound binder threads to the main thread in the phone process. The Binder thread
294 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
295 * on, which will be notified when the operation completes and will contain the result of the
296 * request.
297 *
298 * <p>If a MainThreadRequest object is provided in the msg.obj field,
299 * note that request.result must be set to something non-null for the calling thread to
300 * unblock.
301 */
302 private final class MainThreadHandler extends Handler {
303 @Override
304 public void handleMessage(Message msg) {
305 MainThreadRequest request;
306 Message onCompleted;
307 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800308 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700309 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310
311 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700312 case CMD_HANDLE_USSD_REQUEST: {
313 request = (MainThreadRequest) msg.obj;
314 final Phone phone = getPhoneFromRequest(request);
315 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
316 String ussdRequest = ussdObject.first;
317 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700318
319 if (!isUssdApiAllowed(request.subId)) {
320 // Carrier does not support use of this API, return failure.
321 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
322 UssdResponse response = new UssdResponse(ussdRequest, null);
323 Bundle returnData = new Bundle();
324 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
325 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
326
327 request.result = true;
328 synchronized (request) {
329 request.notifyAll();
330 }
331 return;
332 }
333
Tyler Gunn52dcf772017-04-26 11:30:31 -0700334 try {
335 request.result = phone != null ?
336 phone.handleUssdRequest(ussdRequest, wrappedCallback)
337 : false;
338 } catch (CallStateException cse) {
339 request.result = false;
340 }
pkanwar32d516d2016-10-14 19:37:38 -0700341 // Wake up the requesting thread
342 synchronized (request) {
343 request.notifyAll();
344 }
345 break;
346 }
347
Yorke Lee716f67e2015-06-17 15:39:16 -0700348 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700350 final Phone phone = getPhoneFromRequest(request);
351 request.result = phone != null ?
352 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
353 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 // Wake up the requesting thread
355 synchronized (request) {
356 request.notifyAll();
357 }
358 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
361 case CMD_HANDLE_NEIGHBORING_CELL:
362 request = (MainThreadRequest) msg.obj;
363 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
364 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700365 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 break;
367
368 case EVENT_NEIGHBORING_CELL_DONE:
369 ar = (AsyncResult) msg.obj;
370 request = (MainThreadRequest) ar.userObj;
371 if (ar.exception == null && ar.result != null) {
372 request.result = ar.result;
373 } else {
374 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800375 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 }
377 // Wake up the requesting thread
378 synchronized (request) {
379 request.notifyAll();
380 }
381 break;
382
383 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700384 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800385 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700386 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 break;
388
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 case CMD_END_CALL:
390 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800391 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700392 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700393 Phone phone = getPhone(end_subId);
394 if (phone == null) {
395 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
396 break;
397 }
398 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
400 // CDMA: If the user presses the Power button we treat it as
401 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700402 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
404 // GSM: End the call as per the Phone state
405 hungUp = PhoneUtils.hangup(mCM);
406 } else {
407 throw new IllegalStateException("Unexpected phone type: " + phoneType);
408 }
409 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
410 request.result = hungUp;
411 // Wake up the requesting thread
412 synchronized (request) {
413 request.notifyAll();
414 }
415 break;
416
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800420 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700421 if (uiccCard == null) {
422 loge("iccTransmitApduLogicalChannel: No UICC");
423 request.result = new IccIoResult(0x6F, 0, (byte[])null);
424 synchronized (request) {
425 request.notifyAll();
426 }
427 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
429 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 iccArgument.channel, iccArgument.cla, iccArgument.command,
432 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700434 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 break;
436
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 ar = (AsyncResult) msg.obj;
439 request = (MainThreadRequest) ar.userObj;
440 if (ar.exception == null && ar.result != null) {
441 request.result = ar.result;
442 } else {
443 request.result = new IccIoResult(0x6F, 0, (byte[])null);
444 if (ar.result == null) {
445 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800446 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800448 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 } else {
450 loge("iccTransmitApduLogicalChannel: Unknown exception");
451 }
452 }
453 synchronized (request) {
454 request.notifyAll();
455 }
456 break;
457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
459 request = (MainThreadRequest) msg.obj;
460 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800461 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 if (uiccCard == null) {
463 loge("iccTransmitApduBasicChannel: No UICC");
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
465 synchronized (request) {
466 request.notifyAll();
467 }
468 } else {
469 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
470 request);
471 uiccCard.iccTransmitApduBasicChannel(
472 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
473 iccArgument.p3, iccArgument.data, onCompleted);
474 }
475 break;
476
477 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
478 ar = (AsyncResult) msg.obj;
479 request = (MainThreadRequest) ar.userObj;
480 if (ar.exception == null && ar.result != null) {
481 request.result = ar.result;
482 } else {
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
484 if (ar.result == null) {
485 loge("iccTransmitApduBasicChannel: Empty response");
486 } else if (ar.exception instanceof CommandException) {
487 loge("iccTransmitApduBasicChannel: CommandException: " +
488 ar.exception);
489 } else {
490 loge("iccTransmitApduBasicChannel: Unknown exception");
491 }
492 }
493 synchronized (request) {
494 request.notifyAll();
495 }
496 break;
497
498 case CMD_EXCHANGE_SIM_IO:
499 request = (MainThreadRequest) msg.obj;
500 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 if (uiccCard == null) {
503 loge("iccExchangeSimIO: No UICC");
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
505 synchronized (request) {
506 request.notifyAll();
507 }
508 } else {
509 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
510 request);
511 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
512 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
513 iccArgument.data, onCompleted);
514 }
515 break;
516
517 case EVENT_EXCHANGE_SIM_IO_DONE:
518 ar = (AsyncResult) msg.obj;
519 request = (MainThreadRequest) ar.userObj;
520 if (ar.exception == null && ar.result != null) {
521 request.result = ar.result;
522 } else {
523 request.result = new IccIoResult(0x6f, 0, (byte[])null);
524 }
525 synchronized (request) {
526 request.notifyAll();
527 }
528 break;
529
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 case CMD_SEND_ENVELOPE:
531 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800532 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 if (uiccCard == null) {
534 loge("sendEnvelopeWithStatus: No UICC");
535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
536 synchronized (request) {
537 request.notifyAll();
538 }
539 } else {
540 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
541 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
542 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 break;
544
545 case EVENT_SEND_ENVELOPE_DONE:
546 ar = (AsyncResult) msg.obj;
547 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700548 if (ar.exception == null && ar.result != null) {
549 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
552 if (ar.result == null) {
553 loge("sendEnvelopeWithStatus: Empty response");
554 } else if (ar.exception instanceof CommandException) {
555 loge("sendEnvelopeWithStatus: CommandException: " +
556 ar.exception);
557 } else {
558 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
559 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 }
561 synchronized (request) {
562 request.notifyAll();
563 }
564 break;
565
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 case CMD_OPEN_CHANNEL:
567 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800568 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800569 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 if (uiccCard == null) {
571 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800572 request.result = new IccOpenLogicalChannelResponse(-1,
573 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 synchronized (request) {
575 request.notifyAll();
576 }
577 } else {
578 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800579 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
580 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 break;
583
584 case EVENT_OPEN_CHANNEL_DONE:
585 ar = (AsyncResult) msg.obj;
586 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 int[] result = (int[]) ar.result;
590 int channelId = result[0];
591 byte[] selectResponse = null;
592 if (result.length > 1) {
593 selectResponse = new byte[result.length - 1];
594 for (int i = 1; i < result.length; ++i) {
595 selectResponse[i - 1] = (byte) result[i];
596 }
597 }
598 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700599 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 if (ar.result == null) {
602 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 if (ar.exception != null) {
605 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
606 }
607
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700609 if (ar.exception instanceof CommandException) {
610 CommandException.Error error =
611 ((CommandException) (ar.exception)).getCommandError();
612 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700614 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 }
617 }
618 openChannelResp = new IccOpenLogicalChannelResponse(
619 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700621 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 synchronized (request) {
623 request.notifyAll();
624 }
625 break;
626
627 case CMD_CLOSE_CHANNEL:
628 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 if (uiccCard == null) {
631 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900632 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 synchronized (request) {
634 request.notifyAll();
635 }
636 } else {
637 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
638 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
639 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 break;
641
642 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800643 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
644 break;
645
646 case CMD_NV_READ_ITEM:
647 request = (MainThreadRequest) msg.obj;
648 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
649 mPhone.nvReadItem((Integer) request.argument, onCompleted);
650 break;
651
652 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 ar = (AsyncResult) msg.obj;
654 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800655 if (ar.exception == null && ar.result != null) {
656 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800658 request.result = "";
659 if (ar.result == null) {
660 loge("nvReadItem: Empty response");
661 } else if (ar.exception instanceof CommandException) {
662 loge("nvReadItem: CommandException: " +
663 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800665 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 }
667 }
668 synchronized (request) {
669 request.notifyAll();
670 }
671 break;
672
Jake Hambye994d462014-02-03 13:10:13 -0800673 case CMD_NV_WRITE_ITEM:
674 request = (MainThreadRequest) msg.obj;
675 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
676 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
677 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
678 break;
679
680 case EVENT_NV_WRITE_ITEM_DONE:
681 handleNullReturnEvent(msg, "nvWriteItem");
682 break;
683
684 case CMD_NV_WRITE_CDMA_PRL:
685 request = (MainThreadRequest) msg.obj;
686 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
687 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
688 break;
689
690 case EVENT_NV_WRITE_CDMA_PRL_DONE:
691 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
692 break;
693
694 case CMD_NV_RESET_CONFIG:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
697 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
698 break;
699
700 case EVENT_NV_RESET_CONFIG_DONE:
701 handleNullReturnEvent(msg, "nvResetConfig");
702 break;
703
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 case CMD_GET_PREFERRED_NETWORK_TYPE:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700707 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800708 break;
709
710 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
711 ar = (AsyncResult) msg.obj;
712 request = (MainThreadRequest) ar.userObj;
713 if (ar.exception == null && ar.result != null) {
714 request.result = ar.result; // Integer
715 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800716 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 if (ar.result == null) {
718 loge("getPreferredNetworkType: Empty response");
719 } else if (ar.exception instanceof CommandException) {
720 loge("getPreferredNetworkType: CommandException: " +
721 ar.exception);
722 } else {
723 loge("getPreferredNetworkType: Unknown exception");
724 }
725 }
726 synchronized (request) {
727 request.notifyAll();
728 }
729 break;
730
731 case CMD_SET_PREFERRED_NETWORK_TYPE:
732 request = (MainThreadRequest) msg.obj;
733 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
734 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700735 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 break;
737
738 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
739 handleNullReturnEvent(msg, "setPreferredNetworkType");
740 break;
741
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800742 case CMD_SET_VOICEMAIL_NUMBER:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
745 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800746 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
747 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800748 break;
749
750 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
751 handleNullReturnEvent(msg, "setVoicemailNumber");
752 break;
753
Stuart Scott54788802015-03-30 13:18:01 -0700754 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
757 request);
758 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
759 break;
760
761 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
762 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
763 break;
764
Shishir Agrawal302c8692015-06-19 13:49:39 -0700765 case CMD_PERFORM_NETWORK_SCAN:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
768 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
769 break;
770
771 case EVENT_PERFORM_NETWORK_SCAN_DONE:
772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
774 CellNetworkScanResult cellScanResult;
775 if (ar.exception == null && ar.result != null) {
776 cellScanResult = new CellNetworkScanResult(
777 CellNetworkScanResult.STATUS_SUCCESS,
778 (List<OperatorInfo>) ar.result);
779 } else {
780 if (ar.result == null) {
781 loge("getCellNetworkScanResults: Empty response");
782 }
783 if (ar.exception != null) {
784 loge("getCellNetworkScanResults: Exception: " + ar.exception);
785 }
786 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
787 if (ar.exception instanceof CommandException) {
788 CommandException.Error error =
789 ((CommandException) (ar.exception)).getCommandError();
790 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
791 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
792 } else if (error == CommandException.Error.GENERIC_FAILURE) {
793 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
794 }
795 }
796 cellScanResult = new CellNetworkScanResult(errorCode, null);
797 }
798 request.result = cellScanResult;
799 synchronized (request) {
800 request.notifyAll();
801 }
802 break;
803
804 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
805 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700806 ManualNetworkSelectionArgument selArg =
807 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700808 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
809 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700810 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
811 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700812 break;
813
814 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
815 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
816 break;
817
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700818 case CMD_GET_MODEM_ACTIVITY_INFO:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700821 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700822 break;
823
824 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
825 ar = (AsyncResult) msg.obj;
826 request = (MainThreadRequest) ar.userObj;
827 if (ar.exception == null && ar.result != null) {
828 request.result = ar.result;
829 } else {
830 if (ar.result == null) {
831 loge("queryModemActivityInfo: Empty response");
832 } else if (ar.exception instanceof CommandException) {
833 loge("queryModemActivityInfo: CommandException: " +
834 ar.exception);
835 } else {
836 loge("queryModemActivityInfo: Unknown exception");
837 }
838 }
Amit Mahajand4766222016-01-28 15:28:28 -0800839 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
840 if (request.result == null) {
841 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
842 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 synchronized (request) {
844 request.notifyAll();
845 }
846 break;
847
Meng Wang1a7c35a2016-05-05 20:56:15 -0700848 case CMD_SET_ALLOWED_CARRIERS:
849 request = (MainThreadRequest) msg.obj;
850 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
851 mPhone.setAllowedCarriers(
852 (List<CarrierIdentifier>) request.argument,
853 onCompleted);
854 break;
855
856 case EVENT_SET_ALLOWED_CARRIERS_DONE:
857 ar = (AsyncResult) msg.obj;
858 request = (MainThreadRequest) ar.userObj;
859 if (ar.exception == null && ar.result != null) {
860 request.result = ar.result;
861 } else {
862 if (ar.result == null) {
863 loge("setAllowedCarriers: Empty response");
864 } else if (ar.exception instanceof CommandException) {
865 loge("setAllowedCarriers: CommandException: " +
866 ar.exception);
867 } else {
868 loge("setAllowedCarriers: Unknown exception");
869 }
870 }
871 // Result cannot be null. Return -1 on error.
872 if (request.result == null) {
873 request.result = new int[]{-1};
874 }
875 synchronized (request) {
876 request.notifyAll();
877 }
878 break;
879
880 case CMD_GET_ALLOWED_CARRIERS:
881 request = (MainThreadRequest) msg.obj;
882 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
883 mPhone.getAllowedCarriers(onCompleted);
884 break;
885
886 case EVENT_GET_ALLOWED_CARRIERS_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result;
891 } else {
892 if (ar.result == null) {
893 loge("getAllowedCarriers: Empty response");
894 } else if (ar.exception instanceof CommandException) {
895 loge("getAllowedCarriers: CommandException: " +
896 ar.exception);
897 } else {
898 loge("getAllowedCarriers: Unknown exception");
899 }
900 }
901 // Result cannot be null. Return empty list of CarrierIdentifier.
902 if (request.result == null) {
903 request.result = new ArrayList<CarrierIdentifier>(0);
904 }
905 synchronized (request) {
906 request.notifyAll();
907 }
908 break;
909
Nathan Haroldb3014052017-01-25 15:57:32 -0800910 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result;
915 } else {
916 request.result = new IllegalArgumentException(
917 "Failed to retrieve Forbidden Plmns");
918 if (ar.result == null) {
919 loge("getForbiddenPlmns: Empty response");
920 } else {
921 loge("getForbiddenPlmns: Unknown exception");
922 }
923 }
924 synchronized (request) {
925 request.notifyAll();
926 }
927 break;
928
929 case CMD_GET_FORBIDDEN_PLMNS:
930 request = (MainThreadRequest) msg.obj;
931 uiccCard = getUiccCardFromRequest(request);
932 if (uiccCard == null) {
933 loge("getForbiddenPlmns() UiccCard is null");
934 request.result = new IllegalArgumentException(
935 "getForbiddenPlmns() UiccCard is null");
936 synchronized (request) {
937 request.notifyAll();
938 }
939 break;
940 }
941 Integer appType = (Integer) request.argument;
942 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
943 if (uiccApp == null) {
944 loge("getForbiddenPlmns() no app with specified type -- "
945 + appType);
946 request.result = new IllegalArgumentException("Failed to get UICC App");
947 synchronized (request) {
948 request.notifyAll();
949 }
950 break;
951 } else {
952 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
953 + " specified type -- " + appType);
954 }
955 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
956 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
957 onCompleted);
958 break;
959
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000960 case CMD_SWITCH_SLOTS:
961 request = (MainThreadRequest) msg.obj;
962 int[] physicalSlots = (int[]) request.argument;
963 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
964 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
965 break;
966
967 case EVENT_SWITCH_SLOTS_DONE:
968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
970 request.result = (ar.exception == null);
971 synchronized (request) {
972 request.notifyAll();
973 }
974 break;
975
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700976 default:
977 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
978 break;
979 }
980 }
Jake Hambye994d462014-02-03 13:10:13 -0800981
982 private void handleNullReturnEvent(Message msg, String command) {
983 AsyncResult ar = (AsyncResult) msg.obj;
984 MainThreadRequest request = (MainThreadRequest) ar.userObj;
985 if (ar.exception == null) {
986 request.result = true;
987 } else {
988 request.result = false;
989 if (ar.exception instanceof CommandException) {
990 loge(command + ": CommandException: " + ar.exception);
991 } else {
992 loge(command + ": Unknown exception");
993 }
994 }
995 synchronized (request) {
996 request.notifyAll();
997 }
998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700999 }
1000
1001 /**
1002 * Posts the specified command to be executed on the main thread,
1003 * waits for the request to complete, and returns the result.
1004 * @see #sendRequestAsync
1005 */
1006 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001007 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001008 }
1009
1010 /**
1011 * Posts the specified command to be executed on the main thread,
1012 * waits for the request to complete, and returns the result.
1013 * @see #sendRequestAsync
1014 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001015 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001016 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1017 throw new RuntimeException("This method will deadlock if called from the main thread.");
1018 }
1019
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001020 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001021 Message msg = mMainThreadHandler.obtainMessage(command, request);
1022 msg.sendToTarget();
1023
1024 // Wait for the request to complete
1025 synchronized (request) {
1026 while (request.result == null) {
1027 try {
1028 request.wait();
1029 } catch (InterruptedException e) {
1030 // Do nothing, go back and wait until the request is complete
1031 }
1032 }
1033 }
1034 return request.result;
1035 }
1036
1037 /**
1038 * Asynchronous ("fire and forget") version of sendRequest():
1039 * Posts the specified command to be executed on the main thread, and
1040 * returns immediately.
1041 * @see #sendRequest
1042 */
1043 private void sendRequestAsync(int command) {
1044 mMainThreadHandler.sendEmptyMessage(command);
1045 }
1046
1047 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001048 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1049 * @see {@link #sendRequest(int,Object)}
1050 */
1051 private void sendRequestAsync(int command, Object argument) {
1052 MainThreadRequest request = new MainThreadRequest(argument);
1053 Message msg = mMainThreadHandler.obtainMessage(command, request);
1054 msg.sendToTarget();
1055 }
1056
1057 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001058 * Initialize the singleton PhoneInterfaceManager instance.
1059 * This is only done once, at startup, from PhoneApp.onCreate().
1060 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001061 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001062 synchronized (PhoneInterfaceManager.class) {
1063 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001064 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001065 } else {
1066 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1067 }
1068 return sInstance;
1069 }
1070 }
1071
1072 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001073 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001074 mApp = app;
1075 mPhone = phone;
1076 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001077 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1079 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001080 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001081 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001082 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001083 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 publish();
1086 }
1087
1088 private void publish() {
1089 if (DBG) log("publish: " + this);
1090
1091 ServiceManager.addService("phone", this);
1092 }
1093
Stuart Scott584921c2015-01-15 17:10:34 -08001094 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001095 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1096 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001097 }
1098
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001099 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1100 Phone phone = getPhoneFromRequest(request);
1101 return phone == null ? null :
1102 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1103 }
1104
Wink Saville36469e72014-06-11 15:17:00 -07001105 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001106 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001107 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001109 //
1110 // Implementation of the ITelephony interface.
1111 //
1112
1113 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001114 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001115 }
1116
Wink Savilleb564aae2014-10-23 10:18:09 -07001117 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001118 if (DBG) log("dial: " + number);
1119 // No permission check needed here: This is just a wrapper around the
1120 // ACTION_DIAL intent, which is available to any app since it puts up
1121 // the UI before it does anything.
1122
1123 String url = createTelUrl(number);
1124 if (url == null) {
1125 return;
1126 }
1127
1128 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001129 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1131 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1132 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1133 mApp.startActivity(intent);
1134 }
1135 }
1136
1137 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001138 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001139 }
1140
Wink Savilleb564aae2014-10-23 10:18:09 -07001141 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 if (DBG) log("call: " + number);
1143
1144 // This is just a wrapper around the ACTION_CALL intent, but we still
1145 // need to do a permission check since we're calling startActivity()
1146 // from the context of the phone app.
1147 enforceCallPermission();
1148
1149 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1150 != AppOpsManager.MODE_ALLOWED) {
1151 return;
1152 }
1153
1154 String url = createTelUrl(number);
1155 if (url == null) {
1156 return;
1157 }
1158
Wink Saville08874612014-08-31 19:19:58 -07001159 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001160 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001161 if (slist != null) {
1162 for (SubscriptionInfo subInfoRecord : slist) {
1163 if (subInfoRecord.getSubscriptionId() == subId) {
1164 isValid = true;
1165 break;
1166 }
Wink Saville08874612014-08-31 19:19:58 -07001167 }
1168 }
1169 if (isValid == false) {
1170 return;
1171 }
1172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001174 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1176 mApp.startActivity(intent);
1177 }
1178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001179 /**
1180 * End a call based on call state
1181 * @return true is a call was ended
1182 */
1183 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001184 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001185 }
1186
1187 /**
1188 * End a call based on the call state of the subId
1189 * @return true is a call was ended
1190 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001191 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001192 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1193 != PackageManager.PERMISSION_GRANTED) {
1194 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1195 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1196 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1197 }
Stuart Scott584921c2015-01-15 17:10:34 -08001198 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 }
1200
1201 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001202 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001203 }
1204
Wink Savilleb564aae2014-10-23 10:18:09 -07001205 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 if (DBG) log("answerRingingCall...");
1207 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1208 // but that can probably wait till the big TelephonyManager API overhaul.
1209 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1210 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001211 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001212 }
1213
1214 /**
1215 * Make the actual telephony calls to implement answerRingingCall().
1216 * This should only be called from the main thread of the Phone app.
1217 * @see #answerRingingCall
1218 *
1219 * TODO: it would be nice to return true if we answered the call, or
1220 * false if there wasn't actually a ringing incoming call, or some
1221 * other error occurred. (In other words, pass back the return value
1222 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1223 * But that would require calling this method via sendRequest() rather
1224 * than sendRequestAsync(), and right now we don't actually *need* that
1225 * return value, so let's just return void for now.
1226 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001227 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001228 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001230 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1231 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 if (hasActiveCall && hasHoldingCall) {
1233 // Both lines are in use!
1234 // TODO: provide a flag to let the caller specify what
1235 // policy to use if both lines are in use. (The current
1236 // behavior is hardwired to "answer incoming, end ongoing",
1237 // which is how the CALL button is specced to behave.)
1238 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1239 return;
1240 } else {
1241 // answerCall() will automatically hold the current active
1242 // call, if there is one.
1243 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1244 return;
1245 }
1246 } else {
1247 // No call was ringing.
1248 return;
1249 }
1250 }
1251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001253 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001255 public void silenceRinger() {
1256 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 }
1258
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001259 @Override
1260 public boolean isOffhook(String callingPackage) {
1261 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001262 }
1263
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001264 @Override
1265 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1267 mApp, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001268 return false;
1269 }
1270
Sanket Padawe356d7632015-06-22 14:03:32 -07001271 final Phone phone = getPhone(subId);
1272 if (phone != null) {
1273 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1274 } else {
1275 return false;
1276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 }
1278
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001279 @Override
1280 public boolean isRinging(String callingPackage) {
1281 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001284 @Override
1285 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1287 mApp, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 return false;
1289 }
1290
Sanket Padawe356d7632015-06-22 14:03:32 -07001291 final Phone phone = getPhone(subId);
1292 if (phone != null) {
1293 return (phone.getState() == PhoneConstants.State.RINGING);
1294 } else {
1295 return false;
1296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001297 }
1298
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001299 @Override
1300 public boolean isIdle(String callingPackage) {
1301 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001302 }
1303
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001304 @Override
1305 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1307 mApp, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001308 return false;
1309 }
1310
Sanket Padawe356d7632015-06-22 14:03:32 -07001311 final Phone phone = getPhone(subId);
1312 if (phone != null) {
1313 return (phone.getState() == PhoneConstants.State.IDLE);
1314 } else {
1315 return false;
1316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 }
1318
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001321 }
1322
Wink Savilleb564aae2014-10-23 10:18:09 -07001323 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001324 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001325 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1326 }
1327
1328 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001329 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001330 }
1331
Wink Savilleb564aae2014-10-23 10:18:09 -07001332 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001333 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001334 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1335 }
1336
1337 /** {@hide} */
1338 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001339 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001340 }
1341
Wink Savilleb564aae2014-10-23 10:18:09 -07001342 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001344 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001345 checkSimPin.start();
1346 return checkSimPin.unlockSim(null, pin);
1347 }
1348
Wink Saville9de0f752013-10-22 19:04:03 -07001349 /** {@hide} */
1350 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001351 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001352 }
1353
Wink Savilleb564aae2014-10-23 10:18:09 -07001354 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001355 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001356 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 checkSimPuk.start();
1358 return checkSimPuk.unlockSim(puk, pin);
1359 }
1360
1361 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001362 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 * a synchronous one.
1364 */
1365 private static class UnlockSim extends Thread {
1366
1367 private final IccCard mSimCard;
1368
1369 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001370 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1371 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372
1373 // For replies from SimCard interface
1374 private Handler mHandler;
1375
1376 // For async handler to identify request type
1377 private static final int SUPPLY_PIN_COMPLETE = 100;
1378
1379 public UnlockSim(IccCard simCard) {
1380 mSimCard = simCard;
1381 }
1382
1383 @Override
1384 public void run() {
1385 Looper.prepare();
1386 synchronized (UnlockSim.this) {
1387 mHandler = new Handler() {
1388 @Override
1389 public void handleMessage(Message msg) {
1390 AsyncResult ar = (AsyncResult) msg.obj;
1391 switch (msg.what) {
1392 case SUPPLY_PIN_COMPLETE:
1393 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1394 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001395 mRetryCount = msg.arg1;
1396 if (ar.exception != null) {
1397 if (ar.exception instanceof CommandException &&
1398 ((CommandException)(ar.exception)).getCommandError()
1399 == CommandException.Error.PASSWORD_INCORRECT) {
1400 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1401 } else {
1402 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1403 }
1404 } else {
1405 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 mDone = true;
1408 UnlockSim.this.notifyAll();
1409 }
1410 break;
1411 }
1412 }
1413 };
1414 UnlockSim.this.notifyAll();
1415 }
1416 Looper.loop();
1417 }
1418
1419 /*
1420 * Use PIN or PUK to unlock SIM card
1421 *
1422 * If PUK is null, unlock SIM card with PIN
1423 *
1424 * If PUK is not null, unlock SIM card with PUK and set PIN code
1425 */
Wink Saville9de0f752013-10-22 19:04:03 -07001426 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427
1428 while (mHandler == null) {
1429 try {
1430 wait();
1431 } catch (InterruptedException e) {
1432 Thread.currentThread().interrupt();
1433 }
1434 }
1435 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1436
1437 if (puk == null) {
1438 mSimCard.supplyPin(pin, callback);
1439 } else {
1440 mSimCard.supplyPuk(puk, pin, callback);
1441 }
1442
1443 while (!mDone) {
1444 try {
1445 Log.d(LOG_TAG, "wait for done");
1446 wait();
1447 } catch (InterruptedException e) {
1448 // Restore the interrupted status
1449 Thread.currentThread().interrupt();
1450 }
1451 }
1452 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001453 int[] resultArray = new int[2];
1454 resultArray[0] = mResult;
1455 resultArray[1] = mRetryCount;
1456 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 }
1458 }
1459
1460 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001461 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001462
1463 }
1464
Wink Savilleb564aae2014-10-23 10:18:09 -07001465 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 // No permission check needed here: this call is harmless, and it's
1467 // needed for the ServiceState.requestStateUpdate() call (which is
1468 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001469 final Phone phone = getPhone(subId);
1470 if (phone != null) {
1471 phone.updateServiceLocation();
1472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 }
1474
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001475 @Override
1476 public boolean isRadioOn(String callingPackage) {
1477 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001478 }
1479
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001480 @Override
1481 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1483 mApp, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001484 return false;
1485 }
1486 return isRadioOnForSubscriber(subId);
1487 }
1488
1489 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001490 final Phone phone = getPhone(subId);
1491 if (phone != null) {
1492 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1493 } else {
1494 return false;
1495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 }
1497
1498 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001499 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001500
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
Wink Saville36469e72014-06-11 15:17:00 -07001502
Wink Savilleb564aae2014-10-23 10:18:09 -07001503 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001505 final Phone phone = getPhone(subId);
1506 if (phone != null) {
1507 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1508 }
Wink Saville36469e72014-06-11 15:17:00 -07001509 }
1510
1511 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001513 }
1514
Wink Savilleb564aae2014-10-23 10:18:09 -07001515 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001516 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001517 final Phone phone = getPhone(subId);
1518 if (phone == null) {
1519 return false;
1520 }
1521 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001522 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001523 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 }
1525 return true;
1526 }
Wink Saville36469e72014-06-11 15:17:00 -07001527
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001528 public boolean needMobileRadioShutdown() {
1529 /*
1530 * If any of the Radios are available, it will need to be
1531 * shutdown. So return true if any Radio is available.
1532 */
1533 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1534 Phone phone = PhoneFactory.getPhone(i);
1535 if (phone != null && phone.isRadioAvailable()) return true;
1536 }
1537 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1538 return false;
1539 }
1540
1541 public void shutdownMobileRadios() {
1542 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1543 logv("Shutting down Phone " + i);
1544 shutdownRadioUsingPhoneId(i);
1545 }
1546 }
1547
1548 private void shutdownRadioUsingPhoneId(int phoneId) {
1549 enforceModifyPermission();
1550 Phone phone = PhoneFactory.getPhone(phoneId);
1551 if (phone != null && phone.isRadioAvailable()) {
1552 phone.shutdownRadio();
1553 }
1554 }
1555
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001557 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001558 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1559 if (defaultPhone != null) {
1560 defaultPhone.setRadioPower(turnOn);
1561 return true;
1562 } else {
1563 loge("There's no default phone.");
1564 return false;
1565 }
Wink Saville36469e72014-06-11 15:17:00 -07001566 }
1567
Wink Savilleb564aae2014-10-23 10:18:09 -07001568 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
1572 phone.setRadioPower(turnOn);
1573 return true;
1574 } else {
1575 return false;
1576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
Wink Saville36469e72014-06-11 15:17:00 -07001579 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 public boolean enableDataConnectivity() {
1582 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001583 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001584 final Phone phone = getPhone(subId);
1585 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001586 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 return true;
1588 } else {
1589 return false;
1590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 }
1592
Wink Saville36469e72014-06-11 15:17:00 -07001593 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 public boolean disableDataConnectivity() {
1596 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001597 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001598 final Phone phone = getPhone(subId);
1599 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001600 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001601 return true;
1602 } else {
1603 return false;
1604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 }
1606
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001608 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 final Phone phone = getPhone(subId);
1610 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001611 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 } else {
1613 return false;
1614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
1616
1617 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001618 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001619 }
1620
pkanwarae03a6b2016-11-06 20:37:09 -08001621 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001622 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001623 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1624 return;
1625 }
1626 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1627 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1628 };
1629
Wink Savilleb564aae2014-10-23 10:18:09 -07001630 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1633 return false;
1634 }
Wink Saville36469e72014-06-11 15:17:00 -07001635 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 }
1637
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001639 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001640 }
1641
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001642 public int getCallStateForSlot(int slotIndex) {
1643 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001644 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001645 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 }
1647
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001650 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001651 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001652 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001654 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 }
1657
Sanket Padawe356d7632015-06-22 14:03:32 -07001658 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001660 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001661 if (phone != null) {
1662 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1663 } else {
1664 return TelephonyManager.DATA_ACTIVITY_NONE;
1665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 }
1667
1668 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001669 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001670 mPhone.getContext().getSystemService(AppOpsManager.class)
1671 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001672 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001673 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001674 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 }
1676
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001677 if (DBG_LOC) log("getCellLocation: is active user");
1678 Bundle data = new Bundle();
1679 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1680 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 return null;
1682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001684 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001685 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1686 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001687 }
1688
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001690 public String getNetworkCountryIsoForPhone(int phoneId) {
1691 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1692 // registered cell info, so return a NULL country instead.
1693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1696 if (TelephonyManager.NETWORK_TYPE_IWLAN
1697 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1698 return "";
1699 }
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
1702 }
1703 return TelephonyManager.getTelephonyProperty(
1704 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1705 }
1706
1707 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001709 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001710 }
1711
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001713 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 mApp.enforceCallingOrSelfPermission(
1715 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.enableLocationUpdates();
1719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 }
1721
1722 @Override
1723 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001724 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001725 }
1726
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001728 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 mApp.enforceCallingOrSelfPermission(
1730 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001731 final Phone phone = getPhone(subId);
1732 if (phone != null) {
1733 phone.disableLocationUpdates();
1734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 }
1736
1737 @Override
1738 @SuppressWarnings("unchecked")
1739 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001740 mPhone.getContext().getSystemService(AppOpsManager.class)
1741 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001742 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001743 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001744 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
1747 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1748 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1749 return null;
1750 }
Svetoslav64fad262015-04-14 14:35:21 -07001751
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001752 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001754 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 try {
1758 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1759 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1760 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1761 } catch (RuntimeException e) {
1762 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001764 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 }
1766
1767
1768 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001769 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001770 mPhone.getContext().getSystemService(AppOpsManager.class)
1771 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001772 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001773 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001774 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 }
1776
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001777 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001778 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001779 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1780 for (Phone phone : PhoneFactory.getPhones()) {
1781 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1782 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001784 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001787 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001789 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001790 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001791 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
1793
Shishir Agrawala9f32182016-04-12 12:00:16 -07001794 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001795 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001796 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1797 mApp, callingPackage, "getImeiForSlot")) {
1798 return null;
1799 }
1800 Phone phone = PhoneFactory.getPhone(slotIndex);
1801 return phone == null ? null : phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001802 }
1803
1804 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001805 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1807 mApp, callingPackage, "getMeidForSlot")) {
Jack Yu2af8d712017-03-15 17:14:14 -07001808 return null;
1809 }
1810 Phone phone = PhoneFactory.getPhone(slotIndex);
1811 return phone == null ? null : phone.getMeid();
1812 }
1813
1814 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001815 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001816 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1817 mApp, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1818 return null;
1819 }
1820 Phone phone = PhoneFactory.getPhone(slotIndex);
1821 return phone == null ? null : phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001822 }
1823
fionaxu43304da2017-11-27 22:51:16 -08001824 @Override
1825 public int getSubscriptionCarrierId(int subId) {
1826 final Phone phone = getPhone(subId);
1827 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1828 }
1829
1830 @Override
1831 public String getSubscriptionCarrierName(int subId) {
1832 final Phone phone = getPhone(subId);
1833 return phone == null ? null : phone.getCarrierName();
1834 }
1835
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 //
1837 // Internal helper methods.
1838 //
1839
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001840 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1842 *
1843 * @throws SecurityException if the caller does not have the required permission
1844 */
1845 private void enforceModifyPermission() {
1846 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1847 }
1848
1849 /**
1850 * Make sure the caller has the CALL_PHONE permission.
1851 *
1852 * @throws SecurityException if the caller does not have the required permission
1853 */
1854 private void enforceCallPermission() {
1855 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1856 }
1857
Stuart Scott8eef64f2015-04-08 15:13:54 -07001858 private void enforceConnectivityInternalPermission() {
1859 mApp.enforceCallingOrSelfPermission(
1860 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1861 "ConnectivityService");
1862 }
1863
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 private String createTelUrl(String number) {
1865 if (TextUtils.isEmpty(number)) {
1866 return null;
1867 }
1868
Jake Hambye994d462014-02-03 13:10:13 -08001869 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 }
1871
Ihab Awadf9e92732013-12-05 18:02:52 -08001872 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1874 }
1875
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001876 private static void logv(String msg) {
1877 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1878 }
1879
Ihab Awadf9e92732013-12-05 18:02:52 -08001880 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1882 }
1883
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001884 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001886 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001887 }
1888
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001890 public int getActivePhoneTypeForSlot(int slotIndex) {
1891 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 if (phone == null) {
1893 return PhoneConstants.PHONE_TYPE_NONE;
1894 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001895 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 }
1898
1899 /**
1900 * Returns the CDMA ERI icon index to display
1901 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001902 @Override
1903 public int getCdmaEriIconIndex(String callingPackage) {
1904 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001905 }
1906
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001908 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1910 mApp, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001911 return -1;
1912 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 final Phone phone = getPhone(subId);
1914 if (phone != null) {
1915 return phone.getCdmaEriIconIndex();
1916 } else {
1917 return -1;
1918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 }
1920
1921 /**
1922 * Returns the CDMA ERI icon mode,
1923 * 0 - ON
1924 * 1 - FLASHING
1925 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001926 @Override
1927 public int getCdmaEriIconMode(String callingPackage) {
1928 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001929 }
1930
Sanket Padawe356d7632015-06-22 14:03:32 -07001931 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001932 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1934 mApp, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001935 return -1;
1936 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 final Phone phone = getPhone(subId);
1938 if (phone != null) {
1939 return phone.getCdmaEriIconMode();
1940 } else {
1941 return -1;
1942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
1945 /**
1946 * Returns the CDMA ERI text,
1947 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001948 @Override
1949 public String getCdmaEriText(String callingPackage) {
1950 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001951 }
1952
Sanket Padawe356d7632015-06-22 14:03:32 -07001953 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001954 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1956 mApp, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001957 return null;
1958 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 final Phone phone = getPhone(subId);
1960 if (phone != null) {
1961 return phone.getCdmaEriText();
1962 } else {
1963 return null;
1964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965 }
1966
1967 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001968 * Returns the CDMA MDN.
1969 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001971 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1973 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001974 final Phone phone = getPhone(subId);
1975 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1976 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001977 } else {
1978 return null;
1979 }
1980 }
1981
1982 /**
1983 * Returns the CDMA MIN.
1984 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001985 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001986 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1988 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07001989 final Phone phone = getPhone(subId);
1990 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1991 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001992 } else {
1993 return null;
1994 }
1995 }
1996
1997 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 * Returns true if CDMA provisioning needs to run.
1999 */
2000 public boolean needsOtaServiceProvisioning() {
2001 return mPhone.needsOtaServiceProvisioning();
2002 }
2003
2004 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002005 * Sets the voice mail number of a given subId.
2006 */
2007 @Override
2008 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002009 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002010 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2011 new Pair<String, String>(alphaTag, number), new Integer(subId));
2012 return success;
2013 }
2014
Ta-wei Yen87c49842016-05-13 21:19:52 -07002015 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002016 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2017 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2018 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2019 if (!TextUtils.equals(callingPackage, systemDialer)) {
2020 throw new SecurityException("caller must be system dialer");
2021 }
2022 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2023 if (phoneAccountHandle == null){
2024 return null;
2025 }
2026 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2027 }
2028
2029 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002030 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2033 mApp, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002034 return null;
2035 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002036 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2037 }
2038
2039 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002040 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2041 VisualVoicemailSmsFilterSettings settings) {
2042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002043 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002044 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2045 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002046 }
2047
2048 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002049 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2050 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002051 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002052 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002053 }
2054
2055 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002056 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2057 String callingPackage, int subId) {
2058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002059 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002060 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002061 }
2062
2063 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002064 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002065 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002066 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002067 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2068 }
2069
2070 @Override
2071 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2072 String number, int port, String text, PendingIntent sentIntent) {
2073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002074 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002075 enforceSendSmsPermission();
2076 // Make the calls as the phone process.
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2080 if (port == 0) {
2081 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2082 sentIntent, null, false);
2083 } else {
2084 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2085 smsManager.sendDataMessageWithSelfPermissions(number, null,
2086 (short) port, data, sentIntent, null);
2087 }
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
2090 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002091 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002092 /**
fionaxu0152e512016-11-14 13:36:14 -08002093 * Sets the voice activation state of a given subId.
2094 */
2095 @Override
2096 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2098 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002099 final Phone phone = getPhone(subId);
2100 if (phone != null) {
2101 phone.setVoiceActivationState(activationState);
2102 } else {
2103 loge("setVoiceActivationState fails with invalid subId: " + subId);
2104 }
2105 }
2106
2107 /**
2108 * Sets the data activation state of a given subId.
2109 */
2110 @Override
2111 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2113 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002114 final Phone phone = getPhone(subId);
2115 if (phone != null) {
2116 phone.setDataActivationState(activationState);
2117 } else {
2118 loge("setVoiceActivationState fails with invalid subId: " + subId);
2119 }
2120 }
2121
2122 /**
2123 * Returns the voice activation state of a given subId.
2124 */
2125 @Override
2126 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002127 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002128 final Phone phone = getPhone(subId);
2129 if (phone != null) {
2130 return phone.getVoiceActivationState();
2131 } else {
2132 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2133 }
2134 }
2135
2136 /**
2137 * Returns the data activation state of a given subId.
2138 */
2139 @Override
2140 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002141 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002142 final Phone phone = getPhone(subId);
2143 if (phone != null) {
2144 return phone.getDataActivationState();
2145 } else {
2146 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2147 }
2148 }
2149
2150 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 * Returns the unread count of voicemails
2152 */
2153 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002154 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002155 }
2156
2157 /**
2158 * Returns the unread count of voicemails for a subId
2159 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002161 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002162 final Phone phone = getPhone(subId);
2163 if (phone != null) {
2164 return phone.getVoiceMessageCount();
2165 } else {
2166 return 0;
2167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
2170 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002171 * returns true, if the device is in a state where both voice and data
2172 * are supported simultaneously. This can change based on location or network condition.
2173 */
2174 @Override
2175 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2176 final Phone phone = getPhone(subId);
2177 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2178 }
2179
2180 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002181 * Send the dialer code if called from the current default dialer or the caller has
2182 * carrier privilege.
2183 * @param inputCode The dialer code to send
2184 */
2185 @Override
2186 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2187 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2188 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2189 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002190 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2191 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002192 }
2193 mPhone.sendDialerSpecialCode(inputCode);
2194 }
2195
2196 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002197 * Returns the data network type.
2198 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 *
2200 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2201 */
2202 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002203 public int getNetworkType() {
2204 final Phone phone = getPhone(getDefaultSubscription());
2205 if (phone != null) {
2206 return phone.getServiceState().getDataNetworkType();
2207 } else {
2208 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2209 }
Wink Saville36469e72014-06-11 15:17:00 -07002210 }
2211
2212 /**
2213 * Returns the network type for a subId
2214 */
2215 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002216 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2218 mApp, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002219 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2220 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002221
Sanket Padawe356d7632015-06-22 14:03:32 -07002222 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002223 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002224 return phone.getServiceState().getDataNetworkType();
2225 } else {
2226 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 }
2229
2230 /**
2231 * Returns the data network type
2232 */
2233 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002234 public int getDataNetworkType(String callingPackage) {
2235 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002236 }
2237
2238 /**
2239 * Returns the data network type for a subId
2240 */
2241 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002242 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2244 mApp, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2246 }
2247
Sanket Padawe356d7632015-06-22 14:03:32 -07002248 final Phone phone = getPhone(subId);
2249 if (phone != null) {
2250 return phone.getServiceState().getDataNetworkType();
2251 } else {
2252 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 }
2255
2256 /**
Wink Saville36469e72014-06-11 15:17:00 -07002257 * Returns the Voice network type for a subId
2258 */
2259 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002260 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2262 mApp, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002263 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2264 }
2265
Sanket Padawe356d7632015-06-22 14:03:32 -07002266 final Phone phone = getPhone(subId);
2267 if (phone != null) {
2268 return phone.getServiceState().getVoiceNetworkType();
2269 } else {
2270 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 }
2273
2274 /**
2275 * @return true if a ICC card is present
2276 */
2277 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002278 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002279 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2280 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002281 }
2282
2283 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002284 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002285 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002286 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002287 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2288 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002289 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002290 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002291 } else {
2292 return false;
2293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
2296 /**
2297 * Return if the current radio is LTE on CDMA. This
2298 * is a tri-state return value as for a period of time
2299 * the mode may be unknown.
2300 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002303 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002305 @Override
2306 public int getLteOnCdmaMode(String callingPackage) {
2307 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002308 }
2309
Sanket Padawe356d7632015-06-22 14:03:32 -07002310 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002311 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2313 mApp, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2315 }
2316
Sanket Padawe356d7632015-06-22 14:03:32 -07002317 final Phone phone = getPhone(subId);
2318 if (phone == null) {
2319 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2320 } else {
2321 return phone.getLteOnCdmaMode();
2322 }
Wink Saville36469e72014-06-11 15:17:00 -07002323 }
2324
2325 public void setPhone(Phone phone) {
2326 mPhone = phone;
2327 }
2328
2329 /**
2330 * {@hide}
2331 * Returns Default subId, 0 in the case of single standby.
2332 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002333 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002334 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
Shishir Agrawala9f32182016-04-12 12:00:16 -07002337 private int getSlotForDefaultSubscription() {
2338 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2339 }
2340
Wink Savilleb564aae2014-10-23 10:18:09 -07002341 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002342 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002344
2345 /**
2346 * @see android.telephony.TelephonyManager.WifiCallingChoices
2347 */
2348 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002349 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2350 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002351 }
2352
2353 /**
2354 * @see android.telephony.TelephonyManager.WifiCallingChoices
2355 */
2356 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002357 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2358 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2359 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002360 }
2361
Sailesh Nepald1e68152013-12-12 19:08:02 -08002362 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002363 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002364 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002365 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002366
Shishir Agrawal566b7612013-10-28 14:41:00 -07002367 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002368 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2369 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2371 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002372
Derek Tan740e1672017-06-27 14:56:27 -07002373 if (TextUtils.equals(ISDR_AID, aid)) {
2374 // Only allows LPA to open logical channel to ISD-R.
2375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2376 ComponentInfo bestComponent =
2377 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2378 if (bestComponent == null
2379 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2380 loge("The calling package is not allowed to access ISD-R.");
2381 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2382 }
2383 }
2384
2385 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002386 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002387 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002388 if (DBG) log("iccOpenLogicalChannel: " + response);
2389 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002390 }
2391
2392 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002393 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2395 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002396
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002397 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002398 if (channel < 0) {
2399 return false;
2400 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002401 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002402 if (DBG) log("iccCloseLogicalChannel: " + success);
2403 return success;
2404 }
2405
2406 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002407 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002408 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2410 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002411
2412 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002413 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2414 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002415 " data=" + data);
2416 }
2417
2418 if (channel < 0) {
2419 return "";
2420 }
2421
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002422 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002423 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002424 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2425
Shishir Agrawal566b7612013-10-28 14:41:00 -07002426 // Append the returned status code to the end of the response payload.
2427 String s = Integer.toHexString(
2428 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002429 if (response.payload != null) {
2430 s = IccUtils.bytesToHexString(response.payload) + s;
2431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002432 return s;
2433 }
Jake Hambye994d462014-02-03 13:10:13 -08002434
Evan Charltonc66da362014-05-16 14:06:40 -07002435 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002436 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2437 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2439 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002440
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002441 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2442 && TextUtils.equals(ISDR_AID, data)) {
2443 // Only allows LPA to select ISD-R.
2444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2445 ComponentInfo bestComponent =
2446 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2447 if (bestComponent == null
2448 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2449 loge("The calling package is not allowed to select ISD-R.");
2450 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2451 }
2452 }
2453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002454 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002455 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2456 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002457 }
2458
2459 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002460 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002461 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002463 // Append the returned status code to the end of the response payload.
2464 String s = Integer.toHexString(
2465 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002466 if (response.payload != null) {
2467 s = IccUtils.bytesToHexString(response.payload) + s;
2468 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002469 return s;
2470 }
2471
2472 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002473 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2476 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002477
2478 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002479 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002480 p1 + " " + p2 + " " + p3 + ":" + filePath);
2481 }
2482
2483 IccIoResult response =
2484 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002485 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2486 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002487
2488 if (DBG) {
2489 log("Exchange SIM_IO [R]" + response);
2490 }
2491
2492 byte[] result = null;
2493 int length = 2;
2494 if (response.payload != null) {
2495 length = 2 + response.payload.length;
2496 result = new byte[length];
2497 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2498 } else {
2499 result = new byte[length];
2500 }
2501
2502 result[length - 1] = (byte) response.sw2;
2503 result[length - 2] = (byte) response.sw1;
2504 return result;
2505 }
2506
Nathan Haroldb3014052017-01-25 15:57:32 -08002507 /**
2508 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2509 * on a particular subscription
2510 */
2511 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002512 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2513 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002514 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2515 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2516 return null;
2517 }
2518 Object response = sendRequest(
2519 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2520 if (response instanceof String[]) {
2521 return (String[]) response;
2522 }
2523 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2524 return null;
2525 }
2526
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002527 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002528 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2530 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002531
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002532 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002533 if (response.payload == null) {
2534 return "";
2535 }
2536
2537 // Append the returned status code to the end of the response payload.
2538 String s = Integer.toHexString(
2539 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2540 s = IccUtils.bytesToHexString(response.payload) + s;
2541 return s;
2542 }
2543
Jake Hambye994d462014-02-03 13:10:13 -08002544 /**
2545 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2546 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2547 *
2548 * @param itemID the ID of the item to read
2549 * @return the NV item as a String, or null on error.
2550 */
2551 @Override
2552 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2554 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002555 if (DBG) log("nvReadItem: item " + itemID);
2556 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2557 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2558 return value;
2559 }
2560
2561 /**
2562 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2563 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2564 *
2565 * @param itemID the ID of the item to read
2566 * @param itemValue the value to write, as a String
2567 * @return true on success; false on any failure
2568 */
2569 @Override
2570 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2572 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002573 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2574 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2575 new Pair<Integer, String>(itemID, itemValue));
2576 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2577 return success;
2578 }
2579
2580 /**
2581 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2582 * Used for device configuration by some CDMA operators.
2583 *
2584 * @param preferredRoamingList byte array containing the new PRL
2585 * @return true on success; false on any failure
2586 */
2587 @Override
2588 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2590 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002591 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2592 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2593 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2594 return success;
2595 }
2596
2597 /**
2598 * Perform the specified type of NV config reset.
2599 * Used for device configuration by some CDMA operators.
2600 *
2601 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2602 * @return true on success; false on any failure
2603 */
2604 @Override
2605 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2607 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002608 if (DBG) log("nvResetConfig: type " + resetType);
2609 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2610 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2611 return success;
2612 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002613
2614 /**
Wink Saville36469e72014-06-11 15:17:00 -07002615 * {@hide}
2616 * Returns Default sim, 0 in the case of single standby.
2617 */
2618 public int getDefaultSim() {
2619 //TODO Need to get it from Telephony Devcontroller
2620 return 0;
2621 }
2622
Svet Ganovb320e182015-04-16 12:30:10 -07002623 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2625 mApp, callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002626 return new String[0];
2627 }
2628
2629
ram87fca6f2014-07-18 18:58:44 +05302630 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002631 }
2632
Brad Ebinger51f743a2017-01-23 13:50:20 -08002633 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002634 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2635 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002636 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002637 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002638 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002639 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002640 }
2641
2642 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002643 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2644 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002645 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002646 public void disableIms(int slotId) {
2647 enforceModifyPermission();
2648 PhoneFactory.getImsResolver().disableIms(slotId);
2649 }
2650
2651 /**
2652 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2653 * feature or {@link null} if the service is not available. If the feature is available, the
2654 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2655 */
2656 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002657 IImsServiceFeatureCallback callback) {
2658 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002659 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002660 }
2661
2662 /**
2663 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2664 * feature during emergency calling or {@link null} if the service is not available. If the
2665 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2666 * listener for feature updates.
2667 */
2668 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2669 enforceModifyPermission();
2670 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002671 }
2672
Brad Ebinger5f64b052017-12-14 14:26:15 -08002673 /**
2674 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2675 * specified.
2676 */
2677 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2678 enforceModifyPermission();
2679 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2680 }
2681
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002682 /**
2683 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2684 * specified.
2685 */
2686 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2687 enforceModifyPermission();
2688 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2689 }
2690
Brad Ebinger884c07b2018-02-15 16:17:40 -08002691 /**
Brad Ebinger304415d2018-03-02 13:43:36 -08002692 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2693 * available, false if the IMS resolver is idle.
2694 */
2695 public boolean isResolvingImsBinding() {
2696 enforceModifyPermission();
2697 return PhoneFactory.getImsResolver().isResolvingBinding();
2698 }
2699
Wink Saville36469e72014-06-11 15:17:00 -07002700 public void setImsRegistrationState(boolean registered) {
2701 enforceModifyPermission();
2702 mPhone.setImsRegistrationState(registered);
2703 }
2704
2705 /**
Stuart Scott54788802015-03-30 13:18:01 -07002706 * Set the network selection mode to automatic.
2707 *
2708 */
2709 @Override
2710 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2712 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002713 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2714 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2715 }
2716
2717 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002718 * Set the network selection mode to manual with the selected carrier.
2719 */
2720 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002721 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002722 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2724 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002725 OperatorInfo operator = new OperatorInfo(
2726 /* operatorAlphaLong */ "",
2727 /* operatorAlphaShort */ "",
2728 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002729 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002730 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2731 persistSelection);
2732 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002733 }
2734
2735 /**
2736 * Scans for available networks.
2737 */
2738 @Override
2739 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2741 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002742 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2743 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2744 CMD_PERFORM_NETWORK_SCAN, null, subId);
2745 return result;
2746 }
2747
2748 /**
yinxub1bed742017-04-17 11:45:04 -07002749 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002750 *
yinxub1bed742017-04-17 11:45:04 -07002751 * @param subId id of the subscription
2752 * @param request contains the radio access networks with bands/channels to scan
2753 * @param messenger callback messenger for scan results or errors
2754 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002755 * @return the id of the requested scan which can be used to stop the scan.
2756 */
2757 @Override
2758 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2759 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2761 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002762 return mNetworkScanRequestTracker.startNetworkScan(
2763 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002764 }
2765
2766 /**
2767 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002768 *
2769 * @param subId id of the subscription
2770 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002771 */
2772 @Override
2773 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2775 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002776 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002777 }
2778
2779 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002780 * Get the calculated preferred network type.
2781 * Used for debugging incorrect network type.
2782 *
2783 * @return the preferred network type, defined in RILConstants.java.
2784 */
2785 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002786 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2788 mApp, callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002789 return RILConstants.PREFERRED_NETWORK_MODE;
2790 }
2791
Amit Mahajan43330e02014-11-18 11:54:45 -08002792 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002793 }
2794
2795 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002796 * Get the preferred network type.
2797 * Used for device configuration by some CDMA operators.
2798 *
2799 * @return the preferred network type, defined in RILConstants.java.
2800 */
2801 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002802 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2804 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002805 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002806 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002807 int networkType = (result != null ? result[0] : -1);
2808 if (DBG) log("getPreferredNetworkType: " + networkType);
2809 return networkType;
2810 }
2811
2812 /**
2813 * Set the preferred network type.
2814 * Used for device configuration by some CDMA operators.
2815 *
2816 * @param networkType the preferred network type, defined in RILConstants.java.
2817 * @return true on success; false on any failure.
2818 */
2819 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002820 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2822 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002823 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2824 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002825 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002826 if (success) {
2827 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002828 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002829 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002830 return success;
2831 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002832
2833 /**
Junda Liu475951f2014-11-07 16:45:03 -08002834 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2835 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2836 * tethering.
2837 *
2838 * @return 0: Not required. 1: required. 2: Not set.
2839 * @hide
2840 */
2841 @Override
2842 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002843 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002844 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2845 Settings.Global.TETHER_DUN_REQUIRED, 2);
2846 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2847 // config_tether_apndata.
2848 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2849 dunRequired = 1;
2850 }
2851 return dunRequired;
2852 }
2853
2854 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002855 * Set mobile data enabled
2856 * Used by the user through settings etc to turn on/off mobile data
2857 *
2858 * @param enable {@code true} turn turn data on, else {@code false}
2859 */
2860 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002861 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2863 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002864 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002865 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002866 Phone phone = PhoneFactory.getPhone(phoneId);
2867 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002868 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2869 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002870 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002871 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002872 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002873 }
2874
2875 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002876 * Get the user enabled state of Mobile Data.
2877 *
2878 * TODO: remove and use isUserDataEnabled.
2879 * This can't be removed now because some vendor codes
2880 * calls through ITelephony directly while they should
2881 * use TelephonyManager.
2882 *
2883 * @return true on enabled
2884 */
2885 @Override
2886 public boolean getDataEnabled(int subId) {
2887 return isUserDataEnabled(subId);
2888 }
2889
2890 /**
2891 * Get whether mobile data is enabled per user setting.
2892 *
2893 * There are other factors deciding whether mobile data is actually enabled, but they are
2894 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002895 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002896 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002897 *
2898 * @return {@code true} if data is enabled else {@code false}
2899 */
2900 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002901 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002902 try {
2903 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2904 null);
2905 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2907 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002908 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002909 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002910 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002911 Phone phone = PhoneFactory.getPhone(phoneId);
2912 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002913 boolean retVal = phone.isUserDataEnabled();
2914 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002915 return retVal;
2916 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002917 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2918 return false;
2919 }
2920 }
2921
2922 /**
2923 * Get whether mobile data is enabled.
2924 *
2925 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2926 * whether mobile data is actually enabled.
2927 *
2928 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2929 *
2930 * @return {@code true} if data is enabled else {@code false}
2931 */
2932 @Override
2933 public boolean isDataEnabled(int subId) {
2934 try {
2935 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2936 null);
2937 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2939 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002940 }
2941 int phoneId = mSubscriptionController.getPhoneId(subId);
2942 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2943 Phone phone = PhoneFactory.getPhone(phoneId);
2944 if (phone != null) {
2945 boolean retVal = phone.isDataEnabled();
2946 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2947 return retVal;
2948 } else {
2949 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002950 return false;
2951 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002952 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002953
2954 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002955 public int getCarrierPrivilegeStatus(int subId) {
2956 final Phone phone = getPhone(subId);
2957 if (phone == null) {
2958 loge("getCarrierPrivilegeStatus: Invalid subId");
2959 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2960 }
2961 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002962 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002963 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002964 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2965 }
2966 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002967 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002968 }
Junda Liu29340342014-07-10 15:23:27 -07002969
2970 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08002971 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2972 final Phone phone = getPhone(subId);
2973 if (phone == null) {
2974 loge("getCarrierPrivilegeStatus: Invalid subId");
2975 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2976 }
2977 UiccProfile profile =
2978 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
2979 if (profile == null) {
2980 loge("getCarrierPrivilegeStatus: No UICC");
2981 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2982 }
2983 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
2984 }
2985
2986 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002987 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002988 if (TextUtils.isEmpty(pkgName))
2989 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002990 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002991 if (card == null) {
2992 loge("checkCarrierPrivilegesForPackage: No UICC");
2993 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2994 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002995 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2996 }
2997
2998 @Override
2999 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003000 if (TextUtils.isEmpty(pkgName))
3001 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003002 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3003 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3004 UiccCard card = UiccController.getInstance().getUiccCard(i);
3005 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003006 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003007 continue;
3008 }
3009
3010 result = card.getCarrierPrivilegeStatus(
3011 mPhone.getContext().getPackageManager(), pkgName);
3012 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3013 break;
3014 }
3015 }
3016
3017 return result;
Junda Liu29340342014-07-10 15:23:27 -07003018 }
Derek Tan89e89d42014-07-08 17:00:10 -07003019
3020 @Override
Junda Liue64de782015-04-16 17:19:16 -07003021 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3022 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3023 loge("phoneId " + phoneId + " is not valid.");
3024 return null;
3025 }
3026 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003027 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003028 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003029 return null ;
3030 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003031 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003032 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003033 }
3034
Amith Yamasani6e118872016-02-19 12:53:51 -08003035 @Override
3036 public List<String> getPackagesWithCarrierPrivileges() {
3037 PackageManager pm = mPhone.getContext().getPackageManager();
3038 List<String> privilegedPackages = new ArrayList<>();
3039 List<PackageInfo> packages = null;
3040 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3041 UiccCard card = UiccController.getInstance().getUiccCard(i);
3042 if (card == null) {
3043 // No UICC in that slot.
3044 continue;
3045 }
3046 if (card.hasCarrierPrivilegeRules()) {
3047 if (packages == null) {
3048 // Only check packages in user 0 for now
3049 packages = pm.getInstalledPackagesAsUser(
3050 PackageManager.MATCH_DISABLED_COMPONENTS
3051 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3052 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3053 }
3054 for (int p = packages.size() - 1; p >= 0; p--) {
3055 PackageInfo pkgInfo = packages.get(p);
3056 if (pkgInfo != null && pkgInfo.packageName != null
3057 && card.getCarrierPrivilegeStatus(pkgInfo)
3058 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3059 privilegedPackages.add(pkgInfo.packageName);
3060 }
3061 }
3062 }
3063 }
3064 return privilegedPackages;
3065 }
3066
Wink Savilleb564aae2014-10-23 10:18:09 -07003067 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003068 final Phone phone = getPhone(subId);
3069 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003070 if (card == null) {
3071 loge("getIccId: No UICC");
3072 return null;
3073 }
3074 String iccId = card.getIccId();
3075 if (TextUtils.isEmpty(iccId)) {
3076 loge("getIccId: ICC ID is null or empty.");
3077 return null;
3078 }
3079 return iccId;
3080 }
3081
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003082 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003083 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3084 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003085 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3086 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003087
Jeff Sharkey85190e62014-12-05 09:40:12 -08003088 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003089 final Phone phone = getPhone(subId);
3090 if (phone == null) {
3091 return false;
3092 }
3093 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003094
3095 if (DBG_MERGE) {
3096 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3097 + subscriberId + " to " + number);
3098 }
3099
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003100 if (TextUtils.isEmpty(iccId)) {
3101 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003102 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003103
Jeff Sharkey85190e62014-12-05 09:40:12 -08003104 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3105
3106 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003107 if (alphaTag == null) {
3108 editor.remove(alphaTagPrefKey);
3109 } else {
3110 editor.putString(alphaTagPrefKey, alphaTag);
3111 }
3112
Jeff Sharkey85190e62014-12-05 09:40:12 -08003113 // Record both the line number and IMSI for this ICCID, since we need to
3114 // track all merged IMSIs based on line number
3115 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3116 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003117 if (number == null) {
3118 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003119 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003120 } else {
3121 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003122 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003123 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003124
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003125 editor.commit();
3126 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003127 }
3128
3129 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003130 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003131 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
3133 mApp, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003134 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003135 return null;
3136 }
Derek Tan97ebb422014-09-05 16:55:38 -07003137
3138 String iccId = getIccId(subId);
3139 if (iccId != null) {
3140 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003141 if (DBG_MERGE) {
3142 log("getLine1NumberForDisplay returning " +
3143 mTelephonySharedPreferences.getString(numberPrefKey, null));
3144 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003145 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003146 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003147 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003148 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003149 }
3150
3151 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003152 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3154 mApp, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003155 return null;
3156 }
Derek Tan97ebb422014-09-05 16:55:38 -07003157
3158 String iccId = getIccId(subId);
3159 if (iccId != null) {
3160 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003161 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003162 }
Derek Tan97ebb422014-09-05 16:55:38 -07003163 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003164 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003165
3166 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003167 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3169 mApp, callingPackage, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003170 return null;
3171 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003172 final Context context = mPhone.getContext();
3173 final TelephonyManager tele = TelephonyManager.from(context);
3174 final SubscriptionManager sub = SubscriptionManager.from(context);
3175
3176 // Figure out what subscribers are currently active
3177 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003178 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3179 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3180 final long identity = Binder.clearCallingIdentity();
3181 try {
3182 final int[] subIds = sub.getActiveSubscriptionIdList();
3183 for (int subId : subIds) {
3184 activeSubscriberIds.add(tele.getSubscriberId(subId));
3185 }
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003188 }
3189
3190 // First pass, find a number override for an active subscriber
3191 String mergeNumber = null;
3192 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3193 for (String key : prefs.keySet()) {
3194 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3195 final String subscriberId = (String) prefs.get(key);
3196 if (activeSubscriberIds.contains(subscriberId)) {
3197 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3198 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3199 mergeNumber = (String) prefs.get(numberKey);
3200 if (DBG_MERGE) {
3201 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3202 + " for active subscriber " + subscriberId);
3203 }
3204 if (!TextUtils.isEmpty(mergeNumber)) {
3205 break;
3206 }
3207 }
3208 }
3209 }
3210
3211 // Shortcut when no active merged subscribers
3212 if (TextUtils.isEmpty(mergeNumber)) {
3213 return null;
3214 }
3215
3216 // Second pass, find all subscribers under that line override
3217 final ArraySet<String> result = new ArraySet<>();
3218 for (String key : prefs.keySet()) {
3219 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3220 final String number = (String) prefs.get(key);
3221 if (mergeNumber.equals(number)) {
3222 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3223 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3224 final String subscriberId = (String) prefs.get(subscriberKey);
3225 if (!TextUtils.isEmpty(subscriberId)) {
3226 result.add(subscriberId);
3227 }
3228 }
3229 }
3230 }
3231
3232 final String[] resultArray = result.toArray(new String[result.size()]);
3233 Arrays.sort(resultArray);
3234 if (DBG_MERGE) {
3235 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3236 }
3237 return resultArray;
3238 }
3239
3240 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003241 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003242 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3243 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003244 final Phone phone = getPhone(subId);
3245 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003246 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003247
3248 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003249 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003250 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3251 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003252 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003253 final Phone phone = getPhone(subId);
3254 if (phone == null) {
3255 return false;
3256 }
3257 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003258 cdmaNonRoamingList);
3259 }
3260
3261 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003262 public void setRadioCapability(RadioAccessFamily[] rafs) {
3263 try {
3264 ProxyController.getInstance().setRadioCapability(rafs);
3265 } catch (RuntimeException e) {
3266 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3267 }
3268 }
3269
3270 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003271 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3273 mApp, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003274 return RadioAccessFamily.RAF_UNKNOWN;
3275 }
3276
Wink Saville5d475dd2014-10-17 15:00:58 -07003277 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3278 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003279
3280 @Override
3281 public void enableVideoCalling(boolean enable) {
3282 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003283 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003284 }
3285
3286 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003287 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3289 mApp, callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003290 return false;
3291 }
3292
Andrew Lee77527ac2014-10-21 16:57:39 -07003293 // Check the user preference and the system-level IMS setting. Even if the user has
3294 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3295 // In the long run, we may instead need to check if there exists a connection service
3296 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003297 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3298 return imsManager.isVtEnabledByPlatform()
3299 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3300 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003301 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003302
Andrew Leea1239f22015-03-02 17:44:07 -08003303 @Override
3304 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003305 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003306 }
3307
3308 @Override
3309 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003310 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003311 }
3312
Andrew Lee9431b832015-03-09 18:46:45 -07003313 @Override
3314 public boolean isTtyModeSupported() {
3315 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3316 TelephonyManager telephonyManager =
3317 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003318 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003319 }
3320
3321 @Override
3322 public boolean isHearingAidCompatibilitySupported() {
3323 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3324 }
3325
Hall Liu98187582018-01-22 19:15:32 -08003326 public boolean isRttSupported() {
3327 boolean isCarrierSupported =
3328 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3329 boolean isDeviceSupported =
3330 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3331 return isCarrierSupported && isDeviceSupported;
3332 }
3333
Sanket Padawe7310cc72015-01-14 09:53:20 -08003334 /**
3335 * Returns the unique device ID of phone, for example, the IMEI for
3336 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3337 *
3338 * <p>Requires Permission:
3339 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3340 */
3341 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003342 public String getDeviceId(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3344 mApp, callingPackage, "getDeviceId")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003345 return null;
3346 }
3347
Sanket Padawe7310cc72015-01-14 09:53:20 -08003348 final Phone phone = PhoneFactory.getPhone(0);
3349 if (phone != null) {
3350 return phone.getDeviceId();
3351 } else {
3352 return null;
3353 }
3354 }
3355
Ping Sunc67b7c22016-03-02 19:16:45 +08003356 /**
3357 * {@hide}
3358 * Returns the IMS Registration Status on a particular subid
3359 *
3360 * @param subId
3361 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003362 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003363 Phone phone = getPhone(subId);
3364 if (phone != null) {
3365 return phone.isImsRegistered();
3366 } else {
3367 return false;
3368 }
3369 }
3370
Santos Cordon7a1885b2015-02-03 11:15:19 -08003371 @Override
3372 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3373 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3374 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003375
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003376 /**
3377 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003378 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003379 public boolean isWifiCallingAvailable(int subId) {
3380 Phone phone = getPhone(subId);
3381 if (phone != null) {
3382 return phone.isWifiCallingEnabled();
3383 } else {
3384 return false;
3385 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003386 }
3387
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003388 /**
3389 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003390 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003391 public boolean isVolteAvailable(int subId) {
3392 Phone phone = getPhone(subId);
3393 if (phone != null) {
3394 return phone.isVolteEnabled();
3395 } else {
3396 return false;
3397 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003398 }
Svet Ganovb320e182015-04-16 12:30:10 -07003399
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003400 /**
3401 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003402 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003403 public boolean isVideoTelephonyAvailable(int subId) {
3404 Phone phone = getPhone(subId);
3405 if (phone != null) {
3406 return phone.isVideoEnabled();
3407 } else {
3408 return false;
3409 }
3410 }
3411
3412 /**
3413 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3414 * defined in {@link ImsRegistrationImplBase}.
3415 */
3416 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3417 Phone phone = getPhone(subId);
3418 if (phone != null) {
3419 return phone.getImsRegistrationTech();
3420 } else {
3421 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3422 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003423 }
3424
Stuart Scott8eef64f2015-04-08 15:13:54 -07003425 @Override
3426 public void factoryReset(int subId) {
3427 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003428 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3429 return;
3430 }
3431
Svet Ganovcc087f82015-05-12 20:35:54 -07003432 final long identity = Binder.clearCallingIdentity();
3433 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003434 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3435 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003436 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003437 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003438 // Set network selection mode to automatic
3439 setNetworkSelectionModeAutomatic(subId);
3440 // Set preferred mobile network type to the best available
3441 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3442 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003443 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003444 // Remove IMSI encryption keys from Carrier DB.
3445 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003446 }
3447 } finally {
3448 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003449 }
3450 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003451
3452 @Override
3453 public String getLocaleFromDefaultSim() {
3454 // We query all subscriptions instead of just the active ones, because
3455 // this might be called early on in the provisioning flow when the
3456 // subscriptions potentially aren't active yet.
3457 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3458 if (slist == null || slist.isEmpty()) {
3459 return null;
3460 }
3461
3462 // This function may be called very early, say, from the setup wizard, at
3463 // which point we won't have a default subscription set. If that's the case
3464 // we just choose the first, which will be valid in "most cases".
3465 final int defaultSubId = getDefaultSubscription();
3466 SubscriptionInfo info = null;
3467 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3468 info = slist.get(0);
3469 } else {
3470 for (SubscriptionInfo item : slist) {
3471 if (item.getSubscriptionId() == defaultSubId) {
3472 info = item;
3473 break;
3474 }
3475 }
3476
3477 if (info == null) {
3478 return null;
3479 }
3480 }
3481
3482 // Try and fetch the locale from the carrier properties or from the SIM language
3483 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003484 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003485 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003486 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003487 if (defaultPhone != null) {
3488 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3489 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003490 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003491 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3492 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003493 } else {
3494 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003495 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003496 }
3497 }
3498
Narayan Kamath011676f2015-07-29 12:04:08 +01003499 // The SIM language preferences only store a language (e.g. fr = French), not an
3500 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3501 // the SIM and carrier preferences does not include a country we add the country
3502 // determined from the SIM MCC to provide an exact locale.
3503 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003504 if (mccLocale != null) {
3505 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3506 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003507 }
3508
Tony Hill183b2de2015-06-24 14:53:58 +01003509 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003510 return null;
3511 }
3512
3513 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3514 final long identity = Binder.clearCallingIdentity();
3515 try {
3516 return mSubscriptionController.getAllSubInfoList(
3517 mPhone.getContext().getOpPackageName());
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
3520 }
3521 }
3522
3523 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3524 final long identity = Binder.clearCallingIdentity();
3525 try {
3526 return mSubscriptionController.getActiveSubscriptionInfoList(
3527 mPhone.getContext().getOpPackageName());
3528 } finally {
3529 Binder.restoreCallingIdentity(identity);
3530 }
3531 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003532
Chenjie Yu1ba97252018-01-11 18:16:20 -08003533 private final ModemActivityInfo mLastModemActivityInfo =
3534 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3535
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003536 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003537 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3538 * representing the state of the modem.
3539 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003540 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3541 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003542 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003543 */
3544 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003545 public void requestModemActivityInfo(ResultReceiver result) {
3546 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003547 ModemActivityInfo ret = null;
3548 synchronized (mLastModemActivityInfo) {
3549 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3550 null);
3551 if (info != null) {
3552 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3553 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3554 mergedTxTimeMs[i] =
3555 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3556 }
3557 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3558 mLastModemActivityInfo.setSleepTimeMillis(
3559 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3560 mLastModemActivityInfo.setIdleTimeMillis(
3561 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3562 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3563 mLastModemActivityInfo.setRxTimeMillis(
3564 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3565 mLastModemActivityInfo.setEnergyUsed(
3566 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3567 }
3568 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3569 mLastModemActivityInfo.getSleepTimeMillis(),
3570 mLastModemActivityInfo.getIdleTimeMillis(),
3571 mLastModemActivityInfo.getTxTimeMillis(),
3572 mLastModemActivityInfo.getRxTimeMillis(),
3573 mLastModemActivityInfo.getEnergyUsed());
3574 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003575 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003576 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003577 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003578 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003579
3580 /**
3581 * {@hide}
3582 * Returns the service state information on specified subscription.
3583 */
3584 @Override
3585 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3586
Jeff Davidson7e17e312018-02-13 18:17:36 -08003587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3588 mApp, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003589 return null;
3590 }
3591
3592 final Phone phone = getPhone(subId);
3593 if (phone == null) {
3594 return null;
3595 }
3596
3597 return phone.getServiceState();
3598 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003599
3600 /**
3601 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3602 *
3603 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3604 * voicemail ringtone.
3605 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3606 * PhoneAccount.
3607 */
3608 @Override
3609 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003610 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003611 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003612 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003613 }
3614
fionaxu7ed723d2017-05-30 18:58:54 -07003615 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003616 }
3617
3618 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003619 * Sets the per-account voicemail ringtone.
3620 *
3621 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3622 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3623 *
3624 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3625 * voicemail ringtone.
3626 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3627 * PhoneAccount.
3628 */
3629 @Override
3630 public void setVoicemailRingtoneUri(String callingPackage,
3631 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3632 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3633 if (!TextUtils.equals(callingPackage,
3634 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3636 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3637 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003638 }
3639 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3640 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003641 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003642 }
fionaxu7ed723d2017-05-30 18:58:54 -07003643 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003644 }
3645
3646 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003647 * Returns whether vibration is set for voicemail notification in Phone settings.
3648 *
3649 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3650 * voicemail vibration setting.
3651 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3652 */
3653 @Override
3654 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003655 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003656 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003657 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003658 }
3659
fionaxu7ed723d2017-05-30 18:58:54 -07003660 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003661 }
3662
Youhan Wange64578a2016-05-02 15:32:42 -07003663 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003664 * Sets the per-account voicemail vibration.
3665 *
3666 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3667 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3668 *
3669 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3670 * voicemail vibration setting.
3671 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3672 * specific PhoneAccount.
3673 */
3674 @Override
3675 public void setVoicemailVibrationEnabled(String callingPackage,
3676 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3677 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3678 if (!TextUtils.equals(callingPackage,
3679 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3681 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3682 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003683 }
3684
3685 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3686 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003687 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003688 }
fionaxu7ed723d2017-05-30 18:58:54 -07003689 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003690 }
3691
3692 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003693 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3694 *
3695 * @throws SecurityException if the caller does not have the required permission
3696 */
3697 private void enforceReadPrivilegedPermission() {
3698 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3699 null);
3700 }
3701
3702 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003703 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3704 * permission.
3705 *
3706 * @throws SecurityException if the caller does not have the required permission
3707 */
3708 private void enforceSendSmsPermission() {
3709 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3710 }
3711
3712 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003713 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003714 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003715 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003716 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003717 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003718 ComponentName componentName =
3719 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3720 if(componentName == null) {
3721 throw new SecurityException("Caller not current active visual voicemail package[null]");
3722 }
3723 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003724 if (!callingPackage.equals(vvmPackage)) {
3725 throw new SecurityException("Caller not current active visual voicemail package[" +
3726 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003727 }
3728 }
3729
3730 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003731 * Return the application ID for the app type.
3732 *
3733 * @param subId the subscription ID that this request applies to.
3734 * @param appType the uicc app type.
3735 * @return Application ID for specificied app type, or null if no uicc.
3736 */
3737 @Override
3738 public String getAidForAppType(int subId, int appType) {
3739 enforceReadPrivilegedPermission();
3740 Phone phone = getPhone(subId);
3741 if (phone == null) {
3742 return null;
3743 }
3744 String aid = null;
3745 try {
3746 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3747 .getApplicationByType(appType).getAid();
3748 } catch (Exception e) {
3749 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3750 }
3751 return aid;
3752 }
3753
Youhan Wang4001d252016-05-11 10:29:41 -07003754 /**
3755 * Return the Electronic Serial Number.
3756 *
3757 * @param subId the subscription ID that this request applies to.
3758 * @return ESN or null if error.
3759 */
3760 @Override
3761 public String getEsn(int subId) {
3762 enforceReadPrivilegedPermission();
3763 Phone phone = getPhone(subId);
3764 if (phone == null) {
3765 return null;
3766 }
3767 String esn = null;
3768 try {
3769 esn = phone.getEsn();
3770 } catch (Exception e) {
3771 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3772 }
3773 return esn;
3774 }
3775
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003776 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003777 * Return the Preferred Roaming List Version.
3778 *
3779 * @param subId the subscription ID that this request applies to.
3780 * @return PRLVersion or null if error.
3781 */
3782 @Override
3783 public String getCdmaPrlVersion(int subId) {
3784 enforceReadPrivilegedPermission();
3785 Phone phone = getPhone(subId);
3786 if (phone == null) {
3787 return null;
3788 }
3789 String cdmaPrlVersion = null;
3790 try {
3791 cdmaPrlVersion = phone.getCdmaPrlVersion();
3792 } catch (Exception e) {
3793 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3794 }
3795 return cdmaPrlVersion;
3796 }
3797
3798 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003799 * Get snapshot of Telephony histograms
3800 * @return List of Telephony histograms
3801 * @hide
3802 */
3803 @Override
3804 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3806 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003807 return RIL.getTelephonyRILTimingHistograms();
3808 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003809
3810 /**
3811 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003812 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003813 * Require system privileges. In the future we may add this to carrier APIs.
3814 *
3815 * @return The number of carriers set successfully, should match length of carriers
3816 */
3817 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003818 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003819 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003820
Meng Wang9b7c4e92017-02-17 11:41:27 -08003821 if (carriers == null) {
3822 throw new NullPointerException("carriers cannot be null");
3823 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003824
3825 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003826 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3827 return retVal[0];
3828 }
3829
3830 /**
3831 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003832 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003833 * Require system privileges. In the future we may add this to carrier APIs.
3834 *
3835 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3836 * means all carriers are allowed.
3837 */
3838 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003839 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003840 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003841 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003842 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3843 }
3844
fionaxu59545b42016-05-25 15:53:37 -07003845 /**
3846 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3847 * @param subId the subscription ID that this action applies to.
3848 * @param enabled control enable or disable metered apns.
3849 * {@hide}
3850 */
3851 @Override
3852 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3853 enforceModifyPermission();
3854 final Phone phone = getPhone(subId);
3855 if (phone == null) {
3856 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3857 return;
3858 }
3859 try {
3860 phone.carrierActionSetMeteredApnsEnabled(enabled);
3861 } catch (Exception e) {
3862 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3863 }
3864 }
3865
3866 /**
3867 * Action set from carrier signalling broadcast receivers to enable/disable radio
3868 * @param subId the subscription ID that this action applies to.
3869 * @param enabled control enable or disable radio.
3870 * {@hide}
3871 */
3872 @Override
3873 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3874 enforceModifyPermission();
3875 final Phone phone = getPhone(subId);
3876 if (phone == null) {
3877 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3878 return;
3879 }
3880 try {
3881 phone.carrierActionSetRadioEnabled(enabled);
3882 } catch (Exception e) {
3883 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3884 }
3885 }
3886
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003887 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003888 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3889 * network status based on which carrier apps could apply actions accordingly,
3890 * enable/disable default url handler for example.
3891 *
3892 * @param subId the subscription ID that this action applies to.
3893 * @param report control start/stop reporting the default network status.
3894 * {@hide}
3895 */
3896 @Override
3897 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3898 enforceModifyPermission();
3899 final Phone phone = getPhone(subId);
3900 if (phone == null) {
3901 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3902 return;
3903 }
3904 try {
3905 phone.carrierActionReportDefaultNetworkStatus(report);
3906 } catch (Exception e) {
3907 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3908 }
3909 }
3910
3911 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003912 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3913 * bug report is being generated.
3914 */
3915 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003916 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003917 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3918 != PackageManager.PERMISSION_GRANTED) {
3919 writer.println("Permission Denial: can't dump Phone from pid="
3920 + Binder.getCallingPid()
3921 + ", uid=" + Binder.getCallingUid()
3922 + "without permission "
3923 + android.Manifest.permission.DUMP);
3924 return;
3925 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003926 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003927 }
Jack Yueb89b242016-06-22 13:27:47 -07003928
3929 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003930 * Get aggregated video call data usage since boot.
3931 *
3932 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3933 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003934 * {@hide}
3935 */
3936 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003937 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003938 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3939 null);
3940
Jack Yu84291ec2017-05-26 16:07:50 -07003941 // NetworkStatsService keeps tracking the active network interface and identity. It
3942 // records the delta with the corresponding network identity. We just return the total video
3943 // call data usage snapshot since boot.
3944 Phone phone = getPhone(subId);
3945 if (phone != null) {
3946 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003947 }
Jack Yu84291ec2017-05-26 16:07:50 -07003948 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003949 }
Jack Yu75ab2952016-07-08 14:29:33 -07003950
3951 /**
3952 * Policy control of data connection. Usually used when data limit is passed.
3953 * @param enabled True if enabling the data, otherwise disabling.
3954 * @param subId Subscription index
3955 * {@hide}
3956 */
3957 @Override
3958 public void setPolicyDataEnabled(boolean enabled, int subId) {
3959 enforceModifyPermission();
3960 Phone phone = getPhone(subId);
3961 if (phone != null) {
3962 phone.setPolicyDataEnabled(enabled);
3963 }
3964 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003965
3966 /**
3967 * Get Client request stats
3968 * @return List of Client Request Stats
3969 * @hide
3970 */
3971 @Override
3972 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3974 mApp, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003975 return null;
3976 }
3977
3978 Phone phone = getPhone(subId);
3979 if (phone != null) {
3980 return phone.getClientRequestStats();
3981 }
3982
3983 return null;
3984 }
3985
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003986 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003987 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003988 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003989 }
Jack Yueb4124c2017-02-16 15:32:43 -08003990
3991 /**
Grace Chen70990072017-03-24 17:21:30 -07003992 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003993 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003994 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003995 * @param state State of SIM (power down, power up, pass through)
3996 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3997 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3998 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003999 *
4000 **/
4001 @Override
Grace Chen70990072017-03-24 17:21:30 -07004002 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004003 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004004 Phone phone = PhoneFactory.getPhone(slotIndex);
4005
Jack Yueb4124c2017-02-16 15:32:43 -08004006 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004007 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004008 }
4009 }
Shuo Qiandd210312017-04-12 22:11:33 +00004010
Tyler Gunn65d45c22017-06-05 11:22:26 -07004011 private boolean isUssdApiAllowed(int subId) {
4012 CarrierConfigManager configManager =
4013 (CarrierConfigManager) mPhone.getContext().getSystemService(
4014 Context.CARRIER_CONFIG_SERVICE);
4015 if (configManager == null) {
4016 return false;
4017 }
4018 PersistableBundle pb = configManager.getConfigForSubId(subId);
4019 if (pb == null) {
4020 return false;
4021 }
4022 return pb.getBoolean(
4023 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4024 }
4025
Shuo Qiandd210312017-04-12 22:11:33 +00004026 /**
4027 * Check if phone is in emergency callback mode
4028 * @return true if phone is in emergency callback mode
4029 * @param subId sub id
4030 */
goneil9c5f4872017-12-05 14:07:56 -08004031 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004032 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004033 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004034 final Phone phone = getPhone(subId);
4035 if (phone != null) {
4036 return phone.isInEcm();
4037 } else {
4038 return false;
4039 }
4040 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004041
4042 /**
4043 * Get the current signal strength information for the given subscription.
4044 * Because this information is not updated when the device is in a low power state
4045 * it should not be relied-upon to be current.
4046 * @param subId Subscription index
4047 * @return the most recent cached signal strength info from the modem
4048 */
4049 @Override
4050 public SignalStrength getSignalStrength(int subId) {
4051 Phone p = getPhone(subId);
4052 if (p == null) {
4053 return null;
4054 }
4055
4056 return p.getSignalStrength();
4057 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004058
4059 @Override
4060 public UiccSlotInfo[] getUiccSlotsInfo() {
4061 enforceReadPrivilegedPermission();
4062
4063 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4064 if (slots == null) return null;
4065 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4066 for (int i = 0; i < slots.length; i++) {
4067 UiccSlot slot = slots[i];
4068
4069 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4070
4071 int cardState = 0;
4072 switch (slot.getCardState()) {
4073 case CARDSTATE_ABSENT:
4074 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4075 break;
4076 case CARDSTATE_PRESENT:
4077 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4078 break;
4079 case CARDSTATE_ERROR:
4080 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4081 break;
4082 case CARDSTATE_RESTRICTED:
4083 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4084 break;
4085 default:
4086 break;
4087
4088 }
4089
Qingxi Li795c5882018-01-31 13:43:27 -08004090 infos[i] = new UiccSlotInfo(
4091 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004092 }
4093 return infos;
4094 }
4095
4096 @Override
4097 public boolean switchSlots(int[] physicalSlots) {
4098 enforceModifyPermission();
4099 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4100 }
Jack Yu4c988042018-02-27 15:30:01 -08004101
4102 @Override
4103 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4104 enforceModifyPermission();
4105 final Phone phone = getPhone(subId);
4106 if (phone == null) {
4107 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4108 return;
4109 }
4110
4111 phone.setRadioIndicationUpdateMode(filters, mode);
4112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004113}