blob: e38441f598a06b55fc082750dcc3037b1431102b [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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08001287 if (!isValid) {
1288 return;
1289 }
Wink Saville08874612014-08-31 19:19:58 -07001290
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08001565 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001566 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001785 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1786 // Get default phone in this case.
1787 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1788 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001789 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001790 // Todo: fix this when we can get the actual cellular network info when the device
1791 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001792 if (TelephonyManager.NETWORK_TYPE_IWLAN
1793 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1794 return "";
1795 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001796 Phone phone = PhoneFactory.getPhone(phoneId);
1797 if (phone != null) {
1798 ServiceStateTracker sst = phone.getServiceStateTracker();
1799 if (sst != null) {
1800 LocaleTracker lt = sst.getLocaleTracker();
1801 if (lt != null) {
1802 return lt.getCurrentCountry();
1803 }
1804 }
1805 }
1806 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001807 } finally {
1808 Binder.restoreCallingIdentity(identity);
1809 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001810 }
1811
1812 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001814 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001815 }
1816
Sanket Padawe356d7632015-06-22 14:03:32 -07001817 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001818 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 mApp.enforceCallingOrSelfPermission(
1820 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001821
1822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 final Phone phone = getPhone(subId);
1825 if (phone != null) {
1826 phone.enableLocationUpdates();
1827 }
1828 } finally {
1829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
1832
1833 @Override
1834 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001835 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001836 }
1837
Sanket Padawe356d7632015-06-22 14:03:32 -07001838 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001839 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 mApp.enforceCallingOrSelfPermission(
1841 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001842
1843 final long identity = Binder.clearCallingIdentity();
1844 try {
1845 final Phone phone = getPhone(subId);
1846 if (phone != null) {
1847 phone.disableLocationUpdates();
1848 }
1849 } finally {
1850 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001851 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001852 }
1853
Nathan Harold31d7ff32018-10-15 20:20:30 -07001854 /**
1855 * Returns the target SDK version number for a given package name.
1856 *
1857 * @return target SDK if the package is found or INT_MAX.
1858 */
1859 private int getTargetSdk(String packageName) {
1860 try {
1861 final ApplicationInfo ai =
1862 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1863 if (ai != null) return ai.targetSdkVersion;
1864 } catch (PackageManager.NameNotFoundException unexpected) {
1865 }
1866 return Integer.MAX_VALUE;
1867 }
1868
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 @Override
1870 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001871 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1872 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001873 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1874 throw new SecurityException(
1875 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1876 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001877
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1879 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1880 return null;
1881 }
Svetoslav64fad262015-04-14 14:35:21 -07001882
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001883 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884
Nathan Haroldf180aac2018-06-01 18:43:55 -07001885 List<CellInfo> info = getAllCellInfo(callingPackage);
1886 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887
Nathan Haroldf180aac2018-06-01 18:43:55 -07001888 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1889 for (CellInfo ci : info) {
1890 if (ci instanceof CellInfoGsm) {
1891 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1892 } else if (ci instanceof CellInfoWcdma) {
1893 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001896 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 }
1898
1899
1900 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001901 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001902 mPhone.getContext().getSystemService(AppOpsManager.class)
1903 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001904 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001905 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001906 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001909 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001910 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001911 final long identity = Binder.clearCallingIdentity();
1912 try {
1913 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1914 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001915 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001916 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001917 if (info != null) cellInfos.addAll(info);
1918 }
1919 return cellInfos;
1920 } finally {
1921 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923 }
1924
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001925 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001927 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001928 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001929
1930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 mPhone.setCellInfoListRate(rateInMillis, workSource);
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
1935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
Shishir Agrawala9f32182016-04-12 12:00:16 -07001938 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001939 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001940 Phone phone = PhoneFactory.getPhone(slotIndex);
1941 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001942 return null;
1943 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001944 int subId = phone.getSubId();
1945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1946 mApp, subId, callingPackage, "getImeiForSlot")) {
1947 return null;
1948 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001949
1950 final long identity = Binder.clearCallingIdentity();
1951 try {
1952 return phone.getImei();
1953 } finally {
1954 Binder.restoreCallingIdentity(identity);
1955 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001956 }
1957
1958 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001959 public String getTypeAllocationCodeForSlot(int slotIndex) {
1960 Phone phone = PhoneFactory.getPhone(slotIndex);
1961 String tac = null;
1962 if (phone != null) {
1963 String imei = phone.getImei();
1964 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1965 }
1966 return tac;
1967 }
1968
1969 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001970 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001971 Phone phone = PhoneFactory.getPhone(slotIndex);
1972 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001973 return null;
1974 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001975 int subId = phone.getSubId();
1976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1977 mApp, subId, callingPackage, "getMeidForSlot")) {
1978 return null;
1979 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001980
1981 final long identity = Binder.clearCallingIdentity();
1982 try {
1983 return phone.getMeid();
1984 } finally {
1985 Binder.restoreCallingIdentity(identity);
1986 }
Jack Yu2af8d712017-03-15 17:14:14 -07001987 }
1988
1989 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001990 public String getManufacturerCodeForSlot(int slotIndex) {
1991 Phone phone = PhoneFactory.getPhone(slotIndex);
1992 String manufacturerCode = null;
1993 if (phone != null) {
1994 String meid = phone.getMeid();
1995 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1996 }
1997 return manufacturerCode;
1998 }
1999
2000 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002001 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002002 Phone phone = PhoneFactory.getPhone(slotIndex);
2003 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002004 return null;
2005 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002006 int subId = phone.getSubId();
2007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2008 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2009 return null;
2010 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002011
2012 final long identity = Binder.clearCallingIdentity();
2013 try {
2014 return phone.getDeviceSvn();
2015 } finally {
2016 Binder.restoreCallingIdentity(identity);
2017 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002018 }
2019
fionaxu43304da2017-11-27 22:51:16 -08002020 @Override
2021 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 final Phone phone = getPhone(subId);
2025 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2026 } finally {
2027 Binder.restoreCallingIdentity(identity);
2028 }
fionaxu43304da2017-11-27 22:51:16 -08002029 }
2030
2031 @Override
2032 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002033 final long identity = Binder.clearCallingIdentity();
2034 try {
2035 final Phone phone = getPhone(subId);
2036 return phone == null ? null : phone.getCarrierName();
2037 } finally {
2038 Binder.restoreCallingIdentity(identity);
2039 }
fionaxu43304da2017-11-27 22:51:16 -08002040 }
2041
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 //
2043 // Internal helper methods.
2044 //
2045
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002046 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2048 *
2049 * @throws SecurityException if the caller does not have the required permission
2050 */
2051 private void enforceModifyPermission() {
2052 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2053 }
2054
2055 /**
2056 * Make sure the caller has the CALL_PHONE permission.
2057 *
2058 * @throws SecurityException if the caller does not have the required permission
2059 */
2060 private void enforceCallPermission() {
2061 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2062 }
2063
Stuart Scott8eef64f2015-04-08 15:13:54 -07002064 private void enforceConnectivityInternalPermission() {
2065 mApp.enforceCallingOrSelfPermission(
2066 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2067 "ConnectivityService");
2068 }
2069
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070 private String createTelUrl(String number) {
2071 if (TextUtils.isEmpty(number)) {
2072 return null;
2073 }
2074
Jake Hambye994d462014-02-03 13:10:13 -08002075 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002076 }
2077
Ihab Awadf9e92732013-12-05 18:02:52 -08002078 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2080 }
2081
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002082 private static void logv(String msg) {
2083 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2084 }
2085
Ihab Awadf9e92732013-12-05 18:02:52 -08002086 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2088 }
2089
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002090 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002092 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002093 }
2094
Sanket Padawe356d7632015-06-22 14:03:32 -07002095 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002096 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 final Phone phone = PhoneFactory.getPhone(slotIndex);
2100 if (phone == null) {
2101 return PhoneConstants.PHONE_TYPE_NONE;
2102 } else {
2103 return phone.getPhoneType();
2104 }
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109
2110 /**
2111 * Returns the CDMA ERI icon index to display
2112 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002113 @Override
2114 public int getCdmaEriIconIndex(String callingPackage) {
2115 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002116 }
2117
Sanket Padawe356d7632015-06-22 14:03:32 -07002118 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002119 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002121 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002122 return -1;
2123 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002124
2125 final long identity = Binder.clearCallingIdentity();
2126 try {
2127 final Phone phone = getPhone(subId);
2128 if (phone != null) {
2129 return phone.getCdmaEriIconIndex();
2130 } else {
2131 return -1;
2132 }
2133 } finally {
2134 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 }
2137
2138 /**
2139 * Returns the CDMA ERI icon mode,
2140 * 0 - ON
2141 * 1 - FLASHING
2142 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002143 @Override
2144 public int getCdmaEriIconMode(String callingPackage) {
2145 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002146 }
2147
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002149 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002151 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002152 return -1;
2153 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002154
2155 final long identity = Binder.clearCallingIdentity();
2156 try {
2157 final Phone phone = getPhone(subId);
2158 if (phone != null) {
2159 return phone.getCdmaEriIconMode();
2160 } else {
2161 return -1;
2162 }
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
2167
2168 /**
2169 * Returns the CDMA ERI text,
2170 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002171 @Override
2172 public String getCdmaEriText(String callingPackage) {
2173 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002174 }
2175
Sanket Padawe356d7632015-06-22 14:03:32 -07002176 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002177 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002178 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002179 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002180 return null;
2181 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002182
2183 final long identity = Binder.clearCallingIdentity();
2184 try {
2185 final Phone phone = getPhone(subId);
2186 if (phone != null) {
2187 return phone.getCdmaEriText();
2188 } else {
2189 return null;
2190 }
2191 } finally {
2192 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 }
2195
2196 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002197 * Returns the CDMA MDN.
2198 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002199 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002200 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2202 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002203
2204 final long identity = Binder.clearCallingIdentity();
2205 try {
2206 final Phone phone = getPhone(subId);
2207 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2208 return phone.getLine1Number();
2209 } else {
2210 return null;
2211 }
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002214 }
2215 }
2216
2217 /**
2218 * Returns the CDMA MIN.
2219 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002220 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002221 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2223 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002224
2225 final long identity = Binder.clearCallingIdentity();
2226 try {
2227 final Phone phone = getPhone(subId);
2228 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2229 return phone.getCdmaMin();
2230 } else {
2231 return null;
2232 }
2233 } finally {
2234 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002235 }
2236 }
2237
2238 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 * Returns true if CDMA provisioning needs to run.
2240 */
2241 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 return mPhone.needsOtaServiceProvisioning();
2245 } finally {
2246 Binder.restoreCallingIdentity(identity);
2247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 }
2249
2250 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002251 * Sets the voice mail number of a given subId.
2252 */
2253 @Override
2254 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002255 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002256
2257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2260 new Pair<String, String>(alphaTag, number), new Integer(subId));
2261 return success;
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002265 }
2266
Ta-wei Yen87c49842016-05-13 21:19:52 -07002267 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002268 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2270 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2271 if (!TextUtils.equals(callingPackage, systemDialer)) {
2272 throw new SecurityException("caller must be system dialer");
2273 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002274
2275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2278 if (phoneAccountHandle == null) {
2279 return null;
2280 }
2281 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2282 } finally {
2283 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002284 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002285 }
2286
2287 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002288 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002289 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002291 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002292 return null;
2293 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002294
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002295 final long identity = Binder.clearCallingIdentity();
2296 try {
2297 return RemoteVvmTaskManager
2298 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
2301 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002302 }
2303
2304 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002305 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2306 VisualVoicemailSmsFilterSettings settings) {
2307 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002308
2309 final long identity = Binder.clearCallingIdentity();
2310 try {
2311 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2312 mPhone.getContext(), callingPackage, subId, settings);
2313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002316 }
2317
2318 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002319 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2320 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002321
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2325 mPhone.getContext(), callingPackage, subId);
2326 } finally {
2327 Binder.restoreCallingIdentity(identity);
2328 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002329 }
2330
2331 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002332 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2333 String callingPackage, int subId) {
2334 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002335
2336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2339 mPhone.getContext(), callingPackage, subId);
2340 } finally {
2341 Binder.restoreCallingIdentity(identity);
2342 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002343 }
2344
2345 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002346 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002347 enforceReadPrivilegedPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002348
2349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2352 mPhone.getContext(), subId);
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
2355 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002356 }
2357
2358 @Override
2359 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2360 String number, int port, String text, PendingIntent sentIntent) {
2361 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002362 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002363 enforceSendSmsPermission();
2364 // Make the calls as the phone process.
2365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2368 if (port == 0) {
2369 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2370 sentIntent, null, false);
2371 } else {
2372 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2373 smsManager.sendDataMessageWithSelfPermissions(number, null,
2374 (short) port, data, sentIntent, null);
2375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
2378 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002379 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002380 /**
fionaxu0152e512016-11-14 13:36:14 -08002381 * Sets the voice activation state of a given subId.
2382 */
2383 @Override
2384 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2386 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 if (phone != null) {
2392 phone.setVoiceActivationState(activationState);
2393 } else {
2394 loge("setVoiceActivationState fails with invalid subId: " + subId);
2395 }
2396 } finally {
2397 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002398 }
2399 }
2400
2401 /**
2402 * Sets the data activation state of a given subId.
2403 */
2404 @Override
2405 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2407 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002408
2409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 final Phone phone = getPhone(subId);
2412 if (phone != null) {
2413 phone.setDataActivationState(activationState);
2414 } else {
2415 loge("setVoiceActivationState fails with invalid subId: " + subId);
2416 }
2417 } finally {
2418 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002419 }
2420 }
2421
2422 /**
2423 * Returns the voice activation state of a given subId.
2424 */
2425 @Override
2426 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002427 enforceReadPrivilegedPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002428
fionaxu0152e512016-11-14 13:36:14 -08002429 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002430 final long identity = Binder.clearCallingIdentity();
2431 try {
2432 if (phone != null) {
2433 return phone.getVoiceActivationState();
2434 } else {
2435 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2436 }
2437 } finally {
2438 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002439 }
2440 }
2441
2442 /**
2443 * Returns the data activation state of a given subId.
2444 */
2445 @Override
2446 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002447 enforceReadPrivilegedPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002448
fionaxu0152e512016-11-14 13:36:14 -08002449 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002450 final long identity = Binder.clearCallingIdentity();
2451 try {
2452 if (phone != null) {
2453 return phone.getDataActivationState();
2454 } else {
2455 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2456 }
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002459 }
2460 }
2461
2462 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 * Returns the unread count of voicemails
2464 */
2465 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002466 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
2469 /**
2470 * Returns the unread count of voicemails for a subId
2471 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002472 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002473 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(subId);
2477 if (phone != null) {
2478 return phone.getVoiceMessageCount();
2479 } else {
2480 return 0;
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
2487 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002488 * returns true, if the device is in a state where both voice and data
2489 * are supported simultaneously. This can change based on location or network condition.
2490 */
2491 @Override
2492 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002493 final long identity = Binder.clearCallingIdentity();
2494 try {
2495 final Phone phone = getPhone(subId);
2496 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
2499 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002500 }
2501
2502 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002503 * Send the dialer code if called from the current default dialer or the caller has
2504 * carrier privilege.
2505 * @param inputCode The dialer code to send
2506 */
2507 @Override
2508 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2510 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2511 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002512 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2513 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002514 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002515
2516 final long identity = Binder.clearCallingIdentity();
2517 try {
2518 mPhone.sendDialerSpecialCode(inputCode);
2519 } finally {
2520 Binder.restoreCallingIdentity(identity);
2521 }
fionaxu235cc5e2017-03-06 22:25:57 -08002522 }
2523
2524 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002525 * Returns the data network type.
2526 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 *
2528 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2529 */
2530 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002531 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 final Phone phone = getPhone(getDefaultSubscription());
2535 if (phone != null) {
2536 return phone.getServiceState().getDataNetworkType();
2537 } else {
2538 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2539 }
2540 } finally {
2541 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002542 }
Wink Saville36469e72014-06-11 15:17:00 -07002543 }
2544
Pengquan Meng0c05b502018-09-06 09:59:22 -07002545 @Override
2546 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002547 if (!isActiveSubscription(subId)) {
2548 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2549 }
2550
Pengquan Meng0c05b502018-09-06 09:59:22 -07002551 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2552 }
2553
Wink Saville36469e72014-06-11 15:17:00 -07002554 /**
2555 * Returns the network type for a subId
2556 */
2557 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002558 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002560 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002561 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2562 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002563
Malcolm Chend965c8b2018-02-28 15:00:40 -08002564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 final Phone phone = getPhone(subId);
2567 if (phone != null) {
2568 return phone.getServiceState().getDataNetworkType();
2569 } else {
2570 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2571 }
2572 } finally {
2573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 }
2576
2577 /**
2578 * Returns the data network type
2579 */
2580 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002581 public int getDataNetworkType(String callingPackage) {
2582 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002583 }
2584
2585 /**
2586 * Returns the data network type for a subId
2587 */
2588 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002589 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002591 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002592 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2593 }
2594
Malcolm Chend965c8b2018-02-28 15:00:40 -08002595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 final Phone phone = getPhone(subId);
2598 if (phone != null) {
2599 return phone.getServiceState().getDataNetworkType();
2600 } else {
2601 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2602 }
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
2607
2608 /**
Wink Saville36469e72014-06-11 15:17:00 -07002609 * Returns the Voice network type for a subId
2610 */
2611 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002612 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002614 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002615 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2616 }
2617
Malcolm Chend965c8b2018-02-28 15:00:40 -08002618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 final Phone phone = getPhone(subId);
2621 if (phone != null) {
2622 return phone.getServiceState().getVoiceNetworkType();
2623 } else {
2624 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 }
2630
2631 /**
2632 * @return true if a ICC card is present
2633 */
2634 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002635 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002636 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2637 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002638 }
2639
2640 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002641 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002642 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002643 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002644 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 final Phone phone = PhoneFactory.getPhone(slotIndex);
2648 if (phone != null) {
2649 return phone.getIccCard().hasIccCard();
2650 } else {
2651 return false;
2652 }
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 }
2657
2658 /**
2659 * Return if the current radio is LTE on CDMA. This
2660 * is a tri-state return value as for a period of time
2661 * the mode may be unknown.
2662 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002663 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002665 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002667 @Override
2668 public int getLteOnCdmaMode(String callingPackage) {
2669 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002670 }
2671
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002673 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002674 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002675 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002676 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2677 }
2678
Malcolm Chend965c8b2018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 final Phone phone = getPhone(subId);
2682 if (phone == null) {
2683 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2684 } else {
2685 return phone.getLteOnCdmaMode();
2686 }
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 }
Wink Saville36469e72014-06-11 15:17:00 -07002690 }
2691
2692 public void setPhone(Phone phone) {
2693 mPhone = phone;
2694 }
2695
2696 /**
2697 * {@hide}
2698 * Returns Default subId, 0 in the case of single standby.
2699 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002700 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002701 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002702 }
2703
Shishir Agrawala9f32182016-04-12 12:00:16 -07002704 private int getSlotForDefaultSubscription() {
2705 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2706 }
2707
Wink Savilleb564aae2014-10-23 10:18:09 -07002708 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002709 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002711
Pengquan Meng466e2482018-09-21 15:54:48 -07002712 private boolean isActiveSubscription(int subId) {
2713 return mSubscriptionController.isActiveSubId(subId);
2714 }
2715
Ihab Awadf2177b72013-11-25 13:33:23 -08002716 /**
2717 * @see android.telephony.TelephonyManager.WifiCallingChoices
2718 */
2719 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2723 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2724 getWhenToMakeWifiCallsDefaultPreference());
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
2727 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002728 }
2729
2730 /**
2731 * @see android.telephony.TelephonyManager.WifiCallingChoices
2732 */
2733 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2737 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2738 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2739 } finally {
2740 Binder.restoreCallingIdentity(identity);
2741 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002742 }
2743
Sailesh Nepald1e68152013-12-12 19:08:02 -08002744 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002745 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002746 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002747 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002748
Shishir Agrawal566b7612013-10-28 14:41:00 -07002749 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002750 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2751 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2753 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002755
Malcolm Chend965c8b2018-02-28 15:00:40 -08002756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 if (TextUtils.equals(ISDR_AID, aid)) {
2759 // Only allows LPA to open logical channel to ISD-R.
2760 ComponentInfo bestComponent =
2761 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2762 if (bestComponent == null
2763 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2764 loge("The calling package is not allowed to access ISD-R.");
2765 throw new SecurityException(
2766 "The calling package is not allowed to access ISD-R.");
2767 }
Derek Tan740e1672017-06-27 14:56:27 -07002768 }
Derek Tan740e1672017-06-27 14:56:27 -07002769
Malcolm Chend965c8b2018-02-28 15:00:40 -08002770 if (DBG) {
2771 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2772 }
2773 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2774 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2775 if (DBG) log("iccOpenLogicalChannel: " + response);
2776 return response;
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
2779 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002780 }
2781
2782 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002783 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2785 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002786
Malcolm Chend965c8b2018-02-28 15:00:40 -08002787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2790 if (channel < 0) {
2791 return false;
2792 }
2793 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2794 if (DBG) log("iccCloseLogicalChannel: " + success);
2795 return success;
2796 } finally {
2797 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002798 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002799 }
2800
2801 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002802 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002803 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2805 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002806
Malcolm Chend965c8b2018-02-28 15:00:40 -08002807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 if (DBG) {
2810 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2811 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2812 + p3 + " data=" + data);
2813 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002814
Malcolm Chend965c8b2018-02-28 15:00:40 -08002815 if (channel < 0) {
2816 return "";
2817 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002818
Malcolm Chend965c8b2018-02-28 15:00:40 -08002819 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2820 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2821 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002822
Malcolm Chend965c8b2018-02-28 15:00:40 -08002823 // Append the returned status code to the end of the response payload.
2824 String s = Integer.toHexString(
2825 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2826 if (response.payload != null) {
2827 s = IccUtils.bytesToHexString(response.payload) + s;
2828 }
2829 return s;
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002832 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002833 }
Jake Hambye994d462014-02-03 13:10:13 -08002834
Evan Charltonc66da362014-05-16 14:06:40 -07002835 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002836 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2837 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2839 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002840 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002841
Malcolm Chend965c8b2018-02-28 15:00:40 -08002842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2845 && TextUtils.equals(ISDR_AID, data)) {
2846 // Only allows LPA to select ISD-R.
2847 ComponentInfo bestComponent =
2848 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2849 if (bestComponent == null
2850 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2851 loge("The calling package is not allowed to select ISD-R.");
2852 throw new SecurityException(
2853 "The calling package is not allowed to select ISD-R.");
2854 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002855 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002856
Malcolm Chend965c8b2018-02-28 15:00:40 -08002857 if (DBG) {
2858 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2859 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2860 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002861
Malcolm Chend965c8b2018-02-28 15:00:40 -08002862 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2863 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2864 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002865
Malcolm Chend965c8b2018-02-28 15:00:40 -08002866 // Append the returned status code to the end of the response payload.
2867 String s = Integer.toHexString(
2868 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2869 if (response.payload != null) {
2870 s = IccUtils.bytesToHexString(response.payload) + s;
2871 }
2872 return s;
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002875 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002876 }
2877
2878 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002879 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002880 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2882 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002883
Malcolm Chend965c8b2018-02-28 15:00:40 -08002884 final long identity = Binder.clearCallingIdentity();
2885 try {
2886 if (DBG) {
2887 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2888 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2889 }
2890
2891 IccIoResult response =
2892 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2893 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2894 subId);
2895
2896 if (DBG) {
2897 log("Exchange SIM_IO [R]" + response);
2898 }
2899
2900 byte[] result = null;
2901 int length = 2;
2902 if (response.payload != null) {
2903 length = 2 + response.payload.length;
2904 result = new byte[length];
2905 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2906 } else {
2907 result = new byte[length];
2908 }
2909
2910 result[length - 1] = (byte) response.sw2;
2911 result[length - 2] = (byte) response.sw1;
2912 return result;
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002915 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002916 }
2917
Nathan Haroldb3014052017-01-25 15:57:32 -08002918 /**
2919 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2920 * on a particular subscription
2921 */
sqianb6e41952018-03-12 14:54:01 -07002922 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2924 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2925 return null;
2926 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002927
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 if (appType != TelephonyManager.APPTYPE_USIM
2931 && appType != TelephonyManager.APPTYPE_SIM) {
2932 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2933 return null;
2934 }
2935 Object response = sendRequest(
2936 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2937 if (response instanceof String[]) {
2938 return (String[]) response;
2939 }
2940 // Response is an Exception of some kind,
2941 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08002942 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08002943 } finally {
2944 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002945 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002946 }
2947
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002948 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002949 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2951 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002952
Malcolm Chend965c8b2018-02-28 15:00:40 -08002953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2956 if (response.payload == null) {
2957 return "";
2958 }
Evan Charltonc66da362014-05-16 14:06:40 -07002959
Malcolm Chend965c8b2018-02-28 15:00:40 -08002960 // Append the returned status code to the end of the response payload.
2961 String s = Integer.toHexString(
2962 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2963 s = IccUtils.bytesToHexString(response.payload) + s;
2964 return s;
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
Evan Charltonc66da362014-05-16 14:06:40 -07002968 }
2969
Jake Hambye994d462014-02-03 13:10:13 -08002970 /**
2971 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2972 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2973 *
2974 * @param itemID the ID of the item to read
2975 * @return the NV item as a String, or null on error.
2976 */
2977 @Override
2978 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07002979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2981 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002982
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07002986 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002987 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2988 return value;
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
Jake Hambye994d462014-02-03 13:10:13 -08002992 }
2993
2994 /**
2995 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2996 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2997 *
2998 * @param itemID the ID of the item to read
2999 * @param itemValue the value to write, as a String
3000 * @return true on success; false on any failure
3001 */
3002 @Override
3003 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003004 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3006 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003007
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3011 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003012 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003013 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3014 return success;
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
Jake Hambye994d462014-02-03 13:10:13 -08003018 }
3019
3020 /**
3021 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3022 * Used for device configuration by some CDMA operators.
3023 *
3024 * @param preferredRoamingList byte array containing the new PRL
3025 * @return true on success; false on any failure
3026 */
3027 @Override
3028 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3030 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003031
3032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3035 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3036 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3037 return success;
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
Jake Hambye994d462014-02-03 13:10:13 -08003041 }
3042
3043 /**
3044 * Perform the specified type of NV config reset.
3045 * Used for device configuration by some CDMA operators.
3046 *
3047 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3048 * @return true on success; false on any failure
3049 */
3050 @Override
3051 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3053 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003054
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 if (DBG) log("nvResetConfig: type " + resetType);
3058 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3059 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3060 return success;
3061 } finally {
3062 Binder.restoreCallingIdentity(identity);
3063 }
Jake Hambye994d462014-02-03 13:10:13 -08003064 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003065
Svet Ganovb320e182015-04-16 12:30:10 -07003066 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003068 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003069 return new String[0];
3070 }
3071
Malcolm Chend965c8b2018-02-28 15:00:40 -08003072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 return mPhone.getPcscfAddress(apnType);
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
Wink Saville36469e72014-06-11 15:17:00 -07003078 }
3079
Brad Ebinger51f743a2017-01-23 13:50:20 -08003080 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003081 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3082 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003083 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003084 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003085 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003086
3087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 PhoneFactory.getImsResolver().enableIms(slotId);
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
3092 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003093 }
3094
3095 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003096 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3097 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003098 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003099 public void disableIms(int slotId) {
3100 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003101
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 PhoneFactory.getImsResolver().disableIms(slotId);
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003108 }
3109
3110 /**
3111 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3112 * feature or {@link null} if the service is not available. If the feature is available, the
3113 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3114 */
3115 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003116 IImsServiceFeatureCallback callback) {
3117 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003118
3119 final long identity = Binder.clearCallingIdentity();
3120 try {
3121 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003125 }
3126
3127 /**
3128 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3129 * feature during emergency calling or {@link null} if the service is not available. If the
3130 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3131 * listener for feature updates.
3132 */
3133 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3134 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003135
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
3141 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003142 }
3143
Brad Ebinger5f64b052017-12-14 14:26:15 -08003144 /**
3145 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3146 * specified.
3147 */
3148 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3149 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003150
3151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003157 }
3158
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003159 /**
3160 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3161 * specified.
3162 */
3163 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3164 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003165
3166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003172 }
3173
Brad Ebinger884c07b2018-02-15 16:17:40 -08003174 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003175 * Sets the ImsService Package Name that Telephony will bind to.
3176 *
3177 * @param slotId the slot ID that the ImsService should bind for.
3178 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3179 * ImsService is the device default ImsService.
3180 * @param packageName The package name of the application that contains the ImsService to bind
3181 * to.
3182 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3183 * @hide
3184 */
3185 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003186 int[] subIds = SubscriptionManager.getSubId(slotId);
3187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3188 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3189 "setImsService");
3190
Malcolm Chend965c8b2018-02-28 15:00:40 -08003191 final long identity = Binder.clearCallingIdentity();
3192 try {
3193 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3194 isCarrierImsService, packageName);
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
3197 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003198 }
3199
3200 /**
3201 * Return the ImsService configuration.
3202 *
3203 * @param slotId The slot that the ImsService is associated with.
3204 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3205 * the device default.
3206 * @return the package name of the ImsService configuration.
3207 */
3208 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003209 int[] subIds = SubscriptionManager.getSubId(slotId);
3210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3211 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3212 "getImsService");
3213
Malcolm Chend965c8b2018-02-28 15:00:40 -08003214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3217 isCarrierImsService);
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003221 }
3222
Wink Saville36469e72014-06-11 15:17:00 -07003223 public void setImsRegistrationState(boolean registered) {
3224 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003225
3226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 mPhone.setImsRegistrationState(registered);
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
Wink Saville36469e72014-06-11 15:17:00 -07003232 }
3233
3234 /**
Stuart Scott54788802015-03-30 13:18:01 -07003235 * Set the network selection mode to automatic.
3236 *
3237 */
3238 @Override
3239 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3241 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003242
Pengquan Meng466e2482018-09-21 15:54:48 -07003243 if (!isActiveSubscription(subId)) {
3244 return;
3245 }
3246
Malcolm Chend965c8b2018-02-28 15:00:40 -08003247 final long identity = Binder.clearCallingIdentity();
3248 try {
3249 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3250 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
Stuart Scott54788802015-03-30 13:18:01 -07003254 }
3255
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003256 /**
3257 * Ask the radio to connect to the input network and change selection mode to manual.
3258 *
3259 * @param subId the id of the subscription.
3260 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3261 * the operator to attach to.
3262 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3263 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3264 * normal network selection next time.
3265 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003266 */
3267 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003268 public boolean setNetworkSelectionModeManual(
3269 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3271 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003272
3273 if (!isActiveSubscription(subId)) {
3274 return false;
3275 }
3276
Malcolm Chend965c8b2018-02-28 15:00:40 -08003277 final long identity = Binder.clearCallingIdentity();
3278 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003279 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003280 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003281 if (DBG) {
3282 log("setNetworkSelectionModeManual: subId: " + subId
3283 + " operator: " + operatorInfo);
3284 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003285 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003289 }
3290
3291 /**
3292 * Scans for available networks.
3293 */
3294 @Override
3295 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3297 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003298
Pengquan Meng0c05b502018-09-06 09:59:22 -07003299 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003300 try {
3301 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003302 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003303 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003304 } finally {
3305 Binder.restoreCallingIdentity(identity);
3306 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003307 }
3308
3309 /**
yinxub1bed742017-04-17 11:45:04 -07003310 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003311 *
yinxub1bed742017-04-17 11:45:04 -07003312 * @param subId id of the subscription
3313 * @param request contains the radio access networks with bands/channels to scan
3314 * @param messenger callback messenger for scan results or errors
3315 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003316 * @return the id of the requested scan which can be used to stop the scan.
3317 */
3318 @Override
3319 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3320 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3322 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003323
3324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 return mNetworkScanRequestTracker.startNetworkScan(
3327 request, messenger, binder, getPhone(subId));
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
3330 }
yinxu504e1392017-04-12 16:03:22 -07003331 }
3332
3333 /**
3334 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003335 *
3336 * @param subId id of the subscription
3337 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003338 */
3339 @Override
3340 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3342 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003343
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
yinxu504e1392017-04-12 16:03:22 -07003350 }
3351
3352 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003353 * Get the calculated preferred network type.
3354 * Used for debugging incorrect network type.
3355 *
3356 * @return the preferred network type, defined in RILConstants.java.
3357 */
3358 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003359 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003361 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003362 return RILConstants.PREFERRED_NETWORK_MODE;
3363 }
3364
Malcolm Chend965c8b2018-02-28 15:00:40 -08003365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 // FIXME: need to get SubId from somewhere.
3368 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
Junda Liu84d15a22014-07-02 11:21:04 -07003372 }
3373
3374 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003375 * Get the preferred network type.
3376 * Used for device configuration by some CDMA operators.
3377 *
3378 * @return the preferred network type, defined in RILConstants.java.
3379 */
3380 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003381 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3383 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003384
3385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 if (DBG) log("getPreferredNetworkType");
3388 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3389 int networkType = (result != null ? result[0] : -1);
3390 if (DBG) log("getPreferredNetworkType: " + networkType);
3391 return networkType;
3392 } finally {
3393 Binder.restoreCallingIdentity(identity);
3394 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003395 }
3396
3397 /**
3398 * Set the preferred network type.
3399 * Used for device configuration by some CDMA operators.
3400 *
3401 * @param networkType the preferred network type, defined in RILConstants.java.
3402 * @return true on success; false on any failure.
3403 */
3404 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003405 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3407 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003408
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3412 Boolean success = (Boolean) sendRequest(
3413 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3414 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3415 if (success) {
3416 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3417 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3418 }
3419 return success;
3420 } finally {
3421 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003422 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003423 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003424
3425 /**
Junda Liu475951f2014-11-07 16:45:03 -08003426 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3427 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3428 * tethering.
3429 *
3430 * @return 0: Not required. 1: required. 2: Not set.
3431 * @hide
3432 */
3433 @Override
3434 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003435 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003436
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3440 Settings.Global.TETHER_DUN_REQUIRED, 2);
3441 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3442 // config_tether_apndata.
3443 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3444 dunRequired = 1;
3445 }
3446 return dunRequired;
3447 } finally {
3448 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003449 }
Junda Liu475951f2014-11-07 16:45:03 -08003450 }
3451
3452 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003453 * Set mobile data enabled
3454 * Used by the user through settings etc to turn on/off mobile data
3455 *
3456 * @param enable {@code true} turn turn data on, else {@code false}
3457 */
3458 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003459 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3461 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003462
3463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 int phoneId = mSubscriptionController.getPhoneId(subId);
3466 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3467 Phone phone = PhoneFactory.getPhone(phoneId);
3468 if (phone != null) {
3469 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3470 phone.setUserDataEnabled(enable);
3471 } else {
3472 loge("setUserDataEnabled: no phone for subId=" + subId);
3473 }
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003476 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003477 }
3478
3479 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003480 * Get the user enabled state of Mobile Data.
3481 *
3482 * TODO: remove and use isUserDataEnabled.
3483 * This can't be removed now because some vendor codes
3484 * calls through ITelephony directly while they should
3485 * use TelephonyManager.
3486 *
3487 * @return true on enabled
3488 */
3489 @Override
3490 public boolean getDataEnabled(int subId) {
3491 return isUserDataEnabled(subId);
3492 }
3493
3494 /**
3495 * Get whether mobile data is enabled per user setting.
3496 *
3497 * There are other factors deciding whether mobile data is actually enabled, but they are
3498 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003499 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003500 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003501 *
3502 * @return {@code true} if data is enabled else {@code false}
3503 */
3504 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003505 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003506 try {
3507 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3508 null);
3509 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3511 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003512 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003513
3514 final long identity = Binder.clearCallingIdentity();
3515 try {
3516 int phoneId = mSubscriptionController.getPhoneId(subId);
3517 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3518 Phone phone = PhoneFactory.getPhone(phoneId);
3519 if (phone != null) {
3520 boolean retVal = phone.isUserDataEnabled();
3521 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3522 return retVal;
3523 } else {
3524 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3525 return false;
3526 }
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003529 }
3530 }
3531
3532 /**
3533 * Get whether mobile data is enabled.
3534 *
3535 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3536 * whether mobile data is actually enabled.
3537 *
3538 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3539 *
3540 * @return {@code true} if data is enabled else {@code false}
3541 */
3542 @Override
3543 public boolean isDataEnabled(int subId) {
3544 try {
3545 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3546 null);
3547 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3549 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003550 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003551
3552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 int phoneId = mSubscriptionController.getPhoneId(subId);
3555 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3556 Phone phone = PhoneFactory.getPhone(phoneId);
3557 if (phone != null) {
3558 boolean retVal = phone.isDataEnabled();
3559 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3560 return retVal;
3561 } else {
3562 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3563 return false;
3564 }
3565 } finally {
3566 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003567 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003568 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003569
3570 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003571 public int getCarrierPrivilegeStatus(int subId) {
3572 final Phone phone = getPhone(subId);
3573 if (phone == null) {
3574 loge("getCarrierPrivilegeStatus: Invalid subId");
3575 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3576 }
3577 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003578 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003579 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003580 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3581 }
3582 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003583 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003584 }
Junda Liu29340342014-07-10 15:23:27 -07003585
3586 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003587 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3588 final Phone phone = getPhone(subId);
3589 if (phone == null) {
3590 loge("getCarrierPrivilegeStatus: Invalid subId");
3591 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3592 }
3593 UiccProfile profile =
3594 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3595 if (profile == null) {
3596 loge("getCarrierPrivilegeStatus: No UICC");
3597 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3598 }
3599 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3600 }
3601
3602 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003603 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003604 if (TextUtils.isEmpty(pkgName))
3605 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003606 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003607 if (card == null) {
3608 loge("checkCarrierPrivilegesForPackage: No UICC");
3609 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3610 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003611 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3612 }
3613
3614 @Override
3615 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003616 if (TextUtils.isEmpty(pkgName))
3617 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003618 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3619 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3620 UiccCard card = UiccController.getInstance().getUiccCard(i);
3621 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003622 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003623 continue;
3624 }
3625
3626 result = card.getCarrierPrivilegeStatus(
3627 mPhone.getContext().getPackageManager(), pkgName);
3628 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3629 break;
3630 }
3631 }
3632
3633 return result;
Junda Liu29340342014-07-10 15:23:27 -07003634 }
Derek Tan89e89d42014-07-08 17:00:10 -07003635
3636 @Override
Junda Liue64de782015-04-16 17:19:16 -07003637 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3638 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3639 loge("phoneId " + phoneId + " is not valid.");
3640 return null;
3641 }
3642 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003643 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003644 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003645 return null ;
3646 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003647 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003648 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003649 }
3650
Amith Yamasani6e118872016-02-19 12:53:51 -08003651 @Override
3652 public List<String> getPackagesWithCarrierPrivileges() {
3653 PackageManager pm = mPhone.getContext().getPackageManager();
3654 List<String> privilegedPackages = new ArrayList<>();
3655 List<PackageInfo> packages = null;
3656 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3657 UiccCard card = UiccController.getInstance().getUiccCard(i);
3658 if (card == null) {
3659 // No UICC in that slot.
3660 continue;
3661 }
3662 if (card.hasCarrierPrivilegeRules()) {
3663 if (packages == null) {
3664 // Only check packages in user 0 for now
3665 packages = pm.getInstalledPackagesAsUser(
3666 PackageManager.MATCH_DISABLED_COMPONENTS
3667 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3668 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3669 }
3670 for (int p = packages.size() - 1; p >= 0; p--) {
3671 PackageInfo pkgInfo = packages.get(p);
3672 if (pkgInfo != null && pkgInfo.packageName != null
3673 && card.getCarrierPrivilegeStatus(pkgInfo)
3674 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3675 privilegedPackages.add(pkgInfo.packageName);
3676 }
3677 }
3678 }
3679 }
3680 return privilegedPackages;
3681 }
3682
Wink Savilleb564aae2014-10-23 10:18:09 -07003683 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003684 final Phone phone = getPhone(subId);
3685 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003686 if (card == null) {
3687 loge("getIccId: No UICC");
3688 return null;
3689 }
3690 String iccId = card.getIccId();
3691 if (TextUtils.isEmpty(iccId)) {
3692 loge("getIccId: ICC ID is null or empty.");
3693 return null;
3694 }
3695 return iccId;
3696 }
3697
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003698 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003699 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3700 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003701 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3702 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003703
Malcolm Chend965c8b2018-02-28 15:00:40 -08003704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 final String iccId = getIccId(subId);
3707 final Phone phone = getPhone(subId);
3708 if (phone == null) {
3709 return false;
3710 }
3711 final String subscriberId = phone.getSubscriberId();
3712
3713 if (DBG_MERGE) {
3714 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3715 + subscriberId + " to " + number);
3716 }
3717
3718 if (TextUtils.isEmpty(iccId)) {
3719 return false;
3720 }
3721
3722 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3723
3724 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3725 if (alphaTag == null) {
3726 editor.remove(alphaTagPrefKey);
3727 } else {
3728 editor.putString(alphaTagPrefKey, alphaTag);
3729 }
3730
3731 // Record both the line number and IMSI for this ICCID, since we need to
3732 // track all merged IMSIs based on line number
3733 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3734 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3735 if (number == null) {
3736 editor.remove(numberPrefKey);
3737 editor.remove(subscriberPrefKey);
3738 } else {
3739 editor.putString(numberPrefKey, number);
3740 editor.putString(subscriberPrefKey, subscriberId);
3741 }
3742
3743 editor.commit();
3744 return true;
3745 } finally {
3746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003747 }
Derek Tan7226c842014-07-02 17:42:23 -07003748 }
3749
3750 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003751 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003752 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003754 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003755 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003756 return null;
3757 }
Derek Tan97ebb422014-09-05 16:55:38 -07003758
Malcolm Chend965c8b2018-02-28 15:00:40 -08003759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 String iccId = getIccId(subId);
3762 if (iccId != null) {
3763 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3764 if (DBG_MERGE) {
3765 log("getLine1NumberForDisplay returning "
3766 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3767 }
3768 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003769 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003770 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3771 return null;
3772 } finally {
3773 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003774 }
Derek Tan7226c842014-07-02 17:42:23 -07003775 }
3776
3777 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003778 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003780 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003781 return null;
3782 }
Derek Tan97ebb422014-09-05 16:55:38 -07003783
Malcolm Chend965c8b2018-02-28 15:00:40 -08003784 final long identity = Binder.clearCallingIdentity();
3785 try {
3786 String iccId = getIccId(subId);
3787 if (iccId != null) {
3788 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3789 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3790 }
3791 return null;
3792 } finally {
3793 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003794 }
Derek Tan7226c842014-07-02 17:42:23 -07003795 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003796
3797 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003798 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003799 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3800 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003802 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3803 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003804 return null;
3805 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003806
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003807 final long identity = Binder.clearCallingIdentity();
3808 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003809 final Context context = mPhone.getContext();
3810 final TelephonyManager tele = TelephonyManager.from(context);
3811 final SubscriptionManager sub = SubscriptionManager.from(context);
3812
3813 // Figure out what subscribers are currently active
3814 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3815 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3816 // the process, where TelephonyManager was instantiated.
3817 // Otherwise AppOps check will fail.
3818
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003819 final int[] subIds = sub.getActiveSubscriptionIdList();
3820 for (int subId : subIds) {
3821 activeSubscriberIds.add(tele.getSubscriberId(subId));
3822 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003823
3824 // First pass, find a number override for an active subscriber
3825 String mergeNumber = null;
3826 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3827 for (String key : prefs.keySet()) {
3828 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3829 final String subscriberId = (String) prefs.get(key);
3830 if (activeSubscriberIds.contains(subscriberId)) {
3831 final String iccId = key.substring(
3832 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3833 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3834 mergeNumber = (String) prefs.get(numberKey);
3835 if (DBG_MERGE) {
3836 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3837 + " for active subscriber " + subscriberId);
3838 }
3839 if (!TextUtils.isEmpty(mergeNumber)) {
3840 break;
3841 }
3842 }
3843 }
3844 }
3845
3846 // Shortcut when no active merged subscribers
3847 if (TextUtils.isEmpty(mergeNumber)) {
3848 return null;
3849 }
3850
3851 // Second pass, find all subscribers under that line override
3852 final ArraySet<String> result = new ArraySet<>();
3853 for (String key : prefs.keySet()) {
3854 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3855 final String number = (String) prefs.get(key);
3856 if (mergeNumber.equals(number)) {
3857 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3858 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3859 final String subscriberId = (String) prefs.get(subscriberKey);
3860 if (!TextUtils.isEmpty(subscriberId)) {
3861 result.add(subscriberId);
3862 }
3863 }
3864 }
3865 }
3866
3867 final String[] resultArray = result.toArray(new String[result.size()]);
3868 Arrays.sort(resultArray);
3869 if (DBG_MERGE) {
3870 Slog.d(LOG_TAG,
3871 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3872 }
3873 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003874 } finally {
3875 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003876 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003877 }
3878
3879 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003880 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003881 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3882 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003883
3884 final long identity = Binder.clearCallingIdentity();
3885 try {
3886 final Phone phone = getPhone(subId);
3887 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3888 } finally {
3889 Binder.restoreCallingIdentity(identity);
3890 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003891 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003892
3893 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003894 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003895 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3896 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003897 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003898
3899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 final Phone phone = getPhone(subId);
3902 if (phone == null) {
3903 return false;
3904 }
3905 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3906 cdmaNonRoamingList);
3907 } finally {
3908 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003909 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003910 }
3911
3912 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003913 @Deprecated
3914 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3915 enforceModifyPermission();
3916
3917 int returnValue = 0;
3918 try {
vagdevie435a3e2018-08-15 16:01:53 -07003919 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003920 if(result.exception == null) {
3921 if (result.result != null) {
3922 byte[] responseData = (byte[])(result.result);
3923 if(responseData.length > oemResp.length) {
3924 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3925 responseData.length + "bytes. Buffer Size is " +
3926 oemResp.length + "bytes.");
3927 }
3928 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3929 returnValue = responseData.length;
3930 }
3931 } else {
3932 CommandException ex = (CommandException) result.exception;
3933 returnValue = ex.getCommandError().ordinal();
3934 if(returnValue > 0) returnValue *= -1;
3935 }
3936 } catch (RuntimeException e) {
3937 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3938 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3939 if(returnValue > 0) returnValue *= -1;
3940 }
3941
3942 return returnValue;
3943 }
3944
3945 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003946 public void setRadioCapability(RadioAccessFamily[] rafs) {
3947 try {
3948 ProxyController.getInstance().setRadioCapability(rafs);
3949 } catch (RuntimeException e) {
3950 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3951 }
3952 }
3953
3954 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003955 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003956 Phone phone = PhoneFactory.getPhone(phoneId);
3957 if (phone == null) {
3958 return RadioAccessFamily.RAF_UNKNOWN;
3959 }
3960 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003962 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003963 return RadioAccessFamily.RAF_UNKNOWN;
3964 }
3965
Malcolm Chend965c8b2018-02-28 15:00:40 -08003966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
3971 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003972 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003973
3974 @Override
3975 public void enableVideoCalling(boolean enable) {
3976 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003977
3978 final long identity = Binder.clearCallingIdentity();
3979 try {
3980 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
3981 } finally {
3982 Binder.restoreCallingIdentity(identity);
3983 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003984 }
3985
3986 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003987 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3989 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3990 return false;
3991 }
Svet Ganovb320e182015-04-16 12:30:10 -07003992
Malcolm Chend965c8b2018-02-28 15:00:40 -08003993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 // Check the user preference and the system-level IMS setting. Even if the user has
3996 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3997 // In the long run, we may instead need to check if there exists a connection service
3998 // which can support video calling.
3999 ImsManager imsManager =
4000 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4001 return imsManager.isVtEnabledByPlatform()
4002 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4003 && imsManager.isVtEnabledByUser();
4004 } finally {
4005 Binder.restoreCallingIdentity(identity);
4006 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004007 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004008
Andrew Leea1239f22015-03-02 17:44:07 -08004009 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004010 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4012 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4013 return false;
4014 }
4015
4016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 CarrierConfigManager configManager =
4019 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4020 return configManager.getConfigForSubId(mPhone.getSubId())
4021 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
4024 }
Andrew Leea1239f22015-03-02 17:44:07 -08004025 }
4026
4027 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004028 public boolean isWorldPhone(int subId, String callingPackage) {
4029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4030 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4031 return false;
4032 }
4033
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 CarrierConfigManager configManager =
4037 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4038 return configManager.getConfigForSubId(mPhone.getSubId())
4039 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
Andrew Leea1239f22015-03-02 17:44:07 -08004043 }
4044
Andrew Lee9431b832015-03-09 18:46:45 -07004045 @Override
4046 public boolean isTtyModeSupported() {
4047 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004048 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004049 }
4050
4051 @Override
4052 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
Andrew Lee9431b832015-03-09 18:46:45 -07004059 }
4060
Hall Liu98187582018-01-22 19:15:32 -08004061 public boolean isRttSupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004062 final long identity = Binder.clearCallingIdentity();
4063 try {
4064 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4065 mPhone.getSubId()).getBoolean(
4066 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4067 boolean isDeviceSupported =
4068 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4069 return isCarrierSupported && isDeviceSupported;
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
Hall Liu98187582018-01-22 19:15:32 -08004073 }
4074
Hall Liu3ad5f012018-04-06 16:23:39 -07004075 public boolean isRttEnabled() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004076 final long identity = Binder.clearCallingIdentity();
4077 try {
4078 return isRttSupported() && Settings.Secure.getInt(
4079 mPhone.getContext().getContentResolver(),
4080 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
4083 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004084 }
4085
Sanket Padawe7310cc72015-01-14 09:53:20 -08004086 /**
4087 * Returns the unique device ID of phone, for example, the IMEI for
4088 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4089 *
4090 * <p>Requires Permission:
4091 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4092 */
4093 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004094 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004095 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004096 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004097 return null;
4098 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004099 int subId = phone.getSubId();
4100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4101 mApp, subId, callingPackage, "getDeviceId")) {
4102 return null;
4103 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004104
4105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 return phone.getDeviceId();
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004111 }
4112
Ping Sunc67b7c22016-03-02 19:16:45 +08004113 /**
4114 * {@hide}
4115 * Returns the IMS Registration Status on a particular subid
4116 *
4117 * @param subId
4118 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004119 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004120 Phone phone = getPhone(subId);
4121 if (phone != null) {
4122 return phone.isImsRegistered();
4123 } else {
4124 return false;
4125 }
4126 }
4127
Santos Cordon7a1885b2015-02-03 11:15:19 -08004128 @Override
4129 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4133 } finally {
4134 Binder.restoreCallingIdentity(identity);
4135 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004136 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004137
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004138 /**
4139 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004140 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004141 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 Phone phone = getPhone(subId);
4145 if (phone != null) {
4146 return phone.isWifiCallingEnabled();
4147 } else {
4148 return false;
4149 }
4150 } finally {
4151 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004152 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004153 }
4154
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004155 /**
4156 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004157 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004158 public boolean isVolteAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 Phone phone = getPhone(subId);
4162 if (phone != null) {
4163 return phone.isVolteEnabled();
4164 } else {
4165 return false;
4166 }
4167 } finally {
4168 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004169 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004170 }
Svet Ganovb320e182015-04-16 12:30:10 -07004171
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004172 /**
4173 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004174 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004175 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 Phone phone = getPhone(subId);
4179 if (phone != null) {
4180 return phone.isVideoEnabled();
4181 } else {
4182 return false;
4183 }
4184 } finally {
4185 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004186 }
4187 }
4188
4189 /**
4190 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4191 * defined in {@link ImsRegistrationImplBase}.
4192 */
4193 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 Phone phone = getPhone(subId);
4197 if (phone != null) {
4198 return phone.getImsRegistrationTech();
4199 } else {
4200 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4201 }
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004204 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004205 }
4206
Stuart Scott8eef64f2015-04-08 15:13:54 -07004207 @Override
4208 public void factoryReset(int subId) {
4209 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004210 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4211 return;
4212 }
4213
Svet Ganovcc087f82015-05-12 20:35:54 -07004214 final long identity = Binder.clearCallingIdentity();
4215 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004216 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4217 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004218 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004219 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004220 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4221 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004222 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004223 }
4224 } finally {
4225 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004226 }
4227 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004228
4229 @Override
4230 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 // We query all subscriptions instead of just the active ones, because
4234 // this might be called early on in the provisioning flow when the
4235 // subscriptions potentially aren't active yet.
4236 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4237 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004238 return null;
4239 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004240
Malcolm Chend965c8b2018-02-28 15:00:40 -08004241 // This function may be called very early, say, from the setup wizard, at
4242 // which point we won't have a default subscription set. If that's the case
4243 // we just choose the first, which will be valid in "most cases".
4244 final int defaultSubId = getDefaultSubscription();
4245 SubscriptionInfo info = null;
4246 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4247 info = slist.get(0);
4248 } else {
4249 for (SubscriptionInfo item : slist) {
4250 if (item.getSubscriptionId() == defaultSubId) {
4251 info = item;
4252 break;
4253 }
4254 }
4255
4256 if (info == null) {
4257 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004258 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004259 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004260
Malcolm Chend965c8b2018-02-28 15:00:40 -08004261 // Try and fetch the locale from the carrier properties or from the SIM language
4262 // preferences (EF-PL and EF-LI)...
4263 final int mcc = info.getMcc();
4264 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4265 String simLanguage = null;
4266 if (defaultPhone != null) {
4267 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4268 if (localeFromDefaultSim != null) {
4269 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4270 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4271 return localeFromDefaultSim.toLanguageTag();
4272 } else {
4273 simLanguage = localeFromDefaultSim.getLanguage();
4274 }
4275 }
4276 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004277
Malcolm Chend965c8b2018-02-28 15:00:40 -08004278 // The SIM language preferences only store a language (e.g. fr = French), not an
4279 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4280 // the SIM and carrier preferences does not include a country we add the country
4281 // determined from the SIM MCC to provide an exact locale.
4282 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4283 simLanguage);
4284 if (mccLocale != null) {
4285 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4286 return mccLocale.toLanguageTag();
4287 }
4288
4289 if (DBG) log("No locale found - returning null");
4290 return null;
4291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004294 }
4295
4296 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004297 return mSubscriptionController.getAllSubInfoList(
4298 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004299 }
4300
Malcolm Chend965c8b2018-02-28 15:00:40 -08004301 /**
4302 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4303 */
4304 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4305 return mSubscriptionController.getActiveSubscriptionInfoList(
4306 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004307 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004308
Chenjie Yu1ba97252018-01-11 18:16:20 -08004309 private final ModemActivityInfo mLastModemActivityInfo =
4310 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4311
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004312 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004313 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4314 * representing the state of the modem.
4315 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004316 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4317 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004318 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004319 */
4320 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004321 public void requestModemActivityInfo(ResultReceiver result) {
4322 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004323 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004324
4325 final long identity = Binder.clearCallingIdentity();
4326 try {
4327 ModemActivityInfo ret = null;
4328 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004329 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4330 CMD_GET_MODEM_ACTIVITY_INFO,
4331 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004332 if (isModemActivityInfoValid(info)) {
4333 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4334 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4335 mergedTxTimeMs[i] =
4336 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4337 }
4338 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4339 mLastModemActivityInfo.setSleepTimeMillis(
4340 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4341 mLastModemActivityInfo.setIdleTimeMillis(
4342 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4343 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4344 mLastModemActivityInfo.setRxTimeMillis(
4345 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4346 mLastModemActivityInfo.setEnergyUsed(
4347 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004348 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004349 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4350 mLastModemActivityInfo.getSleepTimeMillis(),
4351 mLastModemActivityInfo.getIdleTimeMillis(),
4352 mLastModemActivityInfo.getTxTimeMillis(),
4353 mLastModemActivityInfo.getRxTimeMillis(),
4354 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004355 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004356 Bundle bundle = new Bundle();
4357 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4358 result.send(0, bundle);
4359 } finally {
4360 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004361 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004362 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004363
Siddharth Rayf5d29552018-06-17 15:02:38 -07004364 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4365 // less than total activity duration.
4366 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4367 if (info == null) {
4368 return false;
4369 }
4370 int activityDurationMs =
4371 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4372 int totalTxTimeMs = 0;
4373 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4374 totalTxTimeMs += info.getTxTimeMillis()[i];
4375 }
4376 return (info.isValid()
4377 && (info.getSleepTimeMillis() <= activityDurationMs)
4378 && (info.getIdleTimeMillis() <= activityDurationMs)
4379 && (info.getRxTimeMillis() <= activityDurationMs)
4380 && (totalTxTimeMs <= activityDurationMs));
4381 }
4382
Jack Yu85bd38a2015-11-09 11:34:32 -08004383 /**
4384 * {@hide}
4385 * Returns the service state information on specified subscription.
4386 */
4387 @Override
4388 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004390 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004391 return null;
4392 }
4393
Malcolm Chend965c8b2018-02-28 15:00:40 -08004394 final long identity = Binder.clearCallingIdentity();
4395 try {
4396 final Phone phone = getPhone(subId);
4397 if (phone == null) {
4398 return null;
4399 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004400
Malcolm Chend965c8b2018-02-28 15:00:40 -08004401 return phone.getServiceState();
4402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004405 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004406
4407 /**
4408 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4409 *
4410 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4411 * voicemail ringtone.
4412 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4413 * PhoneAccount.
4414 */
4415 @Override
4416 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004417 final long identity = Binder.clearCallingIdentity();
4418 try {
4419 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4420 if (phone == null) {
4421 phone = mPhone;
4422 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004423
Malcolm Chend965c8b2018-02-28 15:00:40 -08004424 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4425 } finally {
4426 Binder.restoreCallingIdentity(identity);
4427 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004428 }
4429
4430 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004431 * Sets the per-account voicemail ringtone.
4432 *
4433 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4434 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4435 *
4436 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4437 * voicemail ringtone.
4438 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4439 * PhoneAccount.
4440 */
4441 @Override
4442 public void setVoicemailRingtoneUri(String callingPackage,
4443 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4445 if (!TextUtils.equals(callingPackage,
4446 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4448 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4449 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004450 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004451
4452 final long identity = Binder.clearCallingIdentity();
4453 try {
4454 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4455 if (phone == null) {
4456 phone = mPhone;
4457 }
4458 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4459 } finally {
4460 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004461 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004462 }
4463
4464 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004465 * Returns whether vibration is set for voicemail notification in Phone settings.
4466 *
4467 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4468 * voicemail vibration setting.
4469 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4470 */
4471 @Override
4472 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004473 final long identity = Binder.clearCallingIdentity();
4474 try {
4475 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4476 if (phone == null) {
4477 phone = mPhone;
4478 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004479
Malcolm Chend965c8b2018-02-28 15:00:40 -08004480 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004484 }
4485
Youhan Wange64578a2016-05-02 15:32:42 -07004486 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004487 * Sets the per-account voicemail vibration.
4488 *
4489 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4490 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4491 *
4492 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4493 * voicemail vibration setting.
4494 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4495 * specific PhoneAccount.
4496 */
4497 @Override
4498 public void setVoicemailVibrationEnabled(String callingPackage,
4499 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4501 if (!TextUtils.equals(callingPackage,
4502 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4504 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4505 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004506 }
4507
Malcolm Chend965c8b2018-02-28 15:00:40 -08004508 final long identity = Binder.clearCallingIdentity();
4509 try {
4510 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4511 if (phone == null) {
4512 phone = mPhone;
4513 }
4514 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4515 } finally {
4516 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004517 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004518 }
4519
4520 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004521 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4522 *
4523 * @throws SecurityException if the caller does not have the required permission
4524 */
4525 private void enforceReadPrivilegedPermission() {
4526 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4527 null);
4528 }
4529
4530 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004531 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4532 * permission.
4533 *
4534 * @throws SecurityException if the caller does not have the required permission
4535 */
4536 private void enforceSendSmsPermission() {
4537 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4538 }
4539
4540 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004541 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004542 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004543 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004544 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004545 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004546 final long identity = Binder.clearCallingIdentity();
4547 try {
4548 ComponentName componentName =
4549 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4550 if (componentName == null) {
4551 throw new SecurityException(
4552 "Caller not current active visual voicemail package[null]");
4553 }
4554 String vvmPackage = componentName.getPackageName();
4555 if (!callingPackage.equals(vvmPackage)) {
4556 throw new SecurityException("Caller not current active visual voicemail package["
4557 + vvmPackage + "]");
4558 }
4559 } finally {
4560 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004561 }
4562 }
4563
4564 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004565 * Return the application ID for the app type.
4566 *
4567 * @param subId the subscription ID that this request applies to.
4568 * @param appType the uicc app type.
4569 * @return Application ID for specificied app type, or null if no uicc.
4570 */
4571 @Override
4572 public String getAidForAppType(int subId, int appType) {
4573 enforceReadPrivilegedPermission();
4574 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004575
4576 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004577 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004578 if (phone == null) {
4579 return null;
4580 }
4581 String aid = null;
4582 try {
4583 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4584 .getApplicationByType(appType).getAid();
4585 } catch (Exception e) {
4586 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4587 }
4588 return aid;
4589 } finally {
4590 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004591 }
Youhan Wange64578a2016-05-02 15:32:42 -07004592 }
4593
Youhan Wang4001d252016-05-11 10:29:41 -07004594 /**
4595 * Return the Electronic Serial Number.
4596 *
4597 * @param subId the subscription ID that this request applies to.
4598 * @return ESN or null if error.
4599 */
4600 @Override
4601 public String getEsn(int subId) {
4602 enforceReadPrivilegedPermission();
4603 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004604
4605 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004606 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004607 if (phone == null) {
4608 return null;
4609 }
4610 String esn = null;
4611 try {
4612 esn = phone.getEsn();
4613 } catch (Exception e) {
4614 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4615 }
4616 return esn;
4617 } finally {
4618 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004619 }
Youhan Wang4001d252016-05-11 10:29:41 -07004620 }
4621
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004622 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004623 * Return the Preferred Roaming List Version.
4624 *
4625 * @param subId the subscription ID that this request applies to.
4626 * @return PRLVersion or null if error.
4627 */
4628 @Override
4629 public String getCdmaPrlVersion(int subId) {
4630 enforceReadPrivilegedPermission();
4631 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004632
4633 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004634 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004635 if (phone == null) {
4636 return null;
4637 }
4638 String cdmaPrlVersion = null;
4639 try {
4640 cdmaPrlVersion = phone.getCdmaPrlVersion();
4641 } catch (Exception e) {
4642 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4643 }
4644 return cdmaPrlVersion;
4645 } finally {
4646 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004647 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004648 }
4649
4650 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004651 * Get snapshot of Telephony histograms
4652 * @return List of Telephony histograms
4653 * @hide
4654 */
4655 @Override
4656 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4658 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004659
4660 final long identity = Binder.clearCallingIdentity();
4661 try {
4662 return RIL.getTelephonyRILTimingHistograms();
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004666 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004667
4668 /**
4669 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004670 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004671 * Require system privileges. In the future we may add this to carrier APIs.
4672 *
4673 * @return The number of carriers set successfully, should match length of carriers
4674 */
4675 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004676 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004677 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004678 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004679
Meng Wang9b7c4e92017-02-17 11:41:27 -08004680 if (carriers == null) {
4681 throw new NullPointerException("carriers cannot be null");
4682 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004683
Malcolm Chend965c8b2018-02-28 15:00:40 -08004684 final long identity = Binder.clearCallingIdentity();
4685 try {
4686 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004687 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4688 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004689 return retVal[0];
4690 } finally {
4691 Binder.restoreCallingIdentity(identity);
4692 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004693 }
4694
4695 /**
4696 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004697 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004698 * Require system privileges. In the future we may add this to carrier APIs.
4699 *
4700 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4701 * means all carriers are allowed.
4702 */
4703 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004704 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004705 enforceReadPrivilegedPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004706 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004707
4708 final long identity = Binder.clearCallingIdentity();
4709 try {
4710 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004711 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4712 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004713 } finally {
4714 Binder.restoreCallingIdentity(identity);
4715 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004716 }
4717
fionaxu59545b42016-05-25 15:53:37 -07004718 /**
4719 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4720 * @param subId the subscription ID that this action applies to.
4721 * @param enabled control enable or disable metered apns.
4722 * {@hide}
4723 */
4724 @Override
4725 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4726 enforceModifyPermission();
4727 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004728
4729 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004730 if (phone == null) {
4731 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4732 return;
4733 }
4734 try {
4735 phone.carrierActionSetMeteredApnsEnabled(enabled);
4736 } catch (Exception e) {
4737 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004738 } finally {
4739 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004740 }
4741 }
4742
4743 /**
4744 * Action set from carrier signalling broadcast receivers to enable/disable radio
4745 * @param subId the subscription ID that this action applies to.
4746 * @param enabled control enable or disable radio.
4747 * {@hide}
4748 */
4749 @Override
4750 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4751 enforceModifyPermission();
4752 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004753
4754 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004755 if (phone == null) {
4756 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4757 return;
4758 }
4759 try {
4760 phone.carrierActionSetRadioEnabled(enabled);
4761 } catch (Exception e) {
4762 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004763 } finally {
4764 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004765 }
4766 }
4767
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004768 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004769 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4770 * network status based on which carrier apps could apply actions accordingly,
4771 * enable/disable default url handler for example.
4772 *
4773 * @param subId the subscription ID that this action applies to.
4774 * @param report control start/stop reporting the default network status.
4775 * {@hide}
4776 */
4777 @Override
4778 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4779 enforceModifyPermission();
4780 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004781
4782 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004783 if (phone == null) {
4784 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4785 return;
4786 }
4787 try {
4788 phone.carrierActionReportDefaultNetworkStatus(report);
4789 } catch (Exception e) {
4790 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004791 } finally {
4792 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004793 }
4794 }
4795
4796 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004797 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4798 * bug report is being generated.
4799 */
4800 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004801 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004802 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4803 != PackageManager.PERMISSION_GRANTED) {
4804 writer.println("Permission Denial: can't dump Phone from pid="
4805 + Binder.getCallingPid()
4806 + ", uid=" + Binder.getCallingUid()
4807 + "without permission "
4808 + android.Manifest.permission.DUMP);
4809 return;
4810 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004811 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004812 }
Jack Yueb89b242016-06-22 13:27:47 -07004813
Brad Ebingerdac2f002018-04-03 15:17:52 -07004814 @Override
4815 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4816 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4817 throws RemoteException {
4818 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4819 }
4820
Jack Yueb89b242016-06-22 13:27:47 -07004821 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004822 * Get aggregated video call data usage since boot.
4823 *
4824 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4825 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004826 * {@hide}
4827 */
4828 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004829 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004830 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4831 null);
4832
Malcolm Chend965c8b2018-02-28 15:00:40 -08004833 final long identity = Binder.clearCallingIdentity();
4834 try {
4835 // NetworkStatsService keeps tracking the active network interface and identity. It
4836 // records the delta with the corresponding network identity.
4837 // We just return the total video call data usage snapshot since boot.
4838 Phone phone = getPhone(subId);
4839 if (phone != null) {
4840 return phone.getVtDataUsage(perUidStats);
4841 }
4842 return null;
4843 } finally {
4844 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004845 }
Jack Yueb89b242016-06-22 13:27:47 -07004846 }
Jack Yu75ab2952016-07-08 14:29:33 -07004847
4848 /**
4849 * Policy control of data connection. Usually used when data limit is passed.
4850 * @param enabled True if enabling the data, otherwise disabling.
4851 * @param subId Subscription index
4852 * {@hide}
4853 */
4854 @Override
4855 public void setPolicyDataEnabled(boolean enabled, int subId) {
4856 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004857
4858 final long identity = Binder.clearCallingIdentity();
4859 try {
4860 Phone phone = getPhone(subId);
4861 if (phone != null) {
4862 phone.setPolicyDataEnabled(enabled);
4863 }
4864 } finally {
4865 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004866 }
4867 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004868
4869 /**
4870 * Get Client request stats
4871 * @return List of Client Request Stats
4872 * @hide
4873 */
4874 @Override
4875 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004876 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004877 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004878 return null;
4879 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004880 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004881
Malcolm Chend965c8b2018-02-28 15:00:40 -08004882 final long identity = Binder.clearCallingIdentity();
4883 try {
4884 if (phone != null) {
4885 return phone.getClientRequestStats();
4886 }
4887
4888 return null;
4889 } finally {
4890 Binder.restoreCallingIdentity(identity);
4891 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004892 }
4893
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004894 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004895 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004896 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004897 }
Jack Yueb4124c2017-02-16 15:32:43 -08004898
4899 /**
Grace Chen70990072017-03-24 17:21:30 -07004900 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004901 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004902 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004903 * @param state State of SIM (power down, power up, pass through)
4904 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4905 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4906 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004907 *
4908 **/
4909 @Override
Grace Chen70990072017-03-24 17:21:30 -07004910 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004911 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004912 Phone phone = PhoneFactory.getPhone(slotIndex);
4913
vagdevie435a3e2018-08-15 16:01:53 -07004914 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4915
Malcolm Chend965c8b2018-02-28 15:00:40 -08004916 final long identity = Binder.clearCallingIdentity();
4917 try {
4918 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07004919 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004920 }
4921 } finally {
4922 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004923 }
4924 }
Shuo Qiandd210312017-04-12 22:11:33 +00004925
Tyler Gunn65d45c22017-06-05 11:22:26 -07004926 private boolean isUssdApiAllowed(int subId) {
4927 CarrierConfigManager configManager =
4928 (CarrierConfigManager) mPhone.getContext().getSystemService(
4929 Context.CARRIER_CONFIG_SERVICE);
4930 if (configManager == null) {
4931 return false;
4932 }
4933 PersistableBundle pb = configManager.getConfigForSubId(subId);
4934 if (pb == null) {
4935 return false;
4936 }
4937 return pb.getBoolean(
4938 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4939 }
4940
Shuo Qiandd210312017-04-12 22:11:33 +00004941 /**
4942 * Check if phone is in emergency callback mode
4943 * @return true if phone is in emergency callback mode
4944 * @param subId sub id
4945 */
goneil9c5f4872017-12-05 14:07:56 -08004946 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004947 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004948 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004949 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004950
4951 final long identity = Binder.clearCallingIdentity();
4952 try {
4953 if (phone != null) {
4954 return phone.isInEcm();
4955 } else {
4956 return false;
4957 }
4958 } finally {
4959 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004960 }
4961 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004962
4963 /**
4964 * Get the current signal strength information for the given subscription.
4965 * Because this information is not updated when the device is in a low power state
4966 * it should not be relied-upon to be current.
4967 * @param subId Subscription index
4968 * @return the most recent cached signal strength info from the modem
4969 */
4970 @Override
4971 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004972 final long identity = Binder.clearCallingIdentity();
4973 try {
4974 Phone p = getPhone(subId);
4975 if (p == null) {
4976 return null;
4977 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004978
Malcolm Chend965c8b2018-02-28 15:00:40 -08004979 return p.getSignalStrength();
4980 } finally {
4981 Binder.restoreCallingIdentity(identity);
4982 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004983 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004984
Pengquan Meng9140aec2018-08-22 14:49:57 -07004985 /**
chen xu907e5a22018-10-11 13:21:04 -07004986 * Get the current modem radio state for the given slot.
4987 * @param slotIndex slot index.
4988 * @param callingPackage the name of the package making the call.
4989 * @return the current radio power state from the modem
4990 */
4991 @Override
4992 public int getRadioPowerState(int slotIndex, String callingPackage) {
4993 Phone phone = PhoneFactory.getPhone(slotIndex);
4994 if (phone != null) {
4995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4996 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
4997 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
4998 }
4999
5000 final long identity = Binder.clearCallingIdentity();
5001 try {
5002 return phone.getRadioPowerState();
5003 } finally {
5004 Binder.restoreCallingIdentity(identity);
5005 }
5006 }
5007 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5008 }
5009
5010 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005011 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5012 *
5013 * <p>Requires one of the following permissions:
5014 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5015 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5016 * privileges.
5017 *
5018 * @param subId subscription id
5019 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5020 * {@code false}.
5021 */
5022 @Override
5023 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005024 boolean isEnabled = false;
5025 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005026 try {
5027 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005028 null /* message */);
5029 Phone phone = getPhone(subId);
5030 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005031 } catch (Exception e) {
5032 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5033 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005034 } finally {
5035 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005036 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005037 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005038 }
5039
5040
5041 /**
5042 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5043 *
5044 * <p> Requires permission:
5045 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5046 * privileges.
5047 *
5048 * @param subId subscription id
5049 * @param isEnabled {@code true} means enable, {@code false} means disable.
5050 */
5051 @Override
5052 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005053 final long identity = Binder.clearCallingIdentity();
5054 try {
5055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5056 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005057
Pengquan Meng0c05b502018-09-06 09:59:22 -07005058 Phone phone = getPhone(subId);
5059 if (phone != null) {
5060 phone.setDataRoamingEnabled(isEnabled);
5061 }
5062 } finally {
5063 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005064 }
5065 }
5066
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005067 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005068 public boolean isManualNetworkSelectionAllowed(int subId) {
5069 boolean isAllowed = true;
5070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5073 mApp, subId, "isManualNetworkSelectionAllowed");
5074 Phone phone = getPhone(subId);
5075 if (phone != null) {
5076 isAllowed = phone.isCspPlmnEnabled();
5077 }
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
5080 }
5081 return isAllowed;
5082 }
5083
5084 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005085 public UiccSlotInfo[] getUiccSlotsInfo() {
5086 enforceReadPrivilegedPermission();
5087
Malcolm Chend965c8b2018-02-28 15:00:40 -08005088 final long identity = Binder.clearCallingIdentity();
5089 try {
5090 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5091 if (slots == null) {
5092 Rlog.i(LOG_TAG, "slots is null.");
5093 return null;
5094 }
5095
5096 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5097 for (int i = 0; i < slots.length; i++) {
5098 UiccSlot slot = slots[i];
5099 if (slot == null) {
5100 continue;
5101 }
5102
5103 String cardId;
5104 UiccCard card = slot.getUiccCard();
5105 if (card != null) {
5106 cardId = card.getCardId();
5107 } else {
5108 cardId = slot.getIccId();
5109 }
5110
5111 int cardState = 0;
5112 switch (slot.getCardState()) {
5113 case CARDSTATE_ABSENT:
5114 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5115 break;
5116 case CARDSTATE_PRESENT:
5117 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5118 break;
5119 case CARDSTATE_ERROR:
5120 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5121 break;
5122 case CARDSTATE_RESTRICTED:
5123 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5124 break;
5125 default:
5126 break;
5127
5128 }
5129
5130 infos[i] = new UiccSlotInfo(
5131 slot.isActive(),
5132 slot.isEuicc(),
5133 cardId,
5134 cardState,
5135 slot.getPhoneId(),
5136 slot.isExtendedApduSupported());
5137 }
5138 return infos;
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005141 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005142 }
5143
5144 @Override
5145 public boolean switchSlots(int[] physicalSlots) {
5146 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005147
5148 final long identity = Binder.clearCallingIdentity();
5149 try {
5150 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5151 } finally {
5152 Binder.restoreCallingIdentity(identity);
5153 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005154 }
Jack Yu4c988042018-02-27 15:30:01 -08005155
5156 @Override
5157 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5158 enforceModifyPermission();
5159 final Phone phone = getPhone(subId);
5160 if (phone == null) {
5161 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5162 return;
5163 }
5164
Malcolm Chend965c8b2018-02-28 15:00:40 -08005165 final long identity = Binder.clearCallingIdentity();
5166 try {
5167 phone.setRadioIndicationUpdateMode(filters, mode);
5168 } finally {
5169 Binder.restoreCallingIdentity(identity);
5170 }
Jack Yu4c988042018-02-27 15:30:01 -08005171 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005172
5173 /**
goneil47ffb6e2018-04-06 15:40:58 -07005174 * A test API to reload the UICC profile.
5175 *
5176 * <p>Requires that the calling app has permission
5177 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5178 * @hide
5179 */
5180 @Override
5181 public void refreshUiccProfile(int subId) {
5182 enforceModifyPermission();
5183
5184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 Phone phone = getPhone(subId);
5187 if (phone == null) {
5188 return;
5189 }
5190 UiccCard uiccCard = phone.getUiccCard();
5191 if (uiccCard == null) {
5192 return;
5193 }
5194 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5195 if (uiccProfile == null) {
5196 return;
5197 }
5198 uiccProfile.refresh();
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
5202 }
5203
5204 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005205 * Returns false if the mobile data is disabled by default, otherwise return true.
5206 */
5207 private boolean getDefaultDataEnabled() {
5208 return "true".equalsIgnoreCase(
5209 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5210 }
5211
5212 /**
5213 * Returns true if the data roaming is enabled by default, i.e the system property
5214 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5215 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5216 */
5217 private boolean getDefaultDataRoamingEnabled(int subId) {
5218 final CarrierConfigManager configMgr = (CarrierConfigManager)
5219 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5220 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5221 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5222 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5223 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5224 return isDataRoamingEnabled;
5225 }
5226
5227 /**
5228 * Returns the default network type for the given {@code subId}, if the default network type is
5229 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5230 */
5231 private int getDefaultNetworkType(int subId) {
5232 return Integer.parseInt(
5233 TelephonyManager.getTelephonyProperty(
5234 mSubscriptionController.getPhoneId(subId),
5235 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5236 String.valueOf(Phone.PREFERRED_NT_MODE)));
5237 }
fionaxua13278b2018-03-21 00:08:13 -07005238
5239 @Override
5240 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5241 gid1, String gid2, String plmn, String spn) {
5242 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005243
5244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 final Phone phone = getPhone(subId);
5247 if (phone == null) {
5248 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5249 return;
5250 }
5251 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5252 } finally {
5253 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005254 }
fionaxua13278b2018-03-21 00:08:13 -07005255 }
5256
5257 @Override
5258 public int getCarrierIdListVersion(int subId) {
5259 enforceReadPrivilegedPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005260
5261 final long identity = Binder.clearCallingIdentity();
5262 try {
5263 final Phone phone = getPhone(subId);
5264 if (phone == null) {
5265 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5266 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5267 }
5268 return phone.getCarrierIdListVersion();
5269 } finally {
5270 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005271 }
fionaxua13278b2018-03-21 00:08:13 -07005272 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005273
5274 @Override
5275 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5277 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5278 return -1;
5279 }
5280
5281 final long identity = Binder.clearCallingIdentity();
5282 try {
5283 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
5287 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005288
5289 @Override
5290 public int getCdmaRoamingMode(int subId) {
5291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5292 mApp, subId, "getCdmaRoamingMode");
5293
5294 final long identity = Binder.clearCallingIdentity();
5295 try {
5296 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
5299 }
5300 }
5301
5302 @Override
5303 public boolean setCdmaRoamingMode(int subId, int mode) {
5304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5305 mApp, subId, "setCdmaRoamingMode");
5306
5307 final long identity = Binder.clearCallingIdentity();
5308 try {
5309 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
5312 }
5313 }
5314
5315 @Override
5316 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5318 mApp, subId, "setCdmaSubscriptionMode");
5319
5320 final long identity = Binder.clearCallingIdentity();
5321 try {
5322 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
5326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005327}