blob: f089d8f045a1668d9314020641f26e3f1edf5cda [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;
Nathan Haroldf180aac2018-06-01 18:43:55 -070058import android.telephony.CellInfoGsm;
59import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070060import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070061import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070062import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080063import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070064import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080065import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070066import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070067import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070068import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080070import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070071import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080072import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070074import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070075import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000076import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070077import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070078import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070079import android.telephony.cdma.CdmaCellLocation;
80import android.telephony.gsm.GsmCellLocation;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080081import android.telephony.ims.aidl.IImsConfig;
82import android.telephony.ims.aidl.IImsMmTelFeature;
83import android.telephony.ims.aidl.IImsRcsFeature;
84import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080085import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080087import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080091
Andrew Lee312e8172014-10-23 17:01:36 -070092import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080093import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070094import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070095import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070096import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070097import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070098import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800101import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700102import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100103import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700104import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700105import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700107import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800108import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700109import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700110import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700111import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700112import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700113import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700114import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800115import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800116import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700117import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.uicc.IccIoResult;
119import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800120import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700121import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800122import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800124import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700126import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800127import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700128import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800129import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700130import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700131import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800132
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700133import java.io.FileDescriptor;
134import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800135import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800137import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800138import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100139import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141
142/**
143 * Implementation of the ITelephony interface.
144 */
Santos Cordon117fee72014-05-16 17:56:12 -0700145public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 private static final String LOG_TAG = "PhoneInterfaceManager";
147 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
148 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800149 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150
151 // Message codes used with mMainThreadHandler
152 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700153 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
154 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155 private static final int CMD_OPEN_CHANNEL = 9;
156 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
157 private static final int CMD_CLOSE_CHANNEL = 11;
158 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800159 private static final int CMD_NV_READ_ITEM = 13;
160 private static final int EVENT_NV_READ_ITEM_DONE = 14;
161 private static final int CMD_NV_WRITE_ITEM = 15;
162 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
163 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
164 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
165 private static final int CMD_NV_RESET_CONFIG = 19;
166 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800167 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
168 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
169 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
170 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800171 private static final int CMD_SEND_ENVELOPE = 25;
172 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000173 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
174 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700175 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
176 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
177 private static final int CMD_EXCHANGE_SIM_IO = 31;
178 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800179 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
180 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700181 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
182 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700183 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
184 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700185 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
186 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
187 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
188 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700189 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
190 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
191 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
192 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700193 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800194 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
195 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000196 private static final int CMD_SWITCH_SLOTS = 50;
197 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700198 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
199 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
200 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
201 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
202 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
203 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
204 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
205 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700206 private static final int CMD_GET_ALL_CELL_INFO = 60;
207 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
208 private static final int CMD_GET_CELL_LOCATION = 62;
209 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700210
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800211 // Parameters of select command.
212 private static final int SELECT_COMMAND = 0xA4;
213 private static final int SELECT_P1 = 0x04;
214 private static final int SELECT_P2 = 0;
215 private static final int SELECT_P3 = 0x10;
216
Pengquan Meng85728fb2018-03-12 16:31:21 -0700217 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
218 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
219 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
220
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221 /** The singleton instance. */
222 private static PhoneInterfaceManager sInstance;
223
Wink Saville3ab207e2014-11-20 13:07:20 -0800224 private PhoneGlobals mApp;
225 private Phone mPhone;
226 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700227 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800228 private AppOpsManager mAppOps;
229 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800230 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800231 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700232 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233
Derek Tan97ebb422014-09-05 16:55:38 -0700234 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
235 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700237
Derek Tan740e1672017-06-27 14:56:27 -0700238 // The AID of ISD-R.
239 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
240
yinxub1bed742017-04-17 11:45:04 -0700241 private NetworkScanRequestTracker mNetworkScanRequestTracker;
242
David Kelly5e06a7f2018-03-12 14:10:59 +0000243 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
244 private static final int MANUFACTURER_CODE_LENGTH = 8;
245
Derek Tan89e89d42014-07-08 17:00:10 -0700246 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700247 * A request object to use for transmitting data to an ICC.
248 */
249 private static final class IccAPDUArgument {
250 public int channel, cla, command, p1, p2, p3;
251 public String data;
252
253 public IccAPDUArgument(int channel, int cla, int command,
254 int p1, int p2, int p3, String data) {
255 this.channel = channel;
256 this.cla = cla;
257 this.command = command;
258 this.p1 = p1;
259 this.p2 = p2;
260 this.p3 = p3;
261 this.data = data;
262 }
263 }
264
265 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700266 * A request object to use for transmitting data to an ICC.
267 */
268 private static final class ManualNetworkSelectionArgument {
269 public OperatorInfo operatorInfo;
270 public boolean persistSelection;
271
272 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
273 this.operatorInfo = operatorInfo;
274 this.persistSelection = persistSelection;
275 }
276 }
277
278 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
280 * request after sending. The main thread will notify the request when it is complete.
281 */
282 private static final class MainThreadRequest {
283 /** The argument to use for the request */
284 public Object argument;
285 /** The result of the request that is run on the main thread */
286 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800287 // The subscriber id that this request applies to. Defaults to
288 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
289 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
vagdevie435a3e2018-08-15 16:01:53 -0700291 public WorkSource workSource;
292
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293 public MainThreadRequest(Object argument) {
294 this.argument = argument;
295 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800296
vagdevie435a3e2018-08-15 16:01:53 -0700297 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800298 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800299 if (subId != null) {
300 this.subId = subId;
301 }
vagdevie435a3e2018-08-15 16:01:53 -0700302 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304 }
305
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800306 private static final class IncomingThirdPartyCallArgs {
307 public final ComponentName component;
308 public final String callId;
309 public final String callerDisplayName;
310
311 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
312 String callerDisplayName) {
313 this.component = component;
314 this.callId = callId;
315 this.callerDisplayName = callerDisplayName;
316 }
317 }
318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 /**
320 * A handler that processes messages on the main thread in the phone process. Since many
321 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
322 * inbound binder threads to the main thread in the phone process. The Binder thread
323 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
324 * on, which will be notified when the operation completes and will contain the result of the
325 * request.
326 *
327 * <p>If a MainThreadRequest object is provided in the msg.obj field,
328 * note that request.result must be set to something non-null for the calling thread to
329 * unblock.
330 */
331 private final class MainThreadHandler extends Handler {
332 @Override
333 public void handleMessage(Message msg) {
334 MainThreadRequest request;
335 Message onCompleted;
336 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800337 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700338 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339
340 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700341 case CMD_HANDLE_USSD_REQUEST: {
342 request = (MainThreadRequest) msg.obj;
343 final Phone phone = getPhoneFromRequest(request);
344 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
345 String ussdRequest = ussdObject.first;
346 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700347
Pengquan Meng0c05b502018-09-06 09:59:22 -0700348 if (!isUssdApiAllowed(request.subId)) {
349 // Carrier does not support use of this API, return failure.
350 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
351 UssdResponse response = new UssdResponse(ussdRequest, null);
352 Bundle returnData = new Bundle();
353 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
354 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700355
Pengquan Meng0c05b502018-09-06 09:59:22 -0700356 request.result = true;
357 notifyRequester(request);
358 return;
359 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700360
Pengquan Meng0c05b502018-09-06 09:59:22 -0700361 try {
362 request.result = phone != null
363 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
364 } catch (CallStateException cse) {
365 request.result = false;
366 }
367 // Wake up the requesting thread
368 notifyRequester(request);
369 break;
pkanwar32d516d2016-10-14 19:37:38 -0700370 }
371
Yorke Lee716f67e2015-06-17 15:39:16 -0700372 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700374 final Phone phone = getPhoneFromRequest(request);
375 request.result = phone != null ?
376 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
377 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700379 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700383 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700384 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700385 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800386 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700387 if (uiccCard == null) {
388 loge("iccTransmitApduLogicalChannel: No UICC");
389 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700390 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700391 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700392 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
393 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700394 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700395 iccArgument.channel, iccArgument.cla, iccArgument.command,
396 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700397 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700398 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700399 break;
400
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700402 ar = (AsyncResult) msg.obj;
403 request = (MainThreadRequest) ar.userObj;
404 if (ar.exception == null && ar.result != null) {
405 request.result = ar.result;
406 } else {
407 request.result = new IccIoResult(0x6F, 0, (byte[])null);
408 if (ar.result == null) {
409 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800410 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700411 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800412 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700413 } else {
414 loge("iccTransmitApduLogicalChannel: Unknown exception");
415 }
416 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700417 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 break;
419
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
421 request = (MainThreadRequest) msg.obj;
422 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800423 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 if (uiccCard == null) {
425 loge("iccTransmitApduBasicChannel: No UICC");
426 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700427 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 } else {
429 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
430 request);
431 uiccCard.iccTransmitApduBasicChannel(
432 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
433 iccArgument.p3, iccArgument.data, onCompleted);
434 }
435 break;
436
437 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
438 ar = (AsyncResult) msg.obj;
439 request = (MainThreadRequest) ar.userObj;
440 if (ar.exception == null && ar.result != null) {
441 request.result = ar.result;
442 } else {
443 request.result = new IccIoResult(0x6F, 0, (byte[])null);
444 if (ar.result == null) {
445 loge("iccTransmitApduBasicChannel: Empty response");
446 } else if (ar.exception instanceof CommandException) {
447 loge("iccTransmitApduBasicChannel: CommandException: " +
448 ar.exception);
449 } else {
450 loge("iccTransmitApduBasicChannel: Unknown exception");
451 }
452 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 break;
455
456 case CMD_EXCHANGE_SIM_IO:
457 request = (MainThreadRequest) msg.obj;
458 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800459 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 if (uiccCard == null) {
461 loge("iccExchangeSimIO: No UICC");
462 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700463 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 } else {
465 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
466 request);
467 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
468 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
469 iccArgument.data, onCompleted);
470 }
471 break;
472
473 case EVENT_EXCHANGE_SIM_IO_DONE:
474 ar = (AsyncResult) msg.obj;
475 request = (MainThreadRequest) ar.userObj;
476 if (ar.exception == null && ar.result != null) {
477 request.result = ar.result;
478 } else {
479 request.result = new IccIoResult(0x6f, 0, (byte[])null);
480 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 break;
483
Derek Tan4d5e5c12014-02-04 11:54:58 -0800484 case CMD_SEND_ENVELOPE:
485 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700487 if (uiccCard == null) {
488 loge("sendEnvelopeWithStatus: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 } else {
492 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
493 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
494 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800495 break;
496
497 case EVENT_SEND_ENVELOPE_DONE:
498 ar = (AsyncResult) msg.obj;
499 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700500 if (ar.exception == null && ar.result != null) {
501 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800502 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700503 request.result = new IccIoResult(0x6F, 0, (byte[])null);
504 if (ar.result == null) {
505 loge("sendEnvelopeWithStatus: Empty response");
506 } else if (ar.exception instanceof CommandException) {
507 loge("sendEnvelopeWithStatus: CommandException: " +
508 ar.exception);
509 } else {
510 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
511 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800512 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700513 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800514 break;
515
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 case CMD_OPEN_CHANNEL:
517 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800519 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700520 if (uiccCard == null) {
521 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800522 request.result = new IccOpenLogicalChannelResponse(-1,
523 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700524 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700525 } else {
526 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800527 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
528 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 break;
531
532 case EVENT_OPEN_CHANNEL_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700536 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 int[] result = (int[]) ar.result;
538 int channelId = result[0];
539 byte[] selectResponse = null;
540 if (result.length > 1) {
541 selectResponse = new byte[result.length - 1];
542 for (int i = 1; i < result.length; ++i) {
543 selectResponse[i - 1] = (byte) result[i];
544 }
545 }
546 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700547 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 if (ar.result == null) {
550 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 if (ar.exception != null) {
553 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
554 }
555
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700556 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700557 if (ar.exception instanceof CommandException) {
558 CommandException.Error error =
559 ((CommandException) (ar.exception)).getCommandError();
560 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700561 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700562 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700563 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 }
565 }
566 openChannelResp = new IccOpenLogicalChannelResponse(
567 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700569 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700570 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 break;
572
573 case CMD_CLOSE_CHANNEL:
574 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800575 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 if (uiccCard == null) {
577 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900578 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 } else {
581 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
582 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
583 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 break;
585
586 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800587 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
588 break;
589
590 case CMD_NV_READ_ITEM:
591 request = (MainThreadRequest) msg.obj;
592 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700593 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800594 break;
595
596 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 ar = (AsyncResult) msg.obj;
598 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800599 if (ar.exception == null && ar.result != null) {
600 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800602 request.result = "";
603 if (ar.result == null) {
604 loge("nvReadItem: Empty response");
605 } else if (ar.exception instanceof CommandException) {
606 loge("nvReadItem: CommandException: " +
607 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800609 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 }
611 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 break;
614
Jake Hambye994d462014-02-03 13:10:13 -0800615 case CMD_NV_WRITE_ITEM:
616 request = (MainThreadRequest) msg.obj;
617 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
618 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700619 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
620 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800621 break;
622
623 case EVENT_NV_WRITE_ITEM_DONE:
624 handleNullReturnEvent(msg, "nvWriteItem");
625 break;
626
627 case CMD_NV_WRITE_CDMA_PRL:
628 request = (MainThreadRequest) msg.obj;
629 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
630 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
631 break;
632
633 case EVENT_NV_WRITE_CDMA_PRL_DONE:
634 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
635 break;
636
637 case CMD_NV_RESET_CONFIG:
638 request = (MainThreadRequest) msg.obj;
639 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
640 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
641 break;
642
643 case EVENT_NV_RESET_CONFIG_DONE:
644 handleNullReturnEvent(msg, "nvResetConfig");
645 break;
646
Jake Hamby7c27be32014-03-03 13:25:59 -0800647 case CMD_GET_PREFERRED_NETWORK_TYPE:
648 request = (MainThreadRequest) msg.obj;
649 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700650 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800651 break;
652
653 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result; // Integer
658 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800659 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800660 if (ar.result == null) {
661 loge("getPreferredNetworkType: Empty response");
662 } else if (ar.exception instanceof CommandException) {
663 loge("getPreferredNetworkType: CommandException: " +
664 ar.exception);
665 } else {
666 loge("getPreferredNetworkType: Unknown exception");
667 }
668 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700669 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800670 break;
671
672 case CMD_SET_PREFERRED_NETWORK_TYPE:
673 request = (MainThreadRequest) msg.obj;
674 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
675 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700676 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800677 break;
678
679 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
680 handleNullReturnEvent(msg, "setPreferredNetworkType");
681 break;
682
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000683 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
684 request = (MainThreadRequest)msg.obj;
685 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700686 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000687 break;
688
689 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
690 ar = (AsyncResult)msg.obj;
691 request = (MainThreadRequest)ar.userObj;
692 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700693 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000694 break;
695
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800696 case CMD_SET_VOICEMAIL_NUMBER:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
699 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800700 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
701 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800702 break;
703
704 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
705 handleNullReturnEvent(msg, "setVoicemailNumber");
706 break;
707
Stuart Scott54788802015-03-30 13:18:01 -0700708 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
711 request);
712 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
713 break;
714
715 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
716 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
717 break;
718
Shishir Agrawal302c8692015-06-19 13:49:39 -0700719 case CMD_PERFORM_NETWORK_SCAN:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
722 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
723 break;
724
725 case EVENT_PERFORM_NETWORK_SCAN_DONE:
726 ar = (AsyncResult) msg.obj;
727 request = (MainThreadRequest) ar.userObj;
728 CellNetworkScanResult cellScanResult;
729 if (ar.exception == null && ar.result != null) {
730 cellScanResult = new CellNetworkScanResult(
731 CellNetworkScanResult.STATUS_SUCCESS,
732 (List<OperatorInfo>) ar.result);
733 } else {
734 if (ar.result == null) {
735 loge("getCellNetworkScanResults: Empty response");
736 }
737 if (ar.exception != null) {
738 loge("getCellNetworkScanResults: Exception: " + ar.exception);
739 }
740 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
741 if (ar.exception instanceof CommandException) {
742 CommandException.Error error =
743 ((CommandException) (ar.exception)).getCommandError();
744 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
745 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
746 } else if (error == CommandException.Error.GENERIC_FAILURE) {
747 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
748 }
749 }
750 cellScanResult = new CellNetworkScanResult(errorCode, null);
751 }
752 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700753 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700754 break;
755
756 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
757 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700758 ManualNetworkSelectionArgument selArg =
759 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700760 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
761 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700762 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
763 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700764 break;
765
766 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
767 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
768 break;
769
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700770 case CMD_GET_MODEM_ACTIVITY_INFO:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700773 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700774 break;
775
776 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
779 if (ar.exception == null && ar.result != null) {
780 request.result = ar.result;
781 } else {
782 if (ar.result == null) {
783 loge("queryModemActivityInfo: Empty response");
784 } else if (ar.exception instanceof CommandException) {
785 loge("queryModemActivityInfo: CommandException: " +
786 ar.exception);
787 } else {
788 loge("queryModemActivityInfo: Unknown exception");
789 }
790 }
Amit Mahajand4766222016-01-28 15:28:28 -0800791 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
792 if (request.result == null) {
793 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
794 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700795 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700796 break;
797
Meng Wang1a7c35a2016-05-05 20:56:15 -0700798 case CMD_SET_ALLOWED_CARRIERS:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
801 mPhone.setAllowedCarriers(
802 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700803 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700804 break;
805
806 case EVENT_SET_ALLOWED_CARRIERS_DONE:
807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null && ar.result != null) {
810 request.result = ar.result;
811 } else {
812 if (ar.result == null) {
813 loge("setAllowedCarriers: Empty response");
814 } else if (ar.exception instanceof CommandException) {
815 loge("setAllowedCarriers: CommandException: " +
816 ar.exception);
817 } else {
818 loge("setAllowedCarriers: Unknown exception");
819 }
820 }
821 // Result cannot be null. Return -1 on error.
822 if (request.result == null) {
823 request.result = new int[]{-1};
824 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700825 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700826 break;
827
828 case CMD_GET_ALLOWED_CARRIERS:
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700831 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700832 break;
833
834 case EVENT_GET_ALLOWED_CARRIERS_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result;
839 } else {
840 if (ar.result == null) {
841 loge("getAllowedCarriers: Empty response");
842 } else if (ar.exception instanceof CommandException) {
843 loge("getAllowedCarriers: CommandException: " +
844 ar.exception);
845 } else {
846 loge("getAllowedCarriers: Unknown exception");
847 }
848 }
849 // Result cannot be null. Return empty list of CarrierIdentifier.
850 if (request.result == null) {
851 request.result = new ArrayList<CarrierIdentifier>(0);
852 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700853 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700854 break;
855
Nathan Haroldb3014052017-01-25 15:57:32 -0800856 case EVENT_GET_FORBIDDEN_PLMNS_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 request.result = new IllegalArgumentException(
863 "Failed to retrieve Forbidden Plmns");
864 if (ar.result == null) {
865 loge("getForbiddenPlmns: Empty response");
866 } else {
867 loge("getForbiddenPlmns: Unknown exception");
868 }
869 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700870 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800871 break;
872
873 case CMD_GET_FORBIDDEN_PLMNS:
874 request = (MainThreadRequest) msg.obj;
875 uiccCard = getUiccCardFromRequest(request);
876 if (uiccCard == null) {
877 loge("getForbiddenPlmns() UiccCard is null");
878 request.result = new IllegalArgumentException(
879 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700880 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800881 break;
882 }
883 Integer appType = (Integer) request.argument;
884 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
885 if (uiccApp == null) {
886 loge("getForbiddenPlmns() no app with specified type -- "
887 + appType);
888 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700889 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800890 break;
891 } else {
892 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
893 + " specified type -- " + appType);
894 }
895 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
896 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
897 onCompleted);
898 break;
899
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000900 case CMD_SWITCH_SLOTS:
901 request = (MainThreadRequest) msg.obj;
902 int[] physicalSlots = (int[]) request.argument;
903 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
904 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
905 break;
906
907 case EVENT_SWITCH_SLOTS_DONE:
908 ar = (AsyncResult) msg.obj;
909 request = (MainThreadRequest) ar.userObj;
910 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700911 notifyRequester(request);
912 break;
913 case CMD_GET_NETWORK_SELECTION_MODE:
914 request = (MainThreadRequest) msg.obj;
915 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
916 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
917 break;
918
919 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
920 ar = (AsyncResult) msg.obj;
921 request = (MainThreadRequest) ar.userObj;
922 if (ar.exception != null) {
923 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
924 } else {
925 int mode = ((int[]) ar.result)[0];
926 if (mode == 0) {
927 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
928 } else {
929 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
930 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000931 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700932 notifyRequester(request);
933 break;
934 case CMD_GET_CDMA_ROAMING_MODE:
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
937 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
938 break;
939 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
940 ar = (AsyncResult) msg.obj;
941 request = (MainThreadRequest) ar.userObj;
942 if (ar.exception != null) {
943 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
944 } else {
945 request.result = ((int[]) ar.result)[0];
946 }
947 notifyRequester(request);
948 break;
949 case CMD_SET_CDMA_ROAMING_MODE:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
952 int mode = (int) request.argument;
953 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
954 break;
955 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
956 ar = (AsyncResult) msg.obj;
957 request = (MainThreadRequest) ar.userObj;
958 request.result = ar.exception == null;
959 notifyRequester(request);
960 break;
961 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
964 int subscriptionMode = (int) request.argument;
965 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
966 break;
967 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
970 request.result = ar.exception == null;
971 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000972 break;
973
Nathan Harold3ff88932018-08-14 10:19:49 -0700974 case CMD_GET_ALL_CELL_INFO:
975 request = (MainThreadRequest) msg.obj;
976 Pair<Phone, WorkSource> args = (Pair<Phone, WorkSource>) request.argument;
977 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
978 ((Phone) args.first).getAllCellInfo(args.second, onCompleted);
979 break;
980
981 case EVENT_GET_ALL_CELL_INFO_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 request.result = (ar.exception == null) ? ar.result : new ArrayList<CellInfo>();
985 synchronized (request) {
986 request.notifyAll();
987 }
988 break;
989
990 case CMD_GET_CELL_LOCATION: {
991 request = (MainThreadRequest) msg.obj;
992 WorkSource ws = (WorkSource) request.argument;
993 Phone phone = getPhoneFromRequest(request);
994 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
995 break;
996 }
997
998 case EVENT_GET_CELL_LOCATION_DONE: {
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null) {
1002 request.result = ar.result;
1003 } else {
1004 Phone phone = getPhoneFromRequest(request);
1005 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1006 ? new CdmaCellLocation() : new GsmCellLocation();
1007 }
1008
1009 synchronized (request) {
1010 request.notifyAll();
1011 }
1012 break;
1013 }
1014
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001015 default:
1016 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1017 break;
1018 }
1019 }
Jake Hambye994d462014-02-03 13:10:13 -08001020
Pengquan Meng0c05b502018-09-06 09:59:22 -07001021 private void notifyRequester(MainThreadRequest request) {
1022 synchronized (request) {
1023 request.notifyAll();
1024 }
1025 }
1026
Jake Hambye994d462014-02-03 13:10:13 -08001027 private void handleNullReturnEvent(Message msg, String command) {
1028 AsyncResult ar = (AsyncResult) msg.obj;
1029 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception == null) {
1031 request.result = true;
1032 } else {
1033 request.result = false;
1034 if (ar.exception instanceof CommandException) {
1035 loge(command + ": CommandException: " + ar.exception);
1036 } else {
1037 loge(command + ": Unknown exception");
1038 }
1039 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001040 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001042 }
1043
1044 /**
1045 * Posts the specified command to be executed on the main thread,
1046 * waits for the request to complete, and returns the result.
1047 * @see #sendRequestAsync
1048 */
1049 private Object sendRequest(int command, Object argument) {
vagdevie435a3e2018-08-15 16:01:53 -07001050 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1051 }
1052
1053 /**
1054 * Posts the specified command to be executed on the main thread,
1055 * waits for the request to complete, and returns the result.
1056 * @see #sendRequestAsync
1057 */
1058 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1059 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1060 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001061 }
1062
1063 /**
1064 * Posts the specified command to be executed on the main thread,
1065 * waits for the request to complete, and returns the result.
1066 * @see #sendRequestAsync
1067 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001068 private Object sendRequest(int command, Object argument, Integer subId) {
vagdevie435a3e2018-08-15 16:01:53 -07001069 return sendRequest(command, argument, subId, null);
1070 }
1071
1072 /**
1073 * Posts the specified command to be executed on the main thread,
1074 * waits for the request to complete, and returns the result.
1075 * @see #sendRequestAsync
1076 */
1077 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1079 throw new RuntimeException("This method will deadlock if called from the main thread.");
1080 }
1081
vagdevie435a3e2018-08-15 16:01:53 -07001082 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 Message msg = mMainThreadHandler.obtainMessage(command, request);
1084 msg.sendToTarget();
1085
1086 // Wait for the request to complete
1087 synchronized (request) {
1088 while (request.result == null) {
1089 try {
1090 request.wait();
1091 } catch (InterruptedException e) {
1092 // Do nothing, go back and wait until the request is complete
1093 }
1094 }
1095 }
1096 return request.result;
1097 }
1098
1099 /**
1100 * Asynchronous ("fire and forget") version of sendRequest():
1101 * Posts the specified command to be executed on the main thread, and
1102 * returns immediately.
1103 * @see #sendRequest
1104 */
1105 private void sendRequestAsync(int command) {
1106 mMainThreadHandler.sendEmptyMessage(command);
1107 }
1108
1109 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001110 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1111 * @see {@link #sendRequest(int,Object)}
1112 */
1113 private void sendRequestAsync(int command, Object argument) {
1114 MainThreadRequest request = new MainThreadRequest(argument);
1115 Message msg = mMainThreadHandler.obtainMessage(command, request);
1116 msg.sendToTarget();
1117 }
1118
1119 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001120 * Initialize the singleton PhoneInterfaceManager instance.
1121 * This is only done once, at startup, from PhoneApp.onCreate().
1122 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001123 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001124 synchronized (PhoneInterfaceManager.class) {
1125 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001126 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001127 } else {
1128 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1129 }
1130 return sInstance;
1131 }
1132 }
1133
1134 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001135 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 mApp = app;
1137 mPhone = phone;
1138 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001139 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1141 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001142 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001143 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001144 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001145 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001146 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001147
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 publish();
1149 }
1150
1151 private void publish() {
1152 if (DBG) log("publish: " + this);
1153
1154 ServiceManager.addService("phone", this);
1155 }
1156
Stuart Scott584921c2015-01-15 17:10:34 -08001157 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001158 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1159 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001160 }
1161
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001162 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1163 Phone phone = getPhoneFromRequest(request);
1164 return phone == null ? null :
1165 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1166 }
1167
Wink Saville36469e72014-06-11 15:17:00 -07001168 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001169 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001170 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172 //
1173 // Implementation of the ITelephony interface.
1174 //
1175
1176 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001177 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001178 }
1179
Wink Savilleb564aae2014-10-23 10:18:09 -07001180 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001181 if (DBG) log("dial: " + number);
1182 // No permission check needed here: This is just a wrapper around the
1183 // ACTION_DIAL intent, which is available to any app since it puts up
1184 // the UI before it does anything.
1185
Malcolm Chenaabec062018-02-28 15:00:40 -08001186 final long identity = Binder.clearCallingIdentity();
1187 try {
1188 String url = createTelUrl(number);
1189 if (url == null) {
1190 return;
1191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192
Malcolm Chenaabec062018-02-28 15:00:40 -08001193 // PENDING: should we just silently fail if phone is offhook or ringing?
1194 PhoneConstants.State state = mCM.getState(subId);
1195 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1196 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1197 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1198 mApp.startActivity(intent);
1199 }
1200 } finally {
1201 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 }
1203 }
1204
1205 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001206 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001207 }
1208
Wink Savilleb564aae2014-10-23 10:18:09 -07001209 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001210 if (DBG) log("call: " + number);
1211
1212 // This is just a wrapper around the ACTION_CALL intent, but we still
1213 // need to do a permission check since we're calling startActivity()
1214 // from the context of the phone app.
1215 enforceCallPermission();
1216
1217 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1218 != AppOpsManager.MODE_ALLOWED) {
1219 return;
1220 }
1221
Malcolm Chenaabec062018-02-28 15:00:40 -08001222 final long identity = Binder.clearCallingIdentity();
1223 try {
1224 String url = createTelUrl(number);
1225 if (url == null) {
1226 return;
1227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228
Malcolm Chenaabec062018-02-28 15:00:40 -08001229 boolean isValid = false;
1230 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1231 if (slist != null) {
1232 for (SubscriptionInfo subInfoRecord : slist) {
1233 if (subInfoRecord.getSubscriptionId() == subId) {
1234 isValid = true;
1235 break;
1236 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001237 }
Wink Saville08874612014-08-31 19:19:58 -07001238 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001239 if (!isValid) {
1240 return;
1241 }
Wink Saville08874612014-08-31 19:19:58 -07001242
Malcolm Chenaabec062018-02-28 15:00:40 -08001243 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1244 intent.putExtra(SUBSCRIPTION_KEY, subId);
1245 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1246 mApp.startActivity(intent);
1247 } finally {
1248 Binder.restoreCallingIdentity(identity);
1249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 }
1251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 /**
1253 * End a call based on call state
1254 * @return true is a call was ended
1255 */
1256 public boolean endCall() {
Hall Liu91943182018-09-14 17:42:41 -07001257 return false;
Wink Saville36469e72014-06-11 15:17:00 -07001258 }
1259
1260 /**
1261 * End a call based on the call state of the subId
1262 * @return true is a call was ended
1263 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001264 public boolean endCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001265 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 }
1267
1268 public void answerRingingCall() {
Hall Liu91943182018-09-14 17:42:41 -07001269 // Deprecated.
Wink Saville36469e72014-06-11 15:17:00 -07001270 }
1271
Wink Savilleb564aae2014-10-23 10:18:09 -07001272 public void answerRingingCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001273 // Deprecated
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 }
1275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001277 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001279 public void silenceRinger() {
1280 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 }
1282
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001283 @Override
1284 public boolean isOffhook(String callingPackage) {
1285 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
1287
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 @Override
1289 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001291 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001292 return false;
1293 }
1294
Malcolm Chenaabec062018-02-28 15:00:40 -08001295 final long identity = Binder.clearCallingIdentity();
1296 try {
1297 final Phone phone = getPhone(subId);
1298 if (phone != null) {
1299 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1300 } else {
1301 return false;
1302 }
1303 } finally {
1304 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 }
1307
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001308 @Override
1309 public boolean isRinging(String callingPackage) {
1310 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001311 }
1312
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001313 @Override
1314 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001316 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001317 return false;
1318 }
1319
Malcolm Chenaabec062018-02-28 15:00:40 -08001320 final long identity = Binder.clearCallingIdentity();
1321 try {
1322 final Phone phone = getPhone(subId);
1323 if (phone != null) {
1324 return (phone.getState() == PhoneConstants.State.RINGING);
1325 } else {
1326 return false;
1327 }
1328 } finally {
1329 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 }
1332
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001333 @Override
1334 public boolean isIdle(String callingPackage) {
1335 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001336 }
1337
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001338 @Override
1339 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001341 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001342 return false;
1343 }
1344
Malcolm Chenaabec062018-02-28 15:00:40 -08001345 final long identity = Binder.clearCallingIdentity();
1346 try {
1347 final Phone phone = getPhone(subId);
1348 if (phone != null) {
1349 return (phone.getState() == PhoneConstants.State.IDLE);
1350 } else {
1351 return false;
1352 }
1353 } finally {
1354 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 }
1357
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001359 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001360 }
1361
Wink Savilleb564aae2014-10-23 10:18:09 -07001362 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001363 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001364 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1365 }
1366
1367 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001368 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001369 }
1370
Wink Savilleb564aae2014-10-23 10:18:09 -07001371 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001372 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001373 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1374 }
1375
1376 /** {@hide} */
1377 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001378 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001379 }
1380
Wink Savilleb564aae2014-10-23 10:18:09 -07001381 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001383
1384 final long identity = Binder.clearCallingIdentity();
1385 try {
1386 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1387 checkSimPin.start();
1388 return checkSimPin.unlockSim(null, pin);
1389 } finally {
1390 Binder.restoreCallingIdentity(identity);
1391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 }
1393
Wink Saville9de0f752013-10-22 19:04:03 -07001394 /** {@hide} */
1395 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001396 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001397 }
1398
Wink Savilleb564aae2014-10-23 10:18:09 -07001399 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001401
1402 final long identity = Binder.clearCallingIdentity();
1403 try {
1404 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1405 checkSimPuk.start();
1406 return checkSimPuk.unlockSim(puk, pin);
1407 } finally {
1408 Binder.restoreCallingIdentity(identity);
1409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 }
1411
1412 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001413 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414 * a synchronous one.
1415 */
1416 private static class UnlockSim extends Thread {
1417
1418 private final IccCard mSimCard;
1419
1420 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001421 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1422 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423
1424 // For replies from SimCard interface
1425 private Handler mHandler;
1426
1427 // For async handler to identify request type
1428 private static final int SUPPLY_PIN_COMPLETE = 100;
1429
1430 public UnlockSim(IccCard simCard) {
1431 mSimCard = simCard;
1432 }
1433
1434 @Override
1435 public void run() {
1436 Looper.prepare();
1437 synchronized (UnlockSim.this) {
1438 mHandler = new Handler() {
1439 @Override
1440 public void handleMessage(Message msg) {
1441 AsyncResult ar = (AsyncResult) msg.obj;
1442 switch (msg.what) {
1443 case SUPPLY_PIN_COMPLETE:
1444 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1445 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001446 mRetryCount = msg.arg1;
1447 if (ar.exception != null) {
1448 if (ar.exception instanceof CommandException &&
1449 ((CommandException)(ar.exception)).getCommandError()
1450 == CommandException.Error.PASSWORD_INCORRECT) {
1451 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1452 } else {
1453 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1454 }
1455 } else {
1456 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 mDone = true;
1459 UnlockSim.this.notifyAll();
1460 }
1461 break;
1462 }
1463 }
1464 };
1465 UnlockSim.this.notifyAll();
1466 }
1467 Looper.loop();
1468 }
1469
1470 /*
1471 * Use PIN or PUK to unlock SIM card
1472 *
1473 * If PUK is null, unlock SIM card with PIN
1474 *
1475 * If PUK is not null, unlock SIM card with PUK and set PIN code
1476 */
Wink Saville9de0f752013-10-22 19:04:03 -07001477 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478
1479 while (mHandler == null) {
1480 try {
1481 wait();
1482 } catch (InterruptedException e) {
1483 Thread.currentThread().interrupt();
1484 }
1485 }
1486 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1487
1488 if (puk == null) {
1489 mSimCard.supplyPin(pin, callback);
1490 } else {
1491 mSimCard.supplyPuk(puk, pin, callback);
1492 }
1493
1494 while (!mDone) {
1495 try {
1496 Log.d(LOG_TAG, "wait for done");
1497 wait();
1498 } catch (InterruptedException e) {
1499 // Restore the interrupted status
1500 Thread.currentThread().interrupt();
1501 }
1502 }
1503 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001504 int[] resultArray = new int[2];
1505 resultArray[0] = mResult;
1506 resultArray[1] = mRetryCount;
1507 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 }
1509 }
1510
1511 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001513
1514 }
1515
Wink Savilleb564aae2014-10-23 10:18:09 -07001516 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001517 // No permission check needed here: this call is harmless, and it's
1518 // needed for the ServiceState.requestStateUpdate() call (which is
1519 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001520 final long identity = Binder.clearCallingIdentity();
1521 try {
1522 final Phone phone = getPhone(subId);
1523 if (phone != null) {
1524 phone.updateServiceLocation();
1525 }
1526 } finally {
1527 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
1530
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001531 @Override
1532 public boolean isRadioOn(String callingPackage) {
1533 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001534 }
1535
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001536 @Override
1537 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001539 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001540 return false;
1541 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001542
1543 final long identity = Binder.clearCallingIdentity();
1544 try {
1545 return isRadioOnForSubscriber(subId);
1546 } finally {
1547 Binder.restoreCallingIdentity(identity);
1548 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001549 }
1550
1551 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001552 final long identity = Binder.clearCallingIdentity();
1553 try {
1554 final Phone phone = getPhone(subId);
1555 if (phone != null) {
1556 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1557 } else {
1558 return false;
1559 }
1560 } finally {
1561 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
1564
1565 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001566 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
Wink Saville36469e72014-06-11 15:17:00 -07001568
Wink Savilleb564aae2014-10-23 10:18:09 -07001569 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001571
1572 final long identity = Binder.clearCallingIdentity();
1573 try {
1574 final Phone phone = getPhone(subId);
1575 if (phone != null) {
1576 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1577 }
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 }
Wink Saville36469e72014-06-11 15:17:00 -07001581 }
1582
1583 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001584 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001585 }
1586
Wink Savilleb564aae2014-10-23 10:18:09 -07001587 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001588 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001589
1590 final long identity = Binder.clearCallingIdentity();
1591 try {
1592 final Phone phone = getPhone(subId);
1593 if (phone == null) {
1594 return false;
1595 }
1596 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1597 toggleRadioOnOffForSubscriber(subId);
1598 }
1599 return true;
1600 } finally {
1601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 }
Wink Saville36469e72014-06-11 15:17:00 -07001604
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001605 public boolean needMobileRadioShutdown() {
1606 /*
1607 * If any of the Radios are available, it will need to be
1608 * shutdown. So return true if any Radio is available.
1609 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001610 final long identity = Binder.clearCallingIdentity();
1611 try {
1612 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1613 Phone phone = PhoneFactory.getPhone(i);
1614 if (phone != null && phone.isRadioAvailable()) return true;
1615 }
1616 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1617 return false;
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001620 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001621 }
1622
Malcolm Chenaabec062018-02-28 15:00:40 -08001623 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001624 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001625 enforceModifyPermission();
1626
1627 final long identity = Binder.clearCallingIdentity();
1628 try {
1629 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1630 logv("Shutting down Phone " + i);
1631 shutdownRadioUsingPhoneId(i);
1632 }
1633 } finally {
1634 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001635 }
1636 }
1637
1638 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001639 Phone phone = PhoneFactory.getPhone(phoneId);
1640 if (phone != null && phone.isRadioAvailable()) {
1641 phone.shutdownRadio();
1642 }
1643 }
1644
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001646 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001647
1648 final long identity = Binder.clearCallingIdentity();
1649 try {
1650 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1651 if (defaultPhone != null) {
1652 defaultPhone.setRadioPower(turnOn);
1653 return true;
1654 } else {
1655 loge("There's no default phone.");
1656 return false;
1657 }
1658 } finally {
1659 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001660 }
Wink Saville36469e72014-06-11 15:17:00 -07001661 }
1662
Wink Savilleb564aae2014-10-23 10:18:09 -07001663 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001665
1666 final long identity = Binder.clearCallingIdentity();
1667 try {
1668 final Phone phone = getPhone(subId);
1669 if (phone != null) {
1670 phone.setRadioPower(turnOn);
1671 return true;
1672 } else {
1673 return false;
1674 }
1675 } finally {
1676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 }
1679
Wink Saville36469e72014-06-11 15:17:00 -07001680 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001681 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 public boolean enableDataConnectivity() {
1683 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001684
1685 final long identity = Binder.clearCallingIdentity();
1686 try {
1687 int subId = mSubscriptionController.getDefaultDataSubId();
1688 final Phone phone = getPhone(subId);
1689 if (phone != null) {
1690 phone.setUserDataEnabled(true);
1691 return true;
1692 } else {
1693 return false;
1694 }
1695 } finally {
1696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 }
1699
Wink Saville36469e72014-06-11 15:17:00 -07001700 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 public boolean disableDataConnectivity() {
1703 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001704
1705 final long identity = Binder.clearCallingIdentity();
1706 try {
1707 int subId = mSubscriptionController.getDefaultDataSubId();
1708 final Phone phone = getPhone(subId);
1709 if (phone != null) {
1710 phone.setUserDataEnabled(false);
1711 return true;
1712 } else {
1713 return false;
1714 }
1715 } finally {
1716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 }
1719
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001721 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001722 final long identity = Binder.clearCallingIdentity();
1723 try {
1724 final Phone phone = getPhone(subId);
1725 if (phone != null) {
1726 return phone.isDataAllowed();
1727 } else {
1728 return false;
1729 }
1730 } finally {
1731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 }
1734
1735 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001736 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001737 }
1738
pkanwarae03a6b2016-11-06 20:37:09 -08001739 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001740 enforceCallPermission();
1741
1742 final long identity = Binder.clearCallingIdentity();
1743 try {
1744 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1745 return;
1746 }
1747 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1748 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
1751 }
pkanwar32d516d2016-10-14 19:37:38 -07001752 };
1753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1760 return false;
1761 }
1762 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 }
1767
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001769 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001770 }
1771
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001772 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001773 final long identity = Binder.clearCallingIdentity();
1774 try {
1775 Phone phone = PhoneFactory.getPhone(slotIndex);
1776 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1777 PhoneConstantConversions.convertCallState(phone.getState());
1778 } finally {
1779 Binder.restoreCallingIdentity(identity);
1780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 }
1782
Sanket Padawe356d7632015-06-22 14:03:32 -07001783 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1788 if (phone != null) {
1789 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1790 } else {
1791 return PhoneConstantConversions.convertDataState(
1792 PhoneConstants.DataState.DISCONNECTED);
1793 }
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
Sanket Padawe356d7632015-06-22 14:03:32 -07001799 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1804 if (phone != null) {
1805 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1806 } else {
1807 return TelephonyManager.DATA_ACTIVITY_NONE;
1808 }
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 }
1813
1814 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001815 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001816 mPhone.getContext().getSystemService(AppOpsManager.class)
1817 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001818 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001819 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001820 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 }
1822
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001823 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001824 final long identity = Binder.clearCallingIdentity();
1825 try {
1826 if (DBG_LOC) log("getCellLocation: is active user");
1827 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001828 int subId = mSubscriptionController.getDefaultDataSubId();
1829 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1830 cl.fillInNotifierBundle(data);
Malcolm Chenaabec062018-02-28 15:00:40 -08001831 return data;
1832 } finally {
1833 Binder.restoreCallingIdentity(identity);
1834 }
Svetoslav64fad262015-04-14 14:35:21 -07001835 }
1836
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001838 public String getNetworkCountryIsoForPhone(int phoneId) {
1839 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1840 // registered cell info, so return a NULL country instead.
1841 final long identity = Binder.clearCallingIdentity();
1842 try {
1843 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001844 // Todo: fix this when we can get the actual cellular network info when the device
1845 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001846 if (TelephonyManager.NETWORK_TYPE_IWLAN
1847 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1848 return "";
1849 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001850 Phone phone = PhoneFactory.getPhone(phoneId);
1851 if (phone != null) {
1852 ServiceStateTracker sst = phone.getServiceStateTracker();
1853 if (sst != null) {
1854 LocaleTracker lt = sst.getLocaleTracker();
1855 if (lt != null) {
1856 return lt.getCurrentCountry();
1857 }
1858 }
1859 }
1860 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001861 } finally {
1862 Binder.restoreCallingIdentity(identity);
1863 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001864 }
1865
1866 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001868 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001869 }
1870
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001872 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 mApp.enforceCallingOrSelfPermission(
1874 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001875
1876 final long identity = Binder.clearCallingIdentity();
1877 try {
1878 final Phone phone = getPhone(subId);
1879 if (phone != null) {
1880 phone.enableLocationUpdates();
1881 }
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
1887 @Override
1888 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001889 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001890 }
1891
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001893 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 mApp.enforceCallingOrSelfPermission(
1895 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001896
1897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 final Phone phone = getPhone(subId);
1900 if (phone != null) {
1901 phone.disableLocationUpdates();
1902 }
1903 } finally {
1904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 }
1907
1908 @Override
1909 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001910 public List<NeighboringCellInfo>
1911 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001912 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1913 throw new SecurityException(
1914 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1915 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001916
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1918 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1919 return null;
1920 }
Svetoslav64fad262015-04-14 14:35:21 -07001921
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001922 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923
Nathan Haroldf180aac2018-06-01 18:43:55 -07001924 List<CellInfo> info = getAllCellInfo(callingPackage);
1925 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926
Nathan Haroldf180aac2018-06-01 18:43:55 -07001927 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1928 for (CellInfo ci : info) {
1929 if (ci instanceof CellInfoGsm) {
1930 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1931 } else if (ci instanceof CellInfoWcdma) {
1932 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001935 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
1938
1939 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001940 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001941 mPhone.getContext().getSystemService(AppOpsManager.class)
1942 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001943 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001944 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001945 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001948 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001949 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001950 final long identity = Binder.clearCallingIdentity();
1951 try {
1952 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1953 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001954 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1955 CMD_GET_ALL_CELL_INFO,
1956 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaabec062018-02-28 15:00:40 -08001957 if (info != null) cellInfos.addAll(info);
1958 }
1959 return cellInfos;
1960 } finally {
1961 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963 }
1964
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001965 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001967 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001968 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001969
1970 final long identity = Binder.clearCallingIdentity();
1971 try {
1972 mPhone.setCellInfoListRate(rateInMillis, workSource);
1973 } finally {
1974 Binder.restoreCallingIdentity(identity);
1975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 }
1977
Shishir Agrawala9f32182016-04-12 12:00:16 -07001978 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001979 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001980 Phone phone = PhoneFactory.getPhone(slotIndex);
1981 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001982 return null;
1983 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001984 int subId = phone.getSubId();
1985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1986 mApp, subId, callingPackage, "getImeiForSlot")) {
1987 return null;
1988 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001989
1990 final long identity = Binder.clearCallingIdentity();
1991 try {
1992 return phone.getImei();
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
1995 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001996 }
1997
1998 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001999 public String getTypeAllocationCodeForSlot(int slotIndex) {
2000 Phone phone = PhoneFactory.getPhone(slotIndex);
2001 String tac = null;
2002 if (phone != null) {
2003 String imei = phone.getImei();
2004 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2005 }
2006 return tac;
2007 }
2008
2009 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002010 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002011 Phone phone = PhoneFactory.getPhone(slotIndex);
2012 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002013 return null;
2014 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002015 int subId = phone.getSubId();
2016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2017 mApp, subId, callingPackage, "getMeidForSlot")) {
2018 return null;
2019 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002020
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 return phone.getMeid();
2024 } finally {
2025 Binder.restoreCallingIdentity(identity);
2026 }
Jack Yu2af8d712017-03-15 17:14:14 -07002027 }
2028
2029 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002030 public String getManufacturerCodeForSlot(int slotIndex) {
2031 Phone phone = PhoneFactory.getPhone(slotIndex);
2032 String manufacturerCode = null;
2033 if (phone != null) {
2034 String meid = phone.getMeid();
2035 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2036 }
2037 return manufacturerCode;
2038 }
2039
2040 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002041 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002042 Phone phone = PhoneFactory.getPhone(slotIndex);
2043 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002044 return null;
2045 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002046 int subId = phone.getSubId();
2047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2048 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2049 return null;
2050 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002051
2052 final long identity = Binder.clearCallingIdentity();
2053 try {
2054 return phone.getDeviceSvn();
2055 } finally {
2056 Binder.restoreCallingIdentity(identity);
2057 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002058 }
2059
fionaxu43304da2017-11-27 22:51:16 -08002060 @Override
2061 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002062 final long identity = Binder.clearCallingIdentity();
2063 try {
2064 final Phone phone = getPhone(subId);
2065 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2066 } finally {
2067 Binder.restoreCallingIdentity(identity);
2068 }
fionaxu43304da2017-11-27 22:51:16 -08002069 }
2070
2071 @Override
2072 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002073 final long identity = Binder.clearCallingIdentity();
2074 try {
2075 final Phone phone = getPhone(subId);
2076 return phone == null ? null : phone.getCarrierName();
2077 } finally {
2078 Binder.restoreCallingIdentity(identity);
2079 }
fionaxu43304da2017-11-27 22:51:16 -08002080 }
2081
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 //
2083 // Internal helper methods.
2084 //
2085
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002086 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2088 *
2089 * @throws SecurityException if the caller does not have the required permission
2090 */
2091 private void enforceModifyPermission() {
2092 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2093 }
2094
2095 /**
2096 * Make sure the caller has the CALL_PHONE permission.
2097 *
2098 * @throws SecurityException if the caller does not have the required permission
2099 */
2100 private void enforceCallPermission() {
2101 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2102 }
2103
Stuart Scott8eef64f2015-04-08 15:13:54 -07002104 private void enforceConnectivityInternalPermission() {
2105 mApp.enforceCallingOrSelfPermission(
2106 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2107 "ConnectivityService");
2108 }
2109
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 private String createTelUrl(String number) {
2111 if (TextUtils.isEmpty(number)) {
2112 return null;
2113 }
2114
Jake Hambye994d462014-02-03 13:10:13 -08002115 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 }
2117
Ihab Awadf9e92732013-12-05 18:02:52 -08002118 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2120 }
2121
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002122 private static void logv(String msg) {
2123 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2124 }
2125
Ihab Awadf9e92732013-12-05 18:02:52 -08002126 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2128 }
2129
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002130 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002132 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002133 }
2134
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002136 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002137 final long identity = Binder.clearCallingIdentity();
2138 try {
2139 final Phone phone = PhoneFactory.getPhone(slotIndex);
2140 if (phone == null) {
2141 return PhoneConstants.PHONE_TYPE_NONE;
2142 } else {
2143 return phone.getPhoneType();
2144 }
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 }
2149
2150 /**
2151 * Returns the CDMA ERI icon index to display
2152 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002153 @Override
2154 public int getCdmaEriIconIndex(String callingPackage) {
2155 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002156 }
2157
Sanket Padawe356d7632015-06-22 14:03:32 -07002158 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002159 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002161 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002162 return -1;
2163 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002164
2165 final long identity = Binder.clearCallingIdentity();
2166 try {
2167 final Phone phone = getPhone(subId);
2168 if (phone != null) {
2169 return phone.getCdmaEriIconIndex();
2170 } else {
2171 return -1;
2172 }
2173 } finally {
2174 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 }
2177
2178 /**
2179 * Returns the CDMA ERI icon mode,
2180 * 0 - ON
2181 * 1 - FLASHING
2182 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002183 @Override
2184 public int getCdmaEriIconMode(String callingPackage) {
2185 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002186 }
2187
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002189 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002191 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002192 return -1;
2193 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002194
2195 final long identity = Binder.clearCallingIdentity();
2196 try {
2197 final Phone phone = getPhone(subId);
2198 if (phone != null) {
2199 return phone.getCdmaEriIconMode();
2200 } else {
2201 return -1;
2202 }
2203 } finally {
2204 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002205 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 }
2207
2208 /**
2209 * Returns the CDMA ERI text,
2210 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002211 @Override
2212 public String getCdmaEriText(String callingPackage) {
2213 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002214 }
2215
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002217 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002219 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002220 return null;
2221 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002222
2223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 final Phone phone = getPhone(subId);
2226 if (phone != null) {
2227 return phone.getCdmaEriText();
2228 } else {
2229 return null;
2230 }
2231 } finally {
2232 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235
2236 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002237 * Returns the CDMA MDN.
2238 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002240 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2242 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002243
2244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 final Phone phone = getPhone(subId);
2247 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2248 return phone.getLine1Number();
2249 } else {
2250 return null;
2251 }
2252 } finally {
2253 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002254 }
2255 }
2256
2257 /**
2258 * Returns the CDMA MIN.
2259 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002260 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002261 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2263 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002264
2265 final long identity = Binder.clearCallingIdentity();
2266 try {
2267 final Phone phone = getPhone(subId);
2268 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2269 return phone.getCdmaMin();
2270 } else {
2271 return null;
2272 }
2273 } finally {
2274 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002275 }
2276 }
2277
2278 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 * Returns true if CDMA provisioning needs to run.
2280 */
2281 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002282 final long identity = Binder.clearCallingIdentity();
2283 try {
2284 return mPhone.needsOtaServiceProvisioning();
2285 } finally {
2286 Binder.restoreCallingIdentity(identity);
2287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
2289
2290 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002291 * Sets the voice mail number of a given subId.
2292 */
2293 @Override
2294 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002295 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002296
2297 final long identity = Binder.clearCallingIdentity();
2298 try {
2299 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2300 new Pair<String, String>(alphaTag, number), new Integer(subId));
2301 return success;
2302 } finally {
2303 Binder.restoreCallingIdentity(identity);
2304 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002305 }
2306
Ta-wei Yen87c49842016-05-13 21:19:52 -07002307 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002308 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2309 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2310 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2311 if (!TextUtils.equals(callingPackage, systemDialer)) {
2312 throw new SecurityException("caller must be system dialer");
2313 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002314
2315 final long identity = Binder.clearCallingIdentity();
2316 try {
2317 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2318 if (phoneAccountHandle == null) {
2319 return null;
2320 }
2321 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2322 } finally {
2323 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002324 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002325 }
2326
2327 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002328 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002329 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002331 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002332 return null;
2333 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002334
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002335 final long identity = Binder.clearCallingIdentity();
2336 try {
2337 return RemoteVvmTaskManager
2338 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2339 } finally {
2340 Binder.restoreCallingIdentity(identity);
2341 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002342 }
2343
2344 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002345 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2346 VisualVoicemailSmsFilterSettings settings) {
2347 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002348
2349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2352 mPhone.getContext(), callingPackage, subId, settings);
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
2355 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002356 }
2357
2358 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002359 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2360 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002361
2362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2365 mPhone.getContext(), callingPackage, subId);
2366 } finally {
2367 Binder.restoreCallingIdentity(identity);
2368 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002369 }
2370
2371 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002372 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2373 String callingPackage, int subId) {
2374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002375
2376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2379 mPhone.getContext(), callingPackage, subId);
2380 } finally {
2381 Binder.restoreCallingIdentity(identity);
2382 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002383 }
2384
2385 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002386 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002387 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002388
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2392 mPhone.getContext(), subId);
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
2395 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002396 }
2397
2398 @Override
2399 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2400 String number, int port, String text, PendingIntent sentIntent) {
2401 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002402 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002403 enforceSendSmsPermission();
2404 // Make the calls as the phone process.
2405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2408 if (port == 0) {
2409 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2410 sentIntent, null, false);
2411 } else {
2412 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2413 smsManager.sendDataMessageWithSelfPermissions(number, null,
2414 (short) port, data, sentIntent, null);
2415 }
2416 } finally {
2417 Binder.restoreCallingIdentity(identity);
2418 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002419 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002420 /**
fionaxu0152e512016-11-14 13:36:14 -08002421 * Sets the voice activation state of a given subId.
2422 */
2423 @Override
2424 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2426 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002427
2428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 final Phone phone = getPhone(subId);
2431 if (phone != null) {
2432 phone.setVoiceActivationState(activationState);
2433 } else {
2434 loge("setVoiceActivationState fails with invalid subId: " + subId);
2435 }
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002438 }
2439 }
2440
2441 /**
2442 * Sets the data activation state of a given subId.
2443 */
2444 @Override
2445 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2447 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002448
2449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 final Phone phone = getPhone(subId);
2452 if (phone != null) {
2453 phone.setDataActivationState(activationState);
2454 } else {
2455 loge("setVoiceActivationState fails with invalid subId: " + subId);
2456 }
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002459 }
2460 }
2461
2462 /**
2463 * Returns the voice activation state of a given subId.
2464 */
2465 @Override
2466 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002467 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002468
fionaxu0152e512016-11-14 13:36:14 -08002469 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 if (phone != null) {
2473 return phone.getVoiceActivationState();
2474 } else {
2475 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2476 }
2477 } finally {
2478 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002479 }
2480 }
2481
2482 /**
2483 * Returns the data activation state of a given subId.
2484 */
2485 @Override
2486 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002487 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002488
fionaxu0152e512016-11-14 13:36:14 -08002489 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 if (phone != null) {
2493 return phone.getDataActivationState();
2494 } else {
2495 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002499 }
2500 }
2501
2502 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 * Returns the unread count of voicemails
2504 */
2505 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002506 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002507 }
2508
2509 /**
2510 * Returns the unread count of voicemails for a subId
2511 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002512 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002513 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002514 final long identity = Binder.clearCallingIdentity();
2515 try {
2516 final Phone phone = getPhone(subId);
2517 if (phone != null) {
2518 return phone.getVoiceMessageCount();
2519 } else {
2520 return 0;
2521 }
2522 } finally {
2523 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 }
2526
2527 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002528 * returns true, if the device is in a state where both voice and data
2529 * are supported simultaneously. This can change based on location or network condition.
2530 */
2531 @Override
2532 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 final Phone phone = getPhone(subId);
2536 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2537 } finally {
2538 Binder.restoreCallingIdentity(identity);
2539 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002540 }
2541
2542 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002543 * Send the dialer code if called from the current default dialer or the caller has
2544 * carrier privilege.
2545 * @param inputCode The dialer code to send
2546 */
2547 @Override
2548 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2549 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2550 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2551 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002552 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2553 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002554 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002555
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 mPhone.sendDialerSpecialCode(inputCode);
2559 } finally {
2560 Binder.restoreCallingIdentity(identity);
2561 }
fionaxu235cc5e2017-03-06 22:25:57 -08002562 }
2563
2564 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002565 * Returns the data network type.
2566 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 *
2568 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2569 */
2570 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002571 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 final Phone phone = getPhone(getDefaultSubscription());
2575 if (phone != null) {
2576 return phone.getServiceState().getDataNetworkType();
2577 } else {
2578 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2579 }
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002582 }
Wink Saville36469e72014-06-11 15:17:00 -07002583 }
2584
Pengquan Meng0c05b502018-09-06 09:59:22 -07002585 @Override
2586 public int getNetworkSelectionMode(int subId) {
2587 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2588 }
2589
Wink Saville36469e72014-06-11 15:17:00 -07002590 /**
2591 * Returns the network type for a subId
2592 */
2593 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002594 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002596 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002597 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2598 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002599
Malcolm Chenaabec062018-02-28 15:00:40 -08002600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 final Phone phone = getPhone(subId);
2603 if (phone != null) {
2604 return phone.getServiceState().getDataNetworkType();
2605 } else {
2606 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 }
2612
2613 /**
2614 * Returns the data network type
2615 */
2616 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002617 public int getDataNetworkType(String callingPackage) {
2618 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002619 }
2620
2621 /**
2622 * Returns the data network type for a subId
2623 */
2624 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002625 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002627 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2629 }
2630
Malcolm Chenaabec062018-02-28 15:00:40 -08002631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 final Phone phone = getPhone(subId);
2634 if (phone != null) {
2635 return phone.getServiceState().getDataNetworkType();
2636 } else {
2637 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2638 }
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 }
2643
2644 /**
Wink Saville36469e72014-06-11 15:17:00 -07002645 * Returns the Voice network type for a subId
2646 */
2647 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002648 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002650 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002651 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2652 }
2653
Malcolm Chenaabec062018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 final Phone phone = getPhone(subId);
2657 if (phone != null) {
2658 return phone.getServiceState().getVoiceNetworkType();
2659 } else {
2660 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2661 }
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
2667 /**
2668 * @return true if a ICC card is present
2669 */
2670 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002671 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002672 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2673 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002674 }
2675
2676 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002677 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002678 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002679 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002680 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 final Phone phone = PhoneFactory.getPhone(slotIndex);
2684 if (phone != null) {
2685 return phone.getIccCard().hasIccCard();
2686 } else {
2687 return false;
2688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 }
2693
2694 /**
2695 * Return if the current radio is LTE on CDMA. This
2696 * is a tri-state return value as for a period of time
2697 * the mode may be unknown.
2698 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002699 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002701 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002703 @Override
2704 public int getLteOnCdmaMode(String callingPackage) {
2705 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002706 }
2707
Sanket Padawe356d7632015-06-22 14:03:32 -07002708 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002709 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002711 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002712 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2713 }
2714
Malcolm Chenaabec062018-02-28 15:00:40 -08002715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 final Phone phone = getPhone(subId);
2718 if (phone == null) {
2719 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2720 } else {
2721 return phone.getLteOnCdmaMode();
2722 }
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 }
Wink Saville36469e72014-06-11 15:17:00 -07002726 }
2727
2728 public void setPhone(Phone phone) {
2729 mPhone = phone;
2730 }
2731
2732 /**
2733 * {@hide}
2734 * Returns Default subId, 0 in the case of single standby.
2735 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002736 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002737 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002738 }
2739
Shishir Agrawala9f32182016-04-12 12:00:16 -07002740 private int getSlotForDefaultSubscription() {
2741 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2742 }
2743
Wink Savilleb564aae2014-10-23 10:18:09 -07002744 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002745 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002747
2748 /**
2749 * @see android.telephony.TelephonyManager.WifiCallingChoices
2750 */
2751 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2755 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2756 getWhenToMakeWifiCallsDefaultPreference());
2757 } finally {
2758 Binder.restoreCallingIdentity(identity);
2759 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002760 }
2761
2762 /**
2763 * @see android.telephony.TelephonyManager.WifiCallingChoices
2764 */
2765 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2769 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2770 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
2773 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002774 }
2775
Sailesh Nepald1e68152013-12-12 19:08:02 -08002776 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002777 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002778 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002779 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002780
Shishir Agrawal566b7612013-10-28 14:41:00 -07002781 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002782 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2783 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2785 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002787
Malcolm Chenaabec062018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 if (TextUtils.equals(ISDR_AID, aid)) {
2791 // Only allows LPA to open logical channel to ISD-R.
2792 ComponentInfo bestComponent =
2793 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2794 if (bestComponent == null
2795 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2796 loge("The calling package is not allowed to access ISD-R.");
2797 throw new SecurityException(
2798 "The calling package is not allowed to access ISD-R.");
2799 }
Derek Tan740e1672017-06-27 14:56:27 -07002800 }
Derek Tan740e1672017-06-27 14:56:27 -07002801
Malcolm Chenaabec062018-02-28 15:00:40 -08002802 if (DBG) {
2803 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2804 }
2805 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2806 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2807 if (DBG) log("iccOpenLogicalChannel: " + response);
2808 return response;
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
2811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002812 }
2813
2814 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002815 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2817 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002818
Malcolm Chenaabec062018-02-28 15:00:40 -08002819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2822 if (channel < 0) {
2823 return false;
2824 }
2825 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2826 if (DBG) log("iccCloseLogicalChannel: " + success);
2827 return success;
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002830 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002831 }
2832
2833 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002834 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002835 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2837 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002838
Malcolm Chenaabec062018-02-28 15:00:40 -08002839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 if (DBG) {
2842 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2843 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2844 + p3 + " data=" + data);
2845 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002846
Malcolm Chenaabec062018-02-28 15:00:40 -08002847 if (channel < 0) {
2848 return "";
2849 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002850
Malcolm Chenaabec062018-02-28 15:00:40 -08002851 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2852 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2853 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002854
Malcolm Chenaabec062018-02-28 15:00:40 -08002855 // Append the returned status code to the end of the response payload.
2856 String s = Integer.toHexString(
2857 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2858 if (response.payload != null) {
2859 s = IccUtils.bytesToHexString(response.payload) + s;
2860 }
2861 return s;
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002864 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002865 }
Jake Hambye994d462014-02-03 13:10:13 -08002866
Evan Charltonc66da362014-05-16 14:06:40 -07002867 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002868 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2869 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2871 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002872 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002873
Malcolm Chenaabec062018-02-28 15:00:40 -08002874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2877 && TextUtils.equals(ISDR_AID, data)) {
2878 // Only allows LPA to select ISD-R.
2879 ComponentInfo bestComponent =
2880 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2881 if (bestComponent == null
2882 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2883 loge("The calling package is not allowed to select ISD-R.");
2884 throw new SecurityException(
2885 "The calling package is not allowed to select ISD-R.");
2886 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002887 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002888
Malcolm Chenaabec062018-02-28 15:00:40 -08002889 if (DBG) {
2890 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2891 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2892 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002893
Malcolm Chenaabec062018-02-28 15:00:40 -08002894 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2895 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2896 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002897
Malcolm Chenaabec062018-02-28 15:00:40 -08002898 // Append the returned status code to the end of the response payload.
2899 String s = Integer.toHexString(
2900 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2901 if (response.payload != null) {
2902 s = IccUtils.bytesToHexString(response.payload) + s;
2903 }
2904 return s;
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002907 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002908 }
2909
2910 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002911 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002912 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2914 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002915
Malcolm Chenaabec062018-02-28 15:00:40 -08002916 final long identity = Binder.clearCallingIdentity();
2917 try {
2918 if (DBG) {
2919 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2920 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2921 }
2922
2923 IccIoResult response =
2924 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2925 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2926 subId);
2927
2928 if (DBG) {
2929 log("Exchange SIM_IO [R]" + response);
2930 }
2931
2932 byte[] result = null;
2933 int length = 2;
2934 if (response.payload != null) {
2935 length = 2 + response.payload.length;
2936 result = new byte[length];
2937 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2938 } else {
2939 result = new byte[length];
2940 }
2941
2942 result[length - 1] = (byte) response.sw2;
2943 result[length - 2] = (byte) response.sw1;
2944 return result;
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002947 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002948 }
2949
Nathan Haroldb3014052017-01-25 15:57:32 -08002950 /**
2951 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2952 * on a particular subscription
2953 */
sqianb6e41952018-03-12 14:54:01 -07002954 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2956 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2957 return null;
2958 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002959 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2960 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2961 return null;
2962 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002963
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2967 if (response instanceof String[]) {
2968 return (String[]) response;
2969 }
2970 // Response is an Exception of some kind,
2971 // which is signalled to the user as a NULL retval
2972 return null;
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002975 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002976 }
2977
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002978 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002979 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2981 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002982
Malcolm Chenaabec062018-02-28 15:00:40 -08002983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2986 if (response.payload == null) {
2987 return "";
2988 }
Evan Charltonc66da362014-05-16 14:06:40 -07002989
Malcolm Chenaabec062018-02-28 15:00:40 -08002990 // Append the returned status code to the end of the response payload.
2991 String s = Integer.toHexString(
2992 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2993 s = IccUtils.bytesToHexString(response.payload) + s;
2994 return s;
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
Evan Charltonc66da362014-05-16 14:06:40 -07002998 }
2999
Jake Hambye994d462014-02-03 13:10:13 -08003000 /**
3001 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3002 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3003 *
3004 * @param itemID the ID of the item to read
3005 * @return the NV item as a String, or null on error.
3006 */
3007 @Override
3008 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003009 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3011 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003012
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003016 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003017 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3018 return value;
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
Jake Hambye994d462014-02-03 13:10:13 -08003022 }
3023
3024 /**
3025 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3026 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3027 *
3028 * @param itemID the ID of the item to read
3029 * @param itemValue the value to write, as a String
3030 * @return true on success; false on any failure
3031 */
3032 @Override
3033 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003034 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3036 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003037
3038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3041 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003042 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003043 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3044 return success;
3045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
Jake Hambye994d462014-02-03 13:10:13 -08003048 }
3049
3050 /**
3051 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3052 * Used for device configuration by some CDMA operators.
3053 *
3054 * @param preferredRoamingList byte array containing the new PRL
3055 * @return true on success; false on any failure
3056 */
3057 @Override
3058 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3060 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003061
3062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3065 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3066 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3067 return success;
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
Jake Hambye994d462014-02-03 13:10:13 -08003071 }
3072
3073 /**
3074 * Perform the specified type of NV config reset.
3075 * Used for device configuration by some CDMA operators.
3076 *
3077 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3078 * @return true on success; false on any failure
3079 */
3080 @Override
3081 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3083 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003084
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 if (DBG) log("nvResetConfig: type " + resetType);
3088 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3089 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3090 return success;
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
Jake Hambye994d462014-02-03 13:10:13 -08003094 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003095
Svet Ganovb320e182015-04-16 12:30:10 -07003096 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003098 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003099 return new String[0];
3100 }
3101
Malcolm Chenaabec062018-02-28 15:00:40 -08003102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 return mPhone.getPcscfAddress(apnType);
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
Wink Saville36469e72014-06-11 15:17:00 -07003108 }
3109
Brad Ebinger51f743a2017-01-23 13:50:20 -08003110 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003111 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3112 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003113 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003114 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003115 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003116
3117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 PhoneFactory.getImsResolver().enableIms(slotId);
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003123 }
3124
3125 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003126 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3127 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003128 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003129 public void disableIms(int slotId) {
3130 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003131
3132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 PhoneFactory.getImsResolver().disableIms(slotId);
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
3137 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003138 }
3139
3140 /**
3141 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3142 * feature or {@link null} if the service is not available. If the feature is available, the
3143 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3144 */
3145 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003146 IImsServiceFeatureCallback callback) {
3147 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003148
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3152 } finally {
3153 Binder.restoreCallingIdentity(identity);
3154 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003155 }
3156
3157 /**
3158 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3159 * feature during emergency calling or {@link null} if the service is not available. If the
3160 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3161 * listener for feature updates.
3162 */
3163 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3164 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003165
3166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003172 }
3173
Brad Ebinger5f64b052017-12-14 14:26:15 -08003174 /**
3175 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3176 * specified.
3177 */
3178 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3179 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003180
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003187 }
3188
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003189 /**
3190 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3191 * specified.
3192 */
3193 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3194 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003195
3196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3199 } finally {
3200 Binder.restoreCallingIdentity(identity);
3201 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003202 }
3203
Brad Ebinger884c07b2018-02-15 16:17:40 -08003204 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003205 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3206 * available, false if the IMS resolver is idle.
3207 */
3208 public boolean isResolvingImsBinding() {
3209 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003210
3211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 return PhoneFactory.getImsResolver().isResolvingBinding();
3214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
Brad Ebinger67801702018-03-02 13:43:36 -08003217 }
3218
Brad Ebingerdac2f002018-04-03 15:17:52 -07003219 /**
3220 * Sets the ImsService Package Name that Telephony will bind to.
3221 *
3222 * @param slotId the slot ID that the ImsService should bind for.
3223 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3224 * ImsService is the device default ImsService.
3225 * @param packageName The package name of the application that contains the ImsService to bind
3226 * to.
3227 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3228 * @hide
3229 */
3230 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003231 int[] subIds = SubscriptionManager.getSubId(slotId);
3232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3233 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3234 "setImsService");
3235
Malcolm Chenaabec062018-02-28 15:00:40 -08003236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3239 isCarrierImsService, packageName);
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003243 }
3244
3245 /**
3246 * Return the ImsService configuration.
3247 *
3248 * @param slotId The slot that the ImsService is associated with.
3249 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3250 * the device default.
3251 * @return the package name of the ImsService configuration.
3252 */
3253 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003254 int[] subIds = SubscriptionManager.getSubId(slotId);
3255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3256 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3257 "getImsService");
3258
Malcolm Chenaabec062018-02-28 15:00:40 -08003259 final long identity = Binder.clearCallingIdentity();
3260 try {
3261 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3262 isCarrierImsService);
3263 } finally {
3264 Binder.restoreCallingIdentity(identity);
3265 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003266 }
3267
Wink Saville36469e72014-06-11 15:17:00 -07003268 public void setImsRegistrationState(boolean registered) {
3269 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003270
3271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 mPhone.setImsRegistrationState(registered);
3274 } finally {
3275 Binder.restoreCallingIdentity(identity);
3276 }
Wink Saville36469e72014-06-11 15:17:00 -07003277 }
3278
3279 /**
Stuart Scott54788802015-03-30 13:18:01 -07003280 * Set the network selection mode to automatic.
3281 *
3282 */
3283 @Override
3284 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3286 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003287
3288 final long identity = Binder.clearCallingIdentity();
3289 try {
3290 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3291 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
Stuart Scott54788802015-03-30 13:18:01 -07003295 }
3296
3297 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003298 * Set the network selection mode to manual with the selected carrier.
3299 */
3300 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003301 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003302 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3304 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaabec062018-02-28 15:00:40 -08003305
3306 final long identity = Binder.clearCallingIdentity();
3307 try {
3308 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003309 /* operatorAlphaLong */ "",
3310 /* operatorAlphaShort */ "",
Malcolm Chenaabec062018-02-28 15:00:40 -08003311 operatorNumeric);
3312 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3313 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3314 persistSelection);
3315 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003319 }
3320
3321 /**
3322 * Scans for available networks.
3323 */
3324 @Override
3325 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3327 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003328
Pengquan Meng0c05b502018-09-06 09:59:22 -07003329 long identity = Binder.clearCallingIdentity();
Malcolm Chenaabec062018-02-28 15:00:40 -08003330 try {
3331 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003332 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaabec062018-02-28 15:00:40 -08003333 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08003334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003337 }
3338
3339 /**
yinxub1bed742017-04-17 11:45:04 -07003340 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003341 *
yinxub1bed742017-04-17 11:45:04 -07003342 * @param subId id of the subscription
3343 * @param request contains the radio access networks with bands/channels to scan
3344 * @param messenger callback messenger for scan results or errors
3345 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003346 * @return the id of the requested scan which can be used to stop the scan.
3347 */
3348 @Override
3349 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3350 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3352 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003353
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 return mNetworkScanRequestTracker.startNetworkScan(
3357 request, messenger, binder, getPhone(subId));
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
3360 }
yinxu504e1392017-04-12 16:03:22 -07003361 }
3362
3363 /**
3364 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003365 *
3366 * @param subId id of the subscription
3367 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003368 */
3369 @Override
3370 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3372 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003373
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3377 } finally {
3378 Binder.restoreCallingIdentity(identity);
3379 }
yinxu504e1392017-04-12 16:03:22 -07003380 }
3381
3382 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003383 * Get the calculated preferred network type.
3384 * Used for debugging incorrect network type.
3385 *
3386 * @return the preferred network type, defined in RILConstants.java.
3387 */
3388 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003389 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003391 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003392 return RILConstants.PREFERRED_NETWORK_MODE;
3393 }
3394
Malcolm Chenaabec062018-02-28 15:00:40 -08003395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 // FIXME: need to get SubId from somewhere.
3398 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
Junda Liu84d15a22014-07-02 11:21:04 -07003402 }
3403
3404 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003405 * Get the preferred network type.
3406 * Used for device configuration by some CDMA operators.
3407 *
3408 * @return the preferred network type, defined in RILConstants.java.
3409 */
3410 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003411 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3413 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003414
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 if (DBG) log("getPreferredNetworkType");
3418 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3419 int networkType = (result != null ? result[0] : -1);
3420 if (DBG) log("getPreferredNetworkType: " + networkType);
3421 return networkType;
3422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003425 }
3426
3427 /**
3428 * Set the preferred network type.
3429 * Used for device configuration by some CDMA operators.
3430 *
3431 * @param networkType the preferred network type, defined in RILConstants.java.
3432 * @return true on success; false on any failure.
3433 */
3434 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003435 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3437 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003438
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3442 Boolean success = (Boolean) sendRequest(
3443 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3444 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3445 if (success) {
3446 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3447 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3448 }
3449 return success;
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003452 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003453 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003454
3455 /**
Junda Liu475951f2014-11-07 16:45:03 -08003456 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3457 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3458 * tethering.
3459 *
3460 * @return 0: Not required. 1: required. 2: Not set.
3461 * @hide
3462 */
3463 @Override
3464 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003465 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003466
3467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3470 Settings.Global.TETHER_DUN_REQUIRED, 2);
3471 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3472 // config_tether_apndata.
3473 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3474 dunRequired = 1;
3475 }
3476 return dunRequired;
3477 } finally {
3478 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003479 }
Junda Liu475951f2014-11-07 16:45:03 -08003480 }
3481
3482 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003483 * Set mobile data enabled
3484 * Used by the user through settings etc to turn on/off mobile data
3485 *
3486 * @param enable {@code true} turn turn data on, else {@code false}
3487 */
3488 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003489 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3491 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003492
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 int phoneId = mSubscriptionController.getPhoneId(subId);
3496 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3497 Phone phone = PhoneFactory.getPhone(phoneId);
3498 if (phone != null) {
3499 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3500 phone.setUserDataEnabled(enable);
3501 } else {
3502 loge("setUserDataEnabled: no phone for subId=" + subId);
3503 }
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003506 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003507 }
3508
3509 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003510 * Get the user enabled state of Mobile Data.
3511 *
3512 * TODO: remove and use isUserDataEnabled.
3513 * This can't be removed now because some vendor codes
3514 * calls through ITelephony directly while they should
3515 * use TelephonyManager.
3516 *
3517 * @return true on enabled
3518 */
3519 @Override
3520 public boolean getDataEnabled(int subId) {
3521 return isUserDataEnabled(subId);
3522 }
3523
3524 /**
3525 * Get whether mobile data is enabled per user setting.
3526 *
3527 * There are other factors deciding whether mobile data is actually enabled, but they are
3528 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003529 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003530 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003531 *
3532 * @return {@code true} if data is enabled else {@code false}
3533 */
3534 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003535 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003536 try {
3537 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3538 null);
3539 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3541 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003542 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 int phoneId = mSubscriptionController.getPhoneId(subId);
3547 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3548 Phone phone = PhoneFactory.getPhone(phoneId);
3549 if (phone != null) {
3550 boolean retVal = phone.isUserDataEnabled();
3551 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3552 return retVal;
3553 } else {
3554 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3555 return false;
3556 }
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003559 }
3560 }
3561
3562 /**
3563 * Get whether mobile data is enabled.
3564 *
3565 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3566 * whether mobile data is actually enabled.
3567 *
3568 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3569 *
3570 * @return {@code true} if data is enabled else {@code false}
3571 */
3572 @Override
3573 public boolean isDataEnabled(int subId) {
3574 try {
3575 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3576 null);
3577 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3579 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003580 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003581
3582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 int phoneId = mSubscriptionController.getPhoneId(subId);
3585 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3586 Phone phone = PhoneFactory.getPhone(phoneId);
3587 if (phone != null) {
3588 boolean retVal = phone.isDataEnabled();
3589 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3590 return retVal;
3591 } else {
3592 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3593 return false;
3594 }
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003597 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003598 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003599
3600 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003601 public int getCarrierPrivilegeStatus(int subId) {
3602 final Phone phone = getPhone(subId);
3603 if (phone == null) {
3604 loge("getCarrierPrivilegeStatus: Invalid subId");
3605 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3606 }
3607 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003608 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003609 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003610 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3611 }
3612 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003613 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003614 }
Junda Liu29340342014-07-10 15:23:27 -07003615
3616 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003617 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3618 final Phone phone = getPhone(subId);
3619 if (phone == null) {
3620 loge("getCarrierPrivilegeStatus: Invalid subId");
3621 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3622 }
3623 UiccProfile profile =
3624 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3625 if (profile == null) {
3626 loge("getCarrierPrivilegeStatus: No UICC");
3627 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3628 }
3629 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3630 }
3631
3632 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003633 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003634 if (TextUtils.isEmpty(pkgName))
3635 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003636 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003637 if (card == null) {
3638 loge("checkCarrierPrivilegesForPackage: No UICC");
3639 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3640 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003641 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3642 }
3643
3644 @Override
3645 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003646 if (TextUtils.isEmpty(pkgName))
3647 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003648 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3649 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3650 UiccCard card = UiccController.getInstance().getUiccCard(i);
3651 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003652 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003653 continue;
3654 }
3655
3656 result = card.getCarrierPrivilegeStatus(
3657 mPhone.getContext().getPackageManager(), pkgName);
3658 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3659 break;
3660 }
3661 }
3662
3663 return result;
Junda Liu29340342014-07-10 15:23:27 -07003664 }
Derek Tan89e89d42014-07-08 17:00:10 -07003665
3666 @Override
Junda Liue64de782015-04-16 17:19:16 -07003667 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3668 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3669 loge("phoneId " + phoneId + " is not valid.");
3670 return null;
3671 }
3672 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003673 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003674 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003675 return null ;
3676 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003677 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003678 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003679 }
3680
Amith Yamasani6e118872016-02-19 12:53:51 -08003681 @Override
3682 public List<String> getPackagesWithCarrierPrivileges() {
3683 PackageManager pm = mPhone.getContext().getPackageManager();
3684 List<String> privilegedPackages = new ArrayList<>();
3685 List<PackageInfo> packages = null;
3686 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3687 UiccCard card = UiccController.getInstance().getUiccCard(i);
3688 if (card == null) {
3689 // No UICC in that slot.
3690 continue;
3691 }
3692 if (card.hasCarrierPrivilegeRules()) {
3693 if (packages == null) {
3694 // Only check packages in user 0 for now
3695 packages = pm.getInstalledPackagesAsUser(
3696 PackageManager.MATCH_DISABLED_COMPONENTS
3697 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3698 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3699 }
3700 for (int p = packages.size() - 1; p >= 0; p--) {
3701 PackageInfo pkgInfo = packages.get(p);
3702 if (pkgInfo != null && pkgInfo.packageName != null
3703 && card.getCarrierPrivilegeStatus(pkgInfo)
3704 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3705 privilegedPackages.add(pkgInfo.packageName);
3706 }
3707 }
3708 }
3709 }
3710 return privilegedPackages;
3711 }
3712
Wink Savilleb564aae2014-10-23 10:18:09 -07003713 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003714 final Phone phone = getPhone(subId);
3715 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003716 if (card == null) {
3717 loge("getIccId: No UICC");
3718 return null;
3719 }
3720 String iccId = card.getIccId();
3721 if (TextUtils.isEmpty(iccId)) {
3722 loge("getIccId: ICC ID is null or empty.");
3723 return null;
3724 }
3725 return iccId;
3726 }
3727
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003728 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003729 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3730 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003731 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3732 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003733
Malcolm Chenaabec062018-02-28 15:00:40 -08003734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 final String iccId = getIccId(subId);
3737 final Phone phone = getPhone(subId);
3738 if (phone == null) {
3739 return false;
3740 }
3741 final String subscriberId = phone.getSubscriberId();
3742
3743 if (DBG_MERGE) {
3744 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3745 + subscriberId + " to " + number);
3746 }
3747
3748 if (TextUtils.isEmpty(iccId)) {
3749 return false;
3750 }
3751
3752 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3753
3754 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3755 if (alphaTag == null) {
3756 editor.remove(alphaTagPrefKey);
3757 } else {
3758 editor.putString(alphaTagPrefKey, alphaTag);
3759 }
3760
3761 // Record both the line number and IMSI for this ICCID, since we need to
3762 // track all merged IMSIs based on line number
3763 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3764 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3765 if (number == null) {
3766 editor.remove(numberPrefKey);
3767 editor.remove(subscriberPrefKey);
3768 } else {
3769 editor.putString(numberPrefKey, number);
3770 editor.putString(subscriberPrefKey, subscriberId);
3771 }
3772
3773 editor.commit();
3774 return true;
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003777 }
Derek Tan7226c842014-07-02 17:42:23 -07003778 }
3779
3780 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003781 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003782 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003784 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003785 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003786 return null;
3787 }
Derek Tan97ebb422014-09-05 16:55:38 -07003788
Malcolm Chenaabec062018-02-28 15:00:40 -08003789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 String iccId = getIccId(subId);
3792 if (iccId != null) {
3793 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3794 if (DBG_MERGE) {
3795 log("getLine1NumberForDisplay returning "
3796 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3797 }
3798 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003799 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003800 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3801 return null;
3802 } finally {
3803 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003804 }
Derek Tan7226c842014-07-02 17:42:23 -07003805 }
3806
3807 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003808 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003810 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003811 return null;
3812 }
Derek Tan97ebb422014-09-05 16:55:38 -07003813
Malcolm Chenaabec062018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 String iccId = getIccId(subId);
3817 if (iccId != null) {
3818 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3819 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3820 }
3821 return null;
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003824 }
Derek Tan7226c842014-07-02 17:42:23 -07003825 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003826
3827 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003828 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003829 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3830 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003832 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3833 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003834 return null;
3835 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003836
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003837 final long identity = Binder.clearCallingIdentity();
3838 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003839 final Context context = mPhone.getContext();
3840 final TelephonyManager tele = TelephonyManager.from(context);
3841 final SubscriptionManager sub = SubscriptionManager.from(context);
3842
3843 // Figure out what subscribers are currently active
3844 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3845 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3846 // the process, where TelephonyManager was instantiated.
3847 // Otherwise AppOps check will fail.
3848
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003849 final int[] subIds = sub.getActiveSubscriptionIdList();
3850 for (int subId : subIds) {
3851 activeSubscriberIds.add(tele.getSubscriberId(subId));
3852 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003853
3854 // First pass, find a number override for an active subscriber
3855 String mergeNumber = null;
3856 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3857 for (String key : prefs.keySet()) {
3858 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3859 final String subscriberId = (String) prefs.get(key);
3860 if (activeSubscriberIds.contains(subscriberId)) {
3861 final String iccId = key.substring(
3862 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3863 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3864 mergeNumber = (String) prefs.get(numberKey);
3865 if (DBG_MERGE) {
3866 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3867 + " for active subscriber " + subscriberId);
3868 }
3869 if (!TextUtils.isEmpty(mergeNumber)) {
3870 break;
3871 }
3872 }
3873 }
3874 }
3875
3876 // Shortcut when no active merged subscribers
3877 if (TextUtils.isEmpty(mergeNumber)) {
3878 return null;
3879 }
3880
3881 // Second pass, find all subscribers under that line override
3882 final ArraySet<String> result = new ArraySet<>();
3883 for (String key : prefs.keySet()) {
3884 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3885 final String number = (String) prefs.get(key);
3886 if (mergeNumber.equals(number)) {
3887 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3888 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3889 final String subscriberId = (String) prefs.get(subscriberKey);
3890 if (!TextUtils.isEmpty(subscriberId)) {
3891 result.add(subscriberId);
3892 }
3893 }
3894 }
3895 }
3896
3897 final String[] resultArray = result.toArray(new String[result.size()]);
3898 Arrays.sort(resultArray);
3899 if (DBG_MERGE) {
3900 Slog.d(LOG_TAG,
3901 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3902 }
3903 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003906 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003907 }
3908
3909 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003910 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003911 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3912 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003913
3914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 final Phone phone = getPhone(subId);
3917 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003921 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003922
3923 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003924 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003925 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3926 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003927 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003928
3929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 final Phone phone = getPhone(subId);
3932 if (phone == null) {
3933 return false;
3934 }
3935 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3936 cdmaNonRoamingList);
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003939 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003940 }
3941
3942 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003943 @Deprecated
3944 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3945 enforceModifyPermission();
3946
3947 int returnValue = 0;
3948 try {
vagdevie435a3e2018-08-15 16:01:53 -07003949 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003950 if(result.exception == null) {
3951 if (result.result != null) {
3952 byte[] responseData = (byte[])(result.result);
3953 if(responseData.length > oemResp.length) {
3954 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3955 responseData.length + "bytes. Buffer Size is " +
3956 oemResp.length + "bytes.");
3957 }
3958 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3959 returnValue = responseData.length;
3960 }
3961 } else {
3962 CommandException ex = (CommandException) result.exception;
3963 returnValue = ex.getCommandError().ordinal();
3964 if(returnValue > 0) returnValue *= -1;
3965 }
3966 } catch (RuntimeException e) {
3967 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3968 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3969 if(returnValue > 0) returnValue *= -1;
3970 }
3971
3972 return returnValue;
3973 }
3974
3975 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003976 public void setRadioCapability(RadioAccessFamily[] rafs) {
3977 try {
3978 ProxyController.getInstance().setRadioCapability(rafs);
3979 } catch (RuntimeException e) {
3980 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3981 }
3982 }
3983
3984 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003985 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003986 Phone phone = PhoneFactory.getPhone(phoneId);
3987 if (phone == null) {
3988 return RadioAccessFamily.RAF_UNKNOWN;
3989 }
3990 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003992 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003993 return RadioAccessFamily.RAF_UNKNOWN;
3994 }
3995
Malcolm Chenaabec062018-02-28 15:00:40 -08003996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
4001 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004002 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004003
4004 @Override
4005 public void enableVideoCalling(boolean enable) {
4006 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004007
4008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004014 }
4015
4016 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004017 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4019 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4020 return false;
4021 }
Svet Ganovb320e182015-04-16 12:30:10 -07004022
Malcolm Chenaabec062018-02-28 15:00:40 -08004023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 // Check the user preference and the system-level IMS setting. Even if the user has
4026 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4027 // In the long run, we may instead need to check if there exists a connection service
4028 // which can support video calling.
4029 ImsManager imsManager =
4030 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4031 return imsManager.isVtEnabledByPlatform()
4032 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4033 && imsManager.isVtEnabledByUser();
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004037 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004038
Andrew Leea1239f22015-03-02 17:44:07 -08004039 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004040 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4041 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4042 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4043 return false;
4044 }
4045
4046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 CarrierConfigManager configManager =
4049 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4050 return configManager.getConfigForSubId(mPhone.getSubId())
4051 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
Andrew Leea1239f22015-03-02 17:44:07 -08004055 }
4056
4057 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004058 public boolean isWorldPhone(int subId, String callingPackage) {
4059 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4060 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4061 return false;
4062 }
4063
4064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 CarrierConfigManager configManager =
4067 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4068 return configManager.getConfigForSubId(mPhone.getSubId())
4069 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
Andrew Leea1239f22015-03-02 17:44:07 -08004073 }
4074
Andrew Lee9431b832015-03-09 18:46:45 -07004075 @Override
4076 public boolean isTtyModeSupported() {
4077 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004078 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004079 }
4080
4081 @Override
4082 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
Andrew Lee9431b832015-03-09 18:46:45 -07004089 }
4090
Hall Liu98187582018-01-22 19:15:32 -08004091 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4095 mPhone.getSubId()).getBoolean(
4096 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4097 boolean isDeviceSupported =
4098 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4099 return isCarrierSupported && isDeviceSupported;
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
Hall Liu98187582018-01-22 19:15:32 -08004103 }
4104
Hall Liu3ad5f012018-04-06 16:23:39 -07004105 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 return isRttSupported() && Settings.Secure.getInt(
4109 mPhone.getContext().getContentResolver(),
4110 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004114 }
4115
Sanket Padawe7310cc72015-01-14 09:53:20 -08004116 /**
4117 * Returns the unique device ID of phone, for example, the IMEI for
4118 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4119 *
4120 * <p>Requires Permission:
4121 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4122 */
4123 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004124 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004125 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004126 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004127 return null;
4128 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004129 int subId = phone.getSubId();
4130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4131 mApp, subId, callingPackage, "getDeviceId")) {
4132 return null;
4133 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004134
4135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 return phone.getDeviceId();
4138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004141 }
4142
Ping Sunc67b7c22016-03-02 19:16:45 +08004143 /**
4144 * {@hide}
4145 * Returns the IMS Registration Status on a particular subid
4146 *
4147 * @param subId
4148 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004149 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004150 Phone phone = getPhone(subId);
4151 if (phone != null) {
4152 return phone.isImsRegistered();
4153 } else {
4154 return false;
4155 }
4156 }
4157
Santos Cordon7a1885b2015-02-03 11:15:19 -08004158 @Override
4159 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004166 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004167
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004168 /**
4169 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004170 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004171 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004172 final long identity = Binder.clearCallingIdentity();
4173 try {
4174 Phone phone = getPhone(subId);
4175 if (phone != null) {
4176 return phone.isWifiCallingEnabled();
4177 } else {
4178 return false;
4179 }
4180 } finally {
4181 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004182 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004183 }
4184
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004185 /**
4186 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004187 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004188 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004189 final long identity = Binder.clearCallingIdentity();
4190 try {
4191 Phone phone = getPhone(subId);
4192 if (phone != null) {
4193 return phone.isVolteEnabled();
4194 } else {
4195 return false;
4196 }
4197 } finally {
4198 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004199 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004200 }
Svet Ganovb320e182015-04-16 12:30:10 -07004201
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004202 /**
4203 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004204 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004205 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004206 final long identity = Binder.clearCallingIdentity();
4207 try {
4208 Phone phone = getPhone(subId);
4209 if (phone != null) {
4210 return phone.isVideoEnabled();
4211 } else {
4212 return false;
4213 }
4214 } finally {
4215 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004216 }
4217 }
4218
4219 /**
4220 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4221 * defined in {@link ImsRegistrationImplBase}.
4222 */
4223 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004224 final long identity = Binder.clearCallingIdentity();
4225 try {
4226 Phone phone = getPhone(subId);
4227 if (phone != null) {
4228 return phone.getImsRegistrationTech();
4229 } else {
4230 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4231 }
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004234 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004235 }
4236
Stuart Scott8eef64f2015-04-08 15:13:54 -07004237 @Override
4238 public void factoryReset(int subId) {
4239 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004240 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4241 return;
4242 }
4243
Svet Ganovcc087f82015-05-12 20:35:54 -07004244 final long identity = Binder.clearCallingIdentity();
4245 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004246 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4247 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004248 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004249 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004250 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4251 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004252 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004253 }
4254 } finally {
4255 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004256 }
4257 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004258
4259 @Override
4260 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 // We query all subscriptions instead of just the active ones, because
4264 // this might be called early on in the provisioning flow when the
4265 // subscriptions potentially aren't active yet.
4266 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4267 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004268 return null;
4269 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004270
Malcolm Chenaabec062018-02-28 15:00:40 -08004271 // This function may be called very early, say, from the setup wizard, at
4272 // which point we won't have a default subscription set. If that's the case
4273 // we just choose the first, which will be valid in "most cases".
4274 final int defaultSubId = getDefaultSubscription();
4275 SubscriptionInfo info = null;
4276 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4277 info = slist.get(0);
4278 } else {
4279 for (SubscriptionInfo item : slist) {
4280 if (item.getSubscriptionId() == defaultSubId) {
4281 info = item;
4282 break;
4283 }
4284 }
4285
4286 if (info == null) {
4287 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004288 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004289 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004290
Malcolm Chenaabec062018-02-28 15:00:40 -08004291 // Try and fetch the locale from the carrier properties or from the SIM language
4292 // preferences (EF-PL and EF-LI)...
4293 final int mcc = info.getMcc();
4294 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4295 String simLanguage = null;
4296 if (defaultPhone != null) {
4297 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4298 if (localeFromDefaultSim != null) {
4299 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4300 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4301 return localeFromDefaultSim.toLanguageTag();
4302 } else {
4303 simLanguage = localeFromDefaultSim.getLanguage();
4304 }
4305 }
4306 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004307
Malcolm Chenaabec062018-02-28 15:00:40 -08004308 // The SIM language preferences only store a language (e.g. fr = French), not an
4309 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4310 // the SIM and carrier preferences does not include a country we add the country
4311 // determined from the SIM MCC to provide an exact locale.
4312 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4313 simLanguage);
4314 if (mccLocale != null) {
4315 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4316 return mccLocale.toLanguageTag();
4317 }
4318
4319 if (DBG) log("No locale found - returning null");
4320 return null;
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004324 }
4325
4326 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004327 return mSubscriptionController.getAllSubInfoList(
4328 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004329 }
4330
Malcolm Chenaabec062018-02-28 15:00:40 -08004331 /**
4332 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4333 */
4334 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4335 return mSubscriptionController.getActiveSubscriptionInfoList(
4336 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004337 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004338
Chenjie Yu1ba97252018-01-11 18:16:20 -08004339 private final ModemActivityInfo mLastModemActivityInfo =
4340 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4341
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004342 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004343 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4344 * representing the state of the modem.
4345 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004346 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4347 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004348 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004349 */
4350 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004351 public void requestModemActivityInfo(ResultReceiver result) {
4352 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004353 ModemActivityInfo ret = null;
vagdevie435a3e2018-08-15 16:01:53 -07004354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Adam Lesinski903a54c2016-04-11 14:49:52 -07004355
Malcolm Chenaabec062018-02-28 15:00:40 -08004356 final long identity = Binder.clearCallingIdentity();
4357 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004358 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004359 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4360 CMD_GET_MODEM_ACTIVITY_INFO,
4361 null, workSource);
Siddharth Rayc339f892018-06-17 15:02:38 -07004362 if (isModemActivityInfoValid(info)) {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004363 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4364 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4365 mergedTxTimeMs[i] =
4366 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4367 }
4368 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4369 mLastModemActivityInfo.setSleepTimeMillis(
4370 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4371 mLastModemActivityInfo.setIdleTimeMillis(
4372 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4373 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4374 mLastModemActivityInfo.setRxTimeMillis(
4375 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4376 mLastModemActivityInfo.setEnergyUsed(
4377 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004378 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004379 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4380 mLastModemActivityInfo.getSleepTimeMillis(),
4381 mLastModemActivityInfo.getIdleTimeMillis(),
4382 mLastModemActivityInfo.getTxTimeMillis(),
4383 mLastModemActivityInfo.getRxTimeMillis(),
4384 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004385 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004386 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004387 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004388 result.send(0, bundle);
4389 } finally {
4390 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004391 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004392 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004393
Siddharth Rayc339f892018-06-17 15:02:38 -07004394 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4395 // less than total activity duration.
4396 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4397 if (info == null) {
4398 return false;
4399 }
4400 int activityDurationMs =
4401 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4402 int totalTxTimeMs = 0;
4403 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4404 totalTxTimeMs += info.getTxTimeMillis()[i];
4405 }
4406 return (info.isValid()
4407 && (info.getSleepTimeMillis() <= activityDurationMs)
4408 && (info.getIdleTimeMillis() <= activityDurationMs)
4409 && (info.getRxTimeMillis() <= activityDurationMs)
4410 && (totalTxTimeMs <= activityDurationMs));
4411 }
4412
Jack Yu85bd38a2015-11-09 11:34:32 -08004413 /**
4414 * {@hide}
4415 * Returns the service state information on specified subscription.
4416 */
4417 @Override
4418 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004420 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004421 return null;
4422 }
4423
Malcolm Chenaabec062018-02-28 15:00:40 -08004424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 final Phone phone = getPhone(subId);
4427 if (phone == null) {
4428 return null;
4429 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004430
Malcolm Chenaabec062018-02-28 15:00:40 -08004431 return phone.getServiceState();
4432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004435 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004436
4437 /**
4438 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4439 *
4440 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4441 * voicemail ringtone.
4442 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4443 * PhoneAccount.
4444 */
4445 @Override
4446 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004447 final long identity = Binder.clearCallingIdentity();
4448 try {
4449 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4450 if (phone == null) {
4451 phone = mPhone;
4452 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004453
Malcolm Chenaabec062018-02-28 15:00:40 -08004454 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004458 }
4459
4460 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004461 * Sets the per-account voicemail ringtone.
4462 *
4463 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4464 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4465 *
4466 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4467 * voicemail ringtone.
4468 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4469 * PhoneAccount.
4470 */
4471 @Override
4472 public void setVoicemailRingtoneUri(String callingPackage,
4473 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4475 if (!TextUtils.equals(callingPackage,
4476 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4478 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4479 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004480 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004481
4482 final long identity = Binder.clearCallingIdentity();
4483 try {
4484 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4485 if (phone == null) {
4486 phone = mPhone;
4487 }
4488 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4489 } finally {
4490 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004491 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004492 }
4493
4494 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004495 * Returns whether vibration is set for voicemail notification in Phone settings.
4496 *
4497 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4498 * voicemail vibration setting.
4499 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4500 */
4501 @Override
4502 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004503 final long identity = Binder.clearCallingIdentity();
4504 try {
4505 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4506 if (phone == null) {
4507 phone = mPhone;
4508 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004509
Malcolm Chenaabec062018-02-28 15:00:40 -08004510 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004514 }
4515
Youhan Wange64578a2016-05-02 15:32:42 -07004516 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004517 * Sets the per-account voicemail vibration.
4518 *
4519 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4520 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4521 *
4522 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4523 * voicemail vibration setting.
4524 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4525 * specific PhoneAccount.
4526 */
4527 @Override
4528 public void setVoicemailVibrationEnabled(String callingPackage,
4529 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4530 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4531 if (!TextUtils.equals(callingPackage,
4532 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4534 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4535 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004536 }
4537
Malcolm Chenaabec062018-02-28 15:00:40 -08004538 final long identity = Binder.clearCallingIdentity();
4539 try {
4540 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4541 if (phone == null) {
4542 phone = mPhone;
4543 }
4544 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4545 } finally {
4546 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004547 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004548 }
4549
4550 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004551 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4552 *
4553 * @throws SecurityException if the caller does not have the required permission
4554 */
4555 private void enforceReadPrivilegedPermission() {
4556 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4557 null);
4558 }
4559
4560 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004561 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4562 * permission.
4563 *
4564 * @throws SecurityException if the caller does not have the required permission
4565 */
4566 private void enforceSendSmsPermission() {
4567 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4568 }
4569
4570 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004571 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004572 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004573 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004574 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004575 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004576 final long identity = Binder.clearCallingIdentity();
4577 try {
4578 ComponentName componentName =
4579 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4580 if (componentName == null) {
4581 throw new SecurityException(
4582 "Caller not current active visual voicemail package[null]");
4583 }
4584 String vvmPackage = componentName.getPackageName();
4585 if (!callingPackage.equals(vvmPackage)) {
4586 throw new SecurityException("Caller not current active visual voicemail package["
4587 + vvmPackage + "]");
4588 }
4589 } finally {
4590 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004591 }
4592 }
4593
4594 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004595 * Return the application ID for the app type.
4596 *
4597 * @param subId the subscription ID that this request applies to.
4598 * @param appType the uicc app type.
4599 * @return Application ID for specificied app type, or null if no uicc.
4600 */
4601 @Override
4602 public String getAidForAppType(int subId, int appType) {
4603 enforceReadPrivilegedPermission();
4604 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004605
4606 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004607 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004608 if (phone == null) {
4609 return null;
4610 }
4611 String aid = null;
4612 try {
4613 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4614 .getApplicationByType(appType).getAid();
4615 } catch (Exception e) {
4616 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4617 }
4618 return aid;
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004621 }
Youhan Wange64578a2016-05-02 15:32:42 -07004622 }
4623
Youhan Wang4001d252016-05-11 10:29:41 -07004624 /**
4625 * Return the Electronic Serial Number.
4626 *
4627 * @param subId the subscription ID that this request applies to.
4628 * @return ESN or null if error.
4629 */
4630 @Override
4631 public String getEsn(int subId) {
4632 enforceReadPrivilegedPermission();
4633 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004634
4635 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004636 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004637 if (phone == null) {
4638 return null;
4639 }
4640 String esn = null;
4641 try {
4642 esn = phone.getEsn();
4643 } catch (Exception e) {
4644 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4645 }
4646 return esn;
4647 } finally {
4648 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004649 }
Youhan Wang4001d252016-05-11 10:29:41 -07004650 }
4651
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004652 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004653 * Return the Preferred Roaming List Version.
4654 *
4655 * @param subId the subscription ID that this request applies to.
4656 * @return PRLVersion or null if error.
4657 */
4658 @Override
4659 public String getCdmaPrlVersion(int subId) {
4660 enforceReadPrivilegedPermission();
4661 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004662
4663 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004664 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004665 if (phone == null) {
4666 return null;
4667 }
4668 String cdmaPrlVersion = null;
4669 try {
4670 cdmaPrlVersion = phone.getCdmaPrlVersion();
4671 } catch (Exception e) {
4672 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4673 }
4674 return cdmaPrlVersion;
4675 } finally {
4676 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004677 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004678 }
4679
4680 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004681 * Get snapshot of Telephony histograms
4682 * @return List of Telephony histograms
4683 * @hide
4684 */
4685 @Override
4686 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4688 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 return RIL.getTelephonyRILTimingHistograms();
4693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004696 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004697
4698 /**
4699 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004700 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004701 * Require system privileges. In the future we may add this to carrier APIs.
4702 *
4703 * @return The number of carriers set successfully, should match length of carriers
4704 */
4705 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004706 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004707 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004708 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004709
Meng Wang9b7c4e92017-02-17 11:41:27 -08004710 if (carriers == null) {
4711 throw new NullPointerException("carriers cannot be null");
4712 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004713
Malcolm Chenaabec062018-02-28 15:00:40 -08004714 final long identity = Binder.clearCallingIdentity();
4715 try {
4716 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004717 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4718 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004719 return retVal[0];
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004723 }
4724
4725 /**
4726 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004727 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004728 * Require system privileges. In the future we may add this to carrier APIs.
4729 *
4730 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4731 * means all carriers are allowed.
4732 */
4733 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004734 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004735 enforceReadPrivilegedPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004736 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08004737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004741 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4742 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004743 } finally {
4744 Binder.restoreCallingIdentity(identity);
4745 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004746 }
4747
fionaxu59545b42016-05-25 15:53:37 -07004748 /**
4749 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4750 * @param subId the subscription ID that this action applies to.
4751 * @param enabled control enable or disable metered apns.
4752 * {@hide}
4753 */
4754 @Override
4755 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4756 enforceModifyPermission();
4757 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004758
4759 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004760 if (phone == null) {
4761 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4762 return;
4763 }
4764 try {
4765 phone.carrierActionSetMeteredApnsEnabled(enabled);
4766 } catch (Exception e) {
4767 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004768 } finally {
4769 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004770 }
4771 }
4772
4773 /**
4774 * Action set from carrier signalling broadcast receivers to enable/disable radio
4775 * @param subId the subscription ID that this action applies to.
4776 * @param enabled control enable or disable radio.
4777 * {@hide}
4778 */
4779 @Override
4780 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4781 enforceModifyPermission();
4782 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004783
4784 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004785 if (phone == null) {
4786 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4787 return;
4788 }
4789 try {
4790 phone.carrierActionSetRadioEnabled(enabled);
4791 } catch (Exception e) {
4792 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004793 } finally {
4794 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004795 }
4796 }
4797
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004798 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004799 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4800 * network status based on which carrier apps could apply actions accordingly,
4801 * enable/disable default url handler for example.
4802 *
4803 * @param subId the subscription ID that this action applies to.
4804 * @param report control start/stop reporting the default network status.
4805 * {@hide}
4806 */
4807 @Override
4808 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4809 enforceModifyPermission();
4810 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004811
4812 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004813 if (phone == null) {
4814 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4815 return;
4816 }
4817 try {
4818 phone.carrierActionReportDefaultNetworkStatus(report);
4819 } catch (Exception e) {
4820 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004821 } finally {
4822 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004823 }
4824 }
4825
4826 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004827 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4828 * bug report is being generated.
4829 */
4830 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004831 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004832 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4833 != PackageManager.PERMISSION_GRANTED) {
4834 writer.println("Permission Denial: can't dump Phone from pid="
4835 + Binder.getCallingPid()
4836 + ", uid=" + Binder.getCallingUid()
4837 + "without permission "
4838 + android.Manifest.permission.DUMP);
4839 return;
4840 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004841 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004842 }
Jack Yueb89b242016-06-22 13:27:47 -07004843
Brad Ebingerdac2f002018-04-03 15:17:52 -07004844 @Override
4845 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4846 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4847 throws RemoteException {
4848 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4849 }
4850
Jack Yueb89b242016-06-22 13:27:47 -07004851 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004852 * Get aggregated video call data usage since boot.
4853 *
4854 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4855 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004856 * {@hide}
4857 */
4858 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004859 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004860 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4861 null);
4862
Malcolm Chenaabec062018-02-28 15:00:40 -08004863 final long identity = Binder.clearCallingIdentity();
4864 try {
4865 // NetworkStatsService keeps tracking the active network interface and identity. It
4866 // records the delta with the corresponding network identity.
4867 // We just return the total video call data usage snapshot since boot.
4868 Phone phone = getPhone(subId);
4869 if (phone != null) {
4870 return phone.getVtDataUsage(perUidStats);
4871 }
4872 return null;
4873 } finally {
4874 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004875 }
Jack Yueb89b242016-06-22 13:27:47 -07004876 }
Jack Yu75ab2952016-07-08 14:29:33 -07004877
4878 /**
4879 * Policy control of data connection. Usually used when data limit is passed.
4880 * @param enabled True if enabling the data, otherwise disabling.
4881 * @param subId Subscription index
4882 * {@hide}
4883 */
4884 @Override
4885 public void setPolicyDataEnabled(boolean enabled, int subId) {
4886 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004887
4888 final long identity = Binder.clearCallingIdentity();
4889 try {
4890 Phone phone = getPhone(subId);
4891 if (phone != null) {
4892 phone.setPolicyDataEnabled(enabled);
4893 }
4894 } finally {
4895 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004896 }
4897 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004898
4899 /**
4900 * Get Client request stats
4901 * @return List of Client Request Stats
4902 * @hide
4903 */
4904 @Override
4905 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004907 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004908 return null;
4909 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004910 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004911
Malcolm Chenaabec062018-02-28 15:00:40 -08004912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 if (phone != null) {
4915 return phone.getClientRequestStats();
4916 }
4917
4918 return null;
4919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004922 }
4923
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004924 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004925 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004926 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004927 }
Jack Yueb4124c2017-02-16 15:32:43 -08004928
4929 /**
Grace Chen70990072017-03-24 17:21:30 -07004930 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004931 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004932 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004933 * @param state State of SIM (power down, power up, pass through)
4934 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4935 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4936 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004937 *
4938 **/
4939 @Override
Grace Chen70990072017-03-24 17:21:30 -07004940 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004941 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004942 Phone phone = PhoneFactory.getPhone(slotIndex);
4943
vagdevie435a3e2018-08-15 16:01:53 -07004944 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4945
Malcolm Chenaabec062018-02-28 15:00:40 -08004946 final long identity = Binder.clearCallingIdentity();
4947 try {
4948 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07004949 phone.setSimPowerState(state, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004950 }
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004953 }
4954 }
Shuo Qiandd210312017-04-12 22:11:33 +00004955
Tyler Gunn65d45c22017-06-05 11:22:26 -07004956 private boolean isUssdApiAllowed(int subId) {
4957 CarrierConfigManager configManager =
4958 (CarrierConfigManager) mPhone.getContext().getSystemService(
4959 Context.CARRIER_CONFIG_SERVICE);
4960 if (configManager == null) {
4961 return false;
4962 }
4963 PersistableBundle pb = configManager.getConfigForSubId(subId);
4964 if (pb == null) {
4965 return false;
4966 }
4967 return pb.getBoolean(
4968 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4969 }
4970
Shuo Qiandd210312017-04-12 22:11:33 +00004971 /**
4972 * Check if phone is in emergency callback mode
4973 * @return true if phone is in emergency callback mode
4974 * @param subId sub id
4975 */
goneil9c5f4872017-12-05 14:07:56 -08004976 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004977 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004978 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004979 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004980
4981 final long identity = Binder.clearCallingIdentity();
4982 try {
4983 if (phone != null) {
4984 return phone.isInEcm();
4985 } else {
4986 return false;
4987 }
4988 } finally {
4989 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004990 }
4991 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004992
4993 /**
4994 * Get the current signal strength information for the given subscription.
4995 * Because this information is not updated when the device is in a low power state
4996 * it should not be relied-upon to be current.
4997 * @param subId Subscription index
4998 * @return the most recent cached signal strength info from the modem
4999 */
5000 @Override
5001 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08005002 final long identity = Binder.clearCallingIdentity();
5003 try {
5004 Phone p = getPhone(subId);
5005 if (p == null) {
5006 return null;
5007 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005008
Malcolm Chenaabec062018-02-28 15:00:40 -08005009 return p.getSignalStrength();
5010 } finally {
5011 Binder.restoreCallingIdentity(identity);
5012 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005013 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005014
Pengquan Meng9140aec2018-08-22 14:49:57 -07005015 /**
5016 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5017 *
5018 * <p>Requires one of the following permissions:
5019 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5020 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5021 * privileges.
5022 *
5023 * @param subId subscription id
5024 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5025 * {@code false}.
5026 */
5027 @Override
5028 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005029 boolean isEnabled = false;
5030 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005031 try {
5032 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005033 null /* message */);
5034 Phone phone = getPhone(subId);
5035 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005036 } catch (Exception e) {
5037 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5038 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005039 } finally {
5040 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005041 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005042 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005043 }
5044
5045
5046 /**
5047 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5048 *
5049 * <p> Requires permission:
5050 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5051 * privileges.
5052 *
5053 * @param subId subscription id
5054 * @param isEnabled {@code true} means enable, {@code false} means disable.
5055 */
5056 @Override
5057 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005058 final long identity = Binder.clearCallingIdentity();
5059 try {
5060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5061 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005062
Pengquan Meng0c05b502018-09-06 09:59:22 -07005063 Phone phone = getPhone(subId);
5064 if (phone != null) {
5065 phone.setDataRoamingEnabled(isEnabled);
5066 }
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005069 }
5070 }
5071
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005072 @Override
5073 public UiccSlotInfo[] getUiccSlotsInfo() {
5074 enforceReadPrivilegedPermission();
5075
Malcolm Chenaabec062018-02-28 15:00:40 -08005076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005079 if (slots == null) {
5080 Rlog.i(LOG_TAG, "slots is null.");
5081 return null;
5082 }
5083
Malcolm Chenaabec062018-02-28 15:00:40 -08005084 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5085 for (int i = 0; i < slots.length; i++) {
5086 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005087 if (slot == null) {
5088 continue;
5089 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005090
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005091 String cardId;
5092 UiccCard card = slot.getUiccCard();
5093 if (card != null) {
5094 cardId = card.getCardId();
5095 } else {
5096 cardId = slot.getIccId();
5097 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005098
Malcolm Chenaabec062018-02-28 15:00:40 -08005099 int cardState = 0;
5100 switch (slot.getCardState()) {
5101 case CARDSTATE_ABSENT:
5102 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5103 break;
5104 case CARDSTATE_PRESENT:
5105 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5106 break;
5107 case CARDSTATE_ERROR:
5108 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5109 break;
5110 case CARDSTATE_RESTRICTED:
5111 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5112 break;
5113 default:
5114 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005115
Malcolm Chenaabec062018-02-28 15:00:40 -08005116 }
5117
5118 infos[i] = new UiccSlotInfo(
5119 slot.isActive(),
5120 slot.isEuicc(),
5121 cardId,
5122 cardState,
5123 slot.getPhoneId(),
5124 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005125 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005126 return infos;
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005129 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005130 }
5131
5132 @Override
5133 public boolean switchSlots(int[] physicalSlots) {
5134 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005135
5136 final long identity = Binder.clearCallingIdentity();
5137 try {
5138 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005142 }
Jack Yu4c988042018-02-27 15:30:01 -08005143
5144 @Override
5145 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5146 enforceModifyPermission();
5147 final Phone phone = getPhone(subId);
5148 if (phone == null) {
5149 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5150 return;
5151 }
5152
Malcolm Chenaabec062018-02-28 15:00:40 -08005153 final long identity = Binder.clearCallingIdentity();
5154 try {
5155 phone.setRadioIndicationUpdateMode(filters, mode);
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
5158 }
Jack Yu4c988042018-02-27 15:30:01 -08005159 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005160
5161 /**
goneil47ffb6e2018-04-06 15:40:58 -07005162 * A test API to reload the UICC profile.
5163 *
5164 * <p>Requires that the calling app has permission
5165 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5166 * @hide
5167 */
5168 @Override
5169 public void refreshUiccProfile(int subId) {
5170 enforceModifyPermission();
5171
5172 final long identity = Binder.clearCallingIdentity();
5173 try {
5174 Phone phone = getPhone(subId);
5175 if (phone == null) {
5176 return;
5177 }
5178 UiccCard uiccCard = phone.getUiccCard();
5179 if (uiccCard == null) {
5180 return;
5181 }
5182 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5183 if (uiccProfile == null) {
5184 return;
5185 }
5186 uiccProfile.refresh();
5187 } finally {
5188 Binder.restoreCallingIdentity(identity);
5189 }
5190 }
5191
5192 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005193 * Returns false if the mobile data is disabled by default, otherwise return true.
5194 */
5195 private boolean getDefaultDataEnabled() {
5196 return "true".equalsIgnoreCase(
5197 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5198 }
5199
5200 /**
5201 * Returns true if the data roaming is enabled by default, i.e the system property
5202 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5203 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5204 */
5205 private boolean getDefaultDataRoamingEnabled(int subId) {
5206 final CarrierConfigManager configMgr = (CarrierConfigManager)
5207 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5208 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5209 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5210 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5211 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5212 return isDataRoamingEnabled;
5213 }
5214
5215 /**
5216 * Returns the default network type for the given {@code subId}, if the default network type is
5217 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5218 */
5219 private int getDefaultNetworkType(int subId) {
5220 return Integer.parseInt(
5221 TelephonyManager.getTelephonyProperty(
5222 mSubscriptionController.getPhoneId(subId),
5223 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5224 String.valueOf(Phone.PREFERRED_NT_MODE)));
5225 }
fionaxua13278b2018-03-21 00:08:13 -07005226
5227 @Override
5228 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5229 gid1, String gid2, String plmn, String spn) {
5230 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005231
5232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 final Phone phone = getPhone(subId);
5235 if (phone == null) {
5236 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5237 return;
5238 }
5239 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005242 }
fionaxua13278b2018-03-21 00:08:13 -07005243 }
5244
5245 @Override
5246 public int getCarrierIdListVersion(int subId) {
5247 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005248
5249 final long identity = Binder.clearCallingIdentity();
5250 try {
5251 final Phone phone = getPhone(subId);
5252 if (phone == null) {
5253 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5254 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5255 }
5256 return phone.getCarrierIdListVersion();
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005259 }
fionaxua13278b2018-03-21 00:08:13 -07005260 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005261
5262 @Override
5263 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5265 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5266 return -1;
5267 }
5268
5269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5272 } finally {
5273 Binder.restoreCallingIdentity(identity);
5274 }
5275 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005276
5277 @Override
5278 public int getCdmaRoamingMode(int subId) {
5279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5280 mApp, subId, "getCdmaRoamingMode");
5281
5282 final long identity = Binder.clearCallingIdentity();
5283 try {
5284 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
5288 }
5289
5290 @Override
5291 public boolean setCdmaRoamingMode(int subId, int mode) {
5292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5293 mApp, subId, "setCdmaRoamingMode");
5294
5295 final long identity = Binder.clearCallingIdentity();
5296 try {
5297 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5298 } finally {
5299 Binder.restoreCallingIdentity(identity);
5300 }
5301 }
5302
5303 @Override
5304 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5306 mApp, subId, "setCdmaSubscriptionMode");
5307
5308 final long identity = Binder.clearCallingIdentity();
5309 try {
5310 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
5314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005315}