blob: 6eba28d05d5f3617e8ddd57730ecbdcdb9b0f1a4 [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;
Nathan Harold31d7ff32018-10-15 20:20:30 -070028import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080043import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070046import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070047import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070049import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070050import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080052import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070053import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080054import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080055import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070056import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070057import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070059import android.telephony.CellInfoGsm;
60import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070061import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070063import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080064import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070065import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080066import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070067import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070068import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070069import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080071import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070072import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080073import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070075import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070076import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000077import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070078import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070079import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070080import android.telephony.cdma.CdmaCellLocation;
81import android.telephony.gsm.GsmCellLocation;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080082import android.telephony.ims.aidl.IImsConfig;
83import android.telephony.ims.aidl.IImsMmTelFeature;
84import android.telephony.ims.aidl.IImsRcsFeature;
85import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080086import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080090import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080092
Andrew Lee312e8172014-10-23 17:01:36 -070093import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080094import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070095import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070096import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070097import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070098import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070099import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800102import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700103import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100104import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700105import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700106import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700108import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800109import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700110import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700111import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700112import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700113import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700114import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700115import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800116import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800117import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700118import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700119import com.android.internal.telephony.uicc.IccIoResult;
120import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800121import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700122import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800123import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800125import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000126import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700127import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800128import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700129import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800130import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700131import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700132import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800133
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700134import java.io.FileDescriptor;
135import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800139import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100140import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142
143/**
144 * Implementation of the ITelephony interface.
145 */
Santos Cordon117fee72014-05-16 17:56:12 -0700146public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147 private static final String LOG_TAG = "PhoneInterfaceManager";
148 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
149 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800150 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151
152 // Message codes used with mMainThreadHandler
153 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700154 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
155 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156 private static final int CMD_OPEN_CHANNEL = 9;
157 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
158 private static final int CMD_CLOSE_CHANNEL = 11;
159 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800160 private static final int CMD_NV_READ_ITEM = 13;
161 private static final int EVENT_NV_READ_ITEM_DONE = 14;
162 private static final int CMD_NV_WRITE_ITEM = 15;
163 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
164 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
165 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
166 private static final int CMD_NV_RESET_CONFIG = 19;
167 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800168 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
169 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
170 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
171 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800172 private static final int CMD_SEND_ENVELOPE = 25;
173 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000174 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
175 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700176 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
177 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
178 private static final int CMD_EXCHANGE_SIM_IO = 31;
179 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800180 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
181 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700182 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
183 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700184 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
185 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700186 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
187 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
188 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
189 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700190 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
191 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
192 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
193 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700194 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800195 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
196 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000197 private static final int CMD_SWITCH_SLOTS = 50;
198 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700199 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
200 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
201 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
202 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
203 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
204 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
205 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
206 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700207 private static final int CMD_GET_ALL_CELL_INFO = 60;
208 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
209 private static final int CMD_GET_CELL_LOCATION = 62;
210 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800212 // Parameters of select command.
213 private static final int SELECT_COMMAND = 0xA4;
214 private static final int SELECT_P1 = 0x04;
215 private static final int SELECT_P2 = 0;
216 private static final int SELECT_P3 = 0x10;
217
Pengquan Meng85728fb2018-03-12 16:31:21 -0700218 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
219 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
220 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
221
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222 /** The singleton instance. */
223 private static PhoneInterfaceManager sInstance;
224
Wink Saville3ab207e2014-11-20 13:07:20 -0800225 private PhoneGlobals mApp;
226 private Phone mPhone;
227 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700228 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800229 private AppOpsManager mAppOps;
230 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800231 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800232 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700233 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234
Derek Tan97ebb422014-09-05 16:55:38 -0700235 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
236 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800237 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700238
Derek Tan740e1672017-06-27 14:56:27 -0700239 // The AID of ISD-R.
240 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
241
yinxub1bed742017-04-17 11:45:04 -0700242 private NetworkScanRequestTracker mNetworkScanRequestTracker;
243
David Kelly5e06a7f2018-03-12 14:10:59 +0000244 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
245 private static final int MANUFACTURER_CODE_LENGTH = 8;
246
Derek Tan89e89d42014-07-08 17:00:10 -0700247 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700248 * A request object to use for transmitting data to an ICC.
249 */
250 private static final class IccAPDUArgument {
251 public int channel, cla, command, p1, p2, p3;
252 public String data;
253
254 public IccAPDUArgument(int channel, int cla, int command,
255 int p1, int p2, int p3, String data) {
256 this.channel = channel;
257 this.cla = cla;
258 this.command = command;
259 this.p1 = p1;
260 this.p2 = p2;
261 this.p3 = p3;
262 this.data = data;
263 }
264 }
265
266 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700267 * A request object to use for transmitting data to an ICC.
268 */
269 private static final class ManualNetworkSelectionArgument {
270 public OperatorInfo operatorInfo;
271 public boolean persistSelection;
272
273 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
274 this.operatorInfo = operatorInfo;
275 this.persistSelection = persistSelection;
276 }
277 }
278
279 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
281 * request after sending. The main thread will notify the request when it is complete.
282 */
283 private static final class MainThreadRequest {
284 /** The argument to use for the request */
285 public Object argument;
286 /** The result of the request that is run on the main thread */
287 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800288 // The subscriber id that this request applies to. Defaults to
289 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
290 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
Nathan Harold92bed182018-10-12 18:16:49 -0700292 // In cases where subId is unavailable, the caller needs to specify the phone.
293 public Phone phone;
294
vagdevie435a3e2018-08-15 16:01:53 -0700295 public WorkSource workSource;
296
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 public MainThreadRequest(Object argument) {
298 this.argument = argument;
299 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800300
Nathan Harold92bed182018-10-12 18:16:49 -0700301 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
302 this.argument = argument;
303 if (phone != null) {
304 this.phone = phone;
305 }
306 this.workSource = workSource;
307 }
308
vagdevie435a3e2018-08-15 16:01:53 -0700309 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800310 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800311 if (subId != null) {
312 this.subId = subId;
313 }
vagdevie435a3e2018-08-15 16:01:53 -0700314 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 }
317
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800318 private static final class IncomingThirdPartyCallArgs {
319 public final ComponentName component;
320 public final String callId;
321 public final String callerDisplayName;
322
323 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
324 String callerDisplayName) {
325 this.component = component;
326 this.callId = callId;
327 this.callerDisplayName = callerDisplayName;
328 }
329 }
330
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 /**
332 * A handler that processes messages on the main thread in the phone process. Since many
333 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
334 * inbound binder threads to the main thread in the phone process. The Binder thread
335 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
336 * on, which will be notified when the operation completes and will contain the result of the
337 * request.
338 *
339 * <p>If a MainThreadRequest object is provided in the msg.obj field,
340 * note that request.result must be set to something non-null for the calling thread to
341 * unblock.
342 */
343 private final class MainThreadHandler extends Handler {
344 @Override
345 public void handleMessage(Message msg) {
346 MainThreadRequest request;
347 Message onCompleted;
348 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800349 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700350 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351
352 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700353 case CMD_HANDLE_USSD_REQUEST: {
354 request = (MainThreadRequest) msg.obj;
355 final Phone phone = getPhoneFromRequest(request);
356 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
357 String ussdRequest = ussdObject.first;
358 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700359
Pengquan Meng0c05b502018-09-06 09:59:22 -0700360 if (!isUssdApiAllowed(request.subId)) {
361 // Carrier does not support use of this API, return failure.
362 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
363 UssdResponse response = new UssdResponse(ussdRequest, null);
364 Bundle returnData = new Bundle();
365 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
366 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700367
Pengquan Meng0c05b502018-09-06 09:59:22 -0700368 request.result = true;
369 notifyRequester(request);
370 return;
371 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700372
Pengquan Meng0c05b502018-09-06 09:59:22 -0700373 try {
374 request.result = phone != null
375 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
376 } catch (CallStateException cse) {
377 request.result = false;
378 }
379 // Wake up the requesting thread
380 notifyRequester(request);
381 break;
pkanwar32d516d2016-10-14 19:37:38 -0700382 }
383
Yorke Lee716f67e2015-06-17 15:39:16 -0700384 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700386 final Phone phone = getPhoneFromRequest(request);
387 request.result = phone != null ?
388 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
389 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700391 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700395 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700396 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700397 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800398 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700399 if (uiccCard == null) {
400 loge("iccTransmitApduLogicalChannel: No UICC");
401 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700402 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700403 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
405 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700406 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700407 iccArgument.channel, iccArgument.cla, iccArgument.command,
408 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700409 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700410 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700411 break;
412
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 ar = (AsyncResult) msg.obj;
415 request = (MainThreadRequest) ar.userObj;
416 if (ar.exception == null && ar.result != null) {
417 request.result = ar.result;
418 } else {
419 request.result = new IccIoResult(0x6F, 0, (byte[])null);
420 if (ar.result == null) {
421 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800422 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800424 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 } else {
426 loge("iccTransmitApduLogicalChannel: Unknown exception");
427 }
428 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700429 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 break;
431
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
433 request = (MainThreadRequest) msg.obj;
434 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800435 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 if (uiccCard == null) {
437 loge("iccTransmitApduBasicChannel: No UICC");
438 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700439 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 } else {
441 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
442 request);
443 uiccCard.iccTransmitApduBasicChannel(
444 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
445 iccArgument.p3, iccArgument.data, onCompleted);
446 }
447 break;
448
449 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
450 ar = (AsyncResult) msg.obj;
451 request = (MainThreadRequest) ar.userObj;
452 if (ar.exception == null && ar.result != null) {
453 request.result = ar.result;
454 } else {
455 request.result = new IccIoResult(0x6F, 0, (byte[])null);
456 if (ar.result == null) {
457 loge("iccTransmitApduBasicChannel: Empty response");
458 } else if (ar.exception instanceof CommandException) {
459 loge("iccTransmitApduBasicChannel: CommandException: " +
460 ar.exception);
461 } else {
462 loge("iccTransmitApduBasicChannel: Unknown exception");
463 }
464 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700465 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 break;
467
468 case CMD_EXCHANGE_SIM_IO:
469 request = (MainThreadRequest) msg.obj;
470 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800471 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 if (uiccCard == null) {
473 loge("iccExchangeSimIO: No UICC");
474 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700475 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 } else {
477 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
478 request);
479 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
480 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
481 iccArgument.data, onCompleted);
482 }
483 break;
484
485 case EVENT_EXCHANGE_SIM_IO_DONE:
486 ar = (AsyncResult) msg.obj;
487 request = (MainThreadRequest) ar.userObj;
488 if (ar.exception == null && ar.result != null) {
489 request.result = ar.result;
490 } else {
491 request.result = new IccIoResult(0x6f, 0, (byte[])null);
492 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 break;
495
Derek Tan4d5e5c12014-02-04 11:54:58 -0800496 case CMD_SEND_ENVELOPE:
497 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700499 if (uiccCard == null) {
500 loge("sendEnvelopeWithStatus: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700503 } else {
504 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
505 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
506 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800507 break;
508
509 case EVENT_SEND_ENVELOPE_DONE:
510 ar = (AsyncResult) msg.obj;
511 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700512 if (ar.exception == null && ar.result != null) {
513 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800514 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700515 request.result = new IccIoResult(0x6F, 0, (byte[])null);
516 if (ar.result == null) {
517 loge("sendEnvelopeWithStatus: Empty response");
518 } else if (ar.exception instanceof CommandException) {
519 loge("sendEnvelopeWithStatus: CommandException: " +
520 ar.exception);
521 } else {
522 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
523 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800524 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700525 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 break;
527
Shishir Agrawal566b7612013-10-28 14:41:00 -0700528 case CMD_OPEN_CHANNEL:
529 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800530 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800531 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 if (uiccCard == null) {
533 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800534 request.result = new IccOpenLogicalChannelResponse(-1,
535 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700536 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 } else {
538 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800539 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
540 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 break;
543
544 case EVENT_OPEN_CHANNEL_DONE:
545 ar = (AsyncResult) msg.obj;
546 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 int[] result = (int[]) ar.result;
550 int channelId = result[0];
551 byte[] selectResponse = null;
552 if (result.length > 1) {
553 selectResponse = new byte[result.length - 1];
554 for (int i = 1; i < result.length; ++i) {
555 selectResponse[i - 1] = (byte) result[i];
556 }
557 }
558 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700559 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 if (ar.result == null) {
562 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 if (ar.exception != null) {
565 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
566 }
567
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700568 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700569 if (ar.exception instanceof CommandException) {
570 CommandException.Error error =
571 ((CommandException) (ar.exception)).getCommandError();
572 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700573 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700574 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700575 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 }
577 }
578 openChannelResp = new IccOpenLogicalChannelResponse(
579 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700581 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700582 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 break;
584
585 case CMD_CLOSE_CHANNEL:
586 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800587 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 if (uiccCard == null) {
589 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900590 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 } else {
593 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
594 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
595 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 break;
597
598 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800599 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
600 break;
601
602 case CMD_NV_READ_ITEM:
603 request = (MainThreadRequest) msg.obj;
604 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700605 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800606 break;
607
608 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800611 if (ar.exception == null && ar.result != null) {
612 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800614 request.result = "";
615 if (ar.result == null) {
616 loge("nvReadItem: Empty response");
617 } else if (ar.exception instanceof CommandException) {
618 loge("nvReadItem: CommandException: " +
619 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800621 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 }
623 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
Jake Hambye994d462014-02-03 13:10:13 -0800627 case CMD_NV_WRITE_ITEM:
628 request = (MainThreadRequest) msg.obj;
629 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
630 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700631 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
632 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800633 break;
634
635 case EVENT_NV_WRITE_ITEM_DONE:
636 handleNullReturnEvent(msg, "nvWriteItem");
637 break;
638
639 case CMD_NV_WRITE_CDMA_PRL:
640 request = (MainThreadRequest) msg.obj;
641 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
642 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
643 break;
644
645 case EVENT_NV_WRITE_CDMA_PRL_DONE:
646 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
647 break;
648
649 case CMD_NV_RESET_CONFIG:
650 request = (MainThreadRequest) msg.obj;
651 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
652 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
653 break;
654
655 case EVENT_NV_RESET_CONFIG_DONE:
656 handleNullReturnEvent(msg, "nvResetConfig");
657 break;
658
Jake Hamby7c27be32014-03-03 13:25:59 -0800659 case CMD_GET_PREFERRED_NETWORK_TYPE:
660 request = (MainThreadRequest) msg.obj;
661 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700662 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800663 break;
664
665 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
666 ar = (AsyncResult) msg.obj;
667 request = (MainThreadRequest) ar.userObj;
668 if (ar.exception == null && ar.result != null) {
669 request.result = ar.result; // Integer
670 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800671 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800672 if (ar.result == null) {
673 loge("getPreferredNetworkType: Empty response");
674 } else if (ar.exception instanceof CommandException) {
675 loge("getPreferredNetworkType: CommandException: " +
676 ar.exception);
677 } else {
678 loge("getPreferredNetworkType: Unknown exception");
679 }
680 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700681 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800682 break;
683
684 case CMD_SET_PREFERRED_NETWORK_TYPE:
685 request = (MainThreadRequest) msg.obj;
686 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
687 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700688 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800689 break;
690
691 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
692 handleNullReturnEvent(msg, "setPreferredNetworkType");
693 break;
694
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000695 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
696 request = (MainThreadRequest)msg.obj;
697 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700698 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000699 break;
700
701 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
702 ar = (AsyncResult)msg.obj;
703 request = (MainThreadRequest)ar.userObj;
704 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700705 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000706 break;
707
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800708 case CMD_SET_VOICEMAIL_NUMBER:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
711 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800712 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
713 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800714 break;
715
716 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
717 handleNullReturnEvent(msg, "setVoicemailNumber");
718 break;
719
Stuart Scott54788802015-03-30 13:18:01 -0700720 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
723 request);
724 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
725 break;
726
727 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
728 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
729 break;
730
Shishir Agrawal302c8692015-06-19 13:49:39 -0700731 case CMD_PERFORM_NETWORK_SCAN:
732 request = (MainThreadRequest) msg.obj;
733 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
734 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
735 break;
736
737 case EVENT_PERFORM_NETWORK_SCAN_DONE:
738 ar = (AsyncResult) msg.obj;
739 request = (MainThreadRequest) ar.userObj;
740 CellNetworkScanResult cellScanResult;
741 if (ar.exception == null && ar.result != null) {
742 cellScanResult = new CellNetworkScanResult(
743 CellNetworkScanResult.STATUS_SUCCESS,
744 (List<OperatorInfo>) ar.result);
745 } else {
746 if (ar.result == null) {
747 loge("getCellNetworkScanResults: Empty response");
748 }
749 if (ar.exception != null) {
750 loge("getCellNetworkScanResults: Exception: " + ar.exception);
751 }
752 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
753 if (ar.exception instanceof CommandException) {
754 CommandException.Error error =
755 ((CommandException) (ar.exception)).getCommandError();
756 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
757 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
758 } else if (error == CommandException.Error.GENERIC_FAILURE) {
759 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
760 }
761 }
762 cellScanResult = new CellNetworkScanResult(errorCode, null);
763 }
764 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700765 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700766 break;
767
768 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
769 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700770 ManualNetworkSelectionArgument selArg =
771 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700772 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
773 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700774 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
775 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700776 break;
777
778 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700779 ar = (AsyncResult) msg.obj;
780 request = (MainThreadRequest) ar.userObj;
781 if (ar.exception == null) {
782 request.result = true;
783 } else {
784 request.result = false;
785 loge("setNetworkSelectionModeManual " + ar.exception);
786 }
787 notifyRequester(request);
788 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700789 break;
790
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700791 case CMD_GET_MODEM_ACTIVITY_INFO:
792 request = (MainThreadRequest) msg.obj;
793 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700794 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700795 break;
796
797 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
798 ar = (AsyncResult) msg.obj;
799 request = (MainThreadRequest) ar.userObj;
800 if (ar.exception == null && ar.result != null) {
801 request.result = ar.result;
802 } else {
803 if (ar.result == null) {
804 loge("queryModemActivityInfo: Empty response");
805 } else if (ar.exception instanceof CommandException) {
806 loge("queryModemActivityInfo: CommandException: " +
807 ar.exception);
808 } else {
809 loge("queryModemActivityInfo: Unknown exception");
810 }
811 }
Amit Mahajand4766222016-01-28 15:28:28 -0800812 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
813 if (request.result == null) {
814 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
815 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700816 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700817 break;
818
Meng Wang1a7c35a2016-05-05 20:56:15 -0700819 case CMD_SET_ALLOWED_CARRIERS:
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
822 mPhone.setAllowedCarriers(
823 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700824 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700825 break;
826
827 case EVENT_SET_ALLOWED_CARRIERS_DONE:
828 ar = (AsyncResult) msg.obj;
829 request = (MainThreadRequest) ar.userObj;
830 if (ar.exception == null && ar.result != null) {
831 request.result = ar.result;
832 } else {
833 if (ar.result == null) {
834 loge("setAllowedCarriers: Empty response");
835 } else if (ar.exception instanceof CommandException) {
836 loge("setAllowedCarriers: CommandException: " +
837 ar.exception);
838 } else {
839 loge("setAllowedCarriers: Unknown exception");
840 }
841 }
842 // Result cannot be null. Return -1 on error.
843 if (request.result == null) {
844 request.result = new int[]{-1};
845 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700846 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 break;
848
849 case CMD_GET_ALLOWED_CARRIERS:
850 request = (MainThreadRequest) msg.obj;
851 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700852 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 break;
854
855 case EVENT_GET_ALLOWED_CARRIERS_DONE:
856 ar = (AsyncResult) msg.obj;
857 request = (MainThreadRequest) ar.userObj;
858 if (ar.exception == null && ar.result != null) {
859 request.result = ar.result;
860 } else {
861 if (ar.result == null) {
862 loge("getAllowedCarriers: Empty response");
863 } else if (ar.exception instanceof CommandException) {
864 loge("getAllowedCarriers: CommandException: " +
865 ar.exception);
866 } else {
867 loge("getAllowedCarriers: Unknown exception");
868 }
869 }
870 // Result cannot be null. Return empty list of CarrierIdentifier.
871 if (request.result == null) {
872 request.result = new ArrayList<CarrierIdentifier>(0);
873 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700874 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 break;
876
Nathan Haroldb3014052017-01-25 15:57:32 -0800877 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result;
882 } else {
883 request.result = new IllegalArgumentException(
884 "Failed to retrieve Forbidden Plmns");
885 if (ar.result == null) {
886 loge("getForbiddenPlmns: Empty response");
887 } else {
888 loge("getForbiddenPlmns: Unknown exception");
889 }
890 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700891 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800892 break;
893
894 case CMD_GET_FORBIDDEN_PLMNS:
895 request = (MainThreadRequest) msg.obj;
896 uiccCard = getUiccCardFromRequest(request);
897 if (uiccCard == null) {
898 loge("getForbiddenPlmns() UiccCard is null");
899 request.result = new IllegalArgumentException(
900 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700901 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800902 break;
903 }
904 Integer appType = (Integer) request.argument;
905 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
906 if (uiccApp == null) {
907 loge("getForbiddenPlmns() no app with specified type -- "
908 + appType);
909 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700910 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800911 break;
912 } else {
913 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
914 + " specified type -- " + appType);
915 }
916 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
917 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
918 onCompleted);
919 break;
920
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000921 case CMD_SWITCH_SLOTS:
922 request = (MainThreadRequest) msg.obj;
923 int[] physicalSlots = (int[]) request.argument;
924 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
925 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
926 break;
927
928 case EVENT_SWITCH_SLOTS_DONE:
929 ar = (AsyncResult) msg.obj;
930 request = (MainThreadRequest) ar.userObj;
931 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700932 notifyRequester(request);
933 break;
934 case CMD_GET_NETWORK_SELECTION_MODE:
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
937 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
938 break;
939
940 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
941 ar = (AsyncResult) msg.obj;
942 request = (MainThreadRequest) ar.userObj;
943 if (ar.exception != null) {
944 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
945 } else {
946 int mode = ((int[]) ar.result)[0];
947 if (mode == 0) {
948 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
949 } else {
950 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
951 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000952 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700953 notifyRequester(request);
954 break;
955 case CMD_GET_CDMA_ROAMING_MODE:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
958 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
959 break;
960 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 if (ar.exception != null) {
964 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
965 } else {
966 request.result = ((int[]) ar.result)[0];
967 }
968 notifyRequester(request);
969 break;
970 case CMD_SET_CDMA_ROAMING_MODE:
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
973 int mode = (int) request.argument;
974 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
975 break;
976 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
979 request.result = ar.exception == null;
980 notifyRequester(request);
981 break;
982 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
985 int subscriptionMode = (int) request.argument;
986 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
987 break;
988 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
991 request.result = ar.exception == null;
992 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000993 break;
994
Nathan Harold3ff88932018-08-14 10:19:49 -0700995 case CMD_GET_ALL_CELL_INFO:
996 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -0700997 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -0700998 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -0700999 break;
1000
1001 case EVENT_GET_ALL_CELL_INFO_DONE:
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001004 // If a timeout occurs, the response will be null
1005 request.result = (ar.exception == null && ar.result != null)
1006 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001007 synchronized (request) {
1008 request.notifyAll();
1009 }
1010 break;
1011
1012 case CMD_GET_CELL_LOCATION: {
1013 request = (MainThreadRequest) msg.obj;
1014 WorkSource ws = (WorkSource) request.argument;
1015 Phone phone = getPhoneFromRequest(request);
1016 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1017 break;
1018 }
1019
1020 case EVENT_GET_CELL_LOCATION_DONE: {
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 if (ar.exception == null) {
1024 request.result = ar.result;
1025 } else {
1026 Phone phone = getPhoneFromRequest(request);
1027 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1028 ? new CdmaCellLocation() : new GsmCellLocation();
1029 }
1030
1031 synchronized (request) {
1032 request.notifyAll();
1033 }
1034 break;
1035 }
1036
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001037 default:
1038 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1039 break;
1040 }
1041 }
Jake Hambye994d462014-02-03 13:10:13 -08001042
Pengquan Meng0c05b502018-09-06 09:59:22 -07001043 private void notifyRequester(MainThreadRequest request) {
1044 synchronized (request) {
1045 request.notifyAll();
1046 }
1047 }
1048
Jake Hambye994d462014-02-03 13:10:13 -08001049 private void handleNullReturnEvent(Message msg, String command) {
1050 AsyncResult ar = (AsyncResult) msg.obj;
1051 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1052 if (ar.exception == null) {
1053 request.result = true;
1054 } else {
1055 request.result = false;
1056 if (ar.exception instanceof CommandException) {
1057 loge(command + ": CommandException: " + ar.exception);
1058 } else {
1059 loge(command + ": Unknown exception");
1060 }
1061 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001062 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001064 }
1065
1066 /**
1067 * Posts the specified command to be executed on the main thread,
1068 * waits for the request to complete, and returns the result.
1069 * @see #sendRequestAsync
1070 */
1071 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001072 return sendRequest(
1073 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001074 }
1075
1076 /**
1077 * Posts the specified command to be executed on the main thread,
1078 * waits for the request to complete, and returns the result.
1079 * @see #sendRequestAsync
1080 */
1081 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1082 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001083 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001084 }
1085
1086 /**
1087 * Posts the specified command to be executed on the main thread,
1088 * waits for the request to complete, and returns the result.
1089 * @see #sendRequestAsync
1090 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001091 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001092 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001093 }
1094
1095 /**
1096 * Posts the specified command to be executed on the main thread,
1097 * waits for the request to complete, and returns the result.
1098 * @see #sendRequestAsync
1099 */
Nathan Harold92bed182018-10-12 18:16:49 -07001100 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1101 return sendRequest(command, argument, subId, null, workSource);
1102 }
1103
1104 /**
1105 * Posts the specified command to be executed on the main thread,
1106 * waits for the request to complete, and returns the result.
1107 * @see #sendRequestAsync
1108 */
1109 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1110 return sendRequest(
1111 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1112 }
1113
1114 /**
1115 * Posts the specified command to be executed on the main thread,
1116 * waits for the request to complete, and returns the result.
1117 * @see #sendRequestAsync
1118 */
1119 private Object sendRequest(
1120 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001121 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1122 throw new RuntimeException("This method will deadlock if called from the main thread.");
1123 }
1124
Nathan Harold92bed182018-10-12 18:16:49 -07001125 MainThreadRequest request = null;
1126 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1127 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1128 } else if (phone != null) {
1129 request = new MainThreadRequest(argument, phone, workSource);
1130 } else {
1131 request = new MainThreadRequest(argument, subId, workSource);
1132 }
1133
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001134 Message msg = mMainThreadHandler.obtainMessage(command, request);
1135 msg.sendToTarget();
1136
1137 // Wait for the request to complete
1138 synchronized (request) {
1139 while (request.result == null) {
1140 try {
1141 request.wait();
1142 } catch (InterruptedException e) {
1143 // Do nothing, go back and wait until the request is complete
1144 }
1145 }
1146 }
1147 return request.result;
1148 }
1149
1150 /**
1151 * Asynchronous ("fire and forget") version of sendRequest():
1152 * Posts the specified command to be executed on the main thread, and
1153 * returns immediately.
1154 * @see #sendRequest
1155 */
1156 private void sendRequestAsync(int command) {
1157 mMainThreadHandler.sendEmptyMessage(command);
1158 }
1159
1160 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001161 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1162 * @see {@link #sendRequest(int,Object)}
1163 */
1164 private void sendRequestAsync(int command, Object argument) {
1165 MainThreadRequest request = new MainThreadRequest(argument);
1166 Message msg = mMainThreadHandler.obtainMessage(command, request);
1167 msg.sendToTarget();
1168 }
1169
1170 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 * Initialize the singleton PhoneInterfaceManager instance.
1172 * This is only done once, at startup, from PhoneApp.onCreate().
1173 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001174 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 synchronized (PhoneInterfaceManager.class) {
1176 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001177 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001178 } else {
1179 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1180 }
1181 return sInstance;
1182 }
1183 }
1184
1185 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001186 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001187 mApp = app;
1188 mPhone = phone;
1189 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001190 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1192 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001193 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001194 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001195 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001196 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001197 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001198
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 publish();
1200 }
1201
1202 private void publish() {
1203 if (DBG) log("publish: " + this);
1204
1205 ServiceManager.addService("phone", this);
1206 }
1207
Stuart Scott584921c2015-01-15 17:10:34 -08001208 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001209 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1210 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001211 }
1212
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001213 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1214 Phone phone = getPhoneFromRequest(request);
1215 return phone == null ? null :
1216 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1217 }
1218
Wink Saville36469e72014-06-11 15:17:00 -07001219 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001220 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001221 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223
1224 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001225 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001226 }
1227
Wink Savilleb564aae2014-10-23 10:18:09 -07001228 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 if (DBG) log("dial: " + number);
1230 // No permission check needed here: This is just a wrapper around the
1231 // ACTION_DIAL intent, which is available to any app since it puts up
1232 // the UI before it does anything.
1233
Malcolm Chenaabec062018-02-28 15:00:40 -08001234 final long identity = Binder.clearCallingIdentity();
1235 try {
1236 String url = createTelUrl(number);
1237 if (url == null) {
1238 return;
1239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001240
Malcolm Chenaabec062018-02-28 15:00:40 -08001241 // PENDING: should we just silently fail if phone is offhook or ringing?
1242 PhoneConstants.State state = mCM.getState(subId);
1243 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1244 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1245 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1246 mApp.startActivity(intent);
1247 }
1248 } finally {
1249 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 }
1251 }
1252
1253 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001254 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001255 }
1256
Wink Savilleb564aae2014-10-23 10:18:09 -07001257 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 if (DBG) log("call: " + number);
1259
1260 // This is just a wrapper around the ACTION_CALL intent, but we still
1261 // need to do a permission check since we're calling startActivity()
1262 // from the context of the phone app.
1263 enforceCallPermission();
1264
1265 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1266 != AppOpsManager.MODE_ALLOWED) {
1267 return;
1268 }
1269
Malcolm Chenaabec062018-02-28 15:00:40 -08001270 final long identity = Binder.clearCallingIdentity();
1271 try {
1272 String url = createTelUrl(number);
1273 if (url == null) {
1274 return;
1275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276
Malcolm Chenaabec062018-02-28 15:00:40 -08001277 boolean isValid = false;
1278 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1279 if (slist != null) {
1280 for (SubscriptionInfo subInfoRecord : slist) {
1281 if (subInfoRecord.getSubscriptionId() == subId) {
1282 isValid = true;
1283 break;
1284 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001285 }
Wink Saville08874612014-08-31 19:19:58 -07001286 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001287 if (!isValid) {
1288 return;
1289 }
Wink Saville08874612014-08-31 19:19:58 -07001290
Malcolm Chenaabec062018-02-28 15:00:40 -08001291 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1292 intent.putExtra(SUBSCRIPTION_KEY, subId);
1293 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1294 mApp.startActivity(intent);
1295 } finally {
1296 Binder.restoreCallingIdentity(identity);
1297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 }
1299
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001301 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001302 }
1303
Wink Savilleb564aae2014-10-23 10:18:09 -07001304 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001305 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001306 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1307 }
1308
1309 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001310 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001311 }
1312
Wink Savilleb564aae2014-10-23 10:18:09 -07001313 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001314 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001315 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1316 }
1317
1318 /** {@hide} */
1319 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001321 }
1322
Wink Savilleb564aae2014-10-23 10:18:09 -07001323 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001325
1326 final long identity = Binder.clearCallingIdentity();
1327 try {
1328 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1329 checkSimPin.start();
1330 return checkSimPin.unlockSim(null, pin);
1331 } finally {
1332 Binder.restoreCallingIdentity(identity);
1333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 }
1335
Wink Saville9de0f752013-10-22 19:04:03 -07001336 /** {@hide} */
1337 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001338 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001339 }
1340
Wink Savilleb564aae2014-10-23 10:18:09 -07001341 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001343
1344 final long identity = Binder.clearCallingIdentity();
1345 try {
1346 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1347 checkSimPuk.start();
1348 return checkSimPuk.unlockSim(puk, pin);
1349 } finally {
1350 Binder.restoreCallingIdentity(identity);
1351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001352 }
1353
1354 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001355 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 * a synchronous one.
1357 */
1358 private static class UnlockSim extends Thread {
1359
1360 private final IccCard mSimCard;
1361
1362 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001363 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1364 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365
1366 // For replies from SimCard interface
1367 private Handler mHandler;
1368
1369 // For async handler to identify request type
1370 private static final int SUPPLY_PIN_COMPLETE = 100;
1371
1372 public UnlockSim(IccCard simCard) {
1373 mSimCard = simCard;
1374 }
1375
1376 @Override
1377 public void run() {
1378 Looper.prepare();
1379 synchronized (UnlockSim.this) {
1380 mHandler = new Handler() {
1381 @Override
1382 public void handleMessage(Message msg) {
1383 AsyncResult ar = (AsyncResult) msg.obj;
1384 switch (msg.what) {
1385 case SUPPLY_PIN_COMPLETE:
1386 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1387 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001388 mRetryCount = msg.arg1;
1389 if (ar.exception != null) {
1390 if (ar.exception instanceof CommandException &&
1391 ((CommandException)(ar.exception)).getCommandError()
1392 == CommandException.Error.PASSWORD_INCORRECT) {
1393 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1394 } else {
1395 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1396 }
1397 } else {
1398 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 mDone = true;
1401 UnlockSim.this.notifyAll();
1402 }
1403 break;
1404 }
1405 }
1406 };
1407 UnlockSim.this.notifyAll();
1408 }
1409 Looper.loop();
1410 }
1411
1412 /*
1413 * Use PIN or PUK to unlock SIM card
1414 *
1415 * If PUK is null, unlock SIM card with PIN
1416 *
1417 * If PUK is not null, unlock SIM card with PUK and set PIN code
1418 */
Wink Saville9de0f752013-10-22 19:04:03 -07001419 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420
1421 while (mHandler == null) {
1422 try {
1423 wait();
1424 } catch (InterruptedException e) {
1425 Thread.currentThread().interrupt();
1426 }
1427 }
1428 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1429
1430 if (puk == null) {
1431 mSimCard.supplyPin(pin, callback);
1432 } else {
1433 mSimCard.supplyPuk(puk, pin, callback);
1434 }
1435
1436 while (!mDone) {
1437 try {
1438 Log.d(LOG_TAG, "wait for done");
1439 wait();
1440 } catch (InterruptedException e) {
1441 // Restore the interrupted status
1442 Thread.currentThread().interrupt();
1443 }
1444 }
1445 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001446 int[] resultArray = new int[2];
1447 resultArray[0] = mResult;
1448 resultArray[1] = mRetryCount;
1449 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 }
1451 }
1452
1453 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001455
1456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 // No permission check needed here: this call is harmless, and it's
1460 // needed for the ServiceState.requestStateUpdate() call (which is
1461 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001462 final long identity = Binder.clearCallingIdentity();
1463 try {
1464 final Phone phone = getPhone(subId);
1465 if (phone != null) {
1466 phone.updateServiceLocation();
1467 }
1468 } finally {
1469 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 }
1472
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001473 @Override
1474 public boolean isRadioOn(String callingPackage) {
1475 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001476 }
1477
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001478 @Override
1479 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001481 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001482 return false;
1483 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001484
1485 final long identity = Binder.clearCallingIdentity();
1486 try {
1487 return isRadioOnForSubscriber(subId);
1488 } finally {
1489 Binder.restoreCallingIdentity(identity);
1490 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001491 }
1492
1493 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001494 final long identity = Binder.clearCallingIdentity();
1495 try {
1496 final Phone phone = getPhone(subId);
1497 if (phone != null) {
1498 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1499 } else {
1500 return false;
1501 }
1502 } finally {
1503 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 }
1506
1507 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001508 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 }
Wink Saville36469e72014-06-11 15:17:00 -07001510
Wink Savilleb564aae2014-10-23 10:18:09 -07001511 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001513
1514 final long identity = Binder.clearCallingIdentity();
1515 try {
1516 final Phone phone = getPhone(subId);
1517 if (phone != null) {
1518 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1519 }
1520 } finally {
1521 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001522 }
Wink Saville36469e72014-06-11 15:17:00 -07001523 }
1524
1525 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001526 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001527 }
1528
Wink Savilleb564aae2014-10-23 10:18:09 -07001529 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001530 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001531
1532 final long identity = Binder.clearCallingIdentity();
1533 try {
1534 final Phone phone = getPhone(subId);
1535 if (phone == null) {
1536 return false;
1537 }
1538 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1539 toggleRadioOnOffForSubscriber(subId);
1540 }
1541 return true;
1542 } finally {
1543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 }
Wink Saville36469e72014-06-11 15:17:00 -07001546
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001547 public boolean needMobileRadioShutdown() {
1548 /*
1549 * If any of the Radios are available, it will need to be
1550 * shutdown. So return true if any Radio is available.
1551 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001552 final long identity = Binder.clearCallingIdentity();
1553 try {
1554 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1555 Phone phone = PhoneFactory.getPhone(i);
1556 if (phone != null && phone.isRadioAvailable()) return true;
1557 }
1558 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1559 return false;
1560 } finally {
1561 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001562 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001563 }
1564
Malcolm Chenaabec062018-02-28 15:00:40 -08001565 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001566 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001567 enforceModifyPermission();
1568
1569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1572 logv("Shutting down Phone " + i);
1573 shutdownRadioUsingPhoneId(i);
1574 }
1575 } finally {
1576 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001577 }
1578 }
1579
1580 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001581 Phone phone = PhoneFactory.getPhone(phoneId);
1582 if (phone != null && phone.isRadioAvailable()) {
1583 phone.shutdownRadio();
1584 }
1585 }
1586
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001588 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001589
1590 final long identity = Binder.clearCallingIdentity();
1591 try {
1592 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1593 if (defaultPhone != null) {
1594 defaultPhone.setRadioPower(turnOn);
1595 return true;
1596 } else {
1597 loge("There's no default phone.");
1598 return false;
1599 }
1600 } finally {
1601 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001602 }
Wink Saville36469e72014-06-11 15:17:00 -07001603 }
1604
Wink Savilleb564aae2014-10-23 10:18:09 -07001605 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001607
1608 final long identity = Binder.clearCallingIdentity();
1609 try {
1610 final Phone phone = getPhone(subId);
1611 if (phone != null) {
1612 phone.setRadioPower(turnOn);
1613 return true;
1614 } else {
1615 return false;
1616 }
1617 } finally {
1618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Wink Saville36469e72014-06-11 15:17:00 -07001622 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 public boolean enableDataConnectivity() {
1625 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001626
1627 final long identity = Binder.clearCallingIdentity();
1628 try {
1629 int subId = mSubscriptionController.getDefaultDataSubId();
1630 final Phone phone = getPhone(subId);
1631 if (phone != null) {
1632 phone.setUserDataEnabled(true);
1633 return true;
1634 } else {
1635 return false;
1636 }
1637 } finally {
1638 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 }
1641
Wink Saville36469e72014-06-11 15:17:00 -07001642 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001643 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 public boolean disableDataConnectivity() {
1645 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001646
1647 final long identity = Binder.clearCallingIdentity();
1648 try {
1649 int subId = mSubscriptionController.getDefaultDataSubId();
1650 final Phone phone = getPhone(subId);
1651 if (phone != null) {
1652 phone.setUserDataEnabled(false);
1653 return true;
1654 } else {
1655 return false;
1656 }
1657 } finally {
1658 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 }
1661
Sanket Padawe356d7632015-06-22 14:03:32 -07001662 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001663 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 final Phone phone = getPhone(subId);
1667 if (phone != null) {
1668 return phone.isDataAllowed();
1669 } else {
1670 return false;
1671 }
1672 } finally {
1673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 }
1676
1677 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001678 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001679 }
1680
pkanwarae03a6b2016-11-06 20:37:09 -08001681 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001682 enforceCallPermission();
1683
1684 final long identity = Binder.clearCallingIdentity();
1685 try {
1686 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1687 return;
1688 }
1689 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1690 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
1693 }
pkanwar32d516d2016-10-14 19:37:38 -07001694 };
1695
Wink Savilleb564aae2014-10-23 10:18:09 -07001696 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001698
1699 final long identity = Binder.clearCallingIdentity();
1700 try {
1701 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1702 return false;
1703 }
1704 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 }
1709
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001711 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001712 }
1713
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001714 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 Phone phone = PhoneFactory.getPhone(slotIndex);
1718 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1719 PhoneConstantConversions.convertCallState(phone.getState());
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
1722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 }
1724
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001727 final long identity = Binder.clearCallingIdentity();
1728 try {
1729 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1730 if (phone != null) {
1731 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1732 } else {
1733 return PhoneConstantConversions.convertDataState(
1734 PhoneConstants.DataState.DISCONNECTED);
1735 }
1736 } finally {
1737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 }
1740
Sanket Padawe356d7632015-06-22 14:03:32 -07001741 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1746 if (phone != null) {
1747 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1748 } else {
1749 return TelephonyManager.DATA_ACTIVITY_NONE;
1750 }
1751 } finally {
1752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 }
1755
1756 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001757 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001758 mPhone.getContext().getSystemService(AppOpsManager.class)
1759 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001760 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001761 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001762 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
1764
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001765 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001766 final long identity = Binder.clearCallingIdentity();
1767 try {
1768 if (DBG_LOC) log("getCellLocation: is active user");
1769 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001770 int subId = mSubscriptionController.getDefaultDataSubId();
1771 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1772 cl.fillInNotifierBundle(data);
Malcolm Chenaabec062018-02-28 15:00:40 -08001773 return data;
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
1776 }
Svetoslav64fad262015-04-14 14:35:21 -07001777 }
1778
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001780 public String getNetworkCountryIsoForPhone(int phoneId) {
1781 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1782 // registered cell info, so return a NULL country instead.
1783 final long identity = Binder.clearCallingIdentity();
1784 try {
1785 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001786 // Todo: fix this when we can get the actual cellular network info when the device
1787 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001788 if (TelephonyManager.NETWORK_TYPE_IWLAN
1789 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1790 return "";
1791 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001792 Phone phone = PhoneFactory.getPhone(phoneId);
1793 if (phone != null) {
1794 ServiceStateTracker sst = phone.getServiceStateTracker();
1795 if (sst != null) {
1796 LocaleTracker lt = sst.getLocaleTracker();
1797 if (lt != null) {
1798 return lt.getCurrentCountry();
1799 }
1800 }
1801 }
1802 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001803 } finally {
1804 Binder.restoreCallingIdentity(identity);
1805 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001806 }
1807
1808 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001810 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001811 }
1812
Sanket Padawe356d7632015-06-22 14:03:32 -07001813 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001814 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 mApp.enforceCallingOrSelfPermission(
1816 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001817
1818 final long identity = Binder.clearCallingIdentity();
1819 try {
1820 final Phone phone = getPhone(subId);
1821 if (phone != null) {
1822 phone.enableLocationUpdates();
1823 }
1824 } finally {
1825 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 }
1828
1829 @Override
1830 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001831 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001832 }
1833
Sanket Padawe356d7632015-06-22 14:03:32 -07001834 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001835 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 mApp.enforceCallingOrSelfPermission(
1837 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001838
1839 final long identity = Binder.clearCallingIdentity();
1840 try {
1841 final Phone phone = getPhone(subId);
1842 if (phone != null) {
1843 phone.disableLocationUpdates();
1844 }
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
Nathan Harold31d7ff32018-10-15 20:20:30 -07001850 /**
1851 * Returns the target SDK version number for a given package name.
1852 *
1853 * @return target SDK if the package is found or INT_MAX.
1854 */
1855 private int getTargetSdk(String packageName) {
1856 try {
1857 final ApplicationInfo ai =
1858 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1859 if (ai != null) return ai.targetSdkVersion;
1860 } catch (PackageManager.NameNotFoundException unexpected) {
1861 }
1862 return Integer.MAX_VALUE;
1863 }
1864
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001865 @Override
1866 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001867 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1868 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001869 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1870 throw new SecurityException(
1871 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1872 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001873
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1875 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1876 return null;
1877 }
Svetoslav64fad262015-04-14 14:35:21 -07001878
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001879 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880
Nathan Haroldf180aac2018-06-01 18:43:55 -07001881 List<CellInfo> info = getAllCellInfo(callingPackage);
1882 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883
Nathan Haroldf180aac2018-06-01 18:43:55 -07001884 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1885 for (CellInfo ci : info) {
1886 if (ci instanceof CellInfoGsm) {
1887 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1888 } else if (ci instanceof CellInfoWcdma) {
1889 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001892 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 }
1894
1895
1896 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001897 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001898 mPhone.getContext().getSystemService(AppOpsManager.class)
1899 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001900 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001901 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001902 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001905 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001906 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001907 final long identity = Binder.clearCallingIdentity();
1908 try {
1909 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1910 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001911 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001912 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08001913 if (info != null) cellInfos.addAll(info);
1914 }
1915 return cellInfos;
1916 } finally {
1917 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 }
1919 }
1920
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001921 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001923 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001924 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001925
1926 final long identity = Binder.clearCallingIdentity();
1927 try {
1928 mPhone.setCellInfoListRate(rateInMillis, workSource);
1929 } finally {
1930 Binder.restoreCallingIdentity(identity);
1931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932 }
1933
Shishir Agrawala9f32182016-04-12 12:00:16 -07001934 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001935 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001936 Phone phone = PhoneFactory.getPhone(slotIndex);
1937 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001938 return null;
1939 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001940 int subId = phone.getSubId();
1941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1942 mApp, subId, callingPackage, "getImeiForSlot")) {
1943 return null;
1944 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001945
1946 final long identity = Binder.clearCallingIdentity();
1947 try {
1948 return phone.getImei();
1949 } finally {
1950 Binder.restoreCallingIdentity(identity);
1951 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001952 }
1953
1954 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001955 public String getTypeAllocationCodeForSlot(int slotIndex) {
1956 Phone phone = PhoneFactory.getPhone(slotIndex);
1957 String tac = null;
1958 if (phone != null) {
1959 String imei = phone.getImei();
1960 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1961 }
1962 return tac;
1963 }
1964
1965 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001966 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001967 Phone phone = PhoneFactory.getPhone(slotIndex);
1968 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001969 return null;
1970 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001971 int subId = phone.getSubId();
1972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1973 mApp, subId, callingPackage, "getMeidForSlot")) {
1974 return null;
1975 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001976
1977 final long identity = Binder.clearCallingIdentity();
1978 try {
1979 return phone.getMeid();
1980 } finally {
1981 Binder.restoreCallingIdentity(identity);
1982 }
Jack Yu2af8d712017-03-15 17:14:14 -07001983 }
1984
1985 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001986 public String getManufacturerCodeForSlot(int slotIndex) {
1987 Phone phone = PhoneFactory.getPhone(slotIndex);
1988 String manufacturerCode = null;
1989 if (phone != null) {
1990 String meid = phone.getMeid();
1991 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1992 }
1993 return manufacturerCode;
1994 }
1995
1996 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001997 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001998 Phone phone = PhoneFactory.getPhone(slotIndex);
1999 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002000 return null;
2001 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002002 int subId = phone.getSubId();
2003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2004 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2005 return null;
2006 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002007
2008 final long identity = Binder.clearCallingIdentity();
2009 try {
2010 return phone.getDeviceSvn();
2011 } finally {
2012 Binder.restoreCallingIdentity(identity);
2013 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002014 }
2015
fionaxu43304da2017-11-27 22:51:16 -08002016 @Override
2017 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002018 final long identity = Binder.clearCallingIdentity();
2019 try {
2020 final Phone phone = getPhone(subId);
2021 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2022 } finally {
2023 Binder.restoreCallingIdentity(identity);
2024 }
fionaxu43304da2017-11-27 22:51:16 -08002025 }
2026
2027 @Override
2028 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002029 final long identity = Binder.clearCallingIdentity();
2030 try {
2031 final Phone phone = getPhone(subId);
2032 return phone == null ? null : phone.getCarrierName();
2033 } finally {
2034 Binder.restoreCallingIdentity(identity);
2035 }
fionaxu43304da2017-11-27 22:51:16 -08002036 }
2037
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 //
2039 // Internal helper methods.
2040 //
2041
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002042 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2044 *
2045 * @throws SecurityException if the caller does not have the required permission
2046 */
2047 private void enforceModifyPermission() {
2048 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2049 }
2050
2051 /**
2052 * Make sure the caller has the CALL_PHONE permission.
2053 *
2054 * @throws SecurityException if the caller does not have the required permission
2055 */
2056 private void enforceCallPermission() {
2057 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2058 }
2059
Stuart Scott8eef64f2015-04-08 15:13:54 -07002060 private void enforceConnectivityInternalPermission() {
2061 mApp.enforceCallingOrSelfPermission(
2062 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2063 "ConnectivityService");
2064 }
2065
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 private String createTelUrl(String number) {
2067 if (TextUtils.isEmpty(number)) {
2068 return null;
2069 }
2070
Jake Hambye994d462014-02-03 13:10:13 -08002071 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 }
2073
Ihab Awadf9e92732013-12-05 18:02:52 -08002074 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2076 }
2077
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002078 private static void logv(String msg) {
2079 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2080 }
2081
Ihab Awadf9e92732013-12-05 18:02:52 -08002082 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2084 }
2085
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002086 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002088 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002089 }
2090
Sanket Padawe356d7632015-06-22 14:03:32 -07002091 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002092 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002093 final long identity = Binder.clearCallingIdentity();
2094 try {
2095 final Phone phone = PhoneFactory.getPhone(slotIndex);
2096 if (phone == null) {
2097 return PhoneConstants.PHONE_TYPE_NONE;
2098 } else {
2099 return phone.getPhoneType();
2100 }
2101 } finally {
2102 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 }
2105
2106 /**
2107 * Returns the CDMA ERI icon index to display
2108 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002109 @Override
2110 public int getCdmaEriIconIndex(String callingPackage) {
2111 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002112 }
2113
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002115 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002117 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002118 return -1;
2119 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002120
2121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 final Phone phone = getPhone(subId);
2124 if (phone != null) {
2125 return phone.getCdmaEriIconIndex();
2126 } else {
2127 return -1;
2128 }
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
2133
2134 /**
2135 * Returns the CDMA ERI icon mode,
2136 * 0 - ON
2137 * 1 - FLASHING
2138 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002139 @Override
2140 public int getCdmaEriIconMode(String callingPackage) {
2141 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002142 }
2143
Sanket Padawe356d7632015-06-22 14:03:32 -07002144 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002145 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002146 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002147 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002148 return -1;
2149 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002150
2151 final long identity = Binder.clearCallingIdentity();
2152 try {
2153 final Phone phone = getPhone(subId);
2154 if (phone != null) {
2155 return phone.getCdmaEriIconMode();
2156 } else {
2157 return -1;
2158 }
2159 } finally {
2160 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 }
2163
2164 /**
2165 * Returns the CDMA ERI text,
2166 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002167 @Override
2168 public String getCdmaEriText(String callingPackage) {
2169 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002170 }
2171
Sanket Padawe356d7632015-06-22 14:03:32 -07002172 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002173 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002175 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002176 return null;
2177 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002178
2179 final long identity = Binder.clearCallingIdentity();
2180 try {
2181 final Phone phone = getPhone(subId);
2182 if (phone != null) {
2183 return phone.getCdmaEriText();
2184 } else {
2185 return null;
2186 }
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 }
2191
2192 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002193 * Returns the CDMA MDN.
2194 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002195 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002196 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2198 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002199
2200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 final Phone phone = getPhone(subId);
2203 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2204 return phone.getLine1Number();
2205 } else {
2206 return null;
2207 }
2208 } finally {
2209 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002210 }
2211 }
2212
2213 /**
2214 * Returns the CDMA MIN.
2215 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002217 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2219 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002220
2221 final long identity = Binder.clearCallingIdentity();
2222 try {
2223 final Phone phone = getPhone(subId);
2224 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2225 return phone.getCdmaMin();
2226 } else {
2227 return null;
2228 }
2229 } finally {
2230 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002231 }
2232 }
2233
2234 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 * Returns true if CDMA provisioning needs to run.
2236 */
2237 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002238 final long identity = Binder.clearCallingIdentity();
2239 try {
2240 return mPhone.needsOtaServiceProvisioning();
2241 } finally {
2242 Binder.restoreCallingIdentity(identity);
2243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 }
2245
2246 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002247 * Sets the voice mail number of a given subId.
2248 */
2249 @Override
2250 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002251 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002252
2253 final long identity = Binder.clearCallingIdentity();
2254 try {
2255 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2256 new Pair<String, String>(alphaTag, number), new Integer(subId));
2257 return success;
2258 } finally {
2259 Binder.restoreCallingIdentity(identity);
2260 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002261 }
2262
Ta-wei Yen87c49842016-05-13 21:19:52 -07002263 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002264 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2265 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2266 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2267 if (!TextUtils.equals(callingPackage, systemDialer)) {
2268 throw new SecurityException("caller must be system dialer");
2269 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002270
2271 final long identity = Binder.clearCallingIdentity();
2272 try {
2273 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2274 if (phoneAccountHandle == null) {
2275 return null;
2276 }
2277 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002280 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002281 }
2282
2283 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002284 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002285 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002287 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002288 return null;
2289 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002290
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002291 final long identity = Binder.clearCallingIdentity();
2292 try {
2293 return RemoteVvmTaskManager
2294 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2295 } finally {
2296 Binder.restoreCallingIdentity(identity);
2297 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002298 }
2299
2300 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002301 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2302 VisualVoicemailSmsFilterSettings settings) {
2303 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002304
2305 final long identity = Binder.clearCallingIdentity();
2306 try {
2307 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2308 mPhone.getContext(), callingPackage, subId, settings);
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
2311 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002312 }
2313
2314 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002315 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002317
2318 final long identity = Binder.clearCallingIdentity();
2319 try {
2320 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2321 mPhone.getContext(), callingPackage, subId);
2322 } finally {
2323 Binder.restoreCallingIdentity(identity);
2324 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002325 }
2326
2327 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002328 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2329 String callingPackage, int subId) {
2330 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002331
2332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2335 mPhone.getContext(), callingPackage, subId);
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
2338 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002339 }
2340
2341 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002342 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002343 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2348 mPhone.getContext(), subId);
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
2351 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002352 }
2353
2354 @Override
2355 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2356 String number, int port, String text, PendingIntent sentIntent) {
2357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002358 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002359 enforceSendSmsPermission();
2360 // Make the calls as the phone process.
2361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2364 if (port == 0) {
2365 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2366 sentIntent, null, false);
2367 } else {
2368 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2369 smsManager.sendDataMessageWithSelfPermissions(number, null,
2370 (short) port, data, sentIntent, null);
2371 }
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
2374 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002375 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002376 /**
fionaxu0152e512016-11-14 13:36:14 -08002377 * Sets the voice activation state of a given subId.
2378 */
2379 @Override
2380 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2382 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002383
2384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 final Phone phone = getPhone(subId);
2387 if (phone != null) {
2388 phone.setVoiceActivationState(activationState);
2389 } else {
2390 loge("setVoiceActivationState fails with invalid subId: " + subId);
2391 }
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002394 }
2395 }
2396
2397 /**
2398 * Sets the data activation state of a given subId.
2399 */
2400 @Override
2401 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2403 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002404
2405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 final Phone phone = getPhone(subId);
2408 if (phone != null) {
2409 phone.setDataActivationState(activationState);
2410 } else {
2411 loge("setVoiceActivationState fails with invalid subId: " + subId);
2412 }
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002415 }
2416 }
2417
2418 /**
2419 * Returns the voice activation state of a given subId.
2420 */
2421 @Override
2422 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002423 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002424
fionaxu0152e512016-11-14 13:36:14 -08002425 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 if (phone != null) {
2429 return phone.getVoiceActivationState();
2430 } else {
2431 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2432 }
2433 } finally {
2434 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002435 }
2436 }
2437
2438 /**
2439 * Returns the data activation state of a given subId.
2440 */
2441 @Override
2442 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002443 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002444
fionaxu0152e512016-11-14 13:36:14 -08002445 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 if (phone != null) {
2449 return phone.getDataActivationState();
2450 } else {
2451 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2452 }
2453 } finally {
2454 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002455 }
2456 }
2457
2458 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 * Returns the unread count of voicemails
2460 */
2461 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002462 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002463 }
2464
2465 /**
2466 * Returns the unread count of voicemails for a subId
2467 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002468 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002469 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 final Phone phone = getPhone(subId);
2473 if (phone != null) {
2474 return phone.getVoiceMessageCount();
2475 } else {
2476 return 0;
2477 }
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 }
2482
2483 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002484 * returns true, if the device is in a state where both voice and data
2485 * are supported simultaneously. This can change based on location or network condition.
2486 */
2487 @Override
2488 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = getPhone(subId);
2492 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
2495 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002496 }
2497
2498 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002499 * Send the dialer code if called from the current default dialer or the caller has
2500 * carrier privilege.
2501 * @param inputCode The dialer code to send
2502 */
2503 @Override
2504 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2505 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2506 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2507 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002508 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2509 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002510 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 mPhone.sendDialerSpecialCode(inputCode);
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
fionaxu235cc5e2017-03-06 22:25:57 -08002518 }
2519
2520 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002521 * Returns the data network type.
2522 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 *
2524 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2525 */
2526 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002527 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 final Phone phone = getPhone(getDefaultSubscription());
2531 if (phone != null) {
2532 return phone.getServiceState().getDataNetworkType();
2533 } else {
2534 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2535 }
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002538 }
Wink Saville36469e72014-06-11 15:17:00 -07002539 }
2540
Pengquan Meng0c05b502018-09-06 09:59:22 -07002541 @Override
2542 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002543 if (!isActiveSubscription(subId)) {
2544 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2545 }
2546
Pengquan Meng0c05b502018-09-06 09:59:22 -07002547 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2548 }
2549
Wink Saville36469e72014-06-11 15:17:00 -07002550 /**
2551 * Returns the network type for a subId
2552 */
2553 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002554 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002556 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002557 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2558 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002559
Malcolm Chenaabec062018-02-28 15:00:40 -08002560 final long identity = Binder.clearCallingIdentity();
2561 try {
2562 final Phone phone = getPhone(subId);
2563 if (phone != null) {
2564 return phone.getServiceState().getDataNetworkType();
2565 } else {
2566 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2567 }
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 }
2572
2573 /**
2574 * Returns the data network type
2575 */
2576 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002577 public int getDataNetworkType(String callingPackage) {
2578 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002579 }
2580
2581 /**
2582 * Returns the data network type for a subId
2583 */
2584 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002585 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002587 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002588 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2589 }
2590
Malcolm Chenaabec062018-02-28 15:00:40 -08002591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 final Phone phone = getPhone(subId);
2594 if (phone != null) {
2595 return phone.getServiceState().getDataNetworkType();
2596 } else {
2597 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2598 }
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 }
2603
2604 /**
Wink Saville36469e72014-06-11 15:17:00 -07002605 * Returns the Voice network type for a subId
2606 */
2607 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002608 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002610 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002611 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2612 }
2613
Malcolm Chenaabec062018-02-28 15:00:40 -08002614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 final Phone phone = getPhone(subId);
2617 if (phone != null) {
2618 return phone.getServiceState().getVoiceNetworkType();
2619 } else {
2620 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626
2627 /**
2628 * @return true if a ICC card is present
2629 */
2630 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002631 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002632 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2633 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002634 }
2635
2636 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002637 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002638 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002639 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002640 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 final Phone phone = PhoneFactory.getPhone(slotIndex);
2644 if (phone != null) {
2645 return phone.getIccCard().hasIccCard();
2646 } else {
2647 return false;
2648 }
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 }
2653
2654 /**
2655 * Return if the current radio is LTE on CDMA. This
2656 * is a tri-state return value as for a period of time
2657 * the mode may be unknown.
2658 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002659 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002661 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002663 @Override
2664 public int getLteOnCdmaMode(String callingPackage) {
2665 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002666 }
2667
Sanket Padawe356d7632015-06-22 14:03:32 -07002668 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002669 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002671 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002672 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2673 }
2674
Malcolm Chenaabec062018-02-28 15:00:40 -08002675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 final Phone phone = getPhone(subId);
2678 if (phone == null) {
2679 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2680 } else {
2681 return phone.getLteOnCdmaMode();
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002685 }
Wink Saville36469e72014-06-11 15:17:00 -07002686 }
2687
2688 public void setPhone(Phone phone) {
2689 mPhone = phone;
2690 }
2691
2692 /**
2693 * {@hide}
2694 * Returns Default subId, 0 in the case of single standby.
2695 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002696 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002697 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002698 }
2699
Shishir Agrawala9f32182016-04-12 12:00:16 -07002700 private int getSlotForDefaultSubscription() {
2701 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2702 }
2703
Wink Savilleb564aae2014-10-23 10:18:09 -07002704 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002705 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002707
Pengquan Meng466e2482018-09-21 15:54:48 -07002708 private boolean isActiveSubscription(int subId) {
2709 return mSubscriptionController.isActiveSubId(subId);
2710 }
2711
Ihab Awadf2177b72013-11-25 13:33:23 -08002712 /**
2713 * @see android.telephony.TelephonyManager.WifiCallingChoices
2714 */
2715 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2719 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2720 getWhenToMakeWifiCallsDefaultPreference());
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
2723 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002724 }
2725
2726 /**
2727 * @see android.telephony.TelephonyManager.WifiCallingChoices
2728 */
2729 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2733 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2734 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
2737 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002738 }
2739
Sailesh Nepald1e68152013-12-12 19:08:02 -08002740 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002741 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002742 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002743 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002744
Shishir Agrawal566b7612013-10-28 14:41:00 -07002745 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002746 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2747 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2749 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002751
Malcolm Chenaabec062018-02-28 15:00:40 -08002752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 if (TextUtils.equals(ISDR_AID, aid)) {
2755 // Only allows LPA to open logical channel to ISD-R.
2756 ComponentInfo bestComponent =
2757 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2758 if (bestComponent == null
2759 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2760 loge("The calling package is not allowed to access ISD-R.");
2761 throw new SecurityException(
2762 "The calling package is not allowed to access ISD-R.");
2763 }
Derek Tan740e1672017-06-27 14:56:27 -07002764 }
Derek Tan740e1672017-06-27 14:56:27 -07002765
Malcolm Chenaabec062018-02-28 15:00:40 -08002766 if (DBG) {
2767 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2768 }
2769 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2770 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2771 if (DBG) log("iccOpenLogicalChannel: " + response);
2772 return response;
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002776 }
2777
2778 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002779 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2781 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002782
Malcolm Chenaabec062018-02-28 15:00:40 -08002783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2786 if (channel < 0) {
2787 return false;
2788 }
2789 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2790 if (DBG) log("iccCloseLogicalChannel: " + success);
2791 return success;
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002794 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002795 }
2796
2797 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002798 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002799 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2801 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002802
Malcolm Chenaabec062018-02-28 15:00:40 -08002803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 if (DBG) {
2806 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2807 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2808 + p3 + " data=" + data);
2809 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002810
Malcolm Chenaabec062018-02-28 15:00:40 -08002811 if (channel < 0) {
2812 return "";
2813 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002814
Malcolm Chenaabec062018-02-28 15:00:40 -08002815 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2816 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2817 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002818
Malcolm Chenaabec062018-02-28 15:00:40 -08002819 // Append the returned status code to the end of the response payload.
2820 String s = Integer.toHexString(
2821 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2822 if (response.payload != null) {
2823 s = IccUtils.bytesToHexString(response.payload) + s;
2824 }
2825 return s;
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002828 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002829 }
Jake Hambye994d462014-02-03 13:10:13 -08002830
Evan Charltonc66da362014-05-16 14:06:40 -07002831 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002832 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2833 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2835 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002836 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002837
Malcolm Chenaabec062018-02-28 15:00:40 -08002838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2841 && TextUtils.equals(ISDR_AID, data)) {
2842 // Only allows LPA to select ISD-R.
2843 ComponentInfo bestComponent =
2844 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2845 if (bestComponent == null
2846 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2847 loge("The calling package is not allowed to select ISD-R.");
2848 throw new SecurityException(
2849 "The calling package is not allowed to select ISD-R.");
2850 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002851 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002852
Malcolm Chenaabec062018-02-28 15:00:40 -08002853 if (DBG) {
2854 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2855 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2856 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002857
Malcolm Chenaabec062018-02-28 15:00:40 -08002858 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2859 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2860 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002861
Malcolm Chenaabec062018-02-28 15:00:40 -08002862 // Append the returned status code to the end of the response payload.
2863 String s = Integer.toHexString(
2864 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2865 if (response.payload != null) {
2866 s = IccUtils.bytesToHexString(response.payload) + s;
2867 }
2868 return s;
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002871 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002872 }
2873
2874 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002875 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002876 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2878 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002879
Malcolm Chenaabec062018-02-28 15:00:40 -08002880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 if (DBG) {
2883 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2884 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2885 }
2886
2887 IccIoResult response =
2888 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2889 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2890 subId);
2891
2892 if (DBG) {
2893 log("Exchange SIM_IO [R]" + response);
2894 }
2895
2896 byte[] result = null;
2897 int length = 2;
2898 if (response.payload != null) {
2899 length = 2 + response.payload.length;
2900 result = new byte[length];
2901 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2902 } else {
2903 result = new byte[length];
2904 }
2905
2906 result[length - 1] = (byte) response.sw2;
2907 result[length - 2] = (byte) response.sw1;
2908 return result;
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002911 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002912 }
2913
Nathan Haroldb3014052017-01-25 15:57:32 -08002914 /**
2915 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2916 * on a particular subscription
2917 */
sqianb6e41952018-03-12 14:54:01 -07002918 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2920 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2921 return null;
2922 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002923 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2924 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2925 return null;
2926 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002927
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2931 if (response instanceof String[]) {
2932 return (String[]) response;
2933 }
2934 // Response is an Exception of some kind,
2935 // which is signalled to the user as a NULL retval
2936 return null;
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002939 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002940 }
2941
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002942 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002943 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2945 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002946
Malcolm Chenaabec062018-02-28 15:00:40 -08002947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2950 if (response.payload == null) {
2951 return "";
2952 }
Evan Charltonc66da362014-05-16 14:06:40 -07002953
Malcolm Chenaabec062018-02-28 15:00:40 -08002954 // Append the returned status code to the end of the response payload.
2955 String s = Integer.toHexString(
2956 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2957 s = IccUtils.bytesToHexString(response.payload) + s;
2958 return s;
2959 } finally {
2960 Binder.restoreCallingIdentity(identity);
2961 }
Evan Charltonc66da362014-05-16 14:06:40 -07002962 }
2963
Jake Hambye994d462014-02-03 13:10:13 -08002964 /**
2965 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2966 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2967 *
2968 * @param itemID the ID of the item to read
2969 * @return the NV item as a String, or null on error.
2970 */
2971 @Override
2972 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07002973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2975 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08002976
2977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07002980 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08002981 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2982 return value;
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Jake Hambye994d462014-02-03 13:10:13 -08002986 }
2987
2988 /**
2989 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2990 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2991 *
2992 * @param itemID the ID of the item to read
2993 * @param itemValue the value to write, as a String
2994 * @return true on success; false on any failure
2995 */
2996 @Override
2997 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07002998 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3000 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003001
3002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3005 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003006 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003007 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3008 return success;
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
Jake Hambye994d462014-02-03 13:10:13 -08003012 }
3013
3014 /**
3015 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3016 * Used for device configuration by some CDMA operators.
3017 *
3018 * @param preferredRoamingList byte array containing the new PRL
3019 * @return true on success; false on any failure
3020 */
3021 @Override
3022 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3024 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003025
3026 final long identity = Binder.clearCallingIdentity();
3027 try {
3028 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3029 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3030 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3031 return success;
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
Jake Hambye994d462014-02-03 13:10:13 -08003035 }
3036
3037 /**
3038 * Perform the specified type of NV config reset.
3039 * Used for device configuration by some CDMA operators.
3040 *
3041 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3042 * @return true on success; false on any failure
3043 */
3044 @Override
3045 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3047 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003048
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 if (DBG) log("nvResetConfig: type " + resetType);
3052 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3053 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3054 return success;
3055 } finally {
3056 Binder.restoreCallingIdentity(identity);
3057 }
Jake Hambye994d462014-02-03 13:10:13 -08003058 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003059
Svet Ganovb320e182015-04-16 12:30:10 -07003060 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003062 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003063 return new String[0];
3064 }
3065
Malcolm Chenaabec062018-02-28 15:00:40 -08003066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 return mPhone.getPcscfAddress(apnType);
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Wink Saville36469e72014-06-11 15:17:00 -07003072 }
3073
Brad Ebinger51f743a2017-01-23 13:50:20 -08003074 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003075 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3076 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003077 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003078 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003079 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003080
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 PhoneFactory.getImsResolver().enableIms(slotId);
3084 } finally {
3085 Binder.restoreCallingIdentity(identity);
3086 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003087 }
3088
3089 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003090 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3091 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003092 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003093 public void disableIms(int slotId) {
3094 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003095
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 PhoneFactory.getImsResolver().disableIms(slotId);
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003102 }
3103
3104 /**
3105 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3106 * feature or {@link null} if the service is not available. If the feature is available, the
3107 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3108 */
3109 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003110 IImsServiceFeatureCallback callback) {
3111 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003112
3113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003119 }
3120
3121 /**
3122 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3123 * feature during emergency calling or {@link null} if the service is not available. If the
3124 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3125 * listener for feature updates.
3126 */
3127 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3128 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003129
3130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003136 }
3137
Brad Ebinger5f64b052017-12-14 14:26:15 -08003138 /**
3139 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3140 * specified.
3141 */
3142 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3143 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003144
3145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003151 }
3152
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003153 /**
3154 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3155 * specified.
3156 */
3157 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3158 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003159
3160 final long identity = Binder.clearCallingIdentity();
3161 try {
3162 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003166 }
3167
Brad Ebinger884c07b2018-02-15 16:17:40 -08003168 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003169 * Sets the ImsService Package Name that Telephony will bind to.
3170 *
3171 * @param slotId the slot ID that the ImsService should bind for.
3172 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3173 * ImsService is the device default ImsService.
3174 * @param packageName The package name of the application that contains the ImsService to bind
3175 * to.
3176 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3177 * @hide
3178 */
3179 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003180 int[] subIds = SubscriptionManager.getSubId(slotId);
3181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3182 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3183 "setImsService");
3184
Malcolm Chenaabec062018-02-28 15:00:40 -08003185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3188 isCarrierImsService, packageName);
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003192 }
3193
3194 /**
3195 * Return the ImsService configuration.
3196 *
3197 * @param slotId The slot that the ImsService is associated with.
3198 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3199 * the device default.
3200 * @return the package name of the ImsService configuration.
3201 */
3202 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003203 int[] subIds = SubscriptionManager.getSubId(slotId);
3204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3205 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3206 "getImsService");
3207
Malcolm Chenaabec062018-02-28 15:00:40 -08003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3211 isCarrierImsService);
3212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003215 }
3216
Wink Saville36469e72014-06-11 15:17:00 -07003217 public void setImsRegistrationState(boolean registered) {
3218 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003219
3220 final long identity = Binder.clearCallingIdentity();
3221 try {
3222 mPhone.setImsRegistrationState(registered);
3223 } finally {
3224 Binder.restoreCallingIdentity(identity);
3225 }
Wink Saville36469e72014-06-11 15:17:00 -07003226 }
3227
3228 /**
Stuart Scott54788802015-03-30 13:18:01 -07003229 * Set the network selection mode to automatic.
3230 *
3231 */
3232 @Override
3233 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3235 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003236
Pengquan Meng466e2482018-09-21 15:54:48 -07003237 if (!isActiveSubscription(subId)) {
3238 return;
3239 }
3240
Malcolm Chenaabec062018-02-28 15:00:40 -08003241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3244 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
Stuart Scott54788802015-03-30 13:18:01 -07003248 }
3249
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003250 /**
3251 * Ask the radio to connect to the input network and change selection mode to manual.
3252 *
3253 * @param subId the id of the subscription.
3254 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3255 * the operator to attach to.
3256 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3257 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3258 * normal network selection next time.
3259 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003260 */
3261 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003262 public boolean setNetworkSelectionModeManual(
3263 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3265 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003266
3267 if (!isActiveSubscription(subId)) {
3268 return false;
3269 }
3270
Malcolm Chenaabec062018-02-28 15:00:40 -08003271 final long identity = Binder.clearCallingIdentity();
3272 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003273 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaabec062018-02-28 15:00:40 -08003274 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003275 if (DBG) {
3276 log("setNetworkSelectionModeManual: subId: " + subId
3277 + " operator: " + operatorInfo);
3278 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003279 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003283 }
3284
3285 /**
3286 * Scans for available networks.
3287 */
3288 @Override
3289 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003292
Pengquan Meng0c05b502018-09-06 09:59:22 -07003293 long identity = Binder.clearCallingIdentity();
Malcolm Chenaabec062018-02-28 15:00:40 -08003294 try {
3295 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003296 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaabec062018-02-28 15:00:40 -08003297 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08003298 } finally {
3299 Binder.restoreCallingIdentity(identity);
3300 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003301 }
3302
3303 /**
yinxub1bed742017-04-17 11:45:04 -07003304 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003305 *
yinxub1bed742017-04-17 11:45:04 -07003306 * @param subId id of the subscription
3307 * @param request contains the radio access networks with bands/channels to scan
3308 * @param messenger callback messenger for scan results or errors
3309 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003310 * @return the id of the requested scan which can be used to stop the scan.
3311 */
3312 @Override
3313 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3314 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3316 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003317
3318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 return mNetworkScanRequestTracker.startNetworkScan(
3321 request, messenger, binder, getPhone(subId));
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
yinxu504e1392017-04-12 16:03:22 -07003325 }
3326
3327 /**
3328 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003329 *
3330 * @param subId id of the subscription
3331 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003332 */
3333 @Override
3334 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3336 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003337
3338 final long identity = Binder.clearCallingIdentity();
3339 try {
3340 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
yinxu504e1392017-04-12 16:03:22 -07003344 }
3345
3346 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003347 * Get the calculated preferred network type.
3348 * Used for debugging incorrect network type.
3349 *
3350 * @return the preferred network type, defined in RILConstants.java.
3351 */
3352 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003353 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003354 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003355 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003356 return RILConstants.PREFERRED_NETWORK_MODE;
3357 }
3358
Malcolm Chenaabec062018-02-28 15:00:40 -08003359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 // FIXME: need to get SubId from somewhere.
3362 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
3365 }
Junda Liu84d15a22014-07-02 11:21:04 -07003366 }
3367
3368 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003369 * Get the preferred network type.
3370 * Used for device configuration by some CDMA operators.
3371 *
3372 * @return the preferred network type, defined in RILConstants.java.
3373 */
3374 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003375 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3377 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003378
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 if (DBG) log("getPreferredNetworkType");
3382 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3383 int networkType = (result != null ? result[0] : -1);
3384 if (DBG) log("getPreferredNetworkType: " + networkType);
3385 return networkType;
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003389 }
3390
3391 /**
3392 * Set the preferred network type.
3393 * Used for device configuration by some CDMA operators.
3394 *
3395 * @param networkType the preferred network type, defined in RILConstants.java.
3396 * @return true on success; false on any failure.
3397 */
3398 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003399 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3401 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003402
3403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3406 Boolean success = (Boolean) sendRequest(
3407 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3408 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3409 if (success) {
3410 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3411 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3412 }
3413 return success;
3414 } finally {
3415 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003416 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003417 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003418
3419 /**
Junda Liu475951f2014-11-07 16:45:03 -08003420 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3421 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3422 * tethering.
3423 *
3424 * @return 0: Not required. 1: required. 2: Not set.
3425 * @hide
3426 */
3427 @Override
3428 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003429 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003430
3431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3434 Settings.Global.TETHER_DUN_REQUIRED, 2);
3435 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3436 // config_tether_apndata.
3437 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3438 dunRequired = 1;
3439 }
3440 return dunRequired;
3441 } finally {
3442 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003443 }
Junda Liu475951f2014-11-07 16:45:03 -08003444 }
3445
3446 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003447 * Set mobile data enabled
3448 * Used by the user through settings etc to turn on/off mobile data
3449 *
3450 * @param enable {@code true} turn turn data on, else {@code false}
3451 */
3452 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003453 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3455 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003456
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 int phoneId = mSubscriptionController.getPhoneId(subId);
3460 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3461 Phone phone = PhoneFactory.getPhone(phoneId);
3462 if (phone != null) {
3463 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3464 phone.setUserDataEnabled(enable);
3465 } else {
3466 loge("setUserDataEnabled: no phone for subId=" + subId);
3467 }
3468 } finally {
3469 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003470 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003471 }
3472
3473 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003474 * Get the user enabled state of Mobile Data.
3475 *
3476 * TODO: remove and use isUserDataEnabled.
3477 * This can't be removed now because some vendor codes
3478 * calls through ITelephony directly while they should
3479 * use TelephonyManager.
3480 *
3481 * @return true on enabled
3482 */
3483 @Override
3484 public boolean getDataEnabled(int subId) {
3485 return isUserDataEnabled(subId);
3486 }
3487
3488 /**
3489 * Get whether mobile data is enabled per user setting.
3490 *
3491 * There are other factors deciding whether mobile data is actually enabled, but they are
3492 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003493 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003494 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003495 *
3496 * @return {@code true} if data is enabled else {@code false}
3497 */
3498 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003499 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003500 try {
3501 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3502 null);
3503 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3505 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003506 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003507
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 int phoneId = mSubscriptionController.getPhoneId(subId);
3511 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3512 Phone phone = PhoneFactory.getPhone(phoneId);
3513 if (phone != null) {
3514 boolean retVal = phone.isUserDataEnabled();
3515 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3516 return retVal;
3517 } else {
3518 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3519 return false;
3520 }
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003523 }
3524 }
3525
3526 /**
3527 * Get whether mobile data is enabled.
3528 *
3529 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3530 * whether mobile data is actually enabled.
3531 *
3532 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3533 *
3534 * @return {@code true} if data is enabled else {@code false}
3535 */
3536 @Override
3537 public boolean isDataEnabled(int subId) {
3538 try {
3539 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3540 null);
3541 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3543 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003544 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 int phoneId = mSubscriptionController.getPhoneId(subId);
3549 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3550 Phone phone = PhoneFactory.getPhone(phoneId);
3551 if (phone != null) {
3552 boolean retVal = phone.isDataEnabled();
3553 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3554 return retVal;
3555 } else {
3556 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3557 return false;
3558 }
3559 } finally {
3560 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003561 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003562 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003563
3564 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003565 public int getCarrierPrivilegeStatus(int subId) {
3566 final Phone phone = getPhone(subId);
3567 if (phone == null) {
3568 loge("getCarrierPrivilegeStatus: Invalid subId");
3569 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3570 }
3571 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003572 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003573 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003574 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3575 }
3576 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003577 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003578 }
Junda Liu29340342014-07-10 15:23:27 -07003579
3580 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003581 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3582 final Phone phone = getPhone(subId);
3583 if (phone == null) {
3584 loge("getCarrierPrivilegeStatus: Invalid subId");
3585 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3586 }
3587 UiccProfile profile =
3588 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3589 if (profile == null) {
3590 loge("getCarrierPrivilegeStatus: No UICC");
3591 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3592 }
3593 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3594 }
3595
3596 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003597 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003598 if (TextUtils.isEmpty(pkgName))
3599 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003600 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003601 if (card == null) {
3602 loge("checkCarrierPrivilegesForPackage: No UICC");
3603 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3604 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003605 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3606 }
3607
3608 @Override
3609 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003610 if (TextUtils.isEmpty(pkgName))
3611 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003612 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3613 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3614 UiccCard card = UiccController.getInstance().getUiccCard(i);
3615 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003616 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003617 continue;
3618 }
3619
3620 result = card.getCarrierPrivilegeStatus(
3621 mPhone.getContext().getPackageManager(), pkgName);
3622 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3623 break;
3624 }
3625 }
3626
3627 return result;
Junda Liu29340342014-07-10 15:23:27 -07003628 }
Derek Tan89e89d42014-07-08 17:00:10 -07003629
3630 @Override
Junda Liue64de782015-04-16 17:19:16 -07003631 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3632 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3633 loge("phoneId " + phoneId + " is not valid.");
3634 return null;
3635 }
3636 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003637 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003638 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003639 return null ;
3640 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003641 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003642 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003643 }
3644
Amith Yamasani6e118872016-02-19 12:53:51 -08003645 @Override
3646 public List<String> getPackagesWithCarrierPrivileges() {
3647 PackageManager pm = mPhone.getContext().getPackageManager();
3648 List<String> privilegedPackages = new ArrayList<>();
3649 List<PackageInfo> packages = null;
3650 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3651 UiccCard card = UiccController.getInstance().getUiccCard(i);
3652 if (card == null) {
3653 // No UICC in that slot.
3654 continue;
3655 }
3656 if (card.hasCarrierPrivilegeRules()) {
3657 if (packages == null) {
3658 // Only check packages in user 0 for now
3659 packages = pm.getInstalledPackagesAsUser(
3660 PackageManager.MATCH_DISABLED_COMPONENTS
3661 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3662 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3663 }
3664 for (int p = packages.size() - 1; p >= 0; p--) {
3665 PackageInfo pkgInfo = packages.get(p);
3666 if (pkgInfo != null && pkgInfo.packageName != null
3667 && card.getCarrierPrivilegeStatus(pkgInfo)
3668 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3669 privilegedPackages.add(pkgInfo.packageName);
3670 }
3671 }
3672 }
3673 }
3674 return privilegedPackages;
3675 }
3676
Wink Savilleb564aae2014-10-23 10:18:09 -07003677 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003678 final Phone phone = getPhone(subId);
3679 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003680 if (card == null) {
3681 loge("getIccId: No UICC");
3682 return null;
3683 }
3684 String iccId = card.getIccId();
3685 if (TextUtils.isEmpty(iccId)) {
3686 loge("getIccId: ICC ID is null or empty.");
3687 return null;
3688 }
3689 return iccId;
3690 }
3691
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003692 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003693 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3694 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003695 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3696 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003697
Malcolm Chenaabec062018-02-28 15:00:40 -08003698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 final String iccId = getIccId(subId);
3701 final Phone phone = getPhone(subId);
3702 if (phone == null) {
3703 return false;
3704 }
3705 final String subscriberId = phone.getSubscriberId();
3706
3707 if (DBG_MERGE) {
3708 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3709 + subscriberId + " to " + number);
3710 }
3711
3712 if (TextUtils.isEmpty(iccId)) {
3713 return false;
3714 }
3715
3716 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3717
3718 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3719 if (alphaTag == null) {
3720 editor.remove(alphaTagPrefKey);
3721 } else {
3722 editor.putString(alphaTagPrefKey, alphaTag);
3723 }
3724
3725 // Record both the line number and IMSI for this ICCID, since we need to
3726 // track all merged IMSIs based on line number
3727 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3728 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3729 if (number == null) {
3730 editor.remove(numberPrefKey);
3731 editor.remove(subscriberPrefKey);
3732 } else {
3733 editor.putString(numberPrefKey, number);
3734 editor.putString(subscriberPrefKey, subscriberId);
3735 }
3736
3737 editor.commit();
3738 return true;
3739 } finally {
3740 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003741 }
Derek Tan7226c842014-07-02 17:42:23 -07003742 }
3743
3744 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003745 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003746 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003748 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003749 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003750 return null;
3751 }
Derek Tan97ebb422014-09-05 16:55:38 -07003752
Malcolm Chenaabec062018-02-28 15:00:40 -08003753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 String iccId = getIccId(subId);
3756 if (iccId != null) {
3757 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3758 if (DBG_MERGE) {
3759 log("getLine1NumberForDisplay returning "
3760 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3761 }
3762 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003763 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003764 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3765 return null;
3766 } finally {
3767 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003768 }
Derek Tan7226c842014-07-02 17:42:23 -07003769 }
3770
3771 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003772 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003774 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003775 return null;
3776 }
Derek Tan97ebb422014-09-05 16:55:38 -07003777
Malcolm Chenaabec062018-02-28 15:00:40 -08003778 final long identity = Binder.clearCallingIdentity();
3779 try {
3780 String iccId = getIccId(subId);
3781 if (iccId != null) {
3782 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3783 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3784 }
3785 return null;
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003788 }
Derek Tan7226c842014-07-02 17:42:23 -07003789 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003790
3791 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003792 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003793 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3794 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003796 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3797 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003798 return null;
3799 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003800
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003801 final long identity = Binder.clearCallingIdentity();
3802 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003803 final Context context = mPhone.getContext();
3804 final TelephonyManager tele = TelephonyManager.from(context);
3805 final SubscriptionManager sub = SubscriptionManager.from(context);
3806
3807 // Figure out what subscribers are currently active
3808 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3809 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3810 // the process, where TelephonyManager was instantiated.
3811 // Otherwise AppOps check will fail.
3812
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003813 final int[] subIds = sub.getActiveSubscriptionIdList();
3814 for (int subId : subIds) {
3815 activeSubscriberIds.add(tele.getSubscriberId(subId));
3816 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003817
3818 // First pass, find a number override for an active subscriber
3819 String mergeNumber = null;
3820 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3821 for (String key : prefs.keySet()) {
3822 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3823 final String subscriberId = (String) prefs.get(key);
3824 if (activeSubscriberIds.contains(subscriberId)) {
3825 final String iccId = key.substring(
3826 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3827 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3828 mergeNumber = (String) prefs.get(numberKey);
3829 if (DBG_MERGE) {
3830 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3831 + " for active subscriber " + subscriberId);
3832 }
3833 if (!TextUtils.isEmpty(mergeNumber)) {
3834 break;
3835 }
3836 }
3837 }
3838 }
3839
3840 // Shortcut when no active merged subscribers
3841 if (TextUtils.isEmpty(mergeNumber)) {
3842 return null;
3843 }
3844
3845 // Second pass, find all subscribers under that line override
3846 final ArraySet<String> result = new ArraySet<>();
3847 for (String key : prefs.keySet()) {
3848 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3849 final String number = (String) prefs.get(key);
3850 if (mergeNumber.equals(number)) {
3851 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3852 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3853 final String subscriberId = (String) prefs.get(subscriberKey);
3854 if (!TextUtils.isEmpty(subscriberId)) {
3855 result.add(subscriberId);
3856 }
3857 }
3858 }
3859 }
3860
3861 final String[] resultArray = result.toArray(new String[result.size()]);
3862 Arrays.sort(resultArray);
3863 if (DBG_MERGE) {
3864 Slog.d(LOG_TAG,
3865 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3866 }
3867 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003868 } finally {
3869 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003870 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003871 }
3872
3873 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003874 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003875 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3876 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003877
3878 final long identity = Binder.clearCallingIdentity();
3879 try {
3880 final Phone phone = getPhone(subId);
3881 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
3884 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003885 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003886
3887 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003888 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003889 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3890 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003891 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003892
3893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 final Phone phone = getPhone(subId);
3896 if (phone == null) {
3897 return false;
3898 }
3899 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3900 cdmaNonRoamingList);
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003903 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003904 }
3905
3906 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003907 @Deprecated
3908 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3909 enforceModifyPermission();
3910
3911 int returnValue = 0;
3912 try {
vagdevie435a3e2018-08-15 16:01:53 -07003913 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003914 if(result.exception == null) {
3915 if (result.result != null) {
3916 byte[] responseData = (byte[])(result.result);
3917 if(responseData.length > oemResp.length) {
3918 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3919 responseData.length + "bytes. Buffer Size is " +
3920 oemResp.length + "bytes.");
3921 }
3922 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3923 returnValue = responseData.length;
3924 }
3925 } else {
3926 CommandException ex = (CommandException) result.exception;
3927 returnValue = ex.getCommandError().ordinal();
3928 if(returnValue > 0) returnValue *= -1;
3929 }
3930 } catch (RuntimeException e) {
3931 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3932 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3933 if(returnValue > 0) returnValue *= -1;
3934 }
3935
3936 return returnValue;
3937 }
3938
3939 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003940 public void setRadioCapability(RadioAccessFamily[] rafs) {
3941 try {
3942 ProxyController.getInstance().setRadioCapability(rafs);
3943 } catch (RuntimeException e) {
3944 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3945 }
3946 }
3947
3948 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003949 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003950 Phone phone = PhoneFactory.getPhone(phoneId);
3951 if (phone == null) {
3952 return RadioAccessFamily.RAF_UNKNOWN;
3953 }
3954 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003956 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003957 return RadioAccessFamily.RAF_UNKNOWN;
3958 }
3959
Malcolm Chenaabec062018-02-28 15:00:40 -08003960 final long identity = Binder.clearCallingIdentity();
3961 try {
3962 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003966 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003967
3968 @Override
3969 public void enableVideoCalling(boolean enable) {
3970 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003971
3972 final long identity = Binder.clearCallingIdentity();
3973 try {
3974 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
3975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003978 }
3979
3980 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003981 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3983 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3984 return false;
3985 }
Svet Ganovb320e182015-04-16 12:30:10 -07003986
Malcolm Chenaabec062018-02-28 15:00:40 -08003987 final long identity = Binder.clearCallingIdentity();
3988 try {
3989 // Check the user preference and the system-level IMS setting. Even if the user has
3990 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3991 // In the long run, we may instead need to check if there exists a connection service
3992 // which can support video calling.
3993 ImsManager imsManager =
3994 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3995 return imsManager.isVtEnabledByPlatform()
3996 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3997 && imsManager.isVtEnabledByUser();
3998 } finally {
3999 Binder.restoreCallingIdentity(identity);
4000 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004001 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004002
Andrew Leea1239f22015-03-02 17:44:07 -08004003 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004004 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4006 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4007 return false;
4008 }
4009
4010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 CarrierConfigManager configManager =
4013 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4014 return configManager.getConfigForSubId(mPhone.getSubId())
4015 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
4018 }
Andrew Leea1239f22015-03-02 17:44:07 -08004019 }
4020
4021 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004022 public boolean isWorldPhone(int subId, String callingPackage) {
4023 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4024 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4025 return false;
4026 }
4027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 CarrierConfigManager configManager =
4031 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4032 return configManager.getConfigForSubId(mPhone.getSubId())
4033 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
Andrew Leea1239f22015-03-02 17:44:07 -08004037 }
4038
Andrew Lee9431b832015-03-09 18:46:45 -07004039 @Override
4040 public boolean isTtyModeSupported() {
4041 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004042 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004043 }
4044
4045 @Override
4046 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
4052 }
Andrew Lee9431b832015-03-09 18:46:45 -07004053 }
4054
Hall Liu98187582018-01-22 19:15:32 -08004055 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4059 mPhone.getSubId()).getBoolean(
4060 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4061 boolean isDeviceSupported =
4062 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4063 return isCarrierSupported && isDeviceSupported;
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
4066 }
Hall Liu98187582018-01-22 19:15:32 -08004067 }
4068
Hall Liu3ad5f012018-04-06 16:23:39 -07004069 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 return isRttSupported() && Settings.Secure.getInt(
4073 mPhone.getContext().getContentResolver(),
4074 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004078 }
4079
Sanket Padawe7310cc72015-01-14 09:53:20 -08004080 /**
4081 * Returns the unique device ID of phone, for example, the IMEI for
4082 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4083 *
4084 * <p>Requires Permission:
4085 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4086 */
4087 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004088 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004089 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004090 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004091 return null;
4092 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004093 int subId = phone.getSubId();
4094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4095 mApp, subId, callingPackage, "getDeviceId")) {
4096 return null;
4097 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004098
4099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 return phone.getDeviceId();
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
4104 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004105 }
4106
Ping Sunc67b7c22016-03-02 19:16:45 +08004107 /**
4108 * {@hide}
4109 * Returns the IMS Registration Status on a particular subid
4110 *
4111 * @param subId
4112 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004113 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004114 Phone phone = getPhone(subId);
4115 if (phone != null) {
4116 return phone.isImsRegistered();
4117 } else {
4118 return false;
4119 }
4120 }
4121
Santos Cordon7a1885b2015-02-03 11:15:19 -08004122 @Override
4123 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004130 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004131
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004132 /**
4133 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004134 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004135 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 Phone phone = getPhone(subId);
4139 if (phone != null) {
4140 return phone.isWifiCallingEnabled();
4141 } else {
4142 return false;
4143 }
4144 } finally {
4145 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004146 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004147 }
4148
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004149 /**
4150 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004151 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004152 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 Phone phone = getPhone(subId);
4156 if (phone != null) {
4157 return phone.isVolteEnabled();
4158 } else {
4159 return false;
4160 }
4161 } finally {
4162 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004163 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004164 }
Svet Ganovb320e182015-04-16 12:30:10 -07004165
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004166 /**
4167 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004168 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004169 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004170 final long identity = Binder.clearCallingIdentity();
4171 try {
4172 Phone phone = getPhone(subId);
4173 if (phone != null) {
4174 return phone.isVideoEnabled();
4175 } else {
4176 return false;
4177 }
4178 } finally {
4179 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004180 }
4181 }
4182
4183 /**
4184 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4185 * defined in {@link ImsRegistrationImplBase}.
4186 */
4187 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 Phone phone = getPhone(subId);
4191 if (phone != null) {
4192 return phone.getImsRegistrationTech();
4193 } else {
4194 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4195 }
4196 } finally {
4197 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004198 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004199 }
4200
Stuart Scott8eef64f2015-04-08 15:13:54 -07004201 @Override
4202 public void factoryReset(int subId) {
4203 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004204 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4205 return;
4206 }
4207
Svet Ganovcc087f82015-05-12 20:35:54 -07004208 final long identity = Binder.clearCallingIdentity();
4209 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004210 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4211 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004212 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004213 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004214 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4215 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004216 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004217 }
4218 } finally {
4219 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004220 }
4221 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004222
4223 @Override
4224 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004225 final long identity = Binder.clearCallingIdentity();
4226 try {
4227 // We query all subscriptions instead of just the active ones, because
4228 // this might be called early on in the provisioning flow when the
4229 // subscriptions potentially aren't active yet.
4230 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4231 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004232 return null;
4233 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004234
Malcolm Chenaabec062018-02-28 15:00:40 -08004235 // This function may be called very early, say, from the setup wizard, at
4236 // which point we won't have a default subscription set. If that's the case
4237 // we just choose the first, which will be valid in "most cases".
4238 final int defaultSubId = getDefaultSubscription();
4239 SubscriptionInfo info = null;
4240 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4241 info = slist.get(0);
4242 } else {
4243 for (SubscriptionInfo item : slist) {
4244 if (item.getSubscriptionId() == defaultSubId) {
4245 info = item;
4246 break;
4247 }
4248 }
4249
4250 if (info == null) {
4251 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004252 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004253 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004254
Malcolm Chenaabec062018-02-28 15:00:40 -08004255 // Try and fetch the locale from the carrier properties or from the SIM language
4256 // preferences (EF-PL and EF-LI)...
4257 final int mcc = info.getMcc();
4258 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4259 String simLanguage = null;
4260 if (defaultPhone != null) {
4261 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4262 if (localeFromDefaultSim != null) {
4263 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4264 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4265 return localeFromDefaultSim.toLanguageTag();
4266 } else {
4267 simLanguage = localeFromDefaultSim.getLanguage();
4268 }
4269 }
4270 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004271
Malcolm Chenaabec062018-02-28 15:00:40 -08004272 // The SIM language preferences only store a language (e.g. fr = French), not an
4273 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4274 // the SIM and carrier preferences does not include a country we add the country
4275 // determined from the SIM MCC to provide an exact locale.
4276 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4277 simLanguage);
4278 if (mccLocale != null) {
4279 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4280 return mccLocale.toLanguageTag();
4281 }
4282
4283 if (DBG) log("No locale found - returning null");
4284 return null;
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
4287 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004288 }
4289
4290 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004291 return mSubscriptionController.getAllSubInfoList(
4292 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004293 }
4294
Malcolm Chenaabec062018-02-28 15:00:40 -08004295 /**
4296 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4297 */
4298 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4299 return mSubscriptionController.getActiveSubscriptionInfoList(
4300 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004301 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004302
Chenjie Yu1ba97252018-01-11 18:16:20 -08004303 private final ModemActivityInfo mLastModemActivityInfo =
4304 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4305
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004306 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004307 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4308 * representing the state of the modem.
4309 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004310 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4311 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004312 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004313 */
4314 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004315 public void requestModemActivityInfo(ResultReceiver result) {
4316 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004317 ModemActivityInfo ret = null;
vagdevie435a3e2018-08-15 16:01:53 -07004318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Adam Lesinski903a54c2016-04-11 14:49:52 -07004319
Malcolm Chenaabec062018-02-28 15:00:40 -08004320 final long identity = Binder.clearCallingIdentity();
4321 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004322 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004323 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4324 CMD_GET_MODEM_ACTIVITY_INFO,
4325 null, workSource);
Siddharth Rayc339f892018-06-17 15:02:38 -07004326 if (isModemActivityInfoValid(info)) {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004327 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4328 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4329 mergedTxTimeMs[i] =
4330 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4331 }
4332 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4333 mLastModemActivityInfo.setSleepTimeMillis(
4334 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4335 mLastModemActivityInfo.setIdleTimeMillis(
4336 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4337 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4338 mLastModemActivityInfo.setRxTimeMillis(
4339 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4340 mLastModemActivityInfo.setEnergyUsed(
4341 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004342 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004343 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4344 mLastModemActivityInfo.getSleepTimeMillis(),
4345 mLastModemActivityInfo.getIdleTimeMillis(),
4346 mLastModemActivityInfo.getTxTimeMillis(),
4347 mLastModemActivityInfo.getRxTimeMillis(),
4348 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004349 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004350 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004351 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004352 result.send(0, bundle);
4353 } finally {
4354 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004355 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004356 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004357
Siddharth Rayc339f892018-06-17 15:02:38 -07004358 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4359 // less than total activity duration.
4360 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4361 if (info == null) {
4362 return false;
4363 }
4364 int activityDurationMs =
4365 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4366 int totalTxTimeMs = 0;
4367 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4368 totalTxTimeMs += info.getTxTimeMillis()[i];
4369 }
4370 return (info.isValid()
4371 && (info.getSleepTimeMillis() <= activityDurationMs)
4372 && (info.getIdleTimeMillis() <= activityDurationMs)
4373 && (info.getRxTimeMillis() <= activityDurationMs)
4374 && (totalTxTimeMs <= activityDurationMs));
4375 }
4376
Jack Yu85bd38a2015-11-09 11:34:32 -08004377 /**
4378 * {@hide}
4379 * Returns the service state information on specified subscription.
4380 */
4381 @Override
4382 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004384 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004385 return null;
4386 }
4387
Malcolm Chenaabec062018-02-28 15:00:40 -08004388 final long identity = Binder.clearCallingIdentity();
4389 try {
4390 final Phone phone = getPhone(subId);
4391 if (phone == null) {
4392 return null;
4393 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004394
Malcolm Chenaabec062018-02-28 15:00:40 -08004395 return phone.getServiceState();
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004399 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004400
4401 /**
4402 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4403 *
4404 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4405 * voicemail ringtone.
4406 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4407 * PhoneAccount.
4408 */
4409 @Override
4410 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004411 final long identity = Binder.clearCallingIdentity();
4412 try {
4413 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4414 if (phone == null) {
4415 phone = mPhone;
4416 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004417
Malcolm Chenaabec062018-02-28 15:00:40 -08004418 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004422 }
4423
4424 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004425 * Sets the per-account voicemail ringtone.
4426 *
4427 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4428 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4429 *
4430 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4431 * voicemail ringtone.
4432 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4433 * PhoneAccount.
4434 */
4435 @Override
4436 public void setVoicemailRingtoneUri(String callingPackage,
4437 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4438 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4439 if (!TextUtils.equals(callingPackage,
4440 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4442 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4443 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004444 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004445
4446 final long identity = Binder.clearCallingIdentity();
4447 try {
4448 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4449 if (phone == null) {
4450 phone = mPhone;
4451 }
4452 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004455 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004456 }
4457
4458 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004459 * Returns whether vibration is set for voicemail notification in Phone settings.
4460 *
4461 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4462 * voicemail vibration setting.
4463 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4464 */
4465 @Override
4466 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004467 final long identity = Binder.clearCallingIdentity();
4468 try {
4469 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4470 if (phone == null) {
4471 phone = mPhone;
4472 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004473
Malcolm Chenaabec062018-02-28 15:00:40 -08004474 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004478 }
4479
Youhan Wange64578a2016-05-02 15:32:42 -07004480 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004481 * Sets the per-account voicemail vibration.
4482 *
4483 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4484 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4485 *
4486 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4487 * voicemail vibration setting.
4488 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4489 * specific PhoneAccount.
4490 */
4491 @Override
4492 public void setVoicemailVibrationEnabled(String callingPackage,
4493 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4494 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4495 if (!TextUtils.equals(callingPackage,
4496 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4498 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4499 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004500 }
4501
Malcolm Chenaabec062018-02-28 15:00:40 -08004502 final long identity = Binder.clearCallingIdentity();
4503 try {
4504 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4505 if (phone == null) {
4506 phone = mPhone;
4507 }
4508 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4509 } finally {
4510 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004511 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004512 }
4513
4514 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004515 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4516 *
4517 * @throws SecurityException if the caller does not have the required permission
4518 */
4519 private void enforceReadPrivilegedPermission() {
4520 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4521 null);
4522 }
4523
4524 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004525 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4526 * permission.
4527 *
4528 * @throws SecurityException if the caller does not have the required permission
4529 */
4530 private void enforceSendSmsPermission() {
4531 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4532 }
4533
4534 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004535 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004536 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004537 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004538 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004539 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004540 final long identity = Binder.clearCallingIdentity();
4541 try {
4542 ComponentName componentName =
4543 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4544 if (componentName == null) {
4545 throw new SecurityException(
4546 "Caller not current active visual voicemail package[null]");
4547 }
4548 String vvmPackage = componentName.getPackageName();
4549 if (!callingPackage.equals(vvmPackage)) {
4550 throw new SecurityException("Caller not current active visual voicemail package["
4551 + vvmPackage + "]");
4552 }
4553 } finally {
4554 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004555 }
4556 }
4557
4558 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004559 * Return the application ID for the app type.
4560 *
4561 * @param subId the subscription ID that this request applies to.
4562 * @param appType the uicc app type.
4563 * @return Application ID for specificied app type, or null if no uicc.
4564 */
4565 @Override
4566 public String getAidForAppType(int subId, int appType) {
4567 enforceReadPrivilegedPermission();
4568 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004569
4570 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004571 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004572 if (phone == null) {
4573 return null;
4574 }
4575 String aid = null;
4576 try {
4577 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4578 .getApplicationByType(appType).getAid();
4579 } catch (Exception e) {
4580 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4581 }
4582 return aid;
4583 } finally {
4584 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004585 }
Youhan Wange64578a2016-05-02 15:32:42 -07004586 }
4587
Youhan Wang4001d252016-05-11 10:29:41 -07004588 /**
4589 * Return the Electronic Serial Number.
4590 *
4591 * @param subId the subscription ID that this request applies to.
4592 * @return ESN or null if error.
4593 */
4594 @Override
4595 public String getEsn(int subId) {
4596 enforceReadPrivilegedPermission();
4597 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004598
4599 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004600 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004601 if (phone == null) {
4602 return null;
4603 }
4604 String esn = null;
4605 try {
4606 esn = phone.getEsn();
4607 } catch (Exception e) {
4608 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4609 }
4610 return esn;
4611 } finally {
4612 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004613 }
Youhan Wang4001d252016-05-11 10:29:41 -07004614 }
4615
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004616 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004617 * Return the Preferred Roaming List Version.
4618 *
4619 * @param subId the subscription ID that this request applies to.
4620 * @return PRLVersion or null if error.
4621 */
4622 @Override
4623 public String getCdmaPrlVersion(int subId) {
4624 enforceReadPrivilegedPermission();
4625 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004626
4627 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004628 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004629 if (phone == null) {
4630 return null;
4631 }
4632 String cdmaPrlVersion = null;
4633 try {
4634 cdmaPrlVersion = phone.getCdmaPrlVersion();
4635 } catch (Exception e) {
4636 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4637 }
4638 return cdmaPrlVersion;
4639 } finally {
4640 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004641 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004642 }
4643
4644 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004645 * Get snapshot of Telephony histograms
4646 * @return List of Telephony histograms
4647 * @hide
4648 */
4649 @Override
4650 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4652 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004653
4654 final long identity = Binder.clearCallingIdentity();
4655 try {
4656 return RIL.getTelephonyRILTimingHistograms();
4657 } finally {
4658 Binder.restoreCallingIdentity(identity);
4659 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004660 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004661
4662 /**
4663 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004664 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004665 * Require system privileges. In the future we may add this to carrier APIs.
4666 *
4667 * @return The number of carriers set successfully, should match length of carriers
4668 */
4669 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004670 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004671 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004672 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004673
Meng Wang9b7c4e92017-02-17 11:41:27 -08004674 if (carriers == null) {
4675 throw new NullPointerException("carriers cannot be null");
4676 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004677
Malcolm Chenaabec062018-02-28 15:00:40 -08004678 final long identity = Binder.clearCallingIdentity();
4679 try {
4680 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004681 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4682 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004683 return retVal[0];
4684 } finally {
4685 Binder.restoreCallingIdentity(identity);
4686 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004687 }
4688
4689 /**
4690 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004691 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004692 * Require system privileges. In the future we may add this to carrier APIs.
4693 *
4694 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4695 * means all carriers are allowed.
4696 */
4697 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004698 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004699 enforceReadPrivilegedPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004700 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08004701
4702 final long identity = Binder.clearCallingIdentity();
4703 try {
4704 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004705 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4706 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004707 } finally {
4708 Binder.restoreCallingIdentity(identity);
4709 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004710 }
4711
fionaxu59545b42016-05-25 15:53:37 -07004712 /**
4713 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4714 * @param subId the subscription ID that this action applies to.
4715 * @param enabled control enable or disable metered apns.
4716 * {@hide}
4717 */
4718 @Override
4719 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4720 enforceModifyPermission();
4721 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004722
4723 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004724 if (phone == null) {
4725 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4726 return;
4727 }
4728 try {
4729 phone.carrierActionSetMeteredApnsEnabled(enabled);
4730 } catch (Exception e) {
4731 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004732 } finally {
4733 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004734 }
4735 }
4736
4737 /**
4738 * Action set from carrier signalling broadcast receivers to enable/disable radio
4739 * @param subId the subscription ID that this action applies to.
4740 * @param enabled control enable or disable radio.
4741 * {@hide}
4742 */
4743 @Override
4744 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4745 enforceModifyPermission();
4746 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004747
4748 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004749 if (phone == null) {
4750 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4751 return;
4752 }
4753 try {
4754 phone.carrierActionSetRadioEnabled(enabled);
4755 } catch (Exception e) {
4756 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004757 } finally {
4758 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004759 }
4760 }
4761
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004762 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004763 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4764 * network status based on which carrier apps could apply actions accordingly,
4765 * enable/disable default url handler for example.
4766 *
4767 * @param subId the subscription ID that this action applies to.
4768 * @param report control start/stop reporting the default network status.
4769 * {@hide}
4770 */
4771 @Override
4772 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4773 enforceModifyPermission();
4774 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004775
4776 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004777 if (phone == null) {
4778 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4779 return;
4780 }
4781 try {
4782 phone.carrierActionReportDefaultNetworkStatus(report);
4783 } catch (Exception e) {
4784 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004785 } finally {
4786 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004787 }
4788 }
4789
4790 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004791 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4792 * bug report is being generated.
4793 */
4794 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004795 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004796 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4797 != PackageManager.PERMISSION_GRANTED) {
4798 writer.println("Permission Denial: can't dump Phone from pid="
4799 + Binder.getCallingPid()
4800 + ", uid=" + Binder.getCallingUid()
4801 + "without permission "
4802 + android.Manifest.permission.DUMP);
4803 return;
4804 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004805 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004806 }
Jack Yueb89b242016-06-22 13:27:47 -07004807
Brad Ebingerdac2f002018-04-03 15:17:52 -07004808 @Override
4809 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4810 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4811 throws RemoteException {
4812 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4813 }
4814
Jack Yueb89b242016-06-22 13:27:47 -07004815 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004816 * Get aggregated video call data usage since boot.
4817 *
4818 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4819 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004820 * {@hide}
4821 */
4822 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004823 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004824 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4825 null);
4826
Malcolm Chenaabec062018-02-28 15:00:40 -08004827 final long identity = Binder.clearCallingIdentity();
4828 try {
4829 // NetworkStatsService keeps tracking the active network interface and identity. It
4830 // records the delta with the corresponding network identity.
4831 // We just return the total video call data usage snapshot since boot.
4832 Phone phone = getPhone(subId);
4833 if (phone != null) {
4834 return phone.getVtDataUsage(perUidStats);
4835 }
4836 return null;
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004839 }
Jack Yueb89b242016-06-22 13:27:47 -07004840 }
Jack Yu75ab2952016-07-08 14:29:33 -07004841
4842 /**
4843 * Policy control of data connection. Usually used when data limit is passed.
4844 * @param enabled True if enabling the data, otherwise disabling.
4845 * @param subId Subscription index
4846 * {@hide}
4847 */
4848 @Override
4849 public void setPolicyDataEnabled(boolean enabled, int subId) {
4850 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004851
4852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 Phone phone = getPhone(subId);
4855 if (phone != null) {
4856 phone.setPolicyDataEnabled(enabled);
4857 }
4858 } finally {
4859 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004860 }
4861 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004862
4863 /**
4864 * Get Client request stats
4865 * @return List of Client Request Stats
4866 * @hide
4867 */
4868 @Override
4869 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004871 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004872 return null;
4873 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004874 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004875
Malcolm Chenaabec062018-02-28 15:00:40 -08004876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 if (phone != null) {
4879 return phone.getClientRequestStats();
4880 }
4881
4882 return null;
4883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004886 }
4887
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004888 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004889 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004890 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004891 }
Jack Yueb4124c2017-02-16 15:32:43 -08004892
4893 /**
Grace Chen70990072017-03-24 17:21:30 -07004894 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004895 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004896 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004897 * @param state State of SIM (power down, power up, pass through)
4898 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4899 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4900 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004901 *
4902 **/
4903 @Override
Grace Chen70990072017-03-24 17:21:30 -07004904 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004905 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004906 Phone phone = PhoneFactory.getPhone(slotIndex);
4907
vagdevie435a3e2018-08-15 16:01:53 -07004908 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4909
Malcolm Chenaabec062018-02-28 15:00:40 -08004910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07004913 phone.setSimPowerState(state, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004914 }
4915 } finally {
4916 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004917 }
4918 }
Shuo Qiandd210312017-04-12 22:11:33 +00004919
Tyler Gunn65d45c22017-06-05 11:22:26 -07004920 private boolean isUssdApiAllowed(int subId) {
4921 CarrierConfigManager configManager =
4922 (CarrierConfigManager) mPhone.getContext().getSystemService(
4923 Context.CARRIER_CONFIG_SERVICE);
4924 if (configManager == null) {
4925 return false;
4926 }
4927 PersistableBundle pb = configManager.getConfigForSubId(subId);
4928 if (pb == null) {
4929 return false;
4930 }
4931 return pb.getBoolean(
4932 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4933 }
4934
Shuo Qiandd210312017-04-12 22:11:33 +00004935 /**
4936 * Check if phone is in emergency callback mode
4937 * @return true if phone is in emergency callback mode
4938 * @param subId sub id
4939 */
goneil9c5f4872017-12-05 14:07:56 -08004940 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004941 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004942 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004943 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004944
4945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 if (phone != null) {
4948 return phone.isInEcm();
4949 } else {
4950 return false;
4951 }
4952 } finally {
4953 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004954 }
4955 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004956
4957 /**
4958 * Get the current signal strength information for the given subscription.
4959 * Because this information is not updated when the device is in a low power state
4960 * it should not be relied-upon to be current.
4961 * @param subId Subscription index
4962 * @return the most recent cached signal strength info from the modem
4963 */
4964 @Override
4965 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004966 final long identity = Binder.clearCallingIdentity();
4967 try {
4968 Phone p = getPhone(subId);
4969 if (p == null) {
4970 return null;
4971 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004972
Malcolm Chenaabec062018-02-28 15:00:40 -08004973 return p.getSignalStrength();
4974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004977 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004978
Pengquan Meng9140aec2018-08-22 14:49:57 -07004979 /**
chen xu907e5a22018-10-11 13:21:04 -07004980 * Get the current modem radio state for the given slot.
4981 * @param slotIndex slot index.
4982 * @param callingPackage the name of the package making the call.
4983 * @return the current radio power state from the modem
4984 */
4985 @Override
4986 public int getRadioPowerState(int slotIndex, String callingPackage) {
4987 Phone phone = PhoneFactory.getPhone(slotIndex);
4988 if (phone != null) {
4989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4990 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
4991 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
4992 }
4993
4994 final long identity = Binder.clearCallingIdentity();
4995 try {
4996 return phone.getRadioPowerState();
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
5000 }
5001 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5002 }
5003
5004 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005005 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5006 *
5007 * <p>Requires one of the following permissions:
5008 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5009 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5010 * privileges.
5011 *
5012 * @param subId subscription id
5013 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5014 * {@code false}.
5015 */
5016 @Override
5017 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005018 boolean isEnabled = false;
5019 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005020 try {
5021 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005022 null /* message */);
5023 Phone phone = getPhone(subId);
5024 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005025 } catch (Exception e) {
5026 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5027 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005028 } finally {
5029 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005030 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005031 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005032 }
5033
5034
5035 /**
5036 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5037 *
5038 * <p> Requires permission:
5039 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5040 * privileges.
5041 *
5042 * @param subId subscription id
5043 * @param isEnabled {@code true} means enable, {@code false} means disable.
5044 */
5045 @Override
5046 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5050 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005051
Pengquan Meng0c05b502018-09-06 09:59:22 -07005052 Phone phone = getPhone(subId);
5053 if (phone != null) {
5054 phone.setDataRoamingEnabled(isEnabled);
5055 }
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005058 }
5059 }
5060
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005061 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005062 public boolean isManualNetworkSelectionAllowed(int subId) {
5063 boolean isAllowed = true;
5064 final long identity = Binder.clearCallingIdentity();
5065 try {
5066 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5067 mApp, subId, "isManualNetworkSelectionAllowed");
5068 Phone phone = getPhone(subId);
5069 if (phone != null) {
5070 isAllowed = phone.isCspPlmnEnabled();
5071 }
5072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
5075 return isAllowed;
5076 }
5077
5078 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005079 public UiccSlotInfo[] getUiccSlotsInfo() {
5080 enforceReadPrivilegedPermission();
5081
Malcolm Chenaabec062018-02-28 15:00:40 -08005082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005085 if (slots == null) {
5086 Rlog.i(LOG_TAG, "slots is null.");
5087 return null;
5088 }
5089
Malcolm Chenaabec062018-02-28 15:00:40 -08005090 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5091 for (int i = 0; i < slots.length; i++) {
5092 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005093 if (slot == null) {
5094 continue;
5095 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005096
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005097 String cardId;
5098 UiccCard card = slot.getUiccCard();
5099 if (card != null) {
5100 cardId = card.getCardId();
5101 } else {
5102 cardId = slot.getIccId();
5103 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005104
Malcolm Chenaabec062018-02-28 15:00:40 -08005105 int cardState = 0;
5106 switch (slot.getCardState()) {
5107 case CARDSTATE_ABSENT:
5108 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5109 break;
5110 case CARDSTATE_PRESENT:
5111 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5112 break;
5113 case CARDSTATE_ERROR:
5114 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5115 break;
5116 case CARDSTATE_RESTRICTED:
5117 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5118 break;
5119 default:
5120 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005121
Malcolm Chenaabec062018-02-28 15:00:40 -08005122 }
5123
5124 infos[i] = new UiccSlotInfo(
5125 slot.isActive(),
5126 slot.isEuicc(),
5127 cardId,
5128 cardState,
5129 slot.getPhoneId(),
5130 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005131 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005132 return infos;
5133 } finally {
5134 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005135 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005136 }
5137
5138 @Override
5139 public boolean switchSlots(int[] physicalSlots) {
5140 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005141
5142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5145 } finally {
5146 Binder.restoreCallingIdentity(identity);
5147 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005148 }
Jack Yu4c988042018-02-27 15:30:01 -08005149
5150 @Override
5151 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5152 enforceModifyPermission();
5153 final Phone phone = getPhone(subId);
5154 if (phone == null) {
5155 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5156 return;
5157 }
5158
Malcolm Chenaabec062018-02-28 15:00:40 -08005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 phone.setRadioIndicationUpdateMode(filters, mode);
5162 } finally {
5163 Binder.restoreCallingIdentity(identity);
5164 }
Jack Yu4c988042018-02-27 15:30:01 -08005165 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005166
5167 /**
goneil47ffb6e2018-04-06 15:40:58 -07005168 * A test API to reload the UICC profile.
5169 *
5170 * <p>Requires that the calling app has permission
5171 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5172 * @hide
5173 */
5174 @Override
5175 public void refreshUiccProfile(int subId) {
5176 enforceModifyPermission();
5177
5178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 Phone phone = getPhone(subId);
5181 if (phone == null) {
5182 return;
5183 }
5184 UiccCard uiccCard = phone.getUiccCard();
5185 if (uiccCard == null) {
5186 return;
5187 }
5188 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5189 if (uiccProfile == null) {
5190 return;
5191 }
5192 uiccProfile.refresh();
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
5195 }
5196 }
5197
5198 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005199 * Returns false if the mobile data is disabled by default, otherwise return true.
5200 */
5201 private boolean getDefaultDataEnabled() {
5202 return "true".equalsIgnoreCase(
5203 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5204 }
5205
5206 /**
5207 * Returns true if the data roaming is enabled by default, i.e the system property
5208 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5209 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5210 */
5211 private boolean getDefaultDataRoamingEnabled(int subId) {
5212 final CarrierConfigManager configMgr = (CarrierConfigManager)
5213 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5214 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5215 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5216 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5217 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5218 return isDataRoamingEnabled;
5219 }
5220
5221 /**
5222 * Returns the default network type for the given {@code subId}, if the default network type is
5223 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5224 */
5225 private int getDefaultNetworkType(int subId) {
5226 return Integer.parseInt(
5227 TelephonyManager.getTelephonyProperty(
5228 mSubscriptionController.getPhoneId(subId),
5229 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5230 String.valueOf(Phone.PREFERRED_NT_MODE)));
5231 }
fionaxua13278b2018-03-21 00:08:13 -07005232
5233 @Override
5234 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5235 gid1, String gid2, String plmn, String spn) {
5236 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005237
5238 final long identity = Binder.clearCallingIdentity();
5239 try {
5240 final Phone phone = getPhone(subId);
5241 if (phone == null) {
5242 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5243 return;
5244 }
5245 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5246 } finally {
5247 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005248 }
fionaxua13278b2018-03-21 00:08:13 -07005249 }
5250
5251 @Override
5252 public int getCarrierIdListVersion(int subId) {
5253 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005254
5255 final long identity = Binder.clearCallingIdentity();
5256 try {
5257 final Phone phone = getPhone(subId);
5258 if (phone == null) {
5259 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5260 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5261 }
5262 return phone.getCarrierIdListVersion();
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005265 }
fionaxua13278b2018-03-21 00:08:13 -07005266 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005267
5268 @Override
5269 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5271 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5272 return -1;
5273 }
5274
5275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5278 } finally {
5279 Binder.restoreCallingIdentity(identity);
5280 }
5281 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005282
5283 @Override
5284 public int getCdmaRoamingMode(int subId) {
5285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5286 mApp, subId, "getCdmaRoamingMode");
5287
5288 final long identity = Binder.clearCallingIdentity();
5289 try {
5290 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
5294 }
5295
5296 @Override
5297 public boolean setCdmaRoamingMode(int subId, int mode) {
5298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5299 mApp, subId, "setCdmaRoamingMode");
5300
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
5306 }
5307 }
5308
5309 @Override
5310 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5312 mApp, subId, "setCdmaSubscriptionMode");
5313
5314 final long identity = Binder.clearCallingIdentity();
5315 try {
5316 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
5320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005321}