blob: c1637655b956e336d94c4fc057f45896ac24c87e [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 {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001727 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1728 // Get default phone in this case.
1729 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1730 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001731 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001732 // Todo: fix this when we can get the actual cellular network info when the device
1733 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001734 if (TelephonyManager.NETWORK_TYPE_IWLAN
1735 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1736 return "";
1737 }
1738 } finally {
1739 Binder.restoreCallingIdentity(identity);
1740 }
Jack Yu5f7092c2018-04-13 14:05:37 -07001741
1742 Phone phone = PhoneFactory.getPhone(phoneId);
1743 if (phone != null) {
1744 ServiceStateTracker sst = phone.getServiceStateTracker();
1745 if (sst != null) {
1746 LocaleTracker lt = sst.getLocaleTracker();
1747 if (lt != null) {
1748 return lt.getCurrentCountry();
1749 }
1750 }
1751 }
1752 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001753 }
1754
1755 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001757 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001758 }
1759
Sanket Padawe356d7632015-06-22 14:03:32 -07001760 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001761 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 mApp.enforceCallingOrSelfPermission(
1763 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001764 final Phone phone = getPhone(subId);
1765 if (phone != null) {
1766 phone.enableLocationUpdates();
1767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
1770 @Override
1771 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001772 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001773 }
1774
Sanket Padawe356d7632015-06-22 14:03:32 -07001775 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001776 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 mApp.enforceCallingOrSelfPermission(
1778 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001779 final Phone phone = getPhone(subId);
1780 if (phone != null) {
1781 phone.disableLocationUpdates();
1782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 }
1784
1785 @Override
1786 @SuppressWarnings("unchecked")
1787 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001788 mPhone.getContext().getSystemService(AppOpsManager.class)
1789 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001790 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001791 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001792 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
1795 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1796 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1797 return null;
1798 }
Svetoslav64fad262015-04-14 14:35:21 -07001799
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001800 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001802 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001804 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001805 try {
1806 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1807 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1808 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1809 } catch (RuntimeException e) {
1810 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001812 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
1815
1816 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001817 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001818 mPhone.getContext().getSystemService(AppOpsManager.class)
1819 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001820 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001821 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001822 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001825 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001826 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001827 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1828 for (Phone phone : PhoneFactory.getPhones()) {
1829 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1830 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001832 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 }
1834
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001835 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001837 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001838 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001839 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
Shishir Agrawala9f32182016-04-12 12:00:16 -07001842 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001843 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001844 Phone phone = PhoneFactory.getPhone(slotIndex);
1845 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001846 return null;
1847 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001848 int subId = phone.getSubId();
1849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1850 mApp, subId, callingPackage, "getImeiForSlot")) {
1851 return null;
1852 }
1853 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001854 }
1855
1856 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001857 public String getTypeAllocationCodeForSlot(int slotIndex) {
1858 Phone phone = PhoneFactory.getPhone(slotIndex);
1859 String tac = null;
1860 if (phone != null) {
1861 String imei = phone.getImei();
1862 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1863 }
1864 return tac;
1865 }
1866
1867 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001868 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001869 Phone phone = PhoneFactory.getPhone(slotIndex);
1870 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001871 return null;
1872 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001873 int subId = phone.getSubId();
1874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1875 mApp, subId, callingPackage, "getMeidForSlot")) {
1876 return null;
1877 }
1878 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001879 }
1880
1881 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001882 public String getManufacturerCodeForSlot(int slotIndex) {
1883 Phone phone = PhoneFactory.getPhone(slotIndex);
1884 String manufacturerCode = null;
1885 if (phone != null) {
1886 String meid = phone.getMeid();
1887 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1888 }
1889 return manufacturerCode;
1890 }
1891
1892 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001893 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001894 Phone phone = PhoneFactory.getPhone(slotIndex);
1895 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001896 return null;
1897 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001898 int subId = phone.getSubId();
1899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1900 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1901 return null;
1902 }
1903 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001904 }
1905
fionaxu43304da2017-11-27 22:51:16 -08001906 @Override
1907 public int getSubscriptionCarrierId(int subId) {
1908 final Phone phone = getPhone(subId);
1909 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1910 }
1911
1912 @Override
1913 public String getSubscriptionCarrierName(int subId) {
1914 final Phone phone = getPhone(subId);
1915 return phone == null ? null : phone.getCarrierName();
1916 }
1917
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 //
1919 // Internal helper methods.
1920 //
1921
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001922 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1924 *
1925 * @throws SecurityException if the caller does not have the required permission
1926 */
1927 private void enforceModifyPermission() {
1928 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1929 }
1930
1931 /**
1932 * Make sure the caller has the CALL_PHONE permission.
1933 *
1934 * @throws SecurityException if the caller does not have the required permission
1935 */
1936 private void enforceCallPermission() {
1937 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1938 }
1939
Stuart Scott8eef64f2015-04-08 15:13:54 -07001940 private void enforceConnectivityInternalPermission() {
1941 mApp.enforceCallingOrSelfPermission(
1942 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1943 "ConnectivityService");
1944 }
1945
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 private String createTelUrl(String number) {
1947 if (TextUtils.isEmpty(number)) {
1948 return null;
1949 }
1950
Jake Hambye994d462014-02-03 13:10:13 -08001951 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
Ihab Awadf9e92732013-12-05 18:02:52 -08001954 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1956 }
1957
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001958 private static void logv(String msg) {
1959 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1960 }
1961
Ihab Awadf9e92732013-12-05 18:02:52 -08001962 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1964 }
1965
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001966 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001968 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001969 }
1970
Sanket Padawe356d7632015-06-22 14:03:32 -07001971 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001972 public int getActivePhoneTypeForSlot(int slotIndex) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00001973 final Phone phone = PhoneFactory.getPhone(slotIndex);
1974 if (phone == null) {
1975 return PhoneConstants.PHONE_TYPE_NONE;
1976 } else {
1977 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
1980
1981 /**
1982 * Returns the CDMA ERI icon index to display
1983 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001984 @Override
1985 public int getCdmaEriIconIndex(String callingPackage) {
1986 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001987 }
1988
Sanket Padawe356d7632015-06-22 14:03:32 -07001989 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001990 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001992 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001993 return -1;
1994 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 final Phone phone = getPhone(subId);
1996 if (phone != null) {
1997 return phone.getCdmaEriIconIndex();
1998 } else {
1999 return -1;
2000 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 }
2002
2003 /**
2004 * Returns the CDMA ERI icon mode,
2005 * 0 - ON
2006 * 1 - FLASHING
2007 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002008 @Override
2009 public int getCdmaEriIconMode(String callingPackage) {
2010 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002011 }
2012
Sanket Padawe356d7632015-06-22 14:03:32 -07002013 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002014 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002016 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002017 return -1;
2018 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002019 final Phone phone = getPhone(subId);
2020 if (phone != null) {
2021 return phone.getCdmaEriIconMode();
2022 } else {
2023 return -1;
2024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002025 }
2026
2027 /**
2028 * Returns the CDMA ERI text,
2029 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002030 @Override
2031 public String getCdmaEriText(String callingPackage) {
2032 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002033 }
2034
Sanket Padawe356d7632015-06-22 14:03:32 -07002035 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002036 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002038 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002039 return null;
2040 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002041 final Phone phone = getPhone(subId);
2042 if (phone != null) {
2043 return phone.getCdmaEriText();
2044 } else {
2045 return null;
2046 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 }
2048
2049 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002050 * Returns the CDMA MDN.
2051 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002052 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002053 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2055 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07002056 final Phone phone = getPhone(subId);
2057 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2058 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002059 } else {
2060 return null;
2061 }
2062 }
2063
2064 /**
2065 * Returns the CDMA MIN.
2066 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002067 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002068 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2070 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002071 final Phone phone = getPhone(subId);
2072 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2073 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002074 } else {
2075 return null;
2076 }
2077 }
2078
2079 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 * Returns true if CDMA provisioning needs to run.
2081 */
2082 public boolean needsOtaServiceProvisioning() {
2083 return mPhone.needsOtaServiceProvisioning();
2084 }
2085
2086 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002087 * Sets the voice mail number of a given subId.
2088 */
2089 @Override
2090 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002091 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002092 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2093 new Pair<String, String>(alphaTag, number), new Integer(subId));
2094 return success;
2095 }
2096
Ta-wei Yen87c49842016-05-13 21:19:52 -07002097 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002098 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2099 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2100 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2101 if (!TextUtils.equals(callingPackage, systemDialer)) {
2102 throw new SecurityException("caller must be system dialer");
2103 }
2104 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2105 if (phoneAccountHandle == null){
2106 return null;
2107 }
2108 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2109 }
2110
2111 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002112 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002114 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002115 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002116 return null;
2117 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002118 final long identity = Binder.clearCallingIdentity();
2119 try {
2120 return RemoteVvmTaskManager
2121 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
2124 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002125 }
2126
2127 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002128 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2129 VisualVoicemailSmsFilterSettings settings) {
2130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002131 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002132 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2133 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002134 }
2135
2136 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002137 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2138 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002139 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002140 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002141 }
2142
2143 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002144 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2145 String callingPackage, int subId) {
2146 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002147 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002148 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002149 }
2150
2151 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002152 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002153 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002154 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002155 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2156 }
2157
2158 @Override
2159 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2160 String number, int port, String text, PendingIntent sentIntent) {
2161 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002162 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002163 enforceSendSmsPermission();
2164 // Make the calls as the phone process.
2165 final long identity = Binder.clearCallingIdentity();
2166 try {
2167 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2168 if (port == 0) {
2169 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2170 sentIntent, null, false);
2171 } else {
2172 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2173 smsManager.sendDataMessageWithSelfPermissions(number, null,
2174 (short) port, data, sentIntent, null);
2175 }
2176 } finally {
2177 Binder.restoreCallingIdentity(identity);
2178 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002179 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002180 /**
fionaxu0152e512016-11-14 13:36:14 -08002181 * Sets the voice activation state of a given subId.
2182 */
2183 @Override
2184 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2186 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002187 final Phone phone = getPhone(subId);
2188 if (phone != null) {
2189 phone.setVoiceActivationState(activationState);
2190 } else {
2191 loge("setVoiceActivationState fails with invalid subId: " + subId);
2192 }
2193 }
2194
2195 /**
2196 * Sets the data activation state of a given subId.
2197 */
2198 @Override
2199 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2201 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002202 final Phone phone = getPhone(subId);
2203 if (phone != null) {
2204 phone.setDataActivationState(activationState);
2205 } else {
2206 loge("setVoiceActivationState fails with invalid subId: " + subId);
2207 }
2208 }
2209
2210 /**
2211 * Returns the voice activation state of a given subId.
2212 */
2213 @Override
2214 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002215 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002216 final Phone phone = getPhone(subId);
2217 if (phone != null) {
2218 return phone.getVoiceActivationState();
2219 } else {
2220 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2221 }
2222 }
2223
2224 /**
2225 * Returns the data activation state of a given subId.
2226 */
2227 @Override
2228 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002229 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002230 final Phone phone = getPhone(subId);
2231 if (phone != null) {
2232 return phone.getDataActivationState();
2233 } else {
2234 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2235 }
2236 }
2237
2238 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 * Returns the unread count of voicemails
2240 */
2241 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002242 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002243 }
2244
2245 /**
2246 * Returns the unread count of voicemails for a subId
2247 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002248 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002249 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 final Phone phone = getPhone(subId);
2251 if (phone != null) {
2252 return phone.getVoiceMessageCount();
2253 } else {
2254 return 0;
2255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 }
2257
2258 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002259 * returns true, if the device is in a state where both voice and data
2260 * are supported simultaneously. This can change based on location or network condition.
2261 */
2262 @Override
2263 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2264 final Phone phone = getPhone(subId);
2265 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2266 }
2267
2268 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002269 * Send the dialer code if called from the current default dialer or the caller has
2270 * carrier privilege.
2271 * @param inputCode The dialer code to send
2272 */
2273 @Override
2274 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2275 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2276 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2277 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002278 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2279 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002280 }
2281 mPhone.sendDialerSpecialCode(inputCode);
2282 }
2283
2284 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002285 * Returns the data network type.
2286 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 *
2288 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2289 */
2290 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002291 public int getNetworkType() {
2292 final Phone phone = getPhone(getDefaultSubscription());
2293 if (phone != null) {
2294 return phone.getServiceState().getDataNetworkType();
2295 } else {
2296 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2297 }
Wink Saville36469e72014-06-11 15:17:00 -07002298 }
2299
2300 /**
2301 * Returns the network type for a subId
2302 */
2303 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002304 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002306 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002307 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2308 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002309
Sanket Padawe356d7632015-06-22 14:03:32 -07002310 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002311 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002312 return phone.getServiceState().getDataNetworkType();
2313 } else {
2314 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 }
2317
2318 /**
2319 * Returns the data network type
2320 */
2321 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 public int getDataNetworkType(String callingPackage) {
2323 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002324 }
2325
2326 /**
2327 * Returns the data network type for a subId
2328 */
2329 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002330 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002331 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002332 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002333 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2334 }
2335
Sanket Padawe356d7632015-06-22 14:03:32 -07002336 final Phone phone = getPhone(subId);
2337 if (phone != null) {
2338 return phone.getServiceState().getDataNetworkType();
2339 } else {
2340 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
2343
2344 /**
Wink Saville36469e72014-06-11 15:17:00 -07002345 * Returns the Voice network type for a subId
2346 */
2347 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002348 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002349 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002350 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002351 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2352 }
2353
Sanket Padawe356d7632015-06-22 14:03:32 -07002354 final Phone phone = getPhone(subId);
2355 if (phone != null) {
2356 return phone.getServiceState().getVoiceNetworkType();
2357 } else {
2358 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
2362 /**
2363 * @return true if a ICC card is present
2364 */
2365 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002366 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002367 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2368 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002369 }
2370
2371 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002372 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002373 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002374 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002375 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2376 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002377 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002378 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002379 } else {
2380 return false;
2381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 }
2383
2384 /**
2385 * Return if the current radio is LTE on CDMA. This
2386 * is a tri-state return value as for a period of time
2387 * the mode may be unknown.
2388 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002389 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002391 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002393 @Override
2394 public int getLteOnCdmaMode(String callingPackage) {
2395 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002396 }
2397
Sanket Padawe356d7632015-06-22 14:03:32 -07002398 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002399 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002401 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002402 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2403 }
2404
Sanket Padawe356d7632015-06-22 14:03:32 -07002405 final Phone phone = getPhone(subId);
2406 if (phone == null) {
2407 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2408 } else {
2409 return phone.getLteOnCdmaMode();
2410 }
Wink Saville36469e72014-06-11 15:17:00 -07002411 }
2412
2413 public void setPhone(Phone phone) {
2414 mPhone = phone;
2415 }
2416
2417 /**
2418 * {@hide}
2419 * Returns Default subId, 0 in the case of single standby.
2420 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002421 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002422 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002423 }
2424
Shishir Agrawala9f32182016-04-12 12:00:16 -07002425 private int getSlotForDefaultSubscription() {
2426 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2427 }
2428
Wink Savilleb564aae2014-10-23 10:18:09 -07002429 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002430 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002432
2433 /**
2434 * @see android.telephony.TelephonyManager.WifiCallingChoices
2435 */
2436 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002437 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2438 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002439 }
2440
2441 /**
2442 * @see android.telephony.TelephonyManager.WifiCallingChoices
2443 */
2444 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002445 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2446 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2447 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002448 }
2449
Sailesh Nepald1e68152013-12-12 19:08:02 -08002450 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002451 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002452 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002453 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002454
Shishir Agrawal566b7612013-10-28 14:41:00 -07002455 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002456 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2457 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2459 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002460
Derek Tan740e1672017-06-27 14:56:27 -07002461 if (TextUtils.equals(ISDR_AID, aid)) {
2462 // Only allows LPA to open logical channel to ISD-R.
2463 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2464 ComponentInfo bestComponent =
2465 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2466 if (bestComponent == null
2467 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2468 loge("The calling package is not allowed to access ISD-R.");
2469 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2470 }
2471 }
2472
2473 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002475 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002476 if (DBG) log("iccOpenLogicalChannel: " + response);
2477 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002478 }
2479
2480 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002481 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2483 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002484
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002485 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002486 if (channel < 0) {
2487 return false;
2488 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002489 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002490 if (DBG) log("iccCloseLogicalChannel: " + success);
2491 return success;
2492 }
2493
2494 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002495 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002496 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2498 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002499
2500 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002501 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2502 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002503 " data=" + data);
2504 }
2505
2506 if (channel < 0) {
2507 return "";
2508 }
2509
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002510 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002511 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002512 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2513
Shishir Agrawal566b7612013-10-28 14:41:00 -07002514 // Append the returned status code to the end of the response payload.
2515 String s = Integer.toHexString(
2516 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002517 if (response.payload != null) {
2518 s = IccUtils.bytesToHexString(response.payload) + s;
2519 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002520 return s;
2521 }
Jake Hambye994d462014-02-03 13:10:13 -08002522
Evan Charltonc66da362014-05-16 14:06:40 -07002523 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002524 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2525 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2527 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002528
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002529 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2530 && TextUtils.equals(ISDR_AID, data)) {
2531 // Only allows LPA to select ISD-R.
2532 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2533 ComponentInfo bestComponent =
2534 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2535 if (bestComponent == null
2536 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2537 loge("The calling package is not allowed to select ISD-R.");
2538 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2539 }
2540 }
2541
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002542 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002543 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2544 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002545 }
2546
2547 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002548 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002549 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2550
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002551 // Append the returned status code to the end of the response payload.
2552 String s = Integer.toHexString(
2553 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002554 if (response.payload != null) {
2555 s = IccUtils.bytesToHexString(response.payload) + s;
2556 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002557 return s;
2558 }
2559
2560 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002561 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002562 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2564 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002565
2566 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002567 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002568 p1 + " " + p2 + " " + p3 + ":" + filePath);
2569 }
2570
2571 IccIoResult response =
2572 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002573 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2574 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002575
2576 if (DBG) {
2577 log("Exchange SIM_IO [R]" + response);
2578 }
2579
2580 byte[] result = null;
2581 int length = 2;
2582 if (response.payload != null) {
2583 length = 2 + response.payload.length;
2584 result = new byte[length];
2585 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2586 } else {
2587 result = new byte[length];
2588 }
2589
2590 result[length - 1] = (byte) response.sw2;
2591 result[length - 2] = (byte) response.sw1;
2592 return result;
2593 }
2594
Nathan Haroldb3014052017-01-25 15:57:32 -08002595 /**
2596 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2597 * on a particular subscription
2598 */
sqianb6e41952018-03-12 14:54:01 -07002599 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2601 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2602 return null;
2603 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002604 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2605 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2606 return null;
2607 }
2608 Object response = sendRequest(
2609 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2610 if (response instanceof String[]) {
2611 return (String[]) response;
2612 }
2613 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2614 return null;
2615 }
2616
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002617 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002618 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2620 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002621
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002622 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002623 if (response.payload == null) {
2624 return "";
2625 }
2626
2627 // Append the returned status code to the end of the response payload.
2628 String s = Integer.toHexString(
2629 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2630 s = IccUtils.bytesToHexString(response.payload) + s;
2631 return s;
2632 }
2633
Jake Hambye994d462014-02-03 13:10:13 -08002634 /**
2635 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2636 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2637 *
2638 * @param itemID the ID of the item to read
2639 * @return the NV item as a String, or null on error.
2640 */
2641 @Override
2642 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2644 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002645 if (DBG) log("nvReadItem: item " + itemID);
2646 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2647 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2648 return value;
2649 }
2650
2651 /**
2652 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2653 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2654 *
2655 * @param itemID the ID of the item to read
2656 * @param itemValue the value to write, as a String
2657 * @return true on success; false on any failure
2658 */
2659 @Override
2660 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2662 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002663 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2664 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2665 new Pair<Integer, String>(itemID, itemValue));
2666 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2667 return success;
2668 }
2669
2670 /**
2671 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2672 * Used for device configuration by some CDMA operators.
2673 *
2674 * @param preferredRoamingList byte array containing the new PRL
2675 * @return true on success; false on any failure
2676 */
2677 @Override
2678 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2680 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002681 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2682 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2683 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2684 return success;
2685 }
2686
2687 /**
2688 * Perform the specified type of NV config reset.
2689 * Used for device configuration by some CDMA operators.
2690 *
2691 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2692 * @return true on success; false on any failure
2693 */
2694 @Override
2695 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2697 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002698 if (DBG) log("nvResetConfig: type " + resetType);
2699 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2700 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2701 return success;
2702 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002703
Svet Ganovb320e182015-04-16 12:30:10 -07002704 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002706 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002707 return new String[0];
2708 }
2709
2710
ram87fca6f2014-07-18 18:58:44 +05302711 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002712 }
2713
Brad Ebinger51f743a2017-01-23 13:50:20 -08002714 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002715 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2716 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002717 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002718 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002719 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002720 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002721 }
2722
2723 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002724 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2725 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002726 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002727 public void disableIms(int slotId) {
2728 enforceModifyPermission();
2729 PhoneFactory.getImsResolver().disableIms(slotId);
2730 }
2731
2732 /**
2733 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2734 * feature or {@link null} if the service is not available. If the feature is available, the
2735 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2736 */
2737 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002738 IImsServiceFeatureCallback callback) {
2739 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002740 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002741 }
2742
2743 /**
2744 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2745 * feature during emergency calling or {@link null} if the service is not available. If the
2746 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2747 * listener for feature updates.
2748 */
2749 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2750 enforceModifyPermission();
2751 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002752 }
2753
Brad Ebinger5f64b052017-12-14 14:26:15 -08002754 /**
2755 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2756 * specified.
2757 */
2758 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2759 enforceModifyPermission();
2760 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2761 }
2762
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002763 /**
2764 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2765 * specified.
2766 */
2767 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2768 enforceModifyPermission();
2769 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2770 }
2771
Brad Ebinger884c07b2018-02-15 16:17:40 -08002772 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07002773 * Sets the ImsService Package Name that Telephony will bind to.
2774 *
2775 * @param slotId the slot ID that the ImsService should bind for.
2776 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
2777 * ImsService is the device default ImsService.
2778 * @param packageName The package name of the application that contains the ImsService to bind
2779 * to.
2780 * @return true if setting the ImsService to bind to succeeded, false if it did not.
2781 * @hide
2782 */
2783 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002784 int[] subIds = SubscriptionManager.getSubId(slotId);
2785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2786 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2787 "setImsService");
2788
Brad Ebingerdac2f002018-04-03 15:17:52 -07002789 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
2790 isCarrierImsService, packageName);
2791 }
2792
2793 /**
2794 * Return the ImsService configuration.
2795 *
2796 * @param slotId The slot that the ImsService is associated with.
2797 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
2798 * the device default.
2799 * @return the package name of the ImsService configuration.
2800 */
2801 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07002802 int[] subIds = SubscriptionManager.getSubId(slotId);
2803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2804 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2805 "getImsService");
2806
Brad Ebingerdac2f002018-04-03 15:17:52 -07002807 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
2808 isCarrierImsService);
2809 }
2810
Wink Saville36469e72014-06-11 15:17:00 -07002811 public void setImsRegistrationState(boolean registered) {
2812 enforceModifyPermission();
2813 mPhone.setImsRegistrationState(registered);
2814 }
2815
2816 /**
Stuart Scott54788802015-03-30 13:18:01 -07002817 * Set the network selection mode to automatic.
2818 *
2819 */
2820 @Override
2821 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2823 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002824 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2825 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2826 }
2827
2828 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002829 * Set the network selection mode to manual with the selected carrier.
2830 */
2831 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002832 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002833 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2835 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002836 OperatorInfo operator = new OperatorInfo(
2837 /* operatorAlphaLong */ "",
2838 /* operatorAlphaShort */ "",
2839 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002840 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002841 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2842 persistSelection);
2843 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002844 }
2845
2846 /**
2847 * Scans for available networks.
2848 */
2849 @Override
2850 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2852 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002853 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2854 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2855 CMD_PERFORM_NETWORK_SCAN, null, subId);
2856 return result;
2857 }
2858
2859 /**
yinxub1bed742017-04-17 11:45:04 -07002860 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002861 *
yinxub1bed742017-04-17 11:45:04 -07002862 * @param subId id of the subscription
2863 * @param request contains the radio access networks with bands/channels to scan
2864 * @param messenger callback messenger for scan results or errors
2865 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002866 * @return the id of the requested scan which can be used to stop the scan.
2867 */
2868 @Override
2869 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2870 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2872 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002873 return mNetworkScanRequestTracker.startNetworkScan(
2874 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002875 }
2876
2877 /**
2878 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002879 *
2880 * @param subId id of the subscription
2881 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002882 */
2883 @Override
2884 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2886 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002887 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002888 }
2889
2890 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002891 * Get the calculated preferred network type.
2892 * Used for debugging incorrect network type.
2893 *
2894 * @return the preferred network type, defined in RILConstants.java.
2895 */
2896 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002897 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002899 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002900 return RILConstants.PREFERRED_NETWORK_MODE;
2901 }
2902
Amit Mahajan43330e02014-11-18 11:54:45 -08002903 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002904 }
2905
2906 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002907 * Get the preferred network type.
2908 * Used for device configuration by some CDMA operators.
2909 *
2910 * @return the preferred network type, defined in RILConstants.java.
2911 */
2912 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002913 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2915 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002916 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002917 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002918 int networkType = (result != null ? result[0] : -1);
2919 if (DBG) log("getPreferredNetworkType: " + networkType);
2920 return networkType;
2921 }
2922
2923 /**
2924 * Set the preferred network type.
2925 * Used for device configuration by some CDMA operators.
2926 *
2927 * @param networkType the preferred network type, defined in RILConstants.java.
2928 * @return true on success; false on any failure.
2929 */
2930 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002931 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2933 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002934 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2935 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002936 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002937 if (success) {
2938 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002939 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002940 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002941 return success;
2942 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002943
2944 /**
Junda Liu475951f2014-11-07 16:45:03 -08002945 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2946 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2947 * tethering.
2948 *
2949 * @return 0: Not required. 1: required. 2: Not set.
2950 * @hide
2951 */
2952 @Override
2953 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002954 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002955 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2956 Settings.Global.TETHER_DUN_REQUIRED, 2);
2957 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2958 // config_tether_apndata.
2959 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2960 dunRequired = 1;
2961 }
2962 return dunRequired;
2963 }
2964
2965 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002966 * Set mobile data enabled
2967 * Used by the user through settings etc to turn on/off mobile data
2968 *
2969 * @param enable {@code true} turn turn data on, else {@code false}
2970 */
2971 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002972 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2974 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002975 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002976 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002977 Phone phone = PhoneFactory.getPhone(phoneId);
2978 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002979 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2980 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002981 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002982 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002983 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002984 }
2985
2986 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002987 * Get the user enabled state of Mobile Data.
2988 *
2989 * TODO: remove and use isUserDataEnabled.
2990 * This can't be removed now because some vendor codes
2991 * calls through ITelephony directly while they should
2992 * use TelephonyManager.
2993 *
2994 * @return true on enabled
2995 */
2996 @Override
2997 public boolean getDataEnabled(int subId) {
2998 return isUserDataEnabled(subId);
2999 }
3000
3001 /**
3002 * Get whether mobile data is enabled per user setting.
3003 *
3004 * There are other factors deciding whether mobile data is actually enabled, but they are
3005 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003006 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003007 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003008 *
3009 * @return {@code true} if data is enabled else {@code false}
3010 */
3011 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003012 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003013 try {
3014 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3015 null);
3016 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3018 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003019 }
Wink Savillee7353bb2014-12-05 14:21:41 -08003020 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08003021 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08003022 Phone phone = PhoneFactory.getPhone(phoneId);
3023 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08003024 boolean retVal = phone.isUserDataEnabled();
3025 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08003026 return retVal;
3027 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08003028 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3029 return false;
3030 }
3031 }
3032
3033 /**
3034 * Get whether mobile data is enabled.
3035 *
3036 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3037 * whether mobile data is actually enabled.
3038 *
3039 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3040 *
3041 * @return {@code true} if data is enabled else {@code false}
3042 */
3043 @Override
3044 public boolean isDataEnabled(int subId) {
3045 try {
3046 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3047 null);
3048 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3050 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003051 }
3052 int phoneId = mSubscriptionController.getPhoneId(subId);
3053 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3054 Phone phone = PhoneFactory.getPhone(phoneId);
3055 if (phone != null) {
3056 boolean retVal = phone.isDataEnabled();
3057 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3058 return retVal;
3059 } else {
3060 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08003061 return false;
3062 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003063 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003064
3065 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003066 public int getCarrierPrivilegeStatus(int subId) {
3067 final Phone phone = getPhone(subId);
3068 if (phone == null) {
3069 loge("getCarrierPrivilegeStatus: Invalid subId");
3070 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3071 }
3072 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003073 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003074 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003075 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3076 }
3077 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003078 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003079 }
Junda Liu29340342014-07-10 15:23:27 -07003080
3081 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003082 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3083 final Phone phone = getPhone(subId);
3084 if (phone == null) {
3085 loge("getCarrierPrivilegeStatus: Invalid subId");
3086 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3087 }
3088 UiccProfile profile =
3089 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3090 if (profile == null) {
3091 loge("getCarrierPrivilegeStatus: No UICC");
3092 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3093 }
3094 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3095 }
3096
3097 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003098 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003099 if (TextUtils.isEmpty(pkgName))
3100 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003101 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003102 if (card == null) {
3103 loge("checkCarrierPrivilegesForPackage: No UICC");
3104 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3105 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003106 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3107 }
3108
3109 @Override
3110 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003111 if (TextUtils.isEmpty(pkgName))
3112 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003113 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3114 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3115 UiccCard card = UiccController.getInstance().getUiccCard(i);
3116 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003117 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003118 continue;
3119 }
3120
3121 result = card.getCarrierPrivilegeStatus(
3122 mPhone.getContext().getPackageManager(), pkgName);
3123 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3124 break;
3125 }
3126 }
3127
3128 return result;
Junda Liu29340342014-07-10 15:23:27 -07003129 }
Derek Tan89e89d42014-07-08 17:00:10 -07003130
3131 @Override
Junda Liue64de782015-04-16 17:19:16 -07003132 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3133 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3134 loge("phoneId " + phoneId + " is not valid.");
3135 return null;
3136 }
3137 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003138 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003139 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003140 return null ;
3141 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003142 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003143 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003144 }
3145
Amith Yamasani6e118872016-02-19 12:53:51 -08003146 @Override
3147 public List<String> getPackagesWithCarrierPrivileges() {
3148 PackageManager pm = mPhone.getContext().getPackageManager();
3149 List<String> privilegedPackages = new ArrayList<>();
3150 List<PackageInfo> packages = null;
3151 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3152 UiccCard card = UiccController.getInstance().getUiccCard(i);
3153 if (card == null) {
3154 // No UICC in that slot.
3155 continue;
3156 }
3157 if (card.hasCarrierPrivilegeRules()) {
3158 if (packages == null) {
3159 // Only check packages in user 0 for now
3160 packages = pm.getInstalledPackagesAsUser(
3161 PackageManager.MATCH_DISABLED_COMPONENTS
3162 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3163 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3164 }
3165 for (int p = packages.size() - 1; p >= 0; p--) {
3166 PackageInfo pkgInfo = packages.get(p);
3167 if (pkgInfo != null && pkgInfo.packageName != null
3168 && card.getCarrierPrivilegeStatus(pkgInfo)
3169 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3170 privilegedPackages.add(pkgInfo.packageName);
3171 }
3172 }
3173 }
3174 }
3175 return privilegedPackages;
3176 }
3177
Wink Savilleb564aae2014-10-23 10:18:09 -07003178 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003179 final Phone phone = getPhone(subId);
3180 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003181 if (card == null) {
3182 loge("getIccId: No UICC");
3183 return null;
3184 }
3185 String iccId = card.getIccId();
3186 if (TextUtils.isEmpty(iccId)) {
3187 loge("getIccId: ICC ID is null or empty.");
3188 return null;
3189 }
3190 return iccId;
3191 }
3192
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003193 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003194 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3195 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003196 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3197 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003198
Jeff Sharkey85190e62014-12-05 09:40:12 -08003199 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003200 final Phone phone = getPhone(subId);
3201 if (phone == null) {
3202 return false;
3203 }
3204 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003205
3206 if (DBG_MERGE) {
3207 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3208 + subscriberId + " to " + number);
3209 }
3210
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003211 if (TextUtils.isEmpty(iccId)) {
3212 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003213 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003214
Jeff Sharkey85190e62014-12-05 09:40:12 -08003215 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3216
3217 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003218 if (alphaTag == null) {
3219 editor.remove(alphaTagPrefKey);
3220 } else {
3221 editor.putString(alphaTagPrefKey, alphaTag);
3222 }
3223
Jeff Sharkey85190e62014-12-05 09:40:12 -08003224 // Record both the line number and IMSI for this ICCID, since we need to
3225 // track all merged IMSIs based on line number
3226 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3227 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003228 if (number == null) {
3229 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003230 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003231 } else {
3232 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003233 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003234 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003235
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003236 editor.commit();
3237 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003238 }
3239
3240 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003241 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003242 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003244 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003245 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003246 return null;
3247 }
Derek Tan97ebb422014-09-05 16:55:38 -07003248
3249 String iccId = getIccId(subId);
3250 if (iccId != null) {
3251 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003252 if (DBG_MERGE) {
3253 log("getLine1NumberForDisplay returning " +
3254 mTelephonySharedPreferences.getString(numberPrefKey, null));
3255 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003256 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003257 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003258 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003259 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003260 }
3261
3262 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003263 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003265 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003266 return null;
3267 }
Derek Tan97ebb422014-09-05 16:55:38 -07003268
3269 String iccId = getIccId(subId);
3270 if (iccId != null) {
3271 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003272 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003273 }
Derek Tan97ebb422014-09-05 16:55:38 -07003274 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003275 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003276
3277 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003278 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003279 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3280 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003282 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3283 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003284 return null;
3285 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003286 final Context context = mPhone.getContext();
3287 final TelephonyManager tele = TelephonyManager.from(context);
3288 final SubscriptionManager sub = SubscriptionManager.from(context);
3289
3290 // Figure out what subscribers are currently active
3291 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003292 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3293 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 final int[] subIds = sub.getActiveSubscriptionIdList();
3297 for (int subId : subIds) {
3298 activeSubscriberIds.add(tele.getSubscriberId(subId));
3299 }
3300 } finally {
3301 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003302 }
3303
3304 // First pass, find a number override for an active subscriber
3305 String mergeNumber = null;
3306 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3307 for (String key : prefs.keySet()) {
3308 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3309 final String subscriberId = (String) prefs.get(key);
3310 if (activeSubscriberIds.contains(subscriberId)) {
3311 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3312 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3313 mergeNumber = (String) prefs.get(numberKey);
3314 if (DBG_MERGE) {
3315 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3316 + " for active subscriber " + subscriberId);
3317 }
3318 if (!TextUtils.isEmpty(mergeNumber)) {
3319 break;
3320 }
3321 }
3322 }
3323 }
3324
3325 // Shortcut when no active merged subscribers
3326 if (TextUtils.isEmpty(mergeNumber)) {
3327 return null;
3328 }
3329
3330 // Second pass, find all subscribers under that line override
3331 final ArraySet<String> result = new ArraySet<>();
3332 for (String key : prefs.keySet()) {
3333 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3334 final String number = (String) prefs.get(key);
3335 if (mergeNumber.equals(number)) {
3336 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3337 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3338 final String subscriberId = (String) prefs.get(subscriberKey);
3339 if (!TextUtils.isEmpty(subscriberId)) {
3340 result.add(subscriberId);
3341 }
3342 }
3343 }
3344 }
3345
3346 final String[] resultArray = result.toArray(new String[result.size()]);
3347 Arrays.sort(resultArray);
3348 if (DBG_MERGE) {
3349 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3350 }
3351 return resultArray;
3352 }
3353
3354 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003355 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003356 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3357 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003358 final Phone phone = getPhone(subId);
3359 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003360 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003361
3362 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003363 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003364 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3365 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003366 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003367 final Phone phone = getPhone(subId);
3368 if (phone == null) {
3369 return false;
3370 }
3371 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003372 cdmaNonRoamingList);
3373 }
3374
3375 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003376 @Deprecated
3377 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3378 enforceModifyPermission();
3379
3380 int returnValue = 0;
3381 try {
3382 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3383 if(result.exception == null) {
3384 if (result.result != null) {
3385 byte[] responseData = (byte[])(result.result);
3386 if(responseData.length > oemResp.length) {
3387 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3388 responseData.length + "bytes. Buffer Size is " +
3389 oemResp.length + "bytes.");
3390 }
3391 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3392 returnValue = responseData.length;
3393 }
3394 } else {
3395 CommandException ex = (CommandException) result.exception;
3396 returnValue = ex.getCommandError().ordinal();
3397 if(returnValue > 0) returnValue *= -1;
3398 }
3399 } catch (RuntimeException e) {
3400 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3401 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3402 if(returnValue > 0) returnValue *= -1;
3403 }
3404
3405 return returnValue;
3406 }
3407
3408 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003409 public void setRadioCapability(RadioAccessFamily[] rafs) {
3410 try {
3411 ProxyController.getInstance().setRadioCapability(rafs);
3412 } catch (RuntimeException e) {
3413 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3414 }
3415 }
3416
3417 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003418 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003419 Phone phone = PhoneFactory.getPhone(phoneId);
3420 if (phone == null) {
3421 return RadioAccessFamily.RAF_UNKNOWN;
3422 }
3423 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003424 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003425 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003426 return RadioAccessFamily.RAF_UNKNOWN;
3427 }
3428
Wink Saville5d475dd2014-10-17 15:00:58 -07003429 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3430 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003431
3432 @Override
3433 public void enableVideoCalling(boolean enable) {
3434 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003435 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003436 }
3437
3438 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003439 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3441 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3442 return false;
3443 }
Svet Ganovb320e182015-04-16 12:30:10 -07003444
Andrew Lee77527ac2014-10-21 16:57:39 -07003445 // Check the user preference and the system-level IMS setting. Even if the user has
3446 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3447 // In the long run, we may instead need to check if there exists a connection service
3448 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003449 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3450 return imsManager.isVtEnabledByPlatform()
3451 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3452 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003453 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003454
Andrew Leea1239f22015-03-02 17:44:07 -08003455 @Override
3456 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003457 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003458 }
3459
3460 @Override
3461 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003462 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003463 }
3464
Andrew Lee9431b832015-03-09 18:46:45 -07003465 @Override
3466 public boolean isTtyModeSupported() {
3467 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3468 TelephonyManager telephonyManager =
3469 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003470 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003471 }
3472
3473 @Override
3474 public boolean isHearingAidCompatibilitySupported() {
3475 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3476 }
3477
Hall Liu98187582018-01-22 19:15:32 -08003478 public boolean isRttSupported() {
3479 boolean isCarrierSupported =
3480 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3481 boolean isDeviceSupported =
3482 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3483 return isCarrierSupported && isDeviceSupported;
3484 }
3485
Hall Liu3ad5f012018-04-06 16:23:39 -07003486 public boolean isRttEnabled() {
3487 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3488 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3489 }
3490
Sanket Padawe7310cc72015-01-14 09:53:20 -08003491 /**
3492 * Returns the unique device ID of phone, for example, the IMEI for
3493 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3494 *
3495 * <p>Requires Permission:
3496 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3497 */
3498 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003499 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003500 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003501 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003502 return null;
3503 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003504 int subId = phone.getSubId();
3505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3506 mApp, subId, callingPackage, "getDeviceId")) {
3507 return null;
3508 }
3509 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003510 }
3511
Ping Sunc67b7c22016-03-02 19:16:45 +08003512 /**
3513 * {@hide}
3514 * Returns the IMS Registration Status on a particular subid
3515 *
3516 * @param subId
3517 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003518 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003519 Phone phone = getPhone(subId);
3520 if (phone != null) {
3521 return phone.isImsRegistered();
3522 } else {
3523 return false;
3524 }
3525 }
3526
Santos Cordon7a1885b2015-02-03 11:15:19 -08003527 @Override
3528 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3529 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3530 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003531
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003532 /**
3533 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003534 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003535 public boolean isWifiCallingAvailable(int subId) {
3536 Phone phone = getPhone(subId);
3537 if (phone != null) {
3538 return phone.isWifiCallingEnabled();
3539 } else {
3540 return false;
3541 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003542 }
3543
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003544 /**
3545 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003546 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003547 public boolean isVolteAvailable(int subId) {
3548 Phone phone = getPhone(subId);
3549 if (phone != null) {
3550 return phone.isVolteEnabled();
3551 } else {
3552 return false;
3553 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003554 }
Svet Ganovb320e182015-04-16 12:30:10 -07003555
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003556 /**
3557 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003558 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003559 public boolean isVideoTelephonyAvailable(int subId) {
3560 Phone phone = getPhone(subId);
3561 if (phone != null) {
3562 return phone.isVideoEnabled();
3563 } else {
3564 return false;
3565 }
3566 }
3567
3568 /**
3569 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3570 * defined in {@link ImsRegistrationImplBase}.
3571 */
3572 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3573 Phone phone = getPhone(subId);
3574 if (phone != null) {
3575 return phone.getImsRegistrationTech();
3576 } else {
3577 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3578 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003579 }
3580
Stuart Scott8eef64f2015-04-08 15:13:54 -07003581 @Override
3582 public void factoryReset(int subId) {
3583 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003584 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3585 return;
3586 }
3587
Svet Ganovcc087f82015-05-12 20:35:54 -07003588 final long identity = Binder.clearCallingIdentity();
3589 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003590 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3591 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003592 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003593 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003594 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3595 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003596 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003597 }
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003600 }
3601 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003602
3603 @Override
3604 public String getLocaleFromDefaultSim() {
3605 // We query all subscriptions instead of just the active ones, because
3606 // this might be called early on in the provisioning flow when the
3607 // subscriptions potentially aren't active yet.
3608 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3609 if (slist == null || slist.isEmpty()) {
3610 return null;
3611 }
3612
3613 // This function may be called very early, say, from the setup wizard, at
3614 // which point we won't have a default subscription set. If that's the case
3615 // we just choose the first, which will be valid in "most cases".
3616 final int defaultSubId = getDefaultSubscription();
3617 SubscriptionInfo info = null;
3618 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3619 info = slist.get(0);
3620 } else {
3621 for (SubscriptionInfo item : slist) {
3622 if (item.getSubscriptionId() == defaultSubId) {
3623 info = item;
3624 break;
3625 }
3626 }
3627
3628 if (info == null) {
3629 return null;
3630 }
3631 }
3632
3633 // Try and fetch the locale from the carrier properties or from the SIM language
3634 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003635 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003636 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003637 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003638 if (defaultPhone != null) {
3639 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3640 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003641 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003642 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3643 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003644 } else {
3645 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003646 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003647 }
3648 }
3649
Narayan Kamath011676f2015-07-29 12:04:08 +01003650 // The SIM language preferences only store a language (e.g. fr = French), not an
3651 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3652 // the SIM and carrier preferences does not include a country we add the country
3653 // determined from the SIM MCC to provide an exact locale.
3654 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003655 if (mccLocale != null) {
3656 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3657 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003658 }
3659
Tony Hill183b2de2015-06-24 14:53:58 +01003660 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003661 return null;
3662 }
3663
3664 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 return mSubscriptionController.getAllSubInfoList(
3668 mPhone.getContext().getOpPackageName());
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
3672 }
3673
3674 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3675 final long identity = Binder.clearCallingIdentity();
3676 try {
3677 return mSubscriptionController.getActiveSubscriptionInfoList(
3678 mPhone.getContext().getOpPackageName());
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
3682 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003683
Chenjie Yu1ba97252018-01-11 18:16:20 -08003684 private final ModemActivityInfo mLastModemActivityInfo =
3685 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3686
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003687 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003688 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3689 * representing the state of the modem.
3690 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003691 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3692 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003693 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003694 */
3695 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003696 public void requestModemActivityInfo(ResultReceiver result) {
3697 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003698 ModemActivityInfo ret = null;
3699 synchronized (mLastModemActivityInfo) {
3700 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3701 null);
Siddharth Rayf5d29552018-06-17 15:02:38 -07003702 if (isModemActivityInfoValid(info)) {
Chenjie Yu1ba97252018-01-11 18:16:20 -08003703 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3704 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3705 mergedTxTimeMs[i] =
3706 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3707 }
3708 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3709 mLastModemActivityInfo.setSleepTimeMillis(
3710 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3711 mLastModemActivityInfo.setIdleTimeMillis(
3712 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3713 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3714 mLastModemActivityInfo.setRxTimeMillis(
3715 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3716 mLastModemActivityInfo.setEnergyUsed(
3717 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3718 }
3719 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3720 mLastModemActivityInfo.getSleepTimeMillis(),
3721 mLastModemActivityInfo.getIdleTimeMillis(),
3722 mLastModemActivityInfo.getTxTimeMillis(),
3723 mLastModemActivityInfo.getRxTimeMillis(),
3724 mLastModemActivityInfo.getEnergyUsed());
3725 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003726 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003727 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003728 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003729 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003730
Siddharth Rayf5d29552018-06-17 15:02:38 -07003731 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
3732 // less than total activity duration.
3733 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
3734 if (info == null) {
3735 return false;
3736 }
3737 int activityDurationMs =
3738 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
3739 int totalTxTimeMs = 0;
3740 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
3741 totalTxTimeMs += info.getTxTimeMillis()[i];
3742 }
3743 return (info.isValid()
3744 && (info.getSleepTimeMillis() <= activityDurationMs)
3745 && (info.getIdleTimeMillis() <= activityDurationMs)
3746 && (info.getRxTimeMillis() <= activityDurationMs)
3747 && (totalTxTimeMs <= activityDurationMs));
3748 }
3749
Jack Yu85bd38a2015-11-09 11:34:32 -08003750 /**
3751 * {@hide}
3752 * Returns the service state information on specified subscription.
3753 */
3754 @Override
3755 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3756
Jeff Davidson7e17e312018-02-13 18:17:36 -08003757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003758 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003759 return null;
3760 }
3761
3762 final Phone phone = getPhone(subId);
3763 if (phone == null) {
3764 return null;
3765 }
3766
3767 return phone.getServiceState();
3768 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003769
3770 /**
3771 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3772 *
3773 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3774 * voicemail ringtone.
3775 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3776 * PhoneAccount.
3777 */
3778 @Override
3779 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003780 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003781 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003782 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003783 }
3784
fionaxu7ed723d2017-05-30 18:58:54 -07003785 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003786 }
3787
3788 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003789 * Sets the per-account voicemail ringtone.
3790 *
3791 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3792 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3793 *
3794 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3795 * voicemail ringtone.
3796 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3797 * PhoneAccount.
3798 */
3799 @Override
3800 public void setVoicemailRingtoneUri(String callingPackage,
3801 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3802 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3803 if (!TextUtils.equals(callingPackage,
3804 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3806 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3807 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003808 }
3809 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3810 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003811 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003812 }
fionaxu7ed723d2017-05-30 18:58:54 -07003813 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003814 }
3815
3816 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003817 * Returns whether vibration is set for voicemail notification in Phone settings.
3818 *
3819 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3820 * voicemail vibration setting.
3821 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3822 */
3823 @Override
3824 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003825 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003826 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003827 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003828 }
3829
fionaxu7ed723d2017-05-30 18:58:54 -07003830 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003831 }
3832
Youhan Wange64578a2016-05-02 15:32:42 -07003833 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003834 * Sets the per-account voicemail vibration.
3835 *
3836 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3837 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3838 *
3839 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3840 * voicemail vibration setting.
3841 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3842 * specific PhoneAccount.
3843 */
3844 @Override
3845 public void setVoicemailVibrationEnabled(String callingPackage,
3846 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3847 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3848 if (!TextUtils.equals(callingPackage,
3849 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3851 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3852 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003853 }
3854
3855 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3856 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003857 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003858 }
fionaxu7ed723d2017-05-30 18:58:54 -07003859 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003860 }
3861
3862 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003863 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3864 *
3865 * @throws SecurityException if the caller does not have the required permission
3866 */
3867 private void enforceReadPrivilegedPermission() {
3868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3869 null);
3870 }
3871
3872 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003873 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3874 * permission.
3875 *
3876 * @throws SecurityException if the caller does not have the required permission
3877 */
3878 private void enforceSendSmsPermission() {
3879 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3880 }
3881
3882 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003883 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003884 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003885 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003886 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003887 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003888 ComponentName componentName =
3889 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3890 if(componentName == null) {
3891 throw new SecurityException("Caller not current active visual voicemail package[null]");
3892 }
3893 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003894 if (!callingPackage.equals(vvmPackage)) {
3895 throw new SecurityException("Caller not current active visual voicemail package[" +
3896 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003897 }
3898 }
3899
3900 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003901 * Return the application ID for the app type.
3902 *
3903 * @param subId the subscription ID that this request applies to.
3904 * @param appType the uicc app type.
3905 * @return Application ID for specificied app type, or null if no uicc.
3906 */
3907 @Override
3908 public String getAidForAppType(int subId, int appType) {
3909 enforceReadPrivilegedPermission();
3910 Phone phone = getPhone(subId);
3911 if (phone == null) {
3912 return null;
3913 }
3914 String aid = null;
3915 try {
3916 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3917 .getApplicationByType(appType).getAid();
3918 } catch (Exception e) {
3919 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3920 }
3921 return aid;
3922 }
3923
Youhan Wang4001d252016-05-11 10:29:41 -07003924 /**
3925 * Return the Electronic Serial Number.
3926 *
3927 * @param subId the subscription ID that this request applies to.
3928 * @return ESN or null if error.
3929 */
3930 @Override
3931 public String getEsn(int subId) {
3932 enforceReadPrivilegedPermission();
3933 Phone phone = getPhone(subId);
3934 if (phone == null) {
3935 return null;
3936 }
3937 String esn = null;
3938 try {
3939 esn = phone.getEsn();
3940 } catch (Exception e) {
3941 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3942 }
3943 return esn;
3944 }
3945
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003946 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003947 * Return the Preferred Roaming List Version.
3948 *
3949 * @param subId the subscription ID that this request applies to.
3950 * @return PRLVersion or null if error.
3951 */
3952 @Override
3953 public String getCdmaPrlVersion(int subId) {
3954 enforceReadPrivilegedPermission();
3955 Phone phone = getPhone(subId);
3956 if (phone == null) {
3957 return null;
3958 }
3959 String cdmaPrlVersion = null;
3960 try {
3961 cdmaPrlVersion = phone.getCdmaPrlVersion();
3962 } catch (Exception e) {
3963 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3964 }
3965 return cdmaPrlVersion;
3966 }
3967
3968 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003969 * Get snapshot of Telephony histograms
3970 * @return List of Telephony histograms
3971 * @hide
3972 */
3973 @Override
3974 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3976 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003977 return RIL.getTelephonyRILTimingHistograms();
3978 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003979
3980 /**
3981 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003982 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003983 * Require system privileges. In the future we may add this to carrier APIs.
3984 *
3985 * @return The number of carriers set successfully, should match length of carriers
3986 */
3987 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003988 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003989 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003990
Meng Wang9b7c4e92017-02-17 11:41:27 -08003991 if (carriers == null) {
3992 throw new NullPointerException("carriers cannot be null");
3993 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003994
3995 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003996 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3997 return retVal[0];
3998 }
3999
4000 /**
4001 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004002 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004003 * Require system privileges. In the future we may add this to carrier APIs.
4004 *
4005 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4006 * means all carriers are allowed.
4007 */
4008 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004009 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004010 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004011 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07004012 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4013 }
4014
fionaxu59545b42016-05-25 15:53:37 -07004015 /**
4016 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4017 * @param subId the subscription ID that this action applies to.
4018 * @param enabled control enable or disable metered apns.
4019 * {@hide}
4020 */
4021 @Override
4022 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4023 enforceModifyPermission();
4024 final Phone phone = getPhone(subId);
4025 if (phone == null) {
4026 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4027 return;
4028 }
4029 try {
4030 phone.carrierActionSetMeteredApnsEnabled(enabled);
4031 } catch (Exception e) {
4032 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
4033 }
4034 }
4035
4036 /**
4037 * Action set from carrier signalling broadcast receivers to enable/disable radio
4038 * @param subId the subscription ID that this action applies to.
4039 * @param enabled control enable or disable radio.
4040 * {@hide}
4041 */
4042 @Override
4043 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4044 enforceModifyPermission();
4045 final Phone phone = getPhone(subId);
4046 if (phone == null) {
4047 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4048 return;
4049 }
4050 try {
4051 phone.carrierActionSetRadioEnabled(enabled);
4052 } catch (Exception e) {
4053 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
4054 }
4055 }
4056
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004057 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004058 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4059 * network status based on which carrier apps could apply actions accordingly,
4060 * enable/disable default url handler for example.
4061 *
4062 * @param subId the subscription ID that this action applies to.
4063 * @param report control start/stop reporting the default network status.
4064 * {@hide}
4065 */
4066 @Override
4067 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4068 enforceModifyPermission();
4069 final Phone phone = getPhone(subId);
4070 if (phone == null) {
4071 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4072 return;
4073 }
4074 try {
4075 phone.carrierActionReportDefaultNetworkStatus(report);
4076 } catch (Exception e) {
4077 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
4078 }
4079 }
4080
4081 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004082 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4083 * bug report is being generated.
4084 */
4085 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004086 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004087 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4088 != PackageManager.PERMISSION_GRANTED) {
4089 writer.println("Permission Denial: can't dump Phone from pid="
4090 + Binder.getCallingPid()
4091 + ", uid=" + Binder.getCallingUid()
4092 + "without permission "
4093 + android.Manifest.permission.DUMP);
4094 return;
4095 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004096 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004097 }
Jack Yueb89b242016-06-22 13:27:47 -07004098
Brad Ebingerdac2f002018-04-03 15:17:52 -07004099 @Override
4100 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4101 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4102 throws RemoteException {
4103 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4104 }
4105
Jack Yueb89b242016-06-22 13:27:47 -07004106 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004107 * Get aggregated video call data usage since boot.
4108 *
4109 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4110 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004111 * {@hide}
4112 */
4113 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004114 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004115 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4116 null);
4117
Jack Yu84291ec2017-05-26 16:07:50 -07004118 // NetworkStatsService keeps tracking the active network interface and identity. It
4119 // records the delta with the corresponding network identity. We just return the total video
4120 // call data usage snapshot since boot.
4121 Phone phone = getPhone(subId);
4122 if (phone != null) {
4123 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004124 }
Jack Yu84291ec2017-05-26 16:07:50 -07004125 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004126 }
Jack Yu75ab2952016-07-08 14:29:33 -07004127
4128 /**
4129 * Policy control of data connection. Usually used when data limit is passed.
4130 * @param enabled True if enabling the data, otherwise disabling.
4131 * @param subId Subscription index
4132 * {@hide}
4133 */
4134 @Override
4135 public void setPolicyDataEnabled(boolean enabled, int subId) {
4136 enforceModifyPermission();
4137 Phone phone = getPhone(subId);
4138 if (phone != null) {
4139 phone.setPolicyDataEnabled(enabled);
4140 }
4141 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004142
4143 /**
4144 * Get Client request stats
4145 * @return List of Client Request Stats
4146 * @hide
4147 */
4148 @Override
4149 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004151 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004152 return null;
4153 }
4154
4155 Phone phone = getPhone(subId);
4156 if (phone != null) {
4157 return phone.getClientRequestStats();
4158 }
4159
4160 return null;
4161 }
4162
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004163 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004164 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004165 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004166 }
Jack Yueb4124c2017-02-16 15:32:43 -08004167
4168 /**
Grace Chen70990072017-03-24 17:21:30 -07004169 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004170 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004171 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004172 * @param state State of SIM (power down, power up, pass through)
4173 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4174 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4175 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004176 *
4177 **/
4178 @Override
Grace Chen70990072017-03-24 17:21:30 -07004179 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004180 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004181 Phone phone = PhoneFactory.getPhone(slotIndex);
4182
Jack Yueb4124c2017-02-16 15:32:43 -08004183 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004184 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004185 }
4186 }
Shuo Qiandd210312017-04-12 22:11:33 +00004187
Tyler Gunn65d45c22017-06-05 11:22:26 -07004188 private boolean isUssdApiAllowed(int subId) {
4189 CarrierConfigManager configManager =
4190 (CarrierConfigManager) mPhone.getContext().getSystemService(
4191 Context.CARRIER_CONFIG_SERVICE);
4192 if (configManager == null) {
4193 return false;
4194 }
4195 PersistableBundle pb = configManager.getConfigForSubId(subId);
4196 if (pb == null) {
4197 return false;
4198 }
4199 return pb.getBoolean(
4200 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4201 }
4202
Shuo Qiandd210312017-04-12 22:11:33 +00004203 /**
4204 * Check if phone is in emergency callback mode
4205 * @return true if phone is in emergency callback mode
4206 * @param subId sub id
4207 */
goneil9c5f4872017-12-05 14:07:56 -08004208 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004209 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004210 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004211 final Phone phone = getPhone(subId);
4212 if (phone != null) {
4213 return phone.isInEcm();
4214 } else {
4215 return false;
4216 }
4217 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004218
4219 /**
4220 * Get the current signal strength information for the given subscription.
4221 * Because this information is not updated when the device is in a low power state
4222 * it should not be relied-upon to be current.
4223 * @param subId Subscription index
4224 * @return the most recent cached signal strength info from the modem
4225 */
4226 @Override
4227 public SignalStrength getSignalStrength(int subId) {
4228 Phone p = getPhone(subId);
4229 if (p == null) {
4230 return null;
4231 }
4232
4233 return p.getSignalStrength();
4234 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004235
4236 @Override
4237 public UiccSlotInfo[] getUiccSlotsInfo() {
4238 enforceReadPrivilegedPermission();
4239
4240 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004241 if (slots == null) {
4242 Rlog.i(LOG_TAG, "slots is null.");
4243 return null;
4244 }
4245
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004246 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4247 for (int i = 0; i < slots.length; i++) {
4248 UiccSlot slot = slots[i];
Holly Jiuyu Sun6723f982018-06-04 15:48:38 -07004249 if (slot == null) {
4250 continue;
4251 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004252
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004253 String cardId;
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004254 UiccCard card = slot.getUiccCard();
4255 if (card != null) {
4256 cardId = card.getCardId();
Holly Jiuyu Sun4f124222018-04-18 17:36:34 -07004257 } else {
4258 cardId = slot.getIccId();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004259 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004260
4261 int cardState = 0;
4262 switch (slot.getCardState()) {
4263 case CARDSTATE_ABSENT:
4264 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4265 break;
4266 case CARDSTATE_PRESENT:
4267 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4268 break;
4269 case CARDSTATE_ERROR:
4270 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4271 break;
4272 case CARDSTATE_RESTRICTED:
4273 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4274 break;
4275 default:
4276 break;
4277
4278 }
4279
Qingxi Li795c5882018-01-31 13:43:27 -08004280 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004281 slot.isActive(),
4282 slot.isEuicc(),
4283 cardId,
4284 cardState,
4285 slot.getPhoneId(),
4286 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004287 }
4288 return infos;
4289 }
4290
4291 @Override
4292 public boolean switchSlots(int[] physicalSlots) {
4293 enforceModifyPermission();
4294 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4295 }
Jack Yu4c988042018-02-27 15:30:01 -08004296
4297 @Override
4298 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4299 enforceModifyPermission();
4300 final Phone phone = getPhone(subId);
4301 if (phone == null) {
4302 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4303 return;
4304 }
4305
4306 phone.setRadioIndicationUpdateMode(filters, mode);
4307 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004308
4309 /**
goneil47ffb6e2018-04-06 15:40:58 -07004310 * A test API to reload the UICC profile.
4311 *
4312 * <p>Requires that the calling app has permission
4313 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4314 * @hide
4315 */
4316 @Override
4317 public void refreshUiccProfile(int subId) {
4318 enforceModifyPermission();
4319
4320 final long identity = Binder.clearCallingIdentity();
4321 try {
4322 Phone phone = getPhone(subId);
4323 if (phone == null) {
4324 return;
4325 }
4326 UiccCard uiccCard = phone.getUiccCard();
4327 if (uiccCard == null) {
4328 return;
4329 }
4330 UiccProfile uiccProfile = uiccCard.getUiccProfile();
4331 if (uiccProfile == null) {
4332 return;
4333 }
4334 uiccProfile.refresh();
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
4338 }
4339
4340 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07004341 * Returns false if the mobile data is disabled by default, otherwise return true.
4342 */
4343 private boolean getDefaultDataEnabled() {
4344 return "true".equalsIgnoreCase(
4345 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4346 }
4347
4348 /**
4349 * Returns true if the data roaming is enabled by default, i.e the system property
4350 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4351 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4352 */
4353 private boolean getDefaultDataRoamingEnabled(int subId) {
4354 final CarrierConfigManager configMgr = (CarrierConfigManager)
4355 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4356 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4357 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4358 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4359 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4360 return isDataRoamingEnabled;
4361 }
4362
4363 /**
4364 * Returns the default network type for the given {@code subId}, if the default network type is
4365 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4366 */
4367 private int getDefaultNetworkType(int subId) {
4368 return Integer.parseInt(
4369 TelephonyManager.getTelephonyProperty(
4370 mSubscriptionController.getPhoneId(subId),
4371 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4372 String.valueOf(Phone.PREFERRED_NT_MODE)));
4373 }
fionaxua13278b2018-03-21 00:08:13 -07004374
4375 @Override
4376 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4377 gid1, String gid2, String plmn, String spn) {
4378 enforceModifyPermission();
4379 final Phone phone = getPhone(subId);
4380 if (phone == null) {
4381 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4382 return;
4383 }
4384 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4385 }
4386
4387 @Override
4388 public int getCarrierIdListVersion(int subId) {
4389 enforceReadPrivilegedPermission();
4390 final Phone phone = getPhone(subId);
4391 if (phone == null) {
4392 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4393 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4394 }
4395 return phone.getCarrierIdListVersion();
4396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004397}