blob: 3f658bbb2953b001f756162a10e7a22d16e4eab2 [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;
Brad Ebingerdac2f002018-04-03 15:17:52 -070045import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070046import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070048import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070049import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070050import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080051import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070052import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080053import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080054import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070055import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070056import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070059import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080060import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070061import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080062import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070063import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070064import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070065import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080067import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070068import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080069import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080070import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070071import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000073import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070074import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070075import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080076import android.telephony.ims.aidl.IImsConfig;
77import android.telephony.ims.aidl.IImsMmTelFeature;
78import android.telephony.ims.aidl.IImsRcsFeature;
79import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080080import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080082import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080083import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080086import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080087
Andrew Lee312e8172014-10-23 17:01:36 -070088import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080089import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070091import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070092import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070093import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070094import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080097import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -070098import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +010099import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700100import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700101import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800103import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700105import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700106import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700107import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700108import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700109import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800110import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800111import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700112import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700113import com.android.internal.telephony.uicc.IccIoResult;
114import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800115import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700116import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800117import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800119import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000120import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700121import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800122import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700123import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800124import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700125import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700126import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800127
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700128import java.io.FileDescriptor;
129import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800133import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100134import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800135import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136
137/**
138 * Implementation of the ITelephony interface.
139 */
Santos Cordon117fee72014-05-16 17:56:12 -0700140public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141 private static final String LOG_TAG = "PhoneInterfaceManager";
142 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
143 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800144 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145
146 // Message codes used with mMainThreadHandler
147 private static final int CMD_HANDLE_PIN_MMI = 1;
148 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
149 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
150 private static final int CMD_ANSWER_RINGING_CALL = 4;
151 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700152 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
153 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154 private static final int CMD_OPEN_CHANNEL = 9;
155 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
156 private static final int CMD_CLOSE_CHANNEL = 11;
157 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800158 private static final int CMD_NV_READ_ITEM = 13;
159 private static final int EVENT_NV_READ_ITEM_DONE = 14;
160 private static final int CMD_NV_WRITE_ITEM = 15;
161 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
162 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
163 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
164 private static final int CMD_NV_RESET_CONFIG = 19;
165 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800166 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
167 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
168 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
169 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800170 private static final int CMD_SEND_ENVELOPE = 25;
171 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000172 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
173 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700174 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
175 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
176 private static final int CMD_EXCHANGE_SIM_IO = 31;
177 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800178 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
179 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700180 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
181 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700182 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
183 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700184 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
185 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
186 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
187 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700188 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
189 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
190 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
191 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700192 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800193 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
194 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000195 private static final int CMD_SWITCH_SLOTS = 50;
196 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800198 // Parameters of select command.
199 private static final int SELECT_COMMAND = 0xA4;
200 private static final int SELECT_P1 = 0x04;
201 private static final int SELECT_P2 = 0;
202 private static final int SELECT_P3 = 0x10;
203
Pengquan Meng85728fb2018-03-12 16:31:21 -0700204 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
205 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
206 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
207
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 /** The singleton instance. */
209 private static PhoneInterfaceManager sInstance;
210
Wink Saville3ab207e2014-11-20 13:07:20 -0800211 private PhoneGlobals mApp;
212 private Phone mPhone;
213 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700214 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800215 private AppOpsManager mAppOps;
216 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800217 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800218 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219
Derek Tan97ebb422014-09-05 16:55:38 -0700220 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
221 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700223
Derek Tan740e1672017-06-27 14:56:27 -0700224 // The AID of ISD-R.
225 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
226
yinxub1bed742017-04-17 11:45:04 -0700227 private NetworkScanRequestTracker mNetworkScanRequestTracker;
228
David Kelly5e06a7f2018-03-12 14:10:59 +0000229 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
230 private static final int MANUFACTURER_CODE_LENGTH = 8;
231
Derek Tan89e89d42014-07-08 17:00:10 -0700232 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700233 * A request object to use for transmitting data to an ICC.
234 */
235 private static final class IccAPDUArgument {
236 public int channel, cla, command, p1, p2, p3;
237 public String data;
238
239 public IccAPDUArgument(int channel, int cla, int command,
240 int p1, int p2, int p3, String data) {
241 this.channel = channel;
242 this.cla = cla;
243 this.command = command;
244 this.p1 = p1;
245 this.p2 = p2;
246 this.p3 = p3;
247 this.data = data;
248 }
249 }
250
251 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700252 * A request object to use for transmitting data to an ICC.
253 */
254 private static final class ManualNetworkSelectionArgument {
255 public OperatorInfo operatorInfo;
256 public boolean persistSelection;
257
258 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
259 this.operatorInfo = operatorInfo;
260 this.persistSelection = persistSelection;
261 }
262 }
263
264 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
266 * request after sending. The main thread will notify the request when it is complete.
267 */
268 private static final class MainThreadRequest {
269 /** The argument to use for the request */
270 public Object argument;
271 /** The result of the request that is run on the main thread */
272 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800273 // The subscriber id that this request applies to. Defaults to
274 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
275 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276
277 public MainThreadRequest(Object argument) {
278 this.argument = argument;
279 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800280
281 public MainThreadRequest(Object argument, Integer subId) {
282 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800283 if (subId != null) {
284 this.subId = subId;
285 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287 }
288
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800289 private static final class IncomingThirdPartyCallArgs {
290 public final ComponentName component;
291 public final String callId;
292 public final String callerDisplayName;
293
294 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
295 String callerDisplayName) {
296 this.component = component;
297 this.callId = callId;
298 this.callerDisplayName = callerDisplayName;
299 }
300 }
301
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 /**
303 * A handler that processes messages on the main thread in the phone process. Since many
304 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
305 * inbound binder threads to the main thread in the phone process. The Binder thread
306 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
307 * on, which will be notified when the operation completes and will contain the result of the
308 * request.
309 *
310 * <p>If a MainThreadRequest object is provided in the msg.obj field,
311 * note that request.result must be set to something non-null for the calling thread to
312 * unblock.
313 */
314 private final class MainThreadHandler extends Handler {
315 @Override
316 public void handleMessage(Message msg) {
317 MainThreadRequest request;
318 Message onCompleted;
319 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800320 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700321 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322
323 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700324 case CMD_HANDLE_USSD_REQUEST: {
325 request = (MainThreadRequest) msg.obj;
326 final Phone phone = getPhoneFromRequest(request);
327 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
328 String ussdRequest = ussdObject.first;
329 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700330
331 if (!isUssdApiAllowed(request.subId)) {
332 // Carrier does not support use of this API, return failure.
333 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
334 UssdResponse response = new UssdResponse(ussdRequest, null);
335 Bundle returnData = new Bundle();
336 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
337 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
338
339 request.result = true;
340 synchronized (request) {
341 request.notifyAll();
342 }
343 return;
344 }
345
Tyler Gunn52dcf772017-04-26 11:30:31 -0700346 try {
347 request.result = phone != null ?
348 phone.handleUssdRequest(ussdRequest, wrappedCallback)
349 : false;
350 } catch (CallStateException cse) {
351 request.result = false;
352 }
pkanwar32d516d2016-10-14 19:37:38 -0700353 // Wake up the requesting thread
354 synchronized (request) {
355 request.notifyAll();
356 }
357 break;
358 }
359
Yorke Lee716f67e2015-06-17 15:39:16 -0700360 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700362 final Phone phone = getPhoneFromRequest(request);
363 request.result = phone != null ?
364 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
365 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 // Wake up the requesting thread
367 synchronized (request) {
368 request.notifyAll();
369 }
370 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
373 case CMD_HANDLE_NEIGHBORING_CELL:
374 request = (MainThreadRequest) msg.obj;
375 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
376 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700377 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 break;
379
380 case EVENT_NEIGHBORING_CELL_DONE:
381 ar = (AsyncResult) msg.obj;
382 request = (MainThreadRequest) ar.userObj;
383 if (ar.exception == null && ar.result != null) {
384 request.result = ar.result;
385 } else {
386 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800387 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 }
389 // Wake up the requesting thread
390 synchronized (request) {
391 request.notifyAll();
392 }
393 break;
394
395 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700396 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800397 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700398 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800399 request.result = ""; // dummy result for notifying the waiting thread
400 // Wake up the requesting thread
401 synchronized (request) {
402 request.notifyAll();
403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 break;
405
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 case CMD_END_CALL:
407 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800408 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700409 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700410 Phone phone = getPhone(end_subId);
411 if (phone == null) {
412 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
413 break;
414 }
415 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
417 // CDMA: If the user presses the Power button we treat it as
418 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700419 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
421 // GSM: End the call as per the Phone state
422 hungUp = PhoneUtils.hangup(mCM);
423 } else {
424 throw new IllegalStateException("Unexpected phone type: " + phoneType);
425 }
426 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
427 request.result = hungUp;
428 // Wake up the requesting thread
429 synchronized (request) {
430 request.notifyAll();
431 }
432 break;
433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800437 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700438 if (uiccCard == null) {
439 loge("iccTransmitApduLogicalChannel: No UICC");
440 request.result = new IccIoResult(0x6F, 0, (byte[])null);
441 synchronized (request) {
442 request.notifyAll();
443 }
444 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
446 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700447 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 iccArgument.channel, iccArgument.cla, iccArgument.command,
449 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700451 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 break;
453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 ar = (AsyncResult) msg.obj;
456 request = (MainThreadRequest) ar.userObj;
457 if (ar.exception == null && ar.result != null) {
458 request.result = ar.result;
459 } else {
460 request.result = new IccIoResult(0x6F, 0, (byte[])null);
461 if (ar.result == null) {
462 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800463 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800465 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 } else {
467 loge("iccTransmitApduLogicalChannel: Unknown exception");
468 }
469 }
470 synchronized (request) {
471 request.notifyAll();
472 }
473 break;
474
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
476 request = (MainThreadRequest) msg.obj;
477 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800478 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 if (uiccCard == null) {
480 loge("iccTransmitApduBasicChannel: No UICC");
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
482 synchronized (request) {
483 request.notifyAll();
484 }
485 } else {
486 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
487 request);
488 uiccCard.iccTransmitApduBasicChannel(
489 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
490 iccArgument.p3, iccArgument.data, onCompleted);
491 }
492 break;
493
494 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
495 ar = (AsyncResult) msg.obj;
496 request = (MainThreadRequest) ar.userObj;
497 if (ar.exception == null && ar.result != null) {
498 request.result = ar.result;
499 } else {
500 request.result = new IccIoResult(0x6F, 0, (byte[])null);
501 if (ar.result == null) {
502 loge("iccTransmitApduBasicChannel: Empty response");
503 } else if (ar.exception instanceof CommandException) {
504 loge("iccTransmitApduBasicChannel: CommandException: " +
505 ar.exception);
506 } else {
507 loge("iccTransmitApduBasicChannel: Unknown exception");
508 }
509 }
510 synchronized (request) {
511 request.notifyAll();
512 }
513 break;
514
515 case CMD_EXCHANGE_SIM_IO:
516 request = (MainThreadRequest) msg.obj;
517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 if (uiccCard == null) {
520 loge("iccExchangeSimIO: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
522 synchronized (request) {
523 request.notifyAll();
524 }
525 } else {
526 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
527 request);
528 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
529 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
530 iccArgument.data, onCompleted);
531 }
532 break;
533
534 case EVENT_EXCHANGE_SIM_IO_DONE:
535 ar = (AsyncResult) msg.obj;
536 request = (MainThreadRequest) ar.userObj;
537 if (ar.exception == null && ar.result != null) {
538 request.result = ar.result;
539 } else {
540 request.result = new IccIoResult(0x6f, 0, (byte[])null);
541 }
542 synchronized (request) {
543 request.notifyAll();
544 }
545 break;
546
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 case CMD_SEND_ENVELOPE:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("sendEnvelopeWithStatus: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
553 synchronized (request) {
554 request.notifyAll();
555 }
556 } else {
557 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
558 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
559 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 break;
561
562 case EVENT_SEND_ENVELOPE_DONE:
563 ar = (AsyncResult) msg.obj;
564 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700565 if (ar.exception == null && ar.result != null) {
566 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800567 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
569 if (ar.result == null) {
570 loge("sendEnvelopeWithStatus: Empty response");
571 } else if (ar.exception instanceof CommandException) {
572 loge("sendEnvelopeWithStatus: CommandException: " +
573 ar.exception);
574 } else {
575 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
576 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 }
578 synchronized (request) {
579 request.notifyAll();
580 }
581 break;
582
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 case CMD_OPEN_CHANNEL:
584 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800585 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800586 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 if (uiccCard == null) {
588 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800589 request.result = new IccOpenLogicalChannelResponse(-1,
590 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 synchronized (request) {
592 request.notifyAll();
593 }
594 } else {
595 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800596 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
597 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 break;
600
601 case EVENT_OPEN_CHANNEL_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 int[] result = (int[]) ar.result;
607 int channelId = result[0];
608 byte[] selectResponse = null;
609 if (result.length > 1) {
610 selectResponse = new byte[result.length - 1];
611 for (int i = 1; i < result.length; ++i) {
612 selectResponse[i - 1] = (byte) result[i];
613 }
614 }
615 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700616 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 if (ar.result == null) {
619 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 if (ar.exception != null) {
622 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
623 }
624
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700626 if (ar.exception instanceof CommandException) {
627 CommandException.Error error =
628 ((CommandException) (ar.exception)).getCommandError();
629 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700630 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700631 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700632 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 }
634 }
635 openChannelResp = new IccOpenLogicalChannelResponse(
636 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700638 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 synchronized (request) {
640 request.notifyAll();
641 }
642 break;
643
644 case CMD_CLOSE_CHANNEL:
645 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800646 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 if (uiccCard == null) {
648 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900649 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 synchronized (request) {
651 request.notifyAll();
652 }
653 } else {
654 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
655 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
656 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 break;
658
659 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800660 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
661 break;
662
663 case CMD_NV_READ_ITEM:
664 request = (MainThreadRequest) msg.obj;
665 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
666 mPhone.nvReadItem((Integer) request.argument, onCompleted);
667 break;
668
669 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 ar = (AsyncResult) msg.obj;
671 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800672 if (ar.exception == null && ar.result != null) {
673 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800675 request.result = "";
676 if (ar.result == null) {
677 loge("nvReadItem: Empty response");
678 } else if (ar.exception instanceof CommandException) {
679 loge("nvReadItem: CommandException: " +
680 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800682 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 }
684 }
685 synchronized (request) {
686 request.notifyAll();
687 }
688 break;
689
Jake Hambye994d462014-02-03 13:10:13 -0800690 case CMD_NV_WRITE_ITEM:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
693 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
694 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
695 break;
696
697 case EVENT_NV_WRITE_ITEM_DONE:
698 handleNullReturnEvent(msg, "nvWriteItem");
699 break;
700
701 case CMD_NV_WRITE_CDMA_PRL:
702 request = (MainThreadRequest) msg.obj;
703 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
704 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
705 break;
706
707 case EVENT_NV_WRITE_CDMA_PRL_DONE:
708 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
709 break;
710
711 case CMD_NV_RESET_CONFIG:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
714 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
715 break;
716
717 case EVENT_NV_RESET_CONFIG_DONE:
718 handleNullReturnEvent(msg, "nvResetConfig");
719 break;
720
Jake Hamby7c27be32014-03-03 13:25:59 -0800721 case CMD_GET_PREFERRED_NETWORK_TYPE:
722 request = (MainThreadRequest) msg.obj;
723 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700724 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 break;
726
727 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
728 ar = (AsyncResult) msg.obj;
729 request = (MainThreadRequest) ar.userObj;
730 if (ar.exception == null && ar.result != null) {
731 request.result = ar.result; // Integer
732 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800733 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 if (ar.result == null) {
735 loge("getPreferredNetworkType: Empty response");
736 } else if (ar.exception instanceof CommandException) {
737 loge("getPreferredNetworkType: CommandException: " +
738 ar.exception);
739 } else {
740 loge("getPreferredNetworkType: Unknown exception");
741 }
742 }
743 synchronized (request) {
744 request.notifyAll();
745 }
746 break;
747
748 case CMD_SET_PREFERRED_NETWORK_TYPE:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
751 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700752 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 break;
754
755 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
756 handleNullReturnEvent(msg, "setPreferredNetworkType");
757 break;
758
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
760 request = (MainThreadRequest)msg.obj;
761 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
762 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
763 break;
764
765 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
766 ar = (AsyncResult)msg.obj;
767 request = (MainThreadRequest)ar.userObj;
768 request.result = ar;
769 synchronized (request) {
770 request.notifyAll();
771 }
772 break;
773
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800774 case CMD_SET_VOICEMAIL_NUMBER:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
777 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800778 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
779 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800780 break;
781
782 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
783 handleNullReturnEvent(msg, "setVoicemailNumber");
784 break;
785
Stuart Scott54788802015-03-30 13:18:01 -0700786 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
789 request);
790 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
791 break;
792
793 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
794 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
795 break;
796
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 case CMD_PERFORM_NETWORK_SCAN:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
800 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
801 break;
802
803 case EVENT_PERFORM_NETWORK_SCAN_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 CellNetworkScanResult cellScanResult;
807 if (ar.exception == null && ar.result != null) {
808 cellScanResult = new CellNetworkScanResult(
809 CellNetworkScanResult.STATUS_SUCCESS,
810 (List<OperatorInfo>) ar.result);
811 } else {
812 if (ar.result == null) {
813 loge("getCellNetworkScanResults: Empty response");
814 }
815 if (ar.exception != null) {
816 loge("getCellNetworkScanResults: Exception: " + ar.exception);
817 }
818 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
819 if (ar.exception instanceof CommandException) {
820 CommandException.Error error =
821 ((CommandException) (ar.exception)).getCommandError();
822 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
824 } else if (error == CommandException.Error.GENERIC_FAILURE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
826 }
827 }
828 cellScanResult = new CellNetworkScanResult(errorCode, null);
829 }
830 request.result = cellScanResult;
831 synchronized (request) {
832 request.notifyAll();
833 }
834 break;
835
836 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
837 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 ManualNetworkSelectionArgument selArg =
839 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
841 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700842 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
843 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
846 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
847 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
848 break;
849
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700850 case CMD_GET_MODEM_ACTIVITY_INFO:
851 request = (MainThreadRequest) msg.obj;
852 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700853 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700854 break;
855
856 case EVENT_GET_MODEM_ACTIVITY_INFO_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("queryModemActivityInfo: Empty response");
864 } else if (ar.exception instanceof CommandException) {
865 loge("queryModemActivityInfo: CommandException: " +
866 ar.exception);
867 } else {
868 loge("queryModemActivityInfo: Unknown exception");
869 }
870 }
Amit Mahajand4766222016-01-28 15:28:28 -0800871 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
872 if (request.result == null) {
873 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
874 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700875 synchronized (request) {
876 request.notifyAll();
877 }
878 break;
879
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 case CMD_SET_ALLOWED_CARRIERS:
881 request = (MainThreadRequest) msg.obj;
882 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
883 mPhone.setAllowedCarriers(
884 (List<CarrierIdentifier>) request.argument,
885 onCompleted);
886 break;
887
888 case EVENT_SET_ALLOWED_CARRIERS_DONE:
889 ar = (AsyncResult) msg.obj;
890 request = (MainThreadRequest) ar.userObj;
891 if (ar.exception == null && ar.result != null) {
892 request.result = ar.result;
893 } else {
894 if (ar.result == null) {
895 loge("setAllowedCarriers: Empty response");
896 } else if (ar.exception instanceof CommandException) {
897 loge("setAllowedCarriers: CommandException: " +
898 ar.exception);
899 } else {
900 loge("setAllowedCarriers: Unknown exception");
901 }
902 }
903 // Result cannot be null. Return -1 on error.
904 if (request.result == null) {
905 request.result = new int[]{-1};
906 }
907 synchronized (request) {
908 request.notifyAll();
909 }
910 break;
911
912 case CMD_GET_ALLOWED_CARRIERS:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
915 mPhone.getAllowedCarriers(onCompleted);
916 break;
917
918 case EVENT_GET_ALLOWED_CARRIERS_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 if (ar.exception == null && ar.result != null) {
922 request.result = ar.result;
923 } else {
924 if (ar.result == null) {
925 loge("getAllowedCarriers: Empty response");
926 } else if (ar.exception instanceof CommandException) {
927 loge("getAllowedCarriers: CommandException: " +
928 ar.exception);
929 } else {
930 loge("getAllowedCarriers: Unknown exception");
931 }
932 }
933 // Result cannot be null. Return empty list of CarrierIdentifier.
934 if (request.result == null) {
935 request.result = new ArrayList<CarrierIdentifier>(0);
936 }
937 synchronized (request) {
938 request.notifyAll();
939 }
940 break;
941
Nathan Haroldb3014052017-01-25 15:57:32 -0800942 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 request.result = new IllegalArgumentException(
949 "Failed to retrieve Forbidden Plmns");
950 if (ar.result == null) {
951 loge("getForbiddenPlmns: Empty response");
952 } else {
953 loge("getForbiddenPlmns: Unknown exception");
954 }
955 }
956 synchronized (request) {
957 request.notifyAll();
958 }
959 break;
960
961 case CMD_GET_FORBIDDEN_PLMNS:
962 request = (MainThreadRequest) msg.obj;
963 uiccCard = getUiccCardFromRequest(request);
964 if (uiccCard == null) {
965 loge("getForbiddenPlmns() UiccCard is null");
966 request.result = new IllegalArgumentException(
967 "getForbiddenPlmns() UiccCard is null");
968 synchronized (request) {
969 request.notifyAll();
970 }
971 break;
972 }
973 Integer appType = (Integer) request.argument;
974 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
975 if (uiccApp == null) {
976 loge("getForbiddenPlmns() no app with specified type -- "
977 + appType);
978 request.result = new IllegalArgumentException("Failed to get UICC App");
979 synchronized (request) {
980 request.notifyAll();
981 }
982 break;
983 } else {
984 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
985 + " specified type -- " + appType);
986 }
987 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
988 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
989 onCompleted);
990 break;
991
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000992 case CMD_SWITCH_SLOTS:
993 request = (MainThreadRequest) msg.obj;
994 int[] physicalSlots = (int[]) request.argument;
995 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
996 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
997 break;
998
999 case EVENT_SWITCH_SLOTS_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 request.result = (ar.exception == null);
1003 synchronized (request) {
1004 request.notifyAll();
1005 }
1006 break;
1007
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001008 default:
1009 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1010 break;
1011 }
1012 }
Jake Hambye994d462014-02-03 13:10:13 -08001013
1014 private void handleNullReturnEvent(Message msg, String command) {
1015 AsyncResult ar = (AsyncResult) msg.obj;
1016 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1017 if (ar.exception == null) {
1018 request.result = true;
1019 } else {
1020 request.result = false;
1021 if (ar.exception instanceof CommandException) {
1022 loge(command + ": CommandException: " + ar.exception);
1023 } else {
1024 loge(command + ": Unknown exception");
1025 }
1026 }
1027 synchronized (request) {
1028 request.notifyAll();
1029 }
1030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001031 }
1032
1033 /**
1034 * Posts the specified command to be executed on the main thread,
1035 * waits for the request to complete, and returns the result.
1036 * @see #sendRequestAsync
1037 */
1038 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001039 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001040 }
1041
1042 /**
1043 * Posts the specified command to be executed on the main thread,
1044 * waits for the request to complete, and returns the result.
1045 * @see #sendRequestAsync
1046 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001047 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001048 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1049 throw new RuntimeException("This method will deadlock if called from the main thread.");
1050 }
1051
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001052 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001053 Message msg = mMainThreadHandler.obtainMessage(command, request);
1054 msg.sendToTarget();
1055
1056 // Wait for the request to complete
1057 synchronized (request) {
1058 while (request.result == null) {
1059 try {
1060 request.wait();
1061 } catch (InterruptedException e) {
1062 // Do nothing, go back and wait until the request is complete
1063 }
1064 }
1065 }
1066 return request.result;
1067 }
1068
1069 /**
1070 * Asynchronous ("fire and forget") version of sendRequest():
1071 * Posts the specified command to be executed on the main thread, and
1072 * returns immediately.
1073 * @see #sendRequest
1074 */
1075 private void sendRequestAsync(int command) {
1076 mMainThreadHandler.sendEmptyMessage(command);
1077 }
1078
1079 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001080 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1081 * @see {@link #sendRequest(int,Object)}
1082 */
1083 private void sendRequestAsync(int command, Object argument) {
1084 MainThreadRequest request = new MainThreadRequest(argument);
1085 Message msg = mMainThreadHandler.obtainMessage(command, request);
1086 msg.sendToTarget();
1087 }
1088
1089 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 * Initialize the singleton PhoneInterfaceManager instance.
1091 * This is only done once, at startup, from PhoneApp.onCreate().
1092 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001093 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001094 synchronized (PhoneInterfaceManager.class) {
1095 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001096 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001097 } else {
1098 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1099 }
1100 return sInstance;
1101 }
1102 }
1103
1104 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001105 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001106 mApp = app;
1107 mPhone = phone;
1108 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001109 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1111 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001112 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001113 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001114 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001115 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001116
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001117 publish();
1118 }
1119
1120 private void publish() {
1121 if (DBG) log("publish: " + this);
1122
1123 ServiceManager.addService("phone", this);
1124 }
1125
Stuart Scott584921c2015-01-15 17:10:34 -08001126 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001127 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1128 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001129 }
1130
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001131 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1132 Phone phone = getPhoneFromRequest(request);
1133 return phone == null ? null :
1134 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1135 }
1136
Wink Saville36469e72014-06-11 15:17:00 -07001137 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001138 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001139 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 //
1142 // Implementation of the ITelephony interface.
1143 //
1144
1145 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001146 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001147 }
1148
Wink Savilleb564aae2014-10-23 10:18:09 -07001149 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 if (DBG) log("dial: " + number);
1151 // No permission check needed here: This is just a wrapper around the
1152 // ACTION_DIAL intent, which is available to any app since it puts up
1153 // the UI before it does anything.
1154
1155 String url = createTelUrl(number);
1156 if (url == null) {
1157 return;
1158 }
1159
1160 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001161 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1163 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1164 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1165 mApp.startActivity(intent);
1166 }
1167 }
1168
1169 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001170 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001171 }
1172
Wink Savilleb564aae2014-10-23 10:18:09 -07001173 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 if (DBG) log("call: " + number);
1175
1176 // This is just a wrapper around the ACTION_CALL intent, but we still
1177 // need to do a permission check since we're calling startActivity()
1178 // from the context of the phone app.
1179 enforceCallPermission();
1180
1181 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1182 != AppOpsManager.MODE_ALLOWED) {
1183 return;
1184 }
1185
1186 String url = createTelUrl(number);
1187 if (url == null) {
1188 return;
1189 }
1190
Wink Saville08874612014-08-31 19:19:58 -07001191 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001192 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001193 if (slist != null) {
1194 for (SubscriptionInfo subInfoRecord : slist) {
1195 if (subInfoRecord.getSubscriptionId() == subId) {
1196 isValid = true;
1197 break;
1198 }
Wink Saville08874612014-08-31 19:19:58 -07001199 }
1200 }
1201 if (isValid == false) {
1202 return;
1203 }
1204
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001206 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1208 mApp.startActivity(intent);
1209 }
1210
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001211 /**
1212 * End a call based on call state
1213 * @return true is a call was ended
1214 */
1215 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001216 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001217 }
1218
1219 /**
1220 * End a call based on the call state of the subId
1221 * @return true is a call was ended
1222 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001223 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001224 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1225 != PackageManager.PERMISSION_GRANTED) {
1226 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1227 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1228 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1229 }
Stuart Scott584921c2015-01-15 17:10:34 -08001230 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 }
1232
1233 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001234 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001235 }
1236
Wink Savilleb564aae2014-10-23 10:18:09 -07001237 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001238 if (DBG) log("answerRingingCall...");
1239 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1240 // but that can probably wait till the big TelephonyManager API overhaul.
1241 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1242 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001243 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 }
1245
1246 /**
1247 * Make the actual telephony calls to implement answerRingingCall().
1248 * This should only be called from the main thread of the Phone app.
1249 * @see #answerRingingCall
1250 *
1251 * TODO: it would be nice to return true if we answered the call, or
1252 * false if there wasn't actually a ringing incoming call, or some
1253 * other error occurred. (In other words, pass back the return value
1254 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1255 * But that would require calling this method via sendRequest() rather
1256 * than sendRequestAsync(), and right now we don't actually *need* that
1257 * return value, so let's just return void for now.
1258 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001259 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001260 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001262 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1263 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 if (hasActiveCall && hasHoldingCall) {
1265 // Both lines are in use!
1266 // TODO: provide a flag to let the caller specify what
1267 // policy to use if both lines are in use. (The current
1268 // behavior is hardwired to "answer incoming, end ongoing",
1269 // which is how the CALL button is specced to behave.)
1270 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1271 return;
1272 } else {
1273 // answerCall() will automatically hold the current active
1274 // call, if there is one.
1275 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1276 return;
1277 }
1278 } else {
1279 // No call was ringing.
1280 return;
1281 }
1282 }
1283
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001285 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001287 public void silenceRinger() {
1288 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001289 }
1290
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001291 @Override
1292 public boolean isOffhook(String callingPackage) {
1293 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001294 }
1295
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001296 @Override
1297 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001299 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001300 return false;
1301 }
1302
Sanket Padawe356d7632015-06-22 14:03:32 -07001303 final Phone phone = getPhone(subId);
1304 if (phone != null) {
1305 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1306 } else {
1307 return false;
1308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 }
1310
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001311 @Override
1312 public boolean isRinging(String callingPackage) {
1313 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001316 @Override
1317 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001318 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001319 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001320 return false;
1321 }
1322
Sanket Padawe356d7632015-06-22 14:03:32 -07001323 final Phone phone = getPhone(subId);
1324 if (phone != null) {
1325 return (phone.getState() == PhoneConstants.State.RINGING);
1326 } else {
1327 return false;
1328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 }
1330
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001331 @Override
1332 public boolean isIdle(String callingPackage) {
1333 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001334 }
1335
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001336 @Override
1337 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001339 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001340 return false;
1341 }
1342
Sanket Padawe356d7632015-06-22 14:03:32 -07001343 final Phone phone = getPhone(subId);
1344 if (phone != null) {
1345 return (phone.getState() == PhoneConstants.State.IDLE);
1346 } else {
1347 return false;
1348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 }
1350
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001352 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001353 }
1354
Wink Savilleb564aae2014-10-23 10:18:09 -07001355 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001357 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1358 }
1359
1360 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001361 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001362 }
1363
Wink Savilleb564aae2014-10-23 10:18:09 -07001364 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001365 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001366 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1367 }
1368
1369 /** {@hide} */
1370 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001371 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
1373
Wink Savilleb564aae2014-10-23 10:18:09 -07001374 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001376 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 checkSimPin.start();
1378 return checkSimPin.unlockSim(null, pin);
1379 }
1380
Wink Saville9de0f752013-10-22 19:04:03 -07001381 /** {@hide} */
1382 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001383 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001384 }
1385
Wink Savilleb564aae2014-10-23 10:18:09 -07001386 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001388 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389 checkSimPuk.start();
1390 return checkSimPuk.unlockSim(puk, pin);
1391 }
1392
1393 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001394 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 * a synchronous one.
1396 */
1397 private static class UnlockSim extends Thread {
1398
1399 private final IccCard mSimCard;
1400
1401 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001402 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1403 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404
1405 // For replies from SimCard interface
1406 private Handler mHandler;
1407
1408 // For async handler to identify request type
1409 private static final int SUPPLY_PIN_COMPLETE = 100;
1410
1411 public UnlockSim(IccCard simCard) {
1412 mSimCard = simCard;
1413 }
1414
1415 @Override
1416 public void run() {
1417 Looper.prepare();
1418 synchronized (UnlockSim.this) {
1419 mHandler = new Handler() {
1420 @Override
1421 public void handleMessage(Message msg) {
1422 AsyncResult ar = (AsyncResult) msg.obj;
1423 switch (msg.what) {
1424 case SUPPLY_PIN_COMPLETE:
1425 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1426 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001427 mRetryCount = msg.arg1;
1428 if (ar.exception != null) {
1429 if (ar.exception instanceof CommandException &&
1430 ((CommandException)(ar.exception)).getCommandError()
1431 == CommandException.Error.PASSWORD_INCORRECT) {
1432 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1433 } else {
1434 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1435 }
1436 } else {
1437 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439 mDone = true;
1440 UnlockSim.this.notifyAll();
1441 }
1442 break;
1443 }
1444 }
1445 };
1446 UnlockSim.this.notifyAll();
1447 }
1448 Looper.loop();
1449 }
1450
1451 /*
1452 * Use PIN or PUK to unlock SIM card
1453 *
1454 * If PUK is null, unlock SIM card with PIN
1455 *
1456 * If PUK is not null, unlock SIM card with PUK and set PIN code
1457 */
Wink Saville9de0f752013-10-22 19:04:03 -07001458 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459
1460 while (mHandler == null) {
1461 try {
1462 wait();
1463 } catch (InterruptedException e) {
1464 Thread.currentThread().interrupt();
1465 }
1466 }
1467 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1468
1469 if (puk == null) {
1470 mSimCard.supplyPin(pin, callback);
1471 } else {
1472 mSimCard.supplyPuk(puk, pin, callback);
1473 }
1474
1475 while (!mDone) {
1476 try {
1477 Log.d(LOG_TAG, "wait for done");
1478 wait();
1479 } catch (InterruptedException e) {
1480 // Restore the interrupted status
1481 Thread.currentThread().interrupt();
1482 }
1483 }
1484 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001485 int[] resultArray = new int[2];
1486 resultArray[0] = mResult;
1487 resultArray[1] = mRetryCount;
1488 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 }
1490 }
1491
1492 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001493 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001494
1495 }
1496
Wink Savilleb564aae2014-10-23 10:18:09 -07001497 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 // No permission check needed here: this call is harmless, and it's
1499 // needed for the ServiceState.requestStateUpdate() call (which is
1500 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001501 final Phone phone = getPhone(subId);
1502 if (phone != null) {
1503 phone.updateServiceLocation();
1504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 }
1506
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001507 @Override
1508 public boolean isRadioOn(String callingPackage) {
1509 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001510 }
1511
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001512 @Override
1513 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001515 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001516 return false;
1517 }
1518 return isRadioOnForSubscriber(subId);
1519 }
1520
1521 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001522 final Phone phone = getPhone(subId);
1523 if (phone != null) {
1524 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1525 } else {
1526 return false;
1527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 }
1529
1530 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001531 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001532
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 }
Wink Saville36469e72014-06-11 15:17:00 -07001534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001537 final Phone phone = getPhone(subId);
1538 if (phone != null) {
1539 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1540 }
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
1543 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001544 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001545 }
1546
Wink Savilleb564aae2014-10-23 10:18:09 -07001547 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001548 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001549 final Phone phone = getPhone(subId);
1550 if (phone == null) {
1551 return false;
1552 }
1553 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001554 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001555 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557 return true;
1558 }
Wink Saville36469e72014-06-11 15:17:00 -07001559
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001560 public boolean needMobileRadioShutdown() {
1561 /*
1562 * If any of the Radios are available, it will need to be
1563 * shutdown. So return true if any Radio is available.
1564 */
1565 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1566 Phone phone = PhoneFactory.getPhone(i);
1567 if (phone != null && phone.isRadioAvailable()) return true;
1568 }
1569 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1570 return false;
1571 }
1572
1573 public void shutdownMobileRadios() {
1574 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1575 logv("Shutting down Phone " + i);
1576 shutdownRadioUsingPhoneId(i);
1577 }
1578 }
1579
1580 private void shutdownRadioUsingPhoneId(int phoneId) {
1581 enforceModifyPermission();
1582 Phone phone = PhoneFactory.getPhone(phoneId);
1583 if (phone != null && phone.isRadioAvailable()) {
1584 phone.shutdownRadio();
1585 }
1586 }
1587
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001589 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001590 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1591 if (defaultPhone != null) {
1592 defaultPhone.setRadioPower(turnOn);
1593 return true;
1594 } else {
1595 loge("There's no default phone.");
1596 return false;
1597 }
Wink Saville36469e72014-06-11 15:17:00 -07001598 }
1599
Wink Savilleb564aae2014-10-23 10:18:09 -07001600 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001602 final Phone phone = getPhone(subId);
1603 if (phone != null) {
1604 phone.setRadioPower(turnOn);
1605 return true;
1606 } else {
1607 return false;
1608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 }
1610
Wink Saville36469e72014-06-11 15:17:00 -07001611 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 public boolean enableDataConnectivity() {
1614 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001615 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 final Phone phone = getPhone(subId);
1617 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001618 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 return true;
1620 } else {
1621 return false;
1622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 }
1624
Wink Saville36469e72014-06-11 15:17:00 -07001625 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001626 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 public boolean disableDataConnectivity() {
1628 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001629 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 final Phone phone = getPhone(subId);
1631 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001632 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001633 return true;
1634 } else {
1635 return false;
1636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 }
1638
Sanket Padawe356d7632015-06-22 14:03:32 -07001639 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001640 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001641 final Phone phone = getPhone(subId);
1642 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001643 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001644 } else {
1645 return false;
1646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 }
1648
1649 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001650 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001651 }
1652
pkanwarae03a6b2016-11-06 20:37:09 -08001653 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001654 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001655 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1656 return;
1657 }
1658 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1659 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1660 };
1661
Wink Savilleb564aae2014-10-23 10:18:09 -07001662 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001664 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1665 return false;
1666 }
Wink Saville36469e72014-06-11 15:17:00 -07001667 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 }
1669
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001671 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001674 public int getCallStateForSlot(int slotIndex) {
1675 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001676 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001677 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 }
1679
Sanket Padawe356d7632015-06-22 14:03:32 -07001680 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001682 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001683 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001684 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001686 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 }
1689
Sanket Padawe356d7632015-06-22 14:03:32 -07001690 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001692 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 if (phone != null) {
1694 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1695 } else {
1696 return TelephonyManager.DATA_ACTIVITY_NONE;
1697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 }
1699
1700 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001701 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001702 mPhone.getContext().getSystemService(AppOpsManager.class)
1703 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001704 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001705 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001706 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
1708
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001709 if (DBG_LOC) log("getCellLocation: is active user");
1710 Bundle data = new Bundle();
1711 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1712 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 return null;
1714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001716 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001717 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1718 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001719 }
1720
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001722 public String getNetworkCountryIsoForPhone(int phoneId) {
1723 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1724 // registered cell info, so return a NULL country instead.
1725 final long identity = Binder.clearCallingIdentity();
1726 try {
1727 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001728 // Todo: fix this when we can get the actual cellular network info when the device
1729 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001730 if (TelephonyManager.NETWORK_TYPE_IWLAN
1731 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1732 return "";
1733 }
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
1736 }
Jack Yu5f7092c2018-04-13 14:05:37 -07001737
1738 Phone phone = PhoneFactory.getPhone(phoneId);
1739 if (phone != null) {
1740 ServiceStateTracker sst = phone.getServiceStateTracker();
1741 if (sst != null) {
1742 LocaleTracker lt = sst.getLocaleTracker();
1743 if (lt != null) {
1744 return lt.getCurrentCountry();
1745 }
1746 }
1747 }
1748 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001749 }
1750
1751 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001753 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001754 }
1755
Sanket Padawe356d7632015-06-22 14:03:32 -07001756 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001757 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 mApp.enforceCallingOrSelfPermission(
1759 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
1762 phone.enableLocationUpdates();
1763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 }
1765
1766 @Override
1767 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001768 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001769 }
1770
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001772 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 mApp.enforceCallingOrSelfPermission(
1774 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001775 final Phone phone = getPhone(subId);
1776 if (phone != null) {
1777 phone.disableLocationUpdates();
1778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 }
1780
1781 @Override
1782 @SuppressWarnings("unchecked")
1783 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001784 mPhone.getContext().getSystemService(AppOpsManager.class)
1785 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001786 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001787 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001788 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
1791 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1792 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1793 return null;
1794 }
Svetoslav64fad262015-04-14 14:35:21 -07001795
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001796 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001798 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001800 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001801 try {
1802 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1803 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1804 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1805 } catch (RuntimeException e) {
1806 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001808 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
1811
1812 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001813 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001814 mPhone.getContext().getSystemService(AppOpsManager.class)
1815 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001816 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001817 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001818 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 }
1820
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001821 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001822 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001823 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1824 for (Phone phone : PhoneFactory.getPhones()) {
1825 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1826 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001828 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 }
1830
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001831 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001833 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001834 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001835 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 }
1837
Shishir Agrawala9f32182016-04-12 12:00:16 -07001838 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001839 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001840 Phone phone = PhoneFactory.getPhone(slotIndex);
1841 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001842 return null;
1843 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001844 int subId = phone.getSubId();
1845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1846 mApp, subId, callingPackage, "getImeiForSlot")) {
1847 return null;
1848 }
1849 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001850 }
1851
1852 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001853 public String getTypeAllocationCodeForSlot(int slotIndex) {
1854 Phone phone = PhoneFactory.getPhone(slotIndex);
1855 String tac = null;
1856 if (phone != null) {
1857 String imei = phone.getImei();
1858 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1859 }
1860 return tac;
1861 }
1862
1863 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001864 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001865 Phone phone = PhoneFactory.getPhone(slotIndex);
1866 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001867 return null;
1868 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001869 int subId = phone.getSubId();
1870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1871 mApp, subId, callingPackage, "getMeidForSlot")) {
1872 return null;
1873 }
1874 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001875 }
1876
1877 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001878 public String getManufacturerCodeForSlot(int slotIndex) {
1879 Phone phone = PhoneFactory.getPhone(slotIndex);
1880 String manufacturerCode = null;
1881 if (phone != null) {
1882 String meid = phone.getMeid();
1883 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1884 }
1885 return manufacturerCode;
1886 }
1887
1888 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001889 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001890 Phone phone = PhoneFactory.getPhone(slotIndex);
1891 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001892 return null;
1893 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001894 int subId = phone.getSubId();
1895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1896 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1897 return null;
1898 }
1899 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001900 }
1901
fionaxu43304da2017-11-27 22:51:16 -08001902 @Override
1903 public int getSubscriptionCarrierId(int subId) {
1904 final Phone phone = getPhone(subId);
1905 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1906 }
1907
1908 @Override
1909 public String getSubscriptionCarrierName(int subId) {
1910 final Phone phone = getPhone(subId);
1911 return phone == null ? null : phone.getCarrierName();
1912 }
1913
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 //
1915 // Internal helper methods.
1916 //
1917
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001918 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1920 *
1921 * @throws SecurityException if the caller does not have the required permission
1922 */
1923 private void enforceModifyPermission() {
1924 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1925 }
1926
1927 /**
1928 * Make sure the caller has the CALL_PHONE permission.
1929 *
1930 * @throws SecurityException if the caller does not have the required permission
1931 */
1932 private void enforceCallPermission() {
1933 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1934 }
1935
Stuart Scott8eef64f2015-04-08 15:13:54 -07001936 private void enforceConnectivityInternalPermission() {
1937 mApp.enforceCallingOrSelfPermission(
1938 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1939 "ConnectivityService");
1940 }
1941
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 private String createTelUrl(String number) {
1943 if (TextUtils.isEmpty(number)) {
1944 return null;
1945 }
1946
Jake Hambye994d462014-02-03 13:10:13 -08001947 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 }
1949
Ihab Awadf9e92732013-12-05 18:02:52 -08001950 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1952 }
1953
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001954 private static void logv(String msg) {
1955 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1956 }
1957
Ihab Awadf9e92732013-12-05 18:02:52 -08001958 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1960 }
1961
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001962 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001964 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001965 }
1966
Sanket Padawe356d7632015-06-22 14:03:32 -07001967 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001968 public int getActivePhoneTypeForSlot(int slotIndex) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00001969 final Phone phone = PhoneFactory.getPhone(slotIndex);
1970 if (phone == null) {
1971 return PhoneConstants.PHONE_TYPE_NONE;
1972 } else {
1973 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 }
1976
1977 /**
1978 * Returns the CDMA ERI icon index to display
1979 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001980 @Override
1981 public int getCdmaEriIconIndex(String callingPackage) {
1982 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001983 }
1984
Sanket Padawe356d7632015-06-22 14:03:32 -07001985 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001986 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001988 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001989 return -1;
1990 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 final Phone phone = getPhone(subId);
1992 if (phone != null) {
1993 return phone.getCdmaEriIconIndex();
1994 } else {
1995 return -1;
1996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
1999 /**
2000 * Returns the CDMA ERI icon mode,
2001 * 0 - ON
2002 * 1 - FLASHING
2003 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002004 @Override
2005 public int getCdmaEriIconMode(String callingPackage) {
2006 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002007 }
2008
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002010 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002012 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002013 return -1;
2014 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002015 final Phone phone = getPhone(subId);
2016 if (phone != null) {
2017 return phone.getCdmaEriIconMode();
2018 } else {
2019 return -1;
2020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 }
2022
2023 /**
2024 * Returns the CDMA ERI text,
2025 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002026 @Override
2027 public String getCdmaEriText(String callingPackage) {
2028 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002029 }
2030
Sanket Padawe356d7632015-06-22 14:03:32 -07002031 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002032 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002033 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002034 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002035 return null;
2036 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002037 final Phone phone = getPhone(subId);
2038 if (phone != null) {
2039 return phone.getCdmaEriText();
2040 } else {
2041 return null;
2042 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043 }
2044
2045 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002046 * Returns the CDMA MDN.
2047 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002048 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002049 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2051 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07002052 final Phone phone = getPhone(subId);
2053 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2054 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002055 } else {
2056 return null;
2057 }
2058 }
2059
2060 /**
2061 * Returns the CDMA MIN.
2062 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002063 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002064 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2066 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002067 final Phone phone = getPhone(subId);
2068 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2069 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002070 } else {
2071 return null;
2072 }
2073 }
2074
2075 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002076 * Returns true if CDMA provisioning needs to run.
2077 */
2078 public boolean needsOtaServiceProvisioning() {
2079 return mPhone.needsOtaServiceProvisioning();
2080 }
2081
2082 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002083 * Sets the voice mail number of a given subId.
2084 */
2085 @Override
2086 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002087 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002088 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2089 new Pair<String, String>(alphaTag, number), new Integer(subId));
2090 return success;
2091 }
2092
Ta-wei Yen87c49842016-05-13 21:19:52 -07002093 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002094 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2095 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2096 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2097 if (!TextUtils.equals(callingPackage, systemDialer)) {
2098 throw new SecurityException("caller must be system dialer");
2099 }
2100 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2101 if (phoneAccountHandle == null){
2102 return null;
2103 }
2104 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2105 }
2106
2107 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002108 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002109 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002111 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002112 return null;
2113 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 return RemoteVvmTaskManager
2117 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002121 }
2122
2123 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002124 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2125 VisualVoicemailSmsFilterSettings settings) {
2126 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002127 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002128 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2129 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002130 }
2131
2132 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002133 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2134 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002135 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002136 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002137 }
2138
2139 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002140 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2141 String callingPackage, int subId) {
2142 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002143 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002144 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002145 }
2146
2147 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002148 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002149 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002150 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002151 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2152 }
2153
2154 @Override
2155 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2156 String number, int port, String text, PendingIntent sentIntent) {
2157 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002158 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002159 enforceSendSmsPermission();
2160 // Make the calls as the phone process.
2161 final long identity = Binder.clearCallingIdentity();
2162 try {
2163 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2164 if (port == 0) {
2165 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2166 sentIntent, null, false);
2167 } else {
2168 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2169 smsManager.sendDataMessageWithSelfPermissions(number, null,
2170 (short) port, data, sentIntent, null);
2171 }
2172 } finally {
2173 Binder.restoreCallingIdentity(identity);
2174 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002175 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002176 /**
fionaxu0152e512016-11-14 13:36:14 -08002177 * Sets the voice activation state of a given subId.
2178 */
2179 @Override
2180 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2182 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002183 final Phone phone = getPhone(subId);
2184 if (phone != null) {
2185 phone.setVoiceActivationState(activationState);
2186 } else {
2187 loge("setVoiceActivationState fails with invalid subId: " + subId);
2188 }
2189 }
2190
2191 /**
2192 * Sets the data activation state of a given subId.
2193 */
2194 @Override
2195 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2197 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002198 final Phone phone = getPhone(subId);
2199 if (phone != null) {
2200 phone.setDataActivationState(activationState);
2201 } else {
2202 loge("setVoiceActivationState fails with invalid subId: " + subId);
2203 }
2204 }
2205
2206 /**
2207 * Returns the voice activation state of a given subId.
2208 */
2209 @Override
2210 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002211 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002212 final Phone phone = getPhone(subId);
2213 if (phone != null) {
2214 return phone.getVoiceActivationState();
2215 } else {
2216 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2217 }
2218 }
2219
2220 /**
2221 * Returns the data activation state of a given subId.
2222 */
2223 @Override
2224 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002225 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002226 final Phone phone = getPhone(subId);
2227 if (phone != null) {
2228 return phone.getDataActivationState();
2229 } else {
2230 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2231 }
2232 }
2233
2234 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 * Returns the unread count of voicemails
2236 */
2237 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002238 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002239 }
2240
2241 /**
2242 * Returns the unread count of voicemails for a subId
2243 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002245 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 final Phone phone = getPhone(subId);
2247 if (phone != null) {
2248 return phone.getVoiceMessageCount();
2249 } else {
2250 return 0;
2251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 }
2253
2254 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002255 * returns true, if the device is in a state where both voice and data
2256 * are supported simultaneously. This can change based on location or network condition.
2257 */
2258 @Override
2259 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2260 final Phone phone = getPhone(subId);
2261 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2262 }
2263
2264 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002265 * Send the dialer code if called from the current default dialer or the caller has
2266 * carrier privilege.
2267 * @param inputCode The dialer code to send
2268 */
2269 @Override
2270 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2271 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2272 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2273 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002274 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2275 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002276 }
2277 mPhone.sendDialerSpecialCode(inputCode);
2278 }
2279
2280 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002281 * Returns the data network type.
2282 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 *
2284 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2285 */
2286 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002287 public int getNetworkType() {
2288 final Phone phone = getPhone(getDefaultSubscription());
2289 if (phone != null) {
2290 return phone.getServiceState().getDataNetworkType();
2291 } else {
2292 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2293 }
Wink Saville36469e72014-06-11 15:17:00 -07002294 }
2295
2296 /**
2297 * Returns the network type for a subId
2298 */
2299 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002300 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002302 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002303 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2304 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002305
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002307 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002308 return phone.getServiceState().getDataNetworkType();
2309 } else {
2310 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
2314 /**
2315 * Returns the data network type
2316 */
2317 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002318 public int getDataNetworkType(String callingPackage) {
2319 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002320 }
2321
2322 /**
2323 * Returns the data network type for a subId
2324 */
2325 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002326 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002328 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002329 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2330 }
2331
Sanket Padawe356d7632015-06-22 14:03:32 -07002332 final Phone phone = getPhone(subId);
2333 if (phone != null) {
2334 return phone.getServiceState().getDataNetworkType();
2335 } else {
2336 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 }
2339
2340 /**
Wink Saville36469e72014-06-11 15:17:00 -07002341 * Returns the Voice network type for a subId
2342 */
2343 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002344 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002346 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002347 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2348 }
2349
Sanket Padawe356d7632015-06-22 14:03:32 -07002350 final Phone phone = getPhone(subId);
2351 if (phone != null) {
2352 return phone.getServiceState().getVoiceNetworkType();
2353 } else {
2354 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 }
2357
2358 /**
2359 * @return true if a ICC card is present
2360 */
2361 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002362 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002363 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2364 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002365 }
2366
2367 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002368 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002369 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002370 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002371 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2372 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002373 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002374 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002375 } else {
2376 return false;
2377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 }
2379
2380 /**
2381 * Return if the current radio is LTE on CDMA. This
2382 * is a tri-state return value as for a period of time
2383 * the mode may be unknown.
2384 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002385 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002387 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002389 @Override
2390 public int getLteOnCdmaMode(String callingPackage) {
2391 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002392 }
2393
Sanket Padawe356d7632015-06-22 14:03:32 -07002394 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002395 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002397 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002398 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2399 }
2400
Sanket Padawe356d7632015-06-22 14:03:32 -07002401 final Phone phone = getPhone(subId);
2402 if (phone == null) {
2403 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2404 } else {
2405 return phone.getLteOnCdmaMode();
2406 }
Wink Saville36469e72014-06-11 15:17:00 -07002407 }
2408
2409 public void setPhone(Phone phone) {
2410 mPhone = phone;
2411 }
2412
2413 /**
2414 * {@hide}
2415 * Returns Default subId, 0 in the case of single standby.
2416 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002417 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002418 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002419 }
2420
Shishir Agrawala9f32182016-04-12 12:00:16 -07002421 private int getSlotForDefaultSubscription() {
2422 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2423 }
2424
Wink Savilleb564aae2014-10-23 10:18:09 -07002425 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002426 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002428
2429 /**
2430 * @see android.telephony.TelephonyManager.WifiCallingChoices
2431 */
2432 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002433 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2434 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002435 }
2436
2437 /**
2438 * @see android.telephony.TelephonyManager.WifiCallingChoices
2439 */
2440 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002441 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2442 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2443 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002444 }
2445
Sailesh Nepald1e68152013-12-12 19:08:02 -08002446 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002447 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002448 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002449 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002450
Shishir Agrawal566b7612013-10-28 14:41:00 -07002451 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002452 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2453 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2455 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002456
Derek Tan740e1672017-06-27 14:56:27 -07002457 if (TextUtils.equals(ISDR_AID, aid)) {
2458 // Only allows LPA to open logical channel to ISD-R.
2459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2460 ComponentInfo bestComponent =
2461 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2462 if (bestComponent == null
2463 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2464 loge("The calling package is not allowed to access ISD-R.");
2465 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2466 }
2467 }
2468
2469 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002470 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002471 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002472 if (DBG) log("iccOpenLogicalChannel: " + response);
2473 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002474 }
2475
2476 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2479 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002480
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002481 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002482 if (channel < 0) {
2483 return false;
2484 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002485 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002486 if (DBG) log("iccCloseLogicalChannel: " + success);
2487 return success;
2488 }
2489
2490 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002491 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002492 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2494 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002495
2496 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002497 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2498 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002499 " data=" + data);
2500 }
2501
2502 if (channel < 0) {
2503 return "";
2504 }
2505
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002506 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002507 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002508 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2509
Shishir Agrawal566b7612013-10-28 14:41:00 -07002510 // Append the returned status code to the end of the response payload.
2511 String s = Integer.toHexString(
2512 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002513 if (response.payload != null) {
2514 s = IccUtils.bytesToHexString(response.payload) + s;
2515 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002516 return s;
2517 }
Jake Hambye994d462014-02-03 13:10:13 -08002518
Evan Charltonc66da362014-05-16 14:06:40 -07002519 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002520 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2521 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2523 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002524
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002525 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2526 && TextUtils.equals(ISDR_AID, data)) {
2527 // Only allows LPA to select ISD-R.
2528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2529 ComponentInfo bestComponent =
2530 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2531 if (bestComponent == null
2532 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2533 loge("The calling package is not allowed to select ISD-R.");
2534 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2535 }
2536 }
2537
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002538 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002539 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2540 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002541 }
2542
2543 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002544 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002545 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2546
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002547 // Append the returned status code to the end of the response payload.
2548 String s = Integer.toHexString(
2549 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002550 if (response.payload != null) {
2551 s = IccUtils.bytesToHexString(response.payload) + s;
2552 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002553 return s;
2554 }
2555
2556 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002558 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2560 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002561
2562 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002563 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002564 p1 + " " + p2 + " " + p3 + ":" + filePath);
2565 }
2566
2567 IccIoResult response =
2568 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002569 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2570 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002571
2572 if (DBG) {
2573 log("Exchange SIM_IO [R]" + response);
2574 }
2575
2576 byte[] result = null;
2577 int length = 2;
2578 if (response.payload != null) {
2579 length = 2 + response.payload.length;
2580 result = new byte[length];
2581 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2582 } else {
2583 result = new byte[length];
2584 }
2585
2586 result[length - 1] = (byte) response.sw2;
2587 result[length - 2] = (byte) response.sw1;
2588 return result;
2589 }
2590
Nathan Haroldb3014052017-01-25 15:57:32 -08002591 /**
2592 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2593 * on a particular subscription
2594 */
sqianb6e41952018-03-12 14:54:01 -07002595 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2597 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2598 return null;
2599 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002600 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2601 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2602 return null;
2603 }
2604 Object response = sendRequest(
2605 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2606 if (response instanceof String[]) {
2607 return (String[]) response;
2608 }
2609 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2610 return null;
2611 }
2612
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002613 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002614 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2616 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002617
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002618 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002619 if (response.payload == null) {
2620 return "";
2621 }
2622
2623 // Append the returned status code to the end of the response payload.
2624 String s = Integer.toHexString(
2625 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2626 s = IccUtils.bytesToHexString(response.payload) + s;
2627 return s;
2628 }
2629
Jake Hambye994d462014-02-03 13:10:13 -08002630 /**
2631 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2632 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2633 *
2634 * @param itemID the ID of the item to read
2635 * @return the NV item as a String, or null on error.
2636 */
2637 @Override
2638 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2640 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002641 if (DBG) log("nvReadItem: item " + itemID);
2642 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2643 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2644 return value;
2645 }
2646
2647 /**
2648 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2649 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2650 *
2651 * @param itemID the ID of the item to read
2652 * @param itemValue the value to write, as a String
2653 * @return true on success; false on any failure
2654 */
2655 @Override
2656 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2658 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002659 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2660 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2661 new Pair<Integer, String>(itemID, itemValue));
2662 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2663 return success;
2664 }
2665
2666 /**
2667 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2668 * Used for device configuration by some CDMA operators.
2669 *
2670 * @param preferredRoamingList byte array containing the new PRL
2671 * @return true on success; false on any failure
2672 */
2673 @Override
2674 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2676 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002677 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2678 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2679 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2680 return success;
2681 }
2682
2683 /**
2684 * Perform the specified type of NV config reset.
2685 * Used for device configuration by some CDMA operators.
2686 *
2687 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2688 * @return true on success; false on any failure
2689 */
2690 @Override
2691 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2693 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002694 if (DBG) log("nvResetConfig: type " + resetType);
2695 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2696 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2697 return success;
2698 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002699
Svet Ganovb320e182015-04-16 12:30:10 -07002700 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002702 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002703 return new String[0];
2704 }
2705
2706
ram87fca6f2014-07-18 18:58:44 +05302707 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002708 }
2709
Brad Ebinger51f743a2017-01-23 13:50:20 -08002710 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002711 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2712 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002713 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002714 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002715 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002716 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002717 }
2718
2719 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002720 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2721 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002722 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002723 public void disableIms(int slotId) {
2724 enforceModifyPermission();
2725 PhoneFactory.getImsResolver().disableIms(slotId);
2726 }
2727
2728 /**
2729 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2730 * feature or {@link null} if the service is not available. If the feature is available, the
2731 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2732 */
2733 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002734 IImsServiceFeatureCallback callback) {
2735 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002736 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002737 }
2738
2739 /**
2740 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2741 * feature during emergency calling or {@link null} if the service is not available. If the
2742 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2743 * listener for feature updates.
2744 */
2745 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2746 enforceModifyPermission();
2747 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002748 }
2749
Brad Ebinger5f64b052017-12-14 14:26:15 -08002750 /**
2751 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2752 * specified.
2753 */
2754 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2755 enforceModifyPermission();
2756 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2757 }
2758
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002759 /**
2760 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2761 * specified.
2762 */
2763 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2764 enforceModifyPermission();
2765 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2766 }
2767
Brad Ebinger884c07b2018-02-15 16:17:40 -08002768 /**
Brad Ebinger67801702018-03-02 13:43:36 -08002769 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2770 * available, false if the IMS resolver is idle.
2771 */
2772 public boolean isResolvingImsBinding() {
2773 enforceModifyPermission();
2774 return PhoneFactory.getImsResolver().isResolvingBinding();
2775 }
2776
Brad Ebingerdac2f002018-04-03 15:17:52 -07002777 /**
2778 * Sets the ImsService Package Name that Telephony will bind to.
2779 *
2780 * @param slotId the slot ID that the ImsService should bind for.
2781 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
2782 * ImsService is the device default ImsService.
2783 * @param packageName The package name of the application that contains the ImsService to bind
2784 * to.
2785 * @return true if setting the ImsService to bind to succeeded, false if it did not.
2786 * @hide
2787 */
2788 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002789 int[] subIds = SubscriptionManager.getSubId(slotId);
2790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2791 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2792 "setImsService");
2793
Brad Ebingerdac2f002018-04-03 15:17:52 -07002794 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
2795 isCarrierImsService, packageName);
2796 }
2797
2798 /**
2799 * Return the ImsService configuration.
2800 *
2801 * @param slotId The slot that the ImsService is associated with.
2802 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
2803 * the device default.
2804 * @return the package name of the ImsService configuration.
2805 */
2806 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002807 int[] subIds = SubscriptionManager.getSubId(slotId);
2808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2809 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2810 "getImsService");
2811
Brad Ebingerdac2f002018-04-03 15:17:52 -07002812 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
2813 isCarrierImsService);
2814 }
2815
Wink Saville36469e72014-06-11 15:17:00 -07002816 public void setImsRegistrationState(boolean registered) {
2817 enforceModifyPermission();
2818 mPhone.setImsRegistrationState(registered);
2819 }
2820
2821 /**
Stuart Scott54788802015-03-30 13:18:01 -07002822 * Set the network selection mode to automatic.
2823 *
2824 */
2825 @Override
2826 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2828 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002829 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2830 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2831 }
2832
2833 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002834 * Set the network selection mode to manual with the selected carrier.
2835 */
2836 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002837 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002838 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2840 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002841 OperatorInfo operator = new OperatorInfo(
2842 /* operatorAlphaLong */ "",
2843 /* operatorAlphaShort */ "",
2844 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002845 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002846 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2847 persistSelection);
2848 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002849 }
2850
2851 /**
2852 * Scans for available networks.
2853 */
2854 @Override
2855 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2857 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002858 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2859 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2860 CMD_PERFORM_NETWORK_SCAN, null, subId);
2861 return result;
2862 }
2863
2864 /**
yinxub1bed742017-04-17 11:45:04 -07002865 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002866 *
yinxub1bed742017-04-17 11:45:04 -07002867 * @param subId id of the subscription
2868 * @param request contains the radio access networks with bands/channels to scan
2869 * @param messenger callback messenger for scan results or errors
2870 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002871 * @return the id of the requested scan which can be used to stop the scan.
2872 */
2873 @Override
2874 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2875 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2877 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002878 return mNetworkScanRequestTracker.startNetworkScan(
2879 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002880 }
2881
2882 /**
2883 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002884 *
2885 * @param subId id of the subscription
2886 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002887 */
2888 @Override
2889 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2891 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002892 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002893 }
2894
2895 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002896 * Get the calculated preferred network type.
2897 * Used for debugging incorrect network type.
2898 *
2899 * @return the preferred network type, defined in RILConstants.java.
2900 */
2901 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002902 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002904 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002905 return RILConstants.PREFERRED_NETWORK_MODE;
2906 }
2907
Amit Mahajan43330e02014-11-18 11:54:45 -08002908 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002909 }
2910
2911 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002912 * Get the preferred network type.
2913 * Used for device configuration by some CDMA operators.
2914 *
2915 * @return the preferred network type, defined in RILConstants.java.
2916 */
2917 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002918 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2920 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002921 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002922 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002923 int networkType = (result != null ? result[0] : -1);
2924 if (DBG) log("getPreferredNetworkType: " + networkType);
2925 return networkType;
2926 }
2927
2928 /**
2929 * Set the preferred network type.
2930 * Used for device configuration by some CDMA operators.
2931 *
2932 * @param networkType the preferred network type, defined in RILConstants.java.
2933 * @return true on success; false on any failure.
2934 */
2935 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002936 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2938 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002939 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2940 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002941 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002942 if (success) {
2943 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002944 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002945 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002946 return success;
2947 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002948
2949 /**
Junda Liu475951f2014-11-07 16:45:03 -08002950 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2951 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2952 * tethering.
2953 *
2954 * @return 0: Not required. 1: required. 2: Not set.
2955 * @hide
2956 */
2957 @Override
2958 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002959 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002960 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2961 Settings.Global.TETHER_DUN_REQUIRED, 2);
2962 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2963 // config_tether_apndata.
2964 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2965 dunRequired = 1;
2966 }
2967 return dunRequired;
2968 }
2969
2970 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002971 * Set mobile data enabled
2972 * Used by the user through settings etc to turn on/off mobile data
2973 *
2974 * @param enable {@code true} turn turn data on, else {@code false}
2975 */
2976 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002977 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2979 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002980 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002981 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002982 Phone phone = PhoneFactory.getPhone(phoneId);
2983 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002984 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2985 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002986 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002987 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002988 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002989 }
2990
2991 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002992 * Get the user enabled state of Mobile Data.
2993 *
2994 * TODO: remove and use isUserDataEnabled.
2995 * This can't be removed now because some vendor codes
2996 * calls through ITelephony directly while they should
2997 * use TelephonyManager.
2998 *
2999 * @return true on enabled
3000 */
3001 @Override
3002 public boolean getDataEnabled(int subId) {
3003 return isUserDataEnabled(subId);
3004 }
3005
3006 /**
3007 * Get whether mobile data is enabled per user setting.
3008 *
3009 * There are other factors deciding whether mobile data is actually enabled, but they are
3010 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003011 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003012 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003013 *
3014 * @return {@code true} if data is enabled else {@code false}
3015 */
3016 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003017 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003018 try {
3019 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3020 null);
3021 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3023 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003024 }
Wink Savillee7353bb2014-12-05 14:21:41 -08003025 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08003026 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08003027 Phone phone = PhoneFactory.getPhone(phoneId);
3028 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08003029 boolean retVal = phone.isUserDataEnabled();
3030 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08003031 return retVal;
3032 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08003033 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3034 return false;
3035 }
3036 }
3037
3038 /**
3039 * Get whether mobile data is enabled.
3040 *
3041 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3042 * whether mobile data is actually enabled.
3043 *
3044 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3045 *
3046 * @return {@code true} if data is enabled else {@code false}
3047 */
3048 @Override
3049 public boolean isDataEnabled(int subId) {
3050 try {
3051 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3052 null);
3053 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3055 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003056 }
3057 int phoneId = mSubscriptionController.getPhoneId(subId);
3058 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3059 Phone phone = PhoneFactory.getPhone(phoneId);
3060 if (phone != null) {
3061 boolean retVal = phone.isDataEnabled();
3062 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3063 return retVal;
3064 } else {
3065 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08003066 return false;
3067 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003068 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003069
3070 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003071 public int getCarrierPrivilegeStatus(int subId) {
3072 final Phone phone = getPhone(subId);
3073 if (phone == null) {
3074 loge("getCarrierPrivilegeStatus: Invalid subId");
3075 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3076 }
3077 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003078 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003079 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003080 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3081 }
3082 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003083 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003084 }
Junda Liu29340342014-07-10 15:23:27 -07003085
3086 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003087 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3088 final Phone phone = getPhone(subId);
3089 if (phone == null) {
3090 loge("getCarrierPrivilegeStatus: Invalid subId");
3091 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3092 }
3093 UiccProfile profile =
3094 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3095 if (profile == null) {
3096 loge("getCarrierPrivilegeStatus: No UICC");
3097 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3098 }
3099 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3100 }
3101
3102 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003103 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003104 if (TextUtils.isEmpty(pkgName))
3105 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003106 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003107 if (card == null) {
3108 loge("checkCarrierPrivilegesForPackage: No UICC");
3109 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3110 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003111 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3112 }
3113
3114 @Override
3115 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003116 if (TextUtils.isEmpty(pkgName))
3117 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003118 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3119 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3120 UiccCard card = UiccController.getInstance().getUiccCard(i);
3121 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003122 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003123 continue;
3124 }
3125
3126 result = card.getCarrierPrivilegeStatus(
3127 mPhone.getContext().getPackageManager(), pkgName);
3128 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3129 break;
3130 }
3131 }
3132
3133 return result;
Junda Liu29340342014-07-10 15:23:27 -07003134 }
Derek Tan89e89d42014-07-08 17:00:10 -07003135
3136 @Override
Junda Liue64de782015-04-16 17:19:16 -07003137 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3138 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3139 loge("phoneId " + phoneId + " is not valid.");
3140 return null;
3141 }
3142 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003143 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003144 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003145 return null ;
3146 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003147 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003148 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003149 }
3150
Amith Yamasani6e118872016-02-19 12:53:51 -08003151 @Override
3152 public List<String> getPackagesWithCarrierPrivileges() {
3153 PackageManager pm = mPhone.getContext().getPackageManager();
3154 List<String> privilegedPackages = new ArrayList<>();
3155 List<PackageInfo> packages = null;
3156 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3157 UiccCard card = UiccController.getInstance().getUiccCard(i);
3158 if (card == null) {
3159 // No UICC in that slot.
3160 continue;
3161 }
3162 if (card.hasCarrierPrivilegeRules()) {
3163 if (packages == null) {
3164 // Only check packages in user 0 for now
3165 packages = pm.getInstalledPackagesAsUser(
3166 PackageManager.MATCH_DISABLED_COMPONENTS
3167 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3168 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3169 }
3170 for (int p = packages.size() - 1; p >= 0; p--) {
3171 PackageInfo pkgInfo = packages.get(p);
3172 if (pkgInfo != null && pkgInfo.packageName != null
3173 && card.getCarrierPrivilegeStatus(pkgInfo)
3174 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3175 privilegedPackages.add(pkgInfo.packageName);
3176 }
3177 }
3178 }
3179 }
3180 return privilegedPackages;
3181 }
3182
Wink Savilleb564aae2014-10-23 10:18:09 -07003183 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003184 final Phone phone = getPhone(subId);
3185 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003186 if (card == null) {
3187 loge("getIccId: No UICC");
3188 return null;
3189 }
3190 String iccId = card.getIccId();
3191 if (TextUtils.isEmpty(iccId)) {
3192 loge("getIccId: ICC ID is null or empty.");
3193 return null;
3194 }
3195 return iccId;
3196 }
3197
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003198 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003199 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3200 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003201 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3202 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003203
Jeff Sharkey85190e62014-12-05 09:40:12 -08003204 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003205 final Phone phone = getPhone(subId);
3206 if (phone == null) {
3207 return false;
3208 }
3209 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003210
3211 if (DBG_MERGE) {
3212 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3213 + subscriberId + " to " + number);
3214 }
3215
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003216 if (TextUtils.isEmpty(iccId)) {
3217 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003218 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003219
Jeff Sharkey85190e62014-12-05 09:40:12 -08003220 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3221
3222 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003223 if (alphaTag == null) {
3224 editor.remove(alphaTagPrefKey);
3225 } else {
3226 editor.putString(alphaTagPrefKey, alphaTag);
3227 }
3228
Jeff Sharkey85190e62014-12-05 09:40:12 -08003229 // Record both the line number and IMSI for this ICCID, since we need to
3230 // track all merged IMSIs based on line number
3231 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3232 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003233 if (number == null) {
3234 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003235 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003236 } else {
3237 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003238 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003239 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003240
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003241 editor.commit();
3242 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003243 }
3244
3245 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003246 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003247 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003249 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003250 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003251 return null;
3252 }
Derek Tan97ebb422014-09-05 16:55:38 -07003253
3254 String iccId = getIccId(subId);
3255 if (iccId != null) {
3256 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003257 if (DBG_MERGE) {
3258 log("getLine1NumberForDisplay returning " +
3259 mTelephonySharedPreferences.getString(numberPrefKey, null));
3260 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003261 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003262 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003263 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003264 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003265 }
3266
3267 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003268 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003270 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003271 return null;
3272 }
Derek Tan97ebb422014-09-05 16:55:38 -07003273
3274 String iccId = getIccId(subId);
3275 if (iccId != null) {
3276 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003277 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003278 }
Derek Tan97ebb422014-09-05 16:55:38 -07003279 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003280 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003281
3282 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003283 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003284 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3285 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003287 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3288 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003289 return null;
3290 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003291 final Context context = mPhone.getContext();
3292 final TelephonyManager tele = TelephonyManager.from(context);
3293 final SubscriptionManager sub = SubscriptionManager.from(context);
3294
3295 // Figure out what subscribers are currently active
3296 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003297 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3298 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 final int[] subIds = sub.getActiveSubscriptionIdList();
3302 for (int subId : subIds) {
3303 activeSubscriberIds.add(tele.getSubscriberId(subId));
3304 }
3305 } finally {
3306 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003307 }
3308
3309 // First pass, find a number override for an active subscriber
3310 String mergeNumber = null;
3311 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3312 for (String key : prefs.keySet()) {
3313 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3314 final String subscriberId = (String) prefs.get(key);
3315 if (activeSubscriberIds.contains(subscriberId)) {
3316 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3317 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3318 mergeNumber = (String) prefs.get(numberKey);
3319 if (DBG_MERGE) {
3320 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3321 + " for active subscriber " + subscriberId);
3322 }
3323 if (!TextUtils.isEmpty(mergeNumber)) {
3324 break;
3325 }
3326 }
3327 }
3328 }
3329
3330 // Shortcut when no active merged subscribers
3331 if (TextUtils.isEmpty(mergeNumber)) {
3332 return null;
3333 }
3334
3335 // Second pass, find all subscribers under that line override
3336 final ArraySet<String> result = new ArraySet<>();
3337 for (String key : prefs.keySet()) {
3338 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3339 final String number = (String) prefs.get(key);
3340 if (mergeNumber.equals(number)) {
3341 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3342 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3343 final String subscriberId = (String) prefs.get(subscriberKey);
3344 if (!TextUtils.isEmpty(subscriberId)) {
3345 result.add(subscriberId);
3346 }
3347 }
3348 }
3349 }
3350
3351 final String[] resultArray = result.toArray(new String[result.size()]);
3352 Arrays.sort(resultArray);
3353 if (DBG_MERGE) {
3354 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3355 }
3356 return resultArray;
3357 }
3358
3359 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003360 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003361 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3362 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003363 final Phone phone = getPhone(subId);
3364 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003365 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003366
3367 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003368 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003369 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3370 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003371 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003372 final Phone phone = getPhone(subId);
3373 if (phone == null) {
3374 return false;
3375 }
3376 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003377 cdmaNonRoamingList);
3378 }
3379
3380 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003381 @Deprecated
3382 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3383 enforceModifyPermission();
3384
3385 int returnValue = 0;
3386 try {
3387 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3388 if(result.exception == null) {
3389 if (result.result != null) {
3390 byte[] responseData = (byte[])(result.result);
3391 if(responseData.length > oemResp.length) {
3392 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3393 responseData.length + "bytes. Buffer Size is " +
3394 oemResp.length + "bytes.");
3395 }
3396 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3397 returnValue = responseData.length;
3398 }
3399 } else {
3400 CommandException ex = (CommandException) result.exception;
3401 returnValue = ex.getCommandError().ordinal();
3402 if(returnValue > 0) returnValue *= -1;
3403 }
3404 } catch (RuntimeException e) {
3405 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3406 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3407 if(returnValue > 0) returnValue *= -1;
3408 }
3409
3410 return returnValue;
3411 }
3412
3413 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003414 public void setRadioCapability(RadioAccessFamily[] rafs) {
3415 try {
3416 ProxyController.getInstance().setRadioCapability(rafs);
3417 } catch (RuntimeException e) {
3418 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3419 }
3420 }
3421
3422 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003423 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003424 Phone phone = PhoneFactory.getPhone(phoneId);
3425 if (phone == null) {
3426 return RadioAccessFamily.RAF_UNKNOWN;
3427 }
3428 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003430 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003431 return RadioAccessFamily.RAF_UNKNOWN;
3432 }
3433
Wink Saville5d475dd2014-10-17 15:00:58 -07003434 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3435 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003436
3437 @Override
3438 public void enableVideoCalling(boolean enable) {
3439 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003440 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003441 }
3442
3443 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003444 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3446 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3447 return false;
3448 }
Svet Ganovb320e182015-04-16 12:30:10 -07003449
Andrew Lee77527ac2014-10-21 16:57:39 -07003450 // Check the user preference and the system-level IMS setting. Even if the user has
3451 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3452 // In the long run, we may instead need to check if there exists a connection service
3453 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003454 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3455 return imsManager.isVtEnabledByPlatform()
3456 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3457 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003458 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003459
Andrew Leea1239f22015-03-02 17:44:07 -08003460 @Override
3461 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003462 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003463 }
3464
3465 @Override
3466 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003467 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003468 }
3469
Andrew Lee9431b832015-03-09 18:46:45 -07003470 @Override
3471 public boolean isTtyModeSupported() {
3472 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3473 TelephonyManager telephonyManager =
3474 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003475 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003476 }
3477
3478 @Override
3479 public boolean isHearingAidCompatibilitySupported() {
3480 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3481 }
3482
Hall Liu98187582018-01-22 19:15:32 -08003483 public boolean isRttSupported() {
3484 boolean isCarrierSupported =
3485 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3486 boolean isDeviceSupported =
3487 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3488 return isCarrierSupported && isDeviceSupported;
3489 }
3490
Hall Liu3ad5f012018-04-06 16:23:39 -07003491 public boolean isRttEnabled() {
3492 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3493 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3494 }
3495
Sanket Padawe7310cc72015-01-14 09:53:20 -08003496 /**
3497 * Returns the unique device ID of phone, for example, the IMEI for
3498 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3499 *
3500 * <p>Requires Permission:
3501 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3502 */
3503 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003504 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003505 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003506 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003507 return null;
3508 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003509 int subId = phone.getSubId();
3510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3511 mApp, subId, callingPackage, "getDeviceId")) {
3512 return null;
3513 }
3514 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003515 }
3516
Ping Sunc67b7c22016-03-02 19:16:45 +08003517 /**
3518 * {@hide}
3519 * Returns the IMS Registration Status on a particular subid
3520 *
3521 * @param subId
3522 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003523 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003524 Phone phone = getPhone(subId);
3525 if (phone != null) {
3526 return phone.isImsRegistered();
3527 } else {
3528 return false;
3529 }
3530 }
3531
Santos Cordon7a1885b2015-02-03 11:15:19 -08003532 @Override
3533 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3534 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3535 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003536
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003537 /**
3538 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003539 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003540 public boolean isWifiCallingAvailable(int subId) {
3541 Phone phone = getPhone(subId);
3542 if (phone != null) {
3543 return phone.isWifiCallingEnabled();
3544 } else {
3545 return false;
3546 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003547 }
3548
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003549 /**
3550 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003551 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003552 public boolean isVolteAvailable(int subId) {
3553 Phone phone = getPhone(subId);
3554 if (phone != null) {
3555 return phone.isVolteEnabled();
3556 } else {
3557 return false;
3558 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003559 }
Svet Ganovb320e182015-04-16 12:30:10 -07003560
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003561 /**
3562 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003563 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003564 public boolean isVideoTelephonyAvailable(int subId) {
3565 Phone phone = getPhone(subId);
3566 if (phone != null) {
3567 return phone.isVideoEnabled();
3568 } else {
3569 return false;
3570 }
3571 }
3572
3573 /**
3574 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3575 * defined in {@link ImsRegistrationImplBase}.
3576 */
3577 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3578 Phone phone = getPhone(subId);
3579 if (phone != null) {
3580 return phone.getImsRegistrationTech();
3581 } else {
3582 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3583 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003584 }
3585
Stuart Scott8eef64f2015-04-08 15:13:54 -07003586 @Override
3587 public void factoryReset(int subId) {
3588 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003589 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3590 return;
3591 }
3592
Svet Ganovcc087f82015-05-12 20:35:54 -07003593 final long identity = Binder.clearCallingIdentity();
3594 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003595 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3596 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003597 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003598 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003599 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3600 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003601 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003602 }
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003605 }
3606 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003607
3608 @Override
3609 public String getLocaleFromDefaultSim() {
3610 // We query all subscriptions instead of just the active ones, because
3611 // this might be called early on in the provisioning flow when the
3612 // subscriptions potentially aren't active yet.
3613 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3614 if (slist == null || slist.isEmpty()) {
3615 return null;
3616 }
3617
3618 // This function may be called very early, say, from the setup wizard, at
3619 // which point we won't have a default subscription set. If that's the case
3620 // we just choose the first, which will be valid in "most cases".
3621 final int defaultSubId = getDefaultSubscription();
3622 SubscriptionInfo info = null;
3623 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3624 info = slist.get(0);
3625 } else {
3626 for (SubscriptionInfo item : slist) {
3627 if (item.getSubscriptionId() == defaultSubId) {
3628 info = item;
3629 break;
3630 }
3631 }
3632
3633 if (info == null) {
3634 return null;
3635 }
3636 }
3637
3638 // Try and fetch the locale from the carrier properties or from the SIM language
3639 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003640 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003641 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003642 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003643 if (defaultPhone != null) {
3644 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3645 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003646 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003647 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3648 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003649 } else {
3650 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003651 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003652 }
3653 }
3654
Narayan Kamath011676f2015-07-29 12:04:08 +01003655 // The SIM language preferences only store a language (e.g. fr = French), not an
3656 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3657 // the SIM and carrier preferences does not include a country we add the country
3658 // determined from the SIM MCC to provide an exact locale.
3659 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003660 if (mccLocale != null) {
3661 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3662 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003663 }
3664
Tony Hill183b2de2015-06-24 14:53:58 +01003665 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003666 return null;
3667 }
3668
3669 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 return mSubscriptionController.getAllSubInfoList(
3673 mPhone.getContext().getOpPackageName());
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
3677 }
3678
3679 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 return mSubscriptionController.getActiveSubscriptionInfoList(
3683 mPhone.getContext().getOpPackageName());
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
3686 }
3687 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003688
Chenjie Yu1ba97252018-01-11 18:16:20 -08003689 private final ModemActivityInfo mLastModemActivityInfo =
3690 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3691
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003692 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003693 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3694 * representing the state of the modem.
3695 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003696 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3697 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003698 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003699 */
3700 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003701 public void requestModemActivityInfo(ResultReceiver result) {
3702 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003703 ModemActivityInfo ret = null;
3704 synchronized (mLastModemActivityInfo) {
3705 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3706 null);
3707 if (info != null) {
3708 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3709 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3710 mergedTxTimeMs[i] =
3711 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3712 }
3713 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3714 mLastModemActivityInfo.setSleepTimeMillis(
3715 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3716 mLastModemActivityInfo.setIdleTimeMillis(
3717 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3718 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3719 mLastModemActivityInfo.setRxTimeMillis(
3720 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3721 mLastModemActivityInfo.setEnergyUsed(
3722 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3723 }
3724 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3725 mLastModemActivityInfo.getSleepTimeMillis(),
3726 mLastModemActivityInfo.getIdleTimeMillis(),
3727 mLastModemActivityInfo.getTxTimeMillis(),
3728 mLastModemActivityInfo.getRxTimeMillis(),
3729 mLastModemActivityInfo.getEnergyUsed());
3730 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003731 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003732 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003733 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003734 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003735
3736 /**
3737 * {@hide}
3738 * Returns the service state information on specified subscription.
3739 */
3740 @Override
3741 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3742
Jeff Davidson7e17e312018-02-13 18:17:36 -08003743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003744 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003745 return null;
3746 }
3747
3748 final Phone phone = getPhone(subId);
3749 if (phone == null) {
3750 return null;
3751 }
3752
3753 return phone.getServiceState();
3754 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003755
3756 /**
3757 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3758 *
3759 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3760 * voicemail ringtone.
3761 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3762 * PhoneAccount.
3763 */
3764 @Override
3765 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003766 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003767 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003768 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003769 }
3770
fionaxu7ed723d2017-05-30 18:58:54 -07003771 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003772 }
3773
3774 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003775 * Sets the per-account voicemail ringtone.
3776 *
3777 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3778 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3779 *
3780 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3781 * voicemail ringtone.
3782 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3783 * PhoneAccount.
3784 */
3785 @Override
3786 public void setVoicemailRingtoneUri(String callingPackage,
3787 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3788 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3789 if (!TextUtils.equals(callingPackage,
3790 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3792 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3793 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003794 }
3795 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3796 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003797 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003798 }
fionaxu7ed723d2017-05-30 18:58:54 -07003799 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003800 }
3801
3802 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003803 * Returns whether vibration is set for voicemail notification in Phone settings.
3804 *
3805 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3806 * voicemail vibration setting.
3807 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3808 */
3809 @Override
3810 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003811 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003812 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003813 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003814 }
3815
fionaxu7ed723d2017-05-30 18:58:54 -07003816 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003817 }
3818
Youhan Wange64578a2016-05-02 15:32:42 -07003819 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003820 * Sets the per-account voicemail vibration.
3821 *
3822 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3823 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3824 *
3825 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3826 * voicemail vibration setting.
3827 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3828 * specific PhoneAccount.
3829 */
3830 @Override
3831 public void setVoicemailVibrationEnabled(String callingPackage,
3832 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3833 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3834 if (!TextUtils.equals(callingPackage,
3835 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3837 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3838 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003839 }
3840
3841 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3842 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003843 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003844 }
fionaxu7ed723d2017-05-30 18:58:54 -07003845 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003846 }
3847
3848 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003849 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3850 *
3851 * @throws SecurityException if the caller does not have the required permission
3852 */
3853 private void enforceReadPrivilegedPermission() {
3854 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3855 null);
3856 }
3857
3858 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003859 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3860 * permission.
3861 *
3862 * @throws SecurityException if the caller does not have the required permission
3863 */
3864 private void enforceSendSmsPermission() {
3865 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3866 }
3867
3868 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003869 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003870 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003871 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003872 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003873 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003874 ComponentName componentName =
3875 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3876 if(componentName == null) {
3877 throw new SecurityException("Caller not current active visual voicemail package[null]");
3878 }
3879 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003880 if (!callingPackage.equals(vvmPackage)) {
3881 throw new SecurityException("Caller not current active visual voicemail package[" +
3882 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003883 }
3884 }
3885
3886 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003887 * Return the application ID for the app type.
3888 *
3889 * @param subId the subscription ID that this request applies to.
3890 * @param appType the uicc app type.
3891 * @return Application ID for specificied app type, or null if no uicc.
3892 */
3893 @Override
3894 public String getAidForAppType(int subId, int appType) {
3895 enforceReadPrivilegedPermission();
3896 Phone phone = getPhone(subId);
3897 if (phone == null) {
3898 return null;
3899 }
3900 String aid = null;
3901 try {
3902 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3903 .getApplicationByType(appType).getAid();
3904 } catch (Exception e) {
3905 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3906 }
3907 return aid;
3908 }
3909
Youhan Wang4001d252016-05-11 10:29:41 -07003910 /**
3911 * Return the Electronic Serial Number.
3912 *
3913 * @param subId the subscription ID that this request applies to.
3914 * @return ESN or null if error.
3915 */
3916 @Override
3917 public String getEsn(int subId) {
3918 enforceReadPrivilegedPermission();
3919 Phone phone = getPhone(subId);
3920 if (phone == null) {
3921 return null;
3922 }
3923 String esn = null;
3924 try {
3925 esn = phone.getEsn();
3926 } catch (Exception e) {
3927 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3928 }
3929 return esn;
3930 }
3931
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003932 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003933 * Return the Preferred Roaming List Version.
3934 *
3935 * @param subId the subscription ID that this request applies to.
3936 * @return PRLVersion or null if error.
3937 */
3938 @Override
3939 public String getCdmaPrlVersion(int subId) {
3940 enforceReadPrivilegedPermission();
3941 Phone phone = getPhone(subId);
3942 if (phone == null) {
3943 return null;
3944 }
3945 String cdmaPrlVersion = null;
3946 try {
3947 cdmaPrlVersion = phone.getCdmaPrlVersion();
3948 } catch (Exception e) {
3949 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3950 }
3951 return cdmaPrlVersion;
3952 }
3953
3954 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003955 * Get snapshot of Telephony histograms
3956 * @return List of Telephony histograms
3957 * @hide
3958 */
3959 @Override
3960 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3962 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003963 return RIL.getTelephonyRILTimingHistograms();
3964 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003965
3966 /**
3967 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003968 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003969 * Require system privileges. In the future we may add this to carrier APIs.
3970 *
3971 * @return The number of carriers set successfully, should match length of carriers
3972 */
3973 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003974 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003975 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003976
Meng Wang9b7c4e92017-02-17 11:41:27 -08003977 if (carriers == null) {
3978 throw new NullPointerException("carriers cannot be null");
3979 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003980
3981 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003982 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3983 return retVal[0];
3984 }
3985
3986 /**
3987 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003988 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003989 * Require system privileges. In the future we may add this to carrier APIs.
3990 *
3991 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3992 * means all carriers are allowed.
3993 */
3994 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003995 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003996 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003997 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003998 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3999 }
4000
fionaxu59545b42016-05-25 15:53:37 -07004001 /**
4002 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4003 * @param subId the subscription ID that this action applies to.
4004 * @param enabled control enable or disable metered apns.
4005 * {@hide}
4006 */
4007 @Override
4008 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4009 enforceModifyPermission();
4010 final Phone phone = getPhone(subId);
4011 if (phone == null) {
4012 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4013 return;
4014 }
4015 try {
4016 phone.carrierActionSetMeteredApnsEnabled(enabled);
4017 } catch (Exception e) {
4018 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
4019 }
4020 }
4021
4022 /**
4023 * Action set from carrier signalling broadcast receivers to enable/disable radio
4024 * @param subId the subscription ID that this action applies to.
4025 * @param enabled control enable or disable radio.
4026 * {@hide}
4027 */
4028 @Override
4029 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4030 enforceModifyPermission();
4031 final Phone phone = getPhone(subId);
4032 if (phone == null) {
4033 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4034 return;
4035 }
4036 try {
4037 phone.carrierActionSetRadioEnabled(enabled);
4038 } catch (Exception e) {
4039 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
4040 }
4041 }
4042
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004043 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004044 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4045 * network status based on which carrier apps could apply actions accordingly,
4046 * enable/disable default url handler for example.
4047 *
4048 * @param subId the subscription ID that this action applies to.
4049 * @param report control start/stop reporting the default network status.
4050 * {@hide}
4051 */
4052 @Override
4053 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4054 enforceModifyPermission();
4055 final Phone phone = getPhone(subId);
4056 if (phone == null) {
4057 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4058 return;
4059 }
4060 try {
4061 phone.carrierActionReportDefaultNetworkStatus(report);
4062 } catch (Exception e) {
4063 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
4064 }
4065 }
4066
4067 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004068 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4069 * bug report is being generated.
4070 */
4071 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004072 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004073 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4074 != PackageManager.PERMISSION_GRANTED) {
4075 writer.println("Permission Denial: can't dump Phone from pid="
4076 + Binder.getCallingPid()
4077 + ", uid=" + Binder.getCallingUid()
4078 + "without permission "
4079 + android.Manifest.permission.DUMP);
4080 return;
4081 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004082 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004083 }
Jack Yueb89b242016-06-22 13:27:47 -07004084
Brad Ebingerdac2f002018-04-03 15:17:52 -07004085 @Override
4086 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4087 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4088 throws RemoteException {
4089 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4090 }
4091
Jack Yueb89b242016-06-22 13:27:47 -07004092 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004093 * Get aggregated video call data usage since boot.
4094 *
4095 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4096 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004097 * {@hide}
4098 */
4099 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004100 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004101 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4102 null);
4103
Jack Yu84291ec2017-05-26 16:07:50 -07004104 // NetworkStatsService keeps tracking the active network interface and identity. It
4105 // records the delta with the corresponding network identity. We just return the total video
4106 // call data usage snapshot since boot.
4107 Phone phone = getPhone(subId);
4108 if (phone != null) {
4109 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004110 }
Jack Yu84291ec2017-05-26 16:07:50 -07004111 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004112 }
Jack Yu75ab2952016-07-08 14:29:33 -07004113
4114 /**
4115 * Policy control of data connection. Usually used when data limit is passed.
4116 * @param enabled True if enabling the data, otherwise disabling.
4117 * @param subId Subscription index
4118 * {@hide}
4119 */
4120 @Override
4121 public void setPolicyDataEnabled(boolean enabled, int subId) {
4122 enforceModifyPermission();
4123 Phone phone = getPhone(subId);
4124 if (phone != null) {
4125 phone.setPolicyDataEnabled(enabled);
4126 }
4127 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004128
4129 /**
4130 * Get Client request stats
4131 * @return List of Client Request Stats
4132 * @hide
4133 */
4134 @Override
4135 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004137 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004138 return null;
4139 }
4140
4141 Phone phone = getPhone(subId);
4142 if (phone != null) {
4143 return phone.getClientRequestStats();
4144 }
4145
4146 return null;
4147 }
4148
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004149 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004150 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004151 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004152 }
Jack Yueb4124c2017-02-16 15:32:43 -08004153
4154 /**
Grace Chen70990072017-03-24 17:21:30 -07004155 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004156 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004157 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004158 * @param state State of SIM (power down, power up, pass through)
4159 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4160 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4161 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004162 *
4163 **/
4164 @Override
Grace Chen70990072017-03-24 17:21:30 -07004165 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004166 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004167 Phone phone = PhoneFactory.getPhone(slotIndex);
4168
Jack Yueb4124c2017-02-16 15:32:43 -08004169 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004170 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004171 }
4172 }
Shuo Qiandd210312017-04-12 22:11:33 +00004173
Tyler Gunn65d45c22017-06-05 11:22:26 -07004174 private boolean isUssdApiAllowed(int subId) {
4175 CarrierConfigManager configManager =
4176 (CarrierConfigManager) mPhone.getContext().getSystemService(
4177 Context.CARRIER_CONFIG_SERVICE);
4178 if (configManager == null) {
4179 return false;
4180 }
4181 PersistableBundle pb = configManager.getConfigForSubId(subId);
4182 if (pb == null) {
4183 return false;
4184 }
4185 return pb.getBoolean(
4186 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4187 }
4188
Shuo Qiandd210312017-04-12 22:11:33 +00004189 /**
4190 * Check if phone is in emergency callback mode
4191 * @return true if phone is in emergency callback mode
4192 * @param subId sub id
4193 */
goneil9c5f4872017-12-05 14:07:56 -08004194 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004195 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004196 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004197 final Phone phone = getPhone(subId);
4198 if (phone != null) {
4199 return phone.isInEcm();
4200 } else {
4201 return false;
4202 }
4203 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004204
4205 /**
4206 * Get the current signal strength information for the given subscription.
4207 * Because this information is not updated when the device is in a low power state
4208 * it should not be relied-upon to be current.
4209 * @param subId Subscription index
4210 * @return the most recent cached signal strength info from the modem
4211 */
4212 @Override
4213 public SignalStrength getSignalStrength(int subId) {
4214 Phone p = getPhone(subId);
4215 if (p == null) {
4216 return null;
4217 }
4218
4219 return p.getSignalStrength();
4220 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004221
4222 @Override
4223 public UiccSlotInfo[] getUiccSlotsInfo() {
4224 enforceReadPrivilegedPermission();
4225
4226 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004227 if (slots == null) {
4228 Rlog.i(LOG_TAG, "slots is null.");
4229 return null;
4230 }
4231
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004232 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4233 for (int i = 0; i < slots.length; i++) {
4234 UiccSlot slot = slots[i];
Holly Jiuyu Sun6723f982018-06-04 15:48:38 -07004235 if (slot == null) {
4236 continue;
4237 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004238
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004239 String cardId;
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004240 UiccCard card = slot.getUiccCard();
4241 if (card != null) {
4242 cardId = card.getCardId();
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004243 } else {
4244 cardId = slot.getIccId();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004245 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004246
4247 int cardState = 0;
4248 switch (slot.getCardState()) {
4249 case CARDSTATE_ABSENT:
4250 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4251 break;
4252 case CARDSTATE_PRESENT:
4253 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4254 break;
4255 case CARDSTATE_ERROR:
4256 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4257 break;
4258 case CARDSTATE_RESTRICTED:
4259 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4260 break;
4261 default:
4262 break;
4263
4264 }
4265
Qingxi Li795c5882018-01-31 13:43:27 -08004266 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004267 slot.isActive(),
4268 slot.isEuicc(),
4269 cardId,
4270 cardState,
4271 slot.getPhoneId(),
4272 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004273 }
4274 return infos;
4275 }
4276
4277 @Override
4278 public boolean switchSlots(int[] physicalSlots) {
4279 enforceModifyPermission();
4280 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4281 }
Jack Yu4c988042018-02-27 15:30:01 -08004282
4283 @Override
4284 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4285 enforceModifyPermission();
4286 final Phone phone = getPhone(subId);
4287 if (phone == null) {
4288 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4289 return;
4290 }
4291
4292 phone.setRadioIndicationUpdateMode(filters, mode);
4293 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004294
4295 /**
goneil47ffb6e2018-04-06 15:40:58 -07004296 * A test API to reload the UICC profile.
4297 *
4298 * <p>Requires that the calling app has permission
4299 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4300 * @hide
4301 */
4302 @Override
4303 public void refreshUiccProfile(int subId) {
4304 enforceModifyPermission();
4305
4306 final long identity = Binder.clearCallingIdentity();
4307 try {
4308 Phone phone = getPhone(subId);
4309 if (phone == null) {
4310 return;
4311 }
4312 UiccCard uiccCard = phone.getUiccCard();
4313 if (uiccCard == null) {
4314 return;
4315 }
4316 UiccProfile uiccProfile = uiccCard.getUiccProfile();
4317 if (uiccProfile == null) {
4318 return;
4319 }
4320 uiccProfile.refresh();
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
4324 }
4325
4326 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07004327 * Returns false if the mobile data is disabled by default, otherwise return true.
4328 */
4329 private boolean getDefaultDataEnabled() {
4330 return "true".equalsIgnoreCase(
4331 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4332 }
4333
4334 /**
4335 * Returns true if the data roaming is enabled by default, i.e the system property
4336 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4337 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4338 */
4339 private boolean getDefaultDataRoamingEnabled(int subId) {
4340 final CarrierConfigManager configMgr = (CarrierConfigManager)
4341 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4342 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4343 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4344 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4345 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4346 return isDataRoamingEnabled;
4347 }
4348
4349 /**
4350 * Returns the default network type for the given {@code subId}, if the default network type is
4351 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4352 */
4353 private int getDefaultNetworkType(int subId) {
4354 return Integer.parseInt(
4355 TelephonyManager.getTelephonyProperty(
4356 mSubscriptionController.getPhoneId(subId),
4357 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4358 String.valueOf(Phone.PREFERRED_NT_MODE)));
4359 }
fionaxua13278b2018-03-21 00:08:13 -07004360
4361 @Override
4362 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4363 gid1, String gid2, String plmn, String spn) {
4364 enforceModifyPermission();
4365 final Phone phone = getPhone(subId);
4366 if (phone == null) {
4367 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4368 return;
4369 }
4370 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4371 }
4372
4373 @Override
4374 public int getCarrierIdListVersion(int subId) {
4375 enforceReadPrivilegedPermission();
4376 final Phone phone = getPhone(subId);
4377 if (phone == null) {
4378 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4379 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4380 }
4381 return phone.getCarrierIdListVersion();
4382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004383}