blob: 30ecaed6acfffe732acc287b4af6cd4cc847c3db [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 /**
2692 * @return true if emergency calling is available on IMS, false if it should fallback to CS.
2693 */
2694 public boolean isEmergencyMmTelAvailable(int slotId) {
2695 enforceModifyPermission();
2696 return PhoneFactory.getImsResolver().isEmergencyMmTelAvailable(slotId);
2697 }
2698
Brad Ebinger304415d2018-03-02 13:43:36 -08002699 /**
2700 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2701 * available, false if the IMS resolver is idle.
2702 */
2703 public boolean isResolvingImsBinding() {
2704 enforceModifyPermission();
2705 return PhoneFactory.getImsResolver().isResolvingBinding();
2706 }
2707
Wink Saville36469e72014-06-11 15:17:00 -07002708 public void setImsRegistrationState(boolean registered) {
2709 enforceModifyPermission();
2710 mPhone.setImsRegistrationState(registered);
2711 }
2712
2713 /**
Stuart Scott54788802015-03-30 13:18:01 -07002714 * Set the network selection mode to automatic.
2715 *
2716 */
2717 @Override
2718 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2720 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002721 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2722 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2723 }
2724
2725 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002726 * Set the network selection mode to manual with the selected carrier.
2727 */
2728 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002729 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002730 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2732 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002733 OperatorInfo operator = new OperatorInfo(
2734 /* operatorAlphaLong */ "",
2735 /* operatorAlphaShort */ "",
2736 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002737 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002738 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2739 persistSelection);
2740 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002741 }
2742
2743 /**
2744 * Scans for available networks.
2745 */
2746 @Override
2747 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2749 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002750 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2751 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2752 CMD_PERFORM_NETWORK_SCAN, null, subId);
2753 return result;
2754 }
2755
2756 /**
yinxub1bed742017-04-17 11:45:04 -07002757 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002758 *
yinxub1bed742017-04-17 11:45:04 -07002759 * @param subId id of the subscription
2760 * @param request contains the radio access networks with bands/channels to scan
2761 * @param messenger callback messenger for scan results or errors
2762 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002763 * @return the id of the requested scan which can be used to stop the scan.
2764 */
2765 @Override
2766 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2767 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2769 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002770 return mNetworkScanRequestTracker.startNetworkScan(
2771 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002772 }
2773
2774 /**
2775 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002776 *
2777 * @param subId id of the subscription
2778 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002779 */
2780 @Override
2781 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2783 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002784 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002785 }
2786
2787 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002788 * Get the calculated preferred network type.
2789 * Used for debugging incorrect network type.
2790 *
2791 * @return the preferred network type, defined in RILConstants.java.
2792 */
2793 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002794 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2796 mApp, callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002797 return RILConstants.PREFERRED_NETWORK_MODE;
2798 }
2799
Amit Mahajan43330e02014-11-18 11:54:45 -08002800 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002801 }
2802
2803 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002804 * Get the preferred network type.
2805 * Used for device configuration by some CDMA operators.
2806 *
2807 * @return the preferred network type, defined in RILConstants.java.
2808 */
2809 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002810 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2812 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002813 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002814 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002815 int networkType = (result != null ? result[0] : -1);
2816 if (DBG) log("getPreferredNetworkType: " + networkType);
2817 return networkType;
2818 }
2819
2820 /**
2821 * Set the preferred network type.
2822 * Used for device configuration by some CDMA operators.
2823 *
2824 * @param networkType the preferred network type, defined in RILConstants.java.
2825 * @return true on success; false on any failure.
2826 */
2827 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002828 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2830 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002831 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2832 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002833 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002834 if (success) {
2835 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002836 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002837 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002838 return success;
2839 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002840
2841 /**
Junda Liu475951f2014-11-07 16:45:03 -08002842 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2843 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2844 * tethering.
2845 *
2846 * @return 0: Not required. 1: required. 2: Not set.
2847 * @hide
2848 */
2849 @Override
2850 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002851 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002852 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2853 Settings.Global.TETHER_DUN_REQUIRED, 2);
2854 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2855 // config_tether_apndata.
2856 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2857 dunRequired = 1;
2858 }
2859 return dunRequired;
2860 }
2861
2862 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002863 * Set mobile data enabled
2864 * Used by the user through settings etc to turn on/off mobile data
2865 *
2866 * @param enable {@code true} turn turn data on, else {@code false}
2867 */
2868 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002869 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2871 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002872 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002873 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002874 Phone phone = PhoneFactory.getPhone(phoneId);
2875 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002876 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2877 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002878 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002879 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002880 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002881 }
2882
2883 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002884 * Get the user enabled state of Mobile Data.
2885 *
2886 * TODO: remove and use isUserDataEnabled.
2887 * This can't be removed now because some vendor codes
2888 * calls through ITelephony directly while they should
2889 * use TelephonyManager.
2890 *
2891 * @return true on enabled
2892 */
2893 @Override
2894 public boolean getDataEnabled(int subId) {
2895 return isUserDataEnabled(subId);
2896 }
2897
2898 /**
2899 * Get whether mobile data is enabled per user setting.
2900 *
2901 * There are other factors deciding whether mobile data is actually enabled, but they are
2902 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002903 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002904 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002905 *
2906 * @return {@code true} if data is enabled else {@code false}
2907 */
2908 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002909 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002910 try {
2911 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2912 null);
2913 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2915 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002916 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002917 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002918 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002919 Phone phone = PhoneFactory.getPhone(phoneId);
2920 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002921 boolean retVal = phone.isUserDataEnabled();
2922 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002923 return retVal;
2924 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002925 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2926 return false;
2927 }
2928 }
2929
2930 /**
2931 * Get whether mobile data is enabled.
2932 *
2933 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2934 * whether mobile data is actually enabled.
2935 *
2936 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2937 *
2938 * @return {@code true} if data is enabled else {@code false}
2939 */
2940 @Override
2941 public boolean isDataEnabled(int subId) {
2942 try {
2943 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2944 null);
2945 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2947 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002948 }
2949 int phoneId = mSubscriptionController.getPhoneId(subId);
2950 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2951 Phone phone = PhoneFactory.getPhone(phoneId);
2952 if (phone != null) {
2953 boolean retVal = phone.isDataEnabled();
2954 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2955 return retVal;
2956 } else {
2957 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002958 return false;
2959 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002960 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002961
2962 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002963 public int getCarrierPrivilegeStatus(int subId) {
2964 final Phone phone = getPhone(subId);
2965 if (phone == null) {
2966 loge("getCarrierPrivilegeStatus: Invalid subId");
2967 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2968 }
2969 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002970 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002971 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002972 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2973 }
2974 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002975 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002976 }
Junda Liu29340342014-07-10 15:23:27 -07002977
2978 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08002979 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2980 final Phone phone = getPhone(subId);
2981 if (phone == null) {
2982 loge("getCarrierPrivilegeStatus: Invalid subId");
2983 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2984 }
2985 UiccProfile profile =
2986 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
2987 if (profile == null) {
2988 loge("getCarrierPrivilegeStatus: No UICC");
2989 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2990 }
2991 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
2992 }
2993
2994 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002995 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002996 if (TextUtils.isEmpty(pkgName))
2997 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002998 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002999 if (card == null) {
3000 loge("checkCarrierPrivilegesForPackage: No UICC");
3001 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3002 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003003 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3004 }
3005
3006 @Override
3007 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003008 if (TextUtils.isEmpty(pkgName))
3009 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003010 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3011 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3012 UiccCard card = UiccController.getInstance().getUiccCard(i);
3013 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003014 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003015 continue;
3016 }
3017
3018 result = card.getCarrierPrivilegeStatus(
3019 mPhone.getContext().getPackageManager(), pkgName);
3020 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3021 break;
3022 }
3023 }
3024
3025 return result;
Junda Liu29340342014-07-10 15:23:27 -07003026 }
Derek Tan89e89d42014-07-08 17:00:10 -07003027
3028 @Override
Junda Liue64de782015-04-16 17:19:16 -07003029 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3030 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3031 loge("phoneId " + phoneId + " is not valid.");
3032 return null;
3033 }
3034 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003035 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003036 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003037 return null ;
3038 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003039 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003040 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003041 }
3042
Amith Yamasani6e118872016-02-19 12:53:51 -08003043 @Override
3044 public List<String> getPackagesWithCarrierPrivileges() {
3045 PackageManager pm = mPhone.getContext().getPackageManager();
3046 List<String> privilegedPackages = new ArrayList<>();
3047 List<PackageInfo> packages = null;
3048 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3049 UiccCard card = UiccController.getInstance().getUiccCard(i);
3050 if (card == null) {
3051 // No UICC in that slot.
3052 continue;
3053 }
3054 if (card.hasCarrierPrivilegeRules()) {
3055 if (packages == null) {
3056 // Only check packages in user 0 for now
3057 packages = pm.getInstalledPackagesAsUser(
3058 PackageManager.MATCH_DISABLED_COMPONENTS
3059 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3060 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3061 }
3062 for (int p = packages.size() - 1; p >= 0; p--) {
3063 PackageInfo pkgInfo = packages.get(p);
3064 if (pkgInfo != null && pkgInfo.packageName != null
3065 && card.getCarrierPrivilegeStatus(pkgInfo)
3066 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3067 privilegedPackages.add(pkgInfo.packageName);
3068 }
3069 }
3070 }
3071 }
3072 return privilegedPackages;
3073 }
3074
Wink Savilleb564aae2014-10-23 10:18:09 -07003075 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003076 final Phone phone = getPhone(subId);
3077 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003078 if (card == null) {
3079 loge("getIccId: No UICC");
3080 return null;
3081 }
3082 String iccId = card.getIccId();
3083 if (TextUtils.isEmpty(iccId)) {
3084 loge("getIccId: ICC ID is null or empty.");
3085 return null;
3086 }
3087 return iccId;
3088 }
3089
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003090 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003091 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3092 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003093 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3094 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003095
Jeff Sharkey85190e62014-12-05 09:40:12 -08003096 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003097 final Phone phone = getPhone(subId);
3098 if (phone == null) {
3099 return false;
3100 }
3101 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003102
3103 if (DBG_MERGE) {
3104 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3105 + subscriberId + " to " + number);
3106 }
3107
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003108 if (TextUtils.isEmpty(iccId)) {
3109 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003110 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003111
Jeff Sharkey85190e62014-12-05 09:40:12 -08003112 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3113
3114 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003115 if (alphaTag == null) {
3116 editor.remove(alphaTagPrefKey);
3117 } else {
3118 editor.putString(alphaTagPrefKey, alphaTag);
3119 }
3120
Jeff Sharkey85190e62014-12-05 09:40:12 -08003121 // Record both the line number and IMSI for this ICCID, since we need to
3122 // track all merged IMSIs based on line number
3123 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3124 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003125 if (number == null) {
3126 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003127 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003128 } else {
3129 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003130 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003131 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003132
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003133 editor.commit();
3134 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003135 }
3136
3137 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003138 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003139 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
3141 mApp, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003142 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003143 return null;
3144 }
Derek Tan97ebb422014-09-05 16:55:38 -07003145
3146 String iccId = getIccId(subId);
3147 if (iccId != null) {
3148 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003149 if (DBG_MERGE) {
3150 log("getLine1NumberForDisplay returning " +
3151 mTelephonySharedPreferences.getString(numberPrefKey, null));
3152 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003153 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003154 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003155 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003156 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003157 }
3158
3159 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003160 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3162 mApp, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003163 return null;
3164 }
Derek Tan97ebb422014-09-05 16:55:38 -07003165
3166 String iccId = getIccId(subId);
3167 if (iccId != null) {
3168 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003169 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003170 }
Derek Tan97ebb422014-09-05 16:55:38 -07003171 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003172 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003173
3174 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003175 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3177 mApp, callingPackage, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003178 return null;
3179 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003180 final Context context = mPhone.getContext();
3181 final TelephonyManager tele = TelephonyManager.from(context);
3182 final SubscriptionManager sub = SubscriptionManager.from(context);
3183
3184 // Figure out what subscribers are currently active
3185 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003186 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3187 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 final int[] subIds = sub.getActiveSubscriptionIdList();
3191 for (int subId : subIds) {
3192 activeSubscriberIds.add(tele.getSubscriberId(subId));
3193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003196 }
3197
3198 // First pass, find a number override for an active subscriber
3199 String mergeNumber = null;
3200 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3201 for (String key : prefs.keySet()) {
3202 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3203 final String subscriberId = (String) prefs.get(key);
3204 if (activeSubscriberIds.contains(subscriberId)) {
3205 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3206 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3207 mergeNumber = (String) prefs.get(numberKey);
3208 if (DBG_MERGE) {
3209 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3210 + " for active subscriber " + subscriberId);
3211 }
3212 if (!TextUtils.isEmpty(mergeNumber)) {
3213 break;
3214 }
3215 }
3216 }
3217 }
3218
3219 // Shortcut when no active merged subscribers
3220 if (TextUtils.isEmpty(mergeNumber)) {
3221 return null;
3222 }
3223
3224 // Second pass, find all subscribers under that line override
3225 final ArraySet<String> result = new ArraySet<>();
3226 for (String key : prefs.keySet()) {
3227 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3228 final String number = (String) prefs.get(key);
3229 if (mergeNumber.equals(number)) {
3230 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3231 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3232 final String subscriberId = (String) prefs.get(subscriberKey);
3233 if (!TextUtils.isEmpty(subscriberId)) {
3234 result.add(subscriberId);
3235 }
3236 }
3237 }
3238 }
3239
3240 final String[] resultArray = result.toArray(new String[result.size()]);
3241 Arrays.sort(resultArray);
3242 if (DBG_MERGE) {
3243 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3244 }
3245 return resultArray;
3246 }
3247
3248 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003249 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003250 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3251 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003252 final Phone phone = getPhone(subId);
3253 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003254 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003255
3256 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003257 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003258 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3259 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003260 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003261 final Phone phone = getPhone(subId);
3262 if (phone == null) {
3263 return false;
3264 }
3265 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003266 cdmaNonRoamingList);
3267 }
3268
3269 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003270 public void setRadioCapability(RadioAccessFamily[] rafs) {
3271 try {
3272 ProxyController.getInstance().setRadioCapability(rafs);
3273 } catch (RuntimeException e) {
3274 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3275 }
3276 }
3277
3278 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003279 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3281 mApp, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003282 return RadioAccessFamily.RAF_UNKNOWN;
3283 }
3284
Wink Saville5d475dd2014-10-17 15:00:58 -07003285 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3286 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003287
3288 @Override
3289 public void enableVideoCalling(boolean enable) {
3290 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003291 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003292 }
3293
3294 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003295 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3297 mApp, callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003298 return false;
3299 }
3300
Andrew Lee77527ac2014-10-21 16:57:39 -07003301 // Check the user preference and the system-level IMS setting. Even if the user has
3302 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3303 // In the long run, we may instead need to check if there exists a connection service
3304 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003305 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3306 return imsManager.isVtEnabledByPlatform()
3307 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3308 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003309 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003310
Andrew Leea1239f22015-03-02 17:44:07 -08003311 @Override
3312 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003313 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003314 }
3315
3316 @Override
3317 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003318 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003319 }
3320
Andrew Lee9431b832015-03-09 18:46:45 -07003321 @Override
3322 public boolean isTtyModeSupported() {
3323 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3324 TelephonyManager telephonyManager =
3325 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003326 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003327 }
3328
3329 @Override
3330 public boolean isHearingAidCompatibilitySupported() {
3331 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3332 }
3333
Hall Liu98187582018-01-22 19:15:32 -08003334 public boolean isRttSupported() {
3335 boolean isCarrierSupported =
3336 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3337 boolean isDeviceSupported =
3338 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3339 return isCarrierSupported && isDeviceSupported;
3340 }
3341
Sanket Padawe7310cc72015-01-14 09:53:20 -08003342 /**
3343 * Returns the unique device ID of phone, for example, the IMEI for
3344 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3345 *
3346 * <p>Requires Permission:
3347 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3348 */
3349 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003350 public String getDeviceId(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3352 mApp, callingPackage, "getDeviceId")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003353 return null;
3354 }
3355
Sanket Padawe7310cc72015-01-14 09:53:20 -08003356 final Phone phone = PhoneFactory.getPhone(0);
3357 if (phone != null) {
3358 return phone.getDeviceId();
3359 } else {
3360 return null;
3361 }
3362 }
3363
Ping Sunc67b7c22016-03-02 19:16:45 +08003364 /**
3365 * {@hide}
3366 * Returns the IMS Registration Status on a particular subid
3367 *
3368 * @param subId
3369 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003370 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003371 Phone phone = getPhone(subId);
3372 if (phone != null) {
3373 return phone.isImsRegistered();
3374 } else {
3375 return false;
3376 }
3377 }
3378
Santos Cordon7a1885b2015-02-03 11:15:19 -08003379 @Override
3380 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3381 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3382 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003383
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003384 /**
3385 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003386 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003387 public boolean isWifiCallingAvailable(int subId) {
3388 Phone phone = getPhone(subId);
3389 if (phone != null) {
3390 return phone.isWifiCallingEnabled();
3391 } else {
3392 return false;
3393 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003394 }
3395
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003396 /**
3397 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003398 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003399 public boolean isVolteAvailable(int subId) {
3400 Phone phone = getPhone(subId);
3401 if (phone != null) {
3402 return phone.isVolteEnabled();
3403 } else {
3404 return false;
3405 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003406 }
Svet Ganovb320e182015-04-16 12:30:10 -07003407
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003408 /**
3409 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003410 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003411 public boolean isVideoTelephonyAvailable(int subId) {
3412 Phone phone = getPhone(subId);
3413 if (phone != null) {
3414 return phone.isVideoEnabled();
3415 } else {
3416 return false;
3417 }
3418 }
3419
3420 /**
3421 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3422 * defined in {@link ImsRegistrationImplBase}.
3423 */
3424 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3425 Phone phone = getPhone(subId);
3426 if (phone != null) {
3427 return phone.getImsRegistrationTech();
3428 } else {
3429 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3430 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003431 }
3432
Stuart Scott8eef64f2015-04-08 15:13:54 -07003433 @Override
3434 public void factoryReset(int subId) {
3435 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003436 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3437 return;
3438 }
3439
Svet Ganovcc087f82015-05-12 20:35:54 -07003440 final long identity = Binder.clearCallingIdentity();
3441 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003442 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3443 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003444 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003445 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003446 // Set network selection mode to automatic
3447 setNetworkSelectionModeAutomatic(subId);
3448 // Set preferred mobile network type to the best available
3449 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3450 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003451 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003452 // Remove IMSI encryption keys from Carrier DB.
3453 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003454 }
3455 } finally {
3456 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003457 }
3458 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003459
3460 @Override
3461 public String getLocaleFromDefaultSim() {
3462 // We query all subscriptions instead of just the active ones, because
3463 // this might be called early on in the provisioning flow when the
3464 // subscriptions potentially aren't active yet.
3465 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3466 if (slist == null || slist.isEmpty()) {
3467 return null;
3468 }
3469
3470 // This function may be called very early, say, from the setup wizard, at
3471 // which point we won't have a default subscription set. If that's the case
3472 // we just choose the first, which will be valid in "most cases".
3473 final int defaultSubId = getDefaultSubscription();
3474 SubscriptionInfo info = null;
3475 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3476 info = slist.get(0);
3477 } else {
3478 for (SubscriptionInfo item : slist) {
3479 if (item.getSubscriptionId() == defaultSubId) {
3480 info = item;
3481 break;
3482 }
3483 }
3484
3485 if (info == null) {
3486 return null;
3487 }
3488 }
3489
3490 // Try and fetch the locale from the carrier properties or from the SIM language
3491 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003492 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003493 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003494 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003495 if (defaultPhone != null) {
3496 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3497 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003498 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003499 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3500 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003501 } else {
3502 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003503 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003504 }
3505 }
3506
Narayan Kamath011676f2015-07-29 12:04:08 +01003507 // The SIM language preferences only store a language (e.g. fr = French), not an
3508 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3509 // the SIM and carrier preferences does not include a country we add the country
3510 // determined from the SIM MCC to provide an exact locale.
3511 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003512 if (mccLocale != null) {
3513 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3514 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003515 }
3516
Tony Hill183b2de2015-06-24 14:53:58 +01003517 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003518 return null;
3519 }
3520
3521 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 return mSubscriptionController.getAllSubInfoList(
3525 mPhone.getContext().getOpPackageName());
3526 } finally {
3527 Binder.restoreCallingIdentity(identity);
3528 }
3529 }
3530
3531 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 return mSubscriptionController.getActiveSubscriptionInfoList(
3535 mPhone.getContext().getOpPackageName());
3536 } finally {
3537 Binder.restoreCallingIdentity(identity);
3538 }
3539 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003540
Chenjie Yu1ba97252018-01-11 18:16:20 -08003541 private final ModemActivityInfo mLastModemActivityInfo =
3542 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3543
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003544 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003545 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3546 * representing the state of the modem.
3547 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003548 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3549 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003550 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003551 */
3552 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003553 public void requestModemActivityInfo(ResultReceiver result) {
3554 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003555 ModemActivityInfo ret = null;
3556 synchronized (mLastModemActivityInfo) {
3557 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3558 null);
3559 if (info != null) {
3560 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3561 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3562 mergedTxTimeMs[i] =
3563 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3564 }
3565 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3566 mLastModemActivityInfo.setSleepTimeMillis(
3567 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3568 mLastModemActivityInfo.setIdleTimeMillis(
3569 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3570 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3571 mLastModemActivityInfo.setRxTimeMillis(
3572 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3573 mLastModemActivityInfo.setEnergyUsed(
3574 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3575 }
3576 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3577 mLastModemActivityInfo.getSleepTimeMillis(),
3578 mLastModemActivityInfo.getIdleTimeMillis(),
3579 mLastModemActivityInfo.getTxTimeMillis(),
3580 mLastModemActivityInfo.getRxTimeMillis(),
3581 mLastModemActivityInfo.getEnergyUsed());
3582 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003583 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003584 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003585 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003586 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003587
3588 /**
3589 * {@hide}
3590 * Returns the service state information on specified subscription.
3591 */
3592 @Override
3593 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3594
Jeff Davidson7e17e312018-02-13 18:17:36 -08003595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3596 mApp, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003597 return null;
3598 }
3599
3600 final Phone phone = getPhone(subId);
3601 if (phone == null) {
3602 return null;
3603 }
3604
3605 return phone.getServiceState();
3606 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003607
3608 /**
3609 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3610 *
3611 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3612 * voicemail ringtone.
3613 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3614 * PhoneAccount.
3615 */
3616 @Override
3617 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003618 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003619 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003620 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003621 }
3622
fionaxu7ed723d2017-05-30 18:58:54 -07003623 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003624 }
3625
3626 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003627 * Sets the per-account voicemail ringtone.
3628 *
3629 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3630 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3631 *
3632 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3633 * voicemail ringtone.
3634 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3635 * PhoneAccount.
3636 */
3637 @Override
3638 public void setVoicemailRingtoneUri(String callingPackage,
3639 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3640 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3641 if (!TextUtils.equals(callingPackage,
3642 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3644 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3645 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003646 }
3647 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3648 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003649 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003650 }
fionaxu7ed723d2017-05-30 18:58:54 -07003651 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003652 }
3653
3654 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003655 * Returns whether vibration is set for voicemail notification in Phone settings.
3656 *
3657 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3658 * voicemail vibration setting.
3659 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3660 */
3661 @Override
3662 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003663 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003664 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003665 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003666 }
3667
fionaxu7ed723d2017-05-30 18:58:54 -07003668 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003669 }
3670
Youhan Wange64578a2016-05-02 15:32:42 -07003671 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003672 * Sets the per-account voicemail vibration.
3673 *
3674 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3675 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3676 *
3677 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3678 * voicemail vibration setting.
3679 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3680 * specific PhoneAccount.
3681 */
3682 @Override
3683 public void setVoicemailVibrationEnabled(String callingPackage,
3684 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3685 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3686 if (!TextUtils.equals(callingPackage,
3687 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3689 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3690 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003691 }
3692
3693 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3694 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003695 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003696 }
fionaxu7ed723d2017-05-30 18:58:54 -07003697 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003698 }
3699
3700 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003701 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3702 *
3703 * @throws SecurityException if the caller does not have the required permission
3704 */
3705 private void enforceReadPrivilegedPermission() {
3706 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3707 null);
3708 }
3709
3710 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003711 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3712 * permission.
3713 *
3714 * @throws SecurityException if the caller does not have the required permission
3715 */
3716 private void enforceSendSmsPermission() {
3717 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3718 }
3719
3720 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003721 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003722 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003723 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003724 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003725 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003726 ComponentName componentName =
3727 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3728 if(componentName == null) {
3729 throw new SecurityException("Caller not current active visual voicemail package[null]");
3730 }
3731 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003732 if (!callingPackage.equals(vvmPackage)) {
3733 throw new SecurityException("Caller not current active visual voicemail package[" +
3734 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003735 }
3736 }
3737
3738 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003739 * Return the application ID for the app type.
3740 *
3741 * @param subId the subscription ID that this request applies to.
3742 * @param appType the uicc app type.
3743 * @return Application ID for specificied app type, or null if no uicc.
3744 */
3745 @Override
3746 public String getAidForAppType(int subId, int appType) {
3747 enforceReadPrivilegedPermission();
3748 Phone phone = getPhone(subId);
3749 if (phone == null) {
3750 return null;
3751 }
3752 String aid = null;
3753 try {
3754 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3755 .getApplicationByType(appType).getAid();
3756 } catch (Exception e) {
3757 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3758 }
3759 return aid;
3760 }
3761
Youhan Wang4001d252016-05-11 10:29:41 -07003762 /**
3763 * Return the Electronic Serial Number.
3764 *
3765 * @param subId the subscription ID that this request applies to.
3766 * @return ESN or null if error.
3767 */
3768 @Override
3769 public String getEsn(int subId) {
3770 enforceReadPrivilegedPermission();
3771 Phone phone = getPhone(subId);
3772 if (phone == null) {
3773 return null;
3774 }
3775 String esn = null;
3776 try {
3777 esn = phone.getEsn();
3778 } catch (Exception e) {
3779 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3780 }
3781 return esn;
3782 }
3783
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003784 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003785 * Return the Preferred Roaming List Version.
3786 *
3787 * @param subId the subscription ID that this request applies to.
3788 * @return PRLVersion or null if error.
3789 */
3790 @Override
3791 public String getCdmaPrlVersion(int subId) {
3792 enforceReadPrivilegedPermission();
3793 Phone phone = getPhone(subId);
3794 if (phone == null) {
3795 return null;
3796 }
3797 String cdmaPrlVersion = null;
3798 try {
3799 cdmaPrlVersion = phone.getCdmaPrlVersion();
3800 } catch (Exception e) {
3801 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3802 }
3803 return cdmaPrlVersion;
3804 }
3805
3806 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003807 * Get snapshot of Telephony histograms
3808 * @return List of Telephony histograms
3809 * @hide
3810 */
3811 @Override
3812 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3814 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003815 return RIL.getTelephonyRILTimingHistograms();
3816 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003817
3818 /**
3819 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003820 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003821 * Require system privileges. In the future we may add this to carrier APIs.
3822 *
3823 * @return The number of carriers set successfully, should match length of carriers
3824 */
3825 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003826 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003827 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003828
Meng Wang9b7c4e92017-02-17 11:41:27 -08003829 if (carriers == null) {
3830 throw new NullPointerException("carriers cannot be null");
3831 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003832
3833 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003834 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3835 return retVal[0];
3836 }
3837
3838 /**
3839 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003840 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003841 * Require system privileges. In the future we may add this to carrier APIs.
3842 *
3843 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3844 * means all carriers are allowed.
3845 */
3846 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003847 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003848 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003849 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003850 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3851 }
3852
fionaxu59545b42016-05-25 15:53:37 -07003853 /**
3854 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3855 * @param subId the subscription ID that this action applies to.
3856 * @param enabled control enable or disable metered apns.
3857 * {@hide}
3858 */
3859 @Override
3860 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3861 enforceModifyPermission();
3862 final Phone phone = getPhone(subId);
3863 if (phone == null) {
3864 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3865 return;
3866 }
3867 try {
3868 phone.carrierActionSetMeteredApnsEnabled(enabled);
3869 } catch (Exception e) {
3870 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3871 }
3872 }
3873
3874 /**
3875 * Action set from carrier signalling broadcast receivers to enable/disable radio
3876 * @param subId the subscription ID that this action applies to.
3877 * @param enabled control enable or disable radio.
3878 * {@hide}
3879 */
3880 @Override
3881 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3882 enforceModifyPermission();
3883 final Phone phone = getPhone(subId);
3884 if (phone == null) {
3885 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3886 return;
3887 }
3888 try {
3889 phone.carrierActionSetRadioEnabled(enabled);
3890 } catch (Exception e) {
3891 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3892 }
3893 }
3894
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003895 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003896 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3897 * network status based on which carrier apps could apply actions accordingly,
3898 * enable/disable default url handler for example.
3899 *
3900 * @param subId the subscription ID that this action applies to.
3901 * @param report control start/stop reporting the default network status.
3902 * {@hide}
3903 */
3904 @Override
3905 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3906 enforceModifyPermission();
3907 final Phone phone = getPhone(subId);
3908 if (phone == null) {
3909 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3910 return;
3911 }
3912 try {
3913 phone.carrierActionReportDefaultNetworkStatus(report);
3914 } catch (Exception e) {
3915 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3916 }
3917 }
3918
3919 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003920 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3921 * bug report is being generated.
3922 */
3923 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003924 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003925 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3926 != PackageManager.PERMISSION_GRANTED) {
3927 writer.println("Permission Denial: can't dump Phone from pid="
3928 + Binder.getCallingPid()
3929 + ", uid=" + Binder.getCallingUid()
3930 + "without permission "
3931 + android.Manifest.permission.DUMP);
3932 return;
3933 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003934 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003935 }
Jack Yueb89b242016-06-22 13:27:47 -07003936
3937 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003938 * Get aggregated video call data usage since boot.
3939 *
3940 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3941 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003942 * {@hide}
3943 */
3944 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003945 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003946 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3947 null);
3948
Jack Yu84291ec2017-05-26 16:07:50 -07003949 // NetworkStatsService keeps tracking the active network interface and identity. It
3950 // records the delta with the corresponding network identity. We just return the total video
3951 // call data usage snapshot since boot.
3952 Phone phone = getPhone(subId);
3953 if (phone != null) {
3954 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003955 }
Jack Yu84291ec2017-05-26 16:07:50 -07003956 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003957 }
Jack Yu75ab2952016-07-08 14:29:33 -07003958
3959 /**
3960 * Policy control of data connection. Usually used when data limit is passed.
3961 * @param enabled True if enabling the data, otherwise disabling.
3962 * @param subId Subscription index
3963 * {@hide}
3964 */
3965 @Override
3966 public void setPolicyDataEnabled(boolean enabled, int subId) {
3967 enforceModifyPermission();
3968 Phone phone = getPhone(subId);
3969 if (phone != null) {
3970 phone.setPolicyDataEnabled(enabled);
3971 }
3972 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003973
3974 /**
3975 * Get Client request stats
3976 * @return List of Client Request Stats
3977 * @hide
3978 */
3979 @Override
3980 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3982 mApp, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003983 return null;
3984 }
3985
3986 Phone phone = getPhone(subId);
3987 if (phone != null) {
3988 return phone.getClientRequestStats();
3989 }
3990
3991 return null;
3992 }
3993
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003994 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003995 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003996 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003997 }
Jack Yueb4124c2017-02-16 15:32:43 -08003998
3999 /**
Grace Chen70990072017-03-24 17:21:30 -07004000 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004001 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004002 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004003 * @param state State of SIM (power down, power up, pass through)
4004 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4005 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4006 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004007 *
4008 **/
4009 @Override
Grace Chen70990072017-03-24 17:21:30 -07004010 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004011 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004012 Phone phone = PhoneFactory.getPhone(slotIndex);
4013
Jack Yueb4124c2017-02-16 15:32:43 -08004014 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004015 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004016 }
4017 }
Shuo Qiandd210312017-04-12 22:11:33 +00004018
Tyler Gunn65d45c22017-06-05 11:22:26 -07004019 private boolean isUssdApiAllowed(int subId) {
4020 CarrierConfigManager configManager =
4021 (CarrierConfigManager) mPhone.getContext().getSystemService(
4022 Context.CARRIER_CONFIG_SERVICE);
4023 if (configManager == null) {
4024 return false;
4025 }
4026 PersistableBundle pb = configManager.getConfigForSubId(subId);
4027 if (pb == null) {
4028 return false;
4029 }
4030 return pb.getBoolean(
4031 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4032 }
4033
Shuo Qiandd210312017-04-12 22:11:33 +00004034 /**
4035 * Check if phone is in emergency callback mode
4036 * @return true if phone is in emergency callback mode
4037 * @param subId sub id
4038 */
goneil9c5f4872017-12-05 14:07:56 -08004039 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004040 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004041 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004042 final Phone phone = getPhone(subId);
4043 if (phone != null) {
4044 return phone.isInEcm();
4045 } else {
4046 return false;
4047 }
4048 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004049
4050 /**
4051 * Get the current signal strength information for the given subscription.
4052 * Because this information is not updated when the device is in a low power state
4053 * it should not be relied-upon to be current.
4054 * @param subId Subscription index
4055 * @return the most recent cached signal strength info from the modem
4056 */
4057 @Override
4058 public SignalStrength getSignalStrength(int subId) {
4059 Phone p = getPhone(subId);
4060 if (p == null) {
4061 return null;
4062 }
4063
4064 return p.getSignalStrength();
4065 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004066
4067 @Override
4068 public UiccSlotInfo[] getUiccSlotsInfo() {
4069 enforceReadPrivilegedPermission();
4070
4071 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4072 if (slots == null) return null;
4073 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4074 for (int i = 0; i < slots.length; i++) {
4075 UiccSlot slot = slots[i];
4076
4077 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4078
4079 int cardState = 0;
4080 switch (slot.getCardState()) {
4081 case CARDSTATE_ABSENT:
4082 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4083 break;
4084 case CARDSTATE_PRESENT:
4085 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4086 break;
4087 case CARDSTATE_ERROR:
4088 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4089 break;
4090 case CARDSTATE_RESTRICTED:
4091 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4092 break;
4093 default:
4094 break;
4095
4096 }
4097
Qingxi Li795c5882018-01-31 13:43:27 -08004098 infos[i] = new UiccSlotInfo(
4099 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004100 }
4101 return infos;
4102 }
4103
4104 @Override
4105 public boolean switchSlots(int[] physicalSlots) {
4106 enforceModifyPermission();
4107 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4108 }
Jack Yu4c988042018-02-27 15:30:01 -08004109
4110 @Override
4111 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4112 enforceModifyPermission();
4113 final Phone phone = getPhone(subId);
4114 if (phone == null) {
4115 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4116 return;
4117 }
4118
4119 phone.setRadioIndicationUpdateMode(filters, mode);
4120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004121}