blob: a7e034752656dbc17392d93d3dcc1234e66d321b [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
vagdevie435a3e2018-08-15 16:01:53 -0700292 public WorkSource workSource;
293
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294 public MainThreadRequest(Object argument) {
295 this.argument = argument;
296 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800297
vagdevie435a3e2018-08-15 16:01:53 -0700298 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800299 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800300 if (subId != null) {
301 this.subId = subId;
302 }
vagdevie435a3e2018-08-15 16:01:53 -0700303 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305 }
306
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800307 private static final class IncomingThirdPartyCallArgs {
308 public final ComponentName component;
309 public final String callId;
310 public final String callerDisplayName;
311
312 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
313 String callerDisplayName) {
314 this.component = component;
315 this.callId = callId;
316 this.callerDisplayName = callerDisplayName;
317 }
318 }
319
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 /**
321 * A handler that processes messages on the main thread in the phone process. Since many
322 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
323 * inbound binder threads to the main thread in the phone process. The Binder thread
324 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
325 * on, which will be notified when the operation completes and will contain the result of the
326 * request.
327 *
328 * <p>If a MainThreadRequest object is provided in the msg.obj field,
329 * note that request.result must be set to something non-null for the calling thread to
330 * unblock.
331 */
332 private final class MainThreadHandler extends Handler {
333 @Override
334 public void handleMessage(Message msg) {
335 MainThreadRequest request;
336 Message onCompleted;
337 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800338 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700339 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340
341 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700342 case CMD_HANDLE_USSD_REQUEST: {
343 request = (MainThreadRequest) msg.obj;
344 final Phone phone = getPhoneFromRequest(request);
345 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
346 String ussdRequest = ussdObject.first;
347 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700348
Pengquan Meng0c05b502018-09-06 09:59:22 -0700349 if (!isUssdApiAllowed(request.subId)) {
350 // Carrier does not support use of this API, return failure.
351 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
352 UssdResponse response = new UssdResponse(ussdRequest, null);
353 Bundle returnData = new Bundle();
354 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
355 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700356
Pengquan Meng0c05b502018-09-06 09:59:22 -0700357 request.result = true;
358 notifyRequester(request);
359 return;
360 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700361
Pengquan Meng0c05b502018-09-06 09:59:22 -0700362 try {
363 request.result = phone != null
364 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
365 } catch (CallStateException cse) {
366 request.result = false;
367 }
368 // Wake up the requesting thread
369 notifyRequester(request);
370 break;
pkanwar32d516d2016-10-14 19:37:38 -0700371 }
372
Yorke Lee716f67e2015-06-17 15:39:16 -0700373 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700375 final Phone phone = getPhoneFromRequest(request);
376 request.result = phone != null ?
377 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
378 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700380 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700384 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700385 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700386 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800387 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700388 if (uiccCard == null) {
389 loge("iccTransmitApduLogicalChannel: No UICC");
390 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700391 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700392 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700393 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
394 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700395 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700396 iccArgument.channel, iccArgument.cla, iccArgument.command,
397 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700398 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700399 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700400 break;
401
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700402 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700403 ar = (AsyncResult) msg.obj;
404 request = (MainThreadRequest) ar.userObj;
405 if (ar.exception == null && ar.result != null) {
406 request.result = ar.result;
407 } else {
408 request.result = new IccIoResult(0x6F, 0, (byte[])null);
409 if (ar.result == null) {
410 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800411 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700412 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800413 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 } else {
415 loge("iccTransmitApduLogicalChannel: Unknown exception");
416 }
417 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700418 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 break;
420
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
422 request = (MainThreadRequest) msg.obj;
423 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800424 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 if (uiccCard == null) {
426 loge("iccTransmitApduBasicChannel: No UICC");
427 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700428 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 } else {
430 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
431 request);
432 uiccCard.iccTransmitApduBasicChannel(
433 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
434 iccArgument.p3, iccArgument.data, onCompleted);
435 }
436 break;
437
438 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
439 ar = (AsyncResult) msg.obj;
440 request = (MainThreadRequest) ar.userObj;
441 if (ar.exception == null && ar.result != null) {
442 request.result = ar.result;
443 } else {
444 request.result = new IccIoResult(0x6F, 0, (byte[])null);
445 if (ar.result == null) {
446 loge("iccTransmitApduBasicChannel: Empty response");
447 } else if (ar.exception instanceof CommandException) {
448 loge("iccTransmitApduBasicChannel: CommandException: " +
449 ar.exception);
450 } else {
451 loge("iccTransmitApduBasicChannel: Unknown exception");
452 }
453 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700454 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 break;
456
457 case CMD_EXCHANGE_SIM_IO:
458 request = (MainThreadRequest) msg.obj;
459 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800460 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 if (uiccCard == null) {
462 loge("iccExchangeSimIO: No UICC");
463 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700464 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 } else {
466 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
467 request);
468 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
469 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
470 iccArgument.data, onCompleted);
471 }
472 break;
473
474 case EVENT_EXCHANGE_SIM_IO_DONE:
475 ar = (AsyncResult) msg.obj;
476 request = (MainThreadRequest) ar.userObj;
477 if (ar.exception == null && ar.result != null) {
478 request.result = ar.result;
479 } else {
480 request.result = new IccIoResult(0x6f, 0, (byte[])null);
481 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700482 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 break;
484
Derek Tan4d5e5c12014-02-04 11:54:58 -0800485 case CMD_SEND_ENVELOPE:
486 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800487 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700488 if (uiccCard == null) {
489 loge("sendEnvelopeWithStatus: No UICC");
490 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700491 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700492 } else {
493 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
494 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
495 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800496 break;
497
498 case EVENT_SEND_ENVELOPE_DONE:
499 ar = (AsyncResult) msg.obj;
500 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700501 if (ar.exception == null && ar.result != null) {
502 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800503 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
505 if (ar.result == null) {
506 loge("sendEnvelopeWithStatus: Empty response");
507 } else if (ar.exception instanceof CommandException) {
508 loge("sendEnvelopeWithStatus: CommandException: " +
509 ar.exception);
510 } else {
511 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
512 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800513 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700514 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800515 break;
516
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 case CMD_OPEN_CHANNEL:
518 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800519 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800520 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700521 if (uiccCard == null) {
522 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800523 request.result = new IccOpenLogicalChannelResponse(-1,
524 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 } else {
527 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800528 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
529 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700531 break;
532
533 case EVENT_OPEN_CHANNEL_DONE:
534 ar = (AsyncResult) msg.obj;
535 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 int[] result = (int[]) ar.result;
539 int channelId = result[0];
540 byte[] selectResponse = null;
541 if (result.length > 1) {
542 selectResponse = new byte[result.length - 1];
543 for (int i = 1; i < result.length; ++i) {
544 selectResponse[i - 1] = (byte) result[i];
545 }
546 }
547 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700548 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 if (ar.result == null) {
551 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 if (ar.exception != null) {
554 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
555 }
556
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700557 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700558 if (ar.exception instanceof CommandException) {
559 CommandException.Error error =
560 ((CommandException) (ar.exception)).getCommandError();
561 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700562 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700563 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700564 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 }
566 }
567 openChannelResp = new IccOpenLogicalChannelResponse(
568 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700570 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700571 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 break;
573
574 case CMD_CLOSE_CHANNEL:
575 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800576 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 if (uiccCard == null) {
578 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900579 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 } else {
582 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
583 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
584 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 break;
586
587 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800588 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
589 break;
590
591 case CMD_NV_READ_ITEM:
592 request = (MainThreadRequest) msg.obj;
593 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700594 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800595 break;
596
597 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 ar = (AsyncResult) msg.obj;
599 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800600 if (ar.exception == null && ar.result != null) {
601 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800603 request.result = "";
604 if (ar.result == null) {
605 loge("nvReadItem: Empty response");
606 } else if (ar.exception instanceof CommandException) {
607 loge("nvReadItem: CommandException: " +
608 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800610 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 }
612 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700613 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 break;
615
Jake Hambye994d462014-02-03 13:10:13 -0800616 case CMD_NV_WRITE_ITEM:
617 request = (MainThreadRequest) msg.obj;
618 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
619 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700620 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
621 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800622 break;
623
624 case EVENT_NV_WRITE_ITEM_DONE:
625 handleNullReturnEvent(msg, "nvWriteItem");
626 break;
627
628 case CMD_NV_WRITE_CDMA_PRL:
629 request = (MainThreadRequest) msg.obj;
630 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
631 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
632 break;
633
634 case EVENT_NV_WRITE_CDMA_PRL_DONE:
635 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
636 break;
637
638 case CMD_NV_RESET_CONFIG:
639 request = (MainThreadRequest) msg.obj;
640 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
641 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
642 break;
643
644 case EVENT_NV_RESET_CONFIG_DONE:
645 handleNullReturnEvent(msg, "nvResetConfig");
646 break;
647
Jake Hamby7c27be32014-03-03 13:25:59 -0800648 case CMD_GET_PREFERRED_NETWORK_TYPE:
649 request = (MainThreadRequest) msg.obj;
650 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700651 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800652 break;
653
654 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
655 ar = (AsyncResult) msg.obj;
656 request = (MainThreadRequest) ar.userObj;
657 if (ar.exception == null && ar.result != null) {
658 request.result = ar.result; // Integer
659 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800660 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800661 if (ar.result == null) {
662 loge("getPreferredNetworkType: Empty response");
663 } else if (ar.exception instanceof CommandException) {
664 loge("getPreferredNetworkType: CommandException: " +
665 ar.exception);
666 } else {
667 loge("getPreferredNetworkType: Unknown exception");
668 }
669 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700670 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800671 break;
672
673 case CMD_SET_PREFERRED_NETWORK_TYPE:
674 request = (MainThreadRequest) msg.obj;
675 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
676 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700677 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800678 break;
679
680 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
681 handleNullReturnEvent(msg, "setPreferredNetworkType");
682 break;
683
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000684 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
685 request = (MainThreadRequest)msg.obj;
686 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700687 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000688 break;
689
690 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
691 ar = (AsyncResult)msg.obj;
692 request = (MainThreadRequest)ar.userObj;
693 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700694 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000695 break;
696
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800697 case CMD_SET_VOICEMAIL_NUMBER:
698 request = (MainThreadRequest) msg.obj;
699 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
700 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800701 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
702 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800703 break;
704
705 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
706 handleNullReturnEvent(msg, "setVoicemailNumber");
707 break;
708
Stuart Scott54788802015-03-30 13:18:01 -0700709 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
710 request = (MainThreadRequest) msg.obj;
711 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
712 request);
713 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
714 break;
715
716 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
717 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
718 break;
719
Shishir Agrawal302c8692015-06-19 13:49:39 -0700720 case CMD_PERFORM_NETWORK_SCAN:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
723 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
724 break;
725
726 case EVENT_PERFORM_NETWORK_SCAN_DONE:
727 ar = (AsyncResult) msg.obj;
728 request = (MainThreadRequest) ar.userObj;
729 CellNetworkScanResult cellScanResult;
730 if (ar.exception == null && ar.result != null) {
731 cellScanResult = new CellNetworkScanResult(
732 CellNetworkScanResult.STATUS_SUCCESS,
733 (List<OperatorInfo>) ar.result);
734 } else {
735 if (ar.result == null) {
736 loge("getCellNetworkScanResults: Empty response");
737 }
738 if (ar.exception != null) {
739 loge("getCellNetworkScanResults: Exception: " + ar.exception);
740 }
741 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
742 if (ar.exception instanceof CommandException) {
743 CommandException.Error error =
744 ((CommandException) (ar.exception)).getCommandError();
745 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
746 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
747 } else if (error == CommandException.Error.GENERIC_FAILURE) {
748 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
749 }
750 }
751 cellScanResult = new CellNetworkScanResult(errorCode, null);
752 }
753 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700754 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700755 break;
756
757 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
758 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700759 ManualNetworkSelectionArgument selArg =
760 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700761 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
762 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700763 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
764 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700765 break;
766
767 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700768 ar = (AsyncResult) msg.obj;
769 request = (MainThreadRequest) ar.userObj;
770 if (ar.exception == null) {
771 request.result = true;
772 } else {
773 request.result = false;
774 loge("setNetworkSelectionModeManual " + ar.exception);
775 }
776 notifyRequester(request);
777 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700778 break;
779
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700780 case CMD_GET_MODEM_ACTIVITY_INFO:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700783 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700784 break;
785
786 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
789 if (ar.exception == null && ar.result != null) {
790 request.result = ar.result;
791 } else {
792 if (ar.result == null) {
793 loge("queryModemActivityInfo: Empty response");
794 } else if (ar.exception instanceof CommandException) {
795 loge("queryModemActivityInfo: CommandException: " +
796 ar.exception);
797 } else {
798 loge("queryModemActivityInfo: Unknown exception");
799 }
800 }
Amit Mahajand4766222016-01-28 15:28:28 -0800801 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
802 if (request.result == null) {
803 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
804 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700805 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700806 break;
807
Meng Wang1a7c35a2016-05-05 20:56:15 -0700808 case CMD_SET_ALLOWED_CARRIERS:
809 request = (MainThreadRequest) msg.obj;
810 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
811 mPhone.setAllowedCarriers(
812 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700813 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700814 break;
815
816 case EVENT_SET_ALLOWED_CARRIERS_DONE:
817 ar = (AsyncResult) msg.obj;
818 request = (MainThreadRequest) ar.userObj;
819 if (ar.exception == null && ar.result != null) {
820 request.result = ar.result;
821 } else {
822 if (ar.result == null) {
823 loge("setAllowedCarriers: Empty response");
824 } else if (ar.exception instanceof CommandException) {
825 loge("setAllowedCarriers: CommandException: " +
826 ar.exception);
827 } else {
828 loge("setAllowedCarriers: Unknown exception");
829 }
830 }
831 // Result cannot be null. Return -1 on error.
832 if (request.result == null) {
833 request.result = new int[]{-1};
834 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700835 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700836 break;
837
838 case CMD_GET_ALLOWED_CARRIERS:
839 request = (MainThreadRequest) msg.obj;
840 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700841 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700842 break;
843
844 case EVENT_GET_ALLOWED_CARRIERS_DONE:
845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
847 if (ar.exception == null && ar.result != null) {
848 request.result = ar.result;
849 } else {
850 if (ar.result == null) {
851 loge("getAllowedCarriers: Empty response");
852 } else if (ar.exception instanceof CommandException) {
853 loge("getAllowedCarriers: CommandException: " +
854 ar.exception);
855 } else {
856 loge("getAllowedCarriers: Unknown exception");
857 }
858 }
859 // Result cannot be null. Return empty list of CarrierIdentifier.
860 if (request.result == null) {
861 request.result = new ArrayList<CarrierIdentifier>(0);
862 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700863 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700864 break;
865
Nathan Haroldb3014052017-01-25 15:57:32 -0800866 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result;
871 } else {
872 request.result = new IllegalArgumentException(
873 "Failed to retrieve Forbidden Plmns");
874 if (ar.result == null) {
875 loge("getForbiddenPlmns: Empty response");
876 } else {
877 loge("getForbiddenPlmns: Unknown exception");
878 }
879 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700880 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800881 break;
882
883 case CMD_GET_FORBIDDEN_PLMNS:
884 request = (MainThreadRequest) msg.obj;
885 uiccCard = getUiccCardFromRequest(request);
886 if (uiccCard == null) {
887 loge("getForbiddenPlmns() UiccCard is null");
888 request.result = new IllegalArgumentException(
889 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700890 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800891 break;
892 }
893 Integer appType = (Integer) request.argument;
894 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
895 if (uiccApp == null) {
896 loge("getForbiddenPlmns() no app with specified type -- "
897 + appType);
898 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700899 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800900 break;
901 } else {
902 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
903 + " specified type -- " + appType);
904 }
905 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
906 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
907 onCompleted);
908 break;
909
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000910 case CMD_SWITCH_SLOTS:
911 request = (MainThreadRequest) msg.obj;
912 int[] physicalSlots = (int[]) request.argument;
913 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
914 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
915 break;
916
917 case EVENT_SWITCH_SLOTS_DONE:
918 ar = (AsyncResult) msg.obj;
919 request = (MainThreadRequest) ar.userObj;
920 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700921 notifyRequester(request);
922 break;
923 case CMD_GET_NETWORK_SELECTION_MODE:
924 request = (MainThreadRequest) msg.obj;
925 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
926 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
927 break;
928
929 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception != null) {
933 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
934 } else {
935 int mode = ((int[]) ar.result)[0];
936 if (mode == 0) {
937 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
938 } else {
939 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
940 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000941 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700942 notifyRequester(request);
943 break;
944 case CMD_GET_CDMA_ROAMING_MODE:
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
947 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
948 break;
949 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
950 ar = (AsyncResult) msg.obj;
951 request = (MainThreadRequest) ar.userObj;
952 if (ar.exception != null) {
953 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
954 } else {
955 request.result = ((int[]) ar.result)[0];
956 }
957 notifyRequester(request);
958 break;
959 case CMD_SET_CDMA_ROAMING_MODE:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
962 int mode = (int) request.argument;
963 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
964 break;
965 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
968 request.result = ar.exception == null;
969 notifyRequester(request);
970 break;
971 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
972 request = (MainThreadRequest) msg.obj;
973 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
974 int subscriptionMode = (int) request.argument;
975 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
976 break;
977 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
978 ar = (AsyncResult) msg.obj;
979 request = (MainThreadRequest) ar.userObj;
980 request.result = ar.exception == null;
981 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000982 break;
983
Nathan Harold3ff88932018-08-14 10:19:49 -0700984 case CMD_GET_ALL_CELL_INFO:
985 request = (MainThreadRequest) msg.obj;
986 Pair<Phone, WorkSource> args = (Pair<Phone, WorkSource>) request.argument;
987 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Haroldc8ed2ef2018-10-17 10:51:22 -0700988 ((Phone) args.first).requestCellInfoUpdate(args.second, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -0700989 break;
990
991 case EVENT_GET_ALL_CELL_INFO_DONE:
992 ar = (AsyncResult) msg.obj;
993 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -0700994 // If a timeout occurs, the response will be null
995 request.result = (ar.exception == null && ar.result != null)
996 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -0700997 synchronized (request) {
998 request.notifyAll();
999 }
1000 break;
1001
1002 case CMD_GET_CELL_LOCATION: {
1003 request = (MainThreadRequest) msg.obj;
1004 WorkSource ws = (WorkSource) request.argument;
1005 Phone phone = getPhoneFromRequest(request);
1006 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1007 break;
1008 }
1009
1010 case EVENT_GET_CELL_LOCATION_DONE: {
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 if (ar.exception == null) {
1014 request.result = ar.result;
1015 } else {
1016 Phone phone = getPhoneFromRequest(request);
1017 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1018 ? new CdmaCellLocation() : new GsmCellLocation();
1019 }
1020
1021 synchronized (request) {
1022 request.notifyAll();
1023 }
1024 break;
1025 }
1026
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001027 default:
1028 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1029 break;
1030 }
1031 }
Jake Hambye994d462014-02-03 13:10:13 -08001032
Pengquan Meng0c05b502018-09-06 09:59:22 -07001033 private void notifyRequester(MainThreadRequest request) {
1034 synchronized (request) {
1035 request.notifyAll();
1036 }
1037 }
1038
Jake Hambye994d462014-02-03 13:10:13 -08001039 private void handleNullReturnEvent(Message msg, String command) {
1040 AsyncResult ar = (AsyncResult) msg.obj;
1041 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1042 if (ar.exception == null) {
1043 request.result = true;
1044 } else {
1045 request.result = false;
1046 if (ar.exception instanceof CommandException) {
1047 loge(command + ": CommandException: " + ar.exception);
1048 } else {
1049 loge(command + ": Unknown exception");
1050 }
1051 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001052 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001054 }
1055
1056 /**
1057 * Posts the specified command to be executed on the main thread,
1058 * waits for the request to complete, and returns the result.
1059 * @see #sendRequestAsync
1060 */
1061 private Object sendRequest(int command, Object argument) {
vagdevie435a3e2018-08-15 16:01:53 -07001062 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1063 }
1064
1065 /**
1066 * Posts the specified command to be executed on the main thread,
1067 * waits for the request to complete, and returns the result.
1068 * @see #sendRequestAsync
1069 */
1070 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1071 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1072 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001073 }
1074
1075 /**
1076 * Posts the specified command to be executed on the main thread,
1077 * waits for the request to complete, and returns the result.
1078 * @see #sendRequestAsync
1079 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001080 private Object sendRequest(int command, Object argument, Integer subId) {
vagdevie435a3e2018-08-15 16:01:53 -07001081 return sendRequest(command, argument, subId, null);
1082 }
1083
1084 /**
1085 * Posts the specified command to be executed on the main thread,
1086 * waits for the request to complete, and returns the result.
1087 * @see #sendRequestAsync
1088 */
1089 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1091 throw new RuntimeException("This method will deadlock if called from the main thread.");
1092 }
1093
vagdevie435a3e2018-08-15 16:01:53 -07001094 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001095 Message msg = mMainThreadHandler.obtainMessage(command, request);
1096 msg.sendToTarget();
1097
1098 // Wait for the request to complete
1099 synchronized (request) {
1100 while (request.result == null) {
1101 try {
1102 request.wait();
1103 } catch (InterruptedException e) {
1104 // Do nothing, go back and wait until the request is complete
1105 }
1106 }
1107 }
1108 return request.result;
1109 }
1110
1111 /**
1112 * Asynchronous ("fire and forget") version of sendRequest():
1113 * Posts the specified command to be executed on the main thread, and
1114 * returns immediately.
1115 * @see #sendRequest
1116 */
1117 private void sendRequestAsync(int command) {
1118 mMainThreadHandler.sendEmptyMessage(command);
1119 }
1120
1121 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001122 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1123 * @see {@link #sendRequest(int,Object)}
1124 */
1125 private void sendRequestAsync(int command, Object argument) {
1126 MainThreadRequest request = new MainThreadRequest(argument);
1127 Message msg = mMainThreadHandler.obtainMessage(command, request);
1128 msg.sendToTarget();
1129 }
1130
1131 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001132 * Initialize the singleton PhoneInterfaceManager instance.
1133 * This is only done once, at startup, from PhoneApp.onCreate().
1134 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001135 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 synchronized (PhoneInterfaceManager.class) {
1137 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001138 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 } else {
1140 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1141 }
1142 return sInstance;
1143 }
1144 }
1145
1146 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001147 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 mApp = app;
1149 mPhone = phone;
1150 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001151 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001152 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1153 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001154 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001155 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001156 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001157 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001158 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001159
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 publish();
1161 }
1162
1163 private void publish() {
1164 if (DBG) log("publish: " + this);
1165
1166 ServiceManager.addService("phone", this);
1167 }
1168
Stuart Scott584921c2015-01-15 17:10:34 -08001169 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001170 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1171 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001172 }
1173
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001174 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1175 Phone phone = getPhoneFromRequest(request);
1176 return phone == null ? null :
1177 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1178 }
1179
Wink Saville36469e72014-06-11 15:17:00 -07001180 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001181 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001182 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184
1185 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001186 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001187 }
1188
Wink Savilleb564aae2014-10-23 10:18:09 -07001189 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 if (DBG) log("dial: " + number);
1191 // No permission check needed here: This is just a wrapper around the
1192 // ACTION_DIAL intent, which is available to any app since it puts up
1193 // the UI before it does anything.
1194
Malcolm Chenaabec062018-02-28 15:00:40 -08001195 final long identity = Binder.clearCallingIdentity();
1196 try {
1197 String url = createTelUrl(number);
1198 if (url == null) {
1199 return;
1200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001201
Malcolm Chenaabec062018-02-28 15:00:40 -08001202 // PENDING: should we just silently fail if phone is offhook or ringing?
1203 PhoneConstants.State state = mCM.getState(subId);
1204 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1205 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1206 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1207 mApp.startActivity(intent);
1208 }
1209 } finally {
1210 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001211 }
1212 }
1213
1214 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001215 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001216 }
1217
Wink Savilleb564aae2014-10-23 10:18:09 -07001218 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 if (DBG) log("call: " + number);
1220
1221 // This is just a wrapper around the ACTION_CALL intent, but we still
1222 // need to do a permission check since we're calling startActivity()
1223 // from the context of the phone app.
1224 enforceCallPermission();
1225
1226 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1227 != AppOpsManager.MODE_ALLOWED) {
1228 return;
1229 }
1230
Malcolm Chenaabec062018-02-28 15:00:40 -08001231 final long identity = Binder.clearCallingIdentity();
1232 try {
1233 String url = createTelUrl(number);
1234 if (url == null) {
1235 return;
1236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237
Malcolm Chenaabec062018-02-28 15:00:40 -08001238 boolean isValid = false;
1239 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1240 if (slist != null) {
1241 for (SubscriptionInfo subInfoRecord : slist) {
1242 if (subInfoRecord.getSubscriptionId() == subId) {
1243 isValid = true;
1244 break;
1245 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001246 }
Wink Saville08874612014-08-31 19:19:58 -07001247 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001248 if (!isValid) {
1249 return;
1250 }
Wink Saville08874612014-08-31 19:19:58 -07001251
Malcolm Chenaabec062018-02-28 15:00:40 -08001252 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1253 intent.putExtra(SUBSCRIPTION_KEY, subId);
1254 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1255 mApp.startActivity(intent);
1256 } finally {
1257 Binder.restoreCallingIdentity(identity);
1258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 }
1260
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001262 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001263 }
1264
Wink Savilleb564aae2014-10-23 10:18:09 -07001265 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001266 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001267 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1268 }
1269
1270 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001271 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001272 }
1273
Wink Savilleb564aae2014-10-23 10:18:09 -07001274 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001275 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001276 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1277 }
1278
1279 /** {@hide} */
1280 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001281 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
Wink Savilleb564aae2014-10-23 10:18:09 -07001284 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001286
1287 final long identity = Binder.clearCallingIdentity();
1288 try {
1289 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1290 checkSimPin.start();
1291 return checkSimPin.unlockSim(null, pin);
1292 } finally {
1293 Binder.restoreCallingIdentity(identity);
1294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001295 }
1296
Wink Saville9de0f752013-10-22 19:04:03 -07001297 /** {@hide} */
1298 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001299 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001300 }
1301
Wink Savilleb564aae2014-10-23 10:18:09 -07001302 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001304
1305 final long identity = Binder.clearCallingIdentity();
1306 try {
1307 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1308 checkSimPuk.start();
1309 return checkSimPuk.unlockSim(puk, pin);
1310 } finally {
1311 Binder.restoreCallingIdentity(identity);
1312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 }
1314
1315 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001316 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 * a synchronous one.
1318 */
1319 private static class UnlockSim extends Thread {
1320
1321 private final IccCard mSimCard;
1322
1323 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001324 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1325 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326
1327 // For replies from SimCard interface
1328 private Handler mHandler;
1329
1330 // For async handler to identify request type
1331 private static final int SUPPLY_PIN_COMPLETE = 100;
1332
1333 public UnlockSim(IccCard simCard) {
1334 mSimCard = simCard;
1335 }
1336
1337 @Override
1338 public void run() {
1339 Looper.prepare();
1340 synchronized (UnlockSim.this) {
1341 mHandler = new Handler() {
1342 @Override
1343 public void handleMessage(Message msg) {
1344 AsyncResult ar = (AsyncResult) msg.obj;
1345 switch (msg.what) {
1346 case SUPPLY_PIN_COMPLETE:
1347 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1348 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001349 mRetryCount = msg.arg1;
1350 if (ar.exception != null) {
1351 if (ar.exception instanceof CommandException &&
1352 ((CommandException)(ar.exception)).getCommandError()
1353 == CommandException.Error.PASSWORD_INCORRECT) {
1354 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1355 } else {
1356 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1357 }
1358 } else {
1359 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 mDone = true;
1362 UnlockSim.this.notifyAll();
1363 }
1364 break;
1365 }
1366 }
1367 };
1368 UnlockSim.this.notifyAll();
1369 }
1370 Looper.loop();
1371 }
1372
1373 /*
1374 * Use PIN or PUK to unlock SIM card
1375 *
1376 * If PUK is null, unlock SIM card with PIN
1377 *
1378 * If PUK is not null, unlock SIM card with PUK and set PIN code
1379 */
Wink Saville9de0f752013-10-22 19:04:03 -07001380 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381
1382 while (mHandler == null) {
1383 try {
1384 wait();
1385 } catch (InterruptedException e) {
1386 Thread.currentThread().interrupt();
1387 }
1388 }
1389 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1390
1391 if (puk == null) {
1392 mSimCard.supplyPin(pin, callback);
1393 } else {
1394 mSimCard.supplyPuk(puk, pin, callback);
1395 }
1396
1397 while (!mDone) {
1398 try {
1399 Log.d(LOG_TAG, "wait for done");
1400 wait();
1401 } catch (InterruptedException e) {
1402 // Restore the interrupted status
1403 Thread.currentThread().interrupt();
1404 }
1405 }
1406 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001407 int[] resultArray = new int[2];
1408 resultArray[0] = mResult;
1409 resultArray[1] = mRetryCount;
1410 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 }
1412 }
1413
1414 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001415 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001416
1417 }
1418
Wink Savilleb564aae2014-10-23 10:18:09 -07001419 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 // No permission check needed here: this call is harmless, and it's
1421 // needed for the ServiceState.requestStateUpdate() call (which is
1422 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001423 final long identity = Binder.clearCallingIdentity();
1424 try {
1425 final Phone phone = getPhone(subId);
1426 if (phone != null) {
1427 phone.updateServiceLocation();
1428 }
1429 } finally {
1430 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432 }
1433
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001434 @Override
1435 public boolean isRadioOn(String callingPackage) {
1436 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001437 }
1438
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001439 @Override
1440 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001442 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001443 return false;
1444 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001445
1446 final long identity = Binder.clearCallingIdentity();
1447 try {
1448 return isRadioOnForSubscriber(subId);
1449 } finally {
1450 Binder.restoreCallingIdentity(identity);
1451 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001452 }
1453
1454 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001455 final long identity = Binder.clearCallingIdentity();
1456 try {
1457 final Phone phone = getPhone(subId);
1458 if (phone != null) {
1459 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1460 } else {
1461 return false;
1462 }
1463 } finally {
1464 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 }
1467
1468 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001469 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470 }
Wink Saville36469e72014-06-11 15:17:00 -07001471
Wink Savilleb564aae2014-10-23 10:18:09 -07001472 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001474
1475 final long identity = Binder.clearCallingIdentity();
1476 try {
1477 final Phone phone = getPhone(subId);
1478 if (phone != null) {
1479 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1480 }
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001483 }
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
1486 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001491 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001492
1493 final long identity = Binder.clearCallingIdentity();
1494 try {
1495 final Phone phone = getPhone(subId);
1496 if (phone == null) {
1497 return false;
1498 }
1499 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1500 toggleRadioOnOffForSubscriber(subId);
1501 }
1502 return true;
1503 } finally {
1504 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 }
Wink Saville36469e72014-06-11 15:17:00 -07001507
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001508 public boolean needMobileRadioShutdown() {
1509 /*
1510 * If any of the Radios are available, it will need to be
1511 * shutdown. So return true if any Radio is available.
1512 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001513 final long identity = Binder.clearCallingIdentity();
1514 try {
1515 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1516 Phone phone = PhoneFactory.getPhone(i);
1517 if (phone != null && phone.isRadioAvailable()) return true;
1518 }
1519 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1520 return false;
1521 } finally {
1522 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001523 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001524 }
1525
Malcolm Chenaabec062018-02-28 15:00:40 -08001526 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001527 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001528 enforceModifyPermission();
1529
1530 final long identity = Binder.clearCallingIdentity();
1531 try {
1532 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1533 logv("Shutting down Phone " + i);
1534 shutdownRadioUsingPhoneId(i);
1535 }
1536 } finally {
1537 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001538 }
1539 }
1540
1541 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001542 Phone phone = PhoneFactory.getPhone(phoneId);
1543 if (phone != null && phone.isRadioAvailable()) {
1544 phone.shutdownRadio();
1545 }
1546 }
1547
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001549 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001550
1551 final long identity = Binder.clearCallingIdentity();
1552 try {
1553 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1554 if (defaultPhone != null) {
1555 defaultPhone.setRadioPower(turnOn);
1556 return true;
1557 } else {
1558 loge("There's no default phone.");
1559 return false;
1560 }
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001563 }
Wink Saville36469e72014-06-11 15:17:00 -07001564 }
1565
Wink Savilleb564aae2014-10-23 10:18:09 -07001566 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001568
1569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 final Phone phone = getPhone(subId);
1572 if (phone != null) {
1573 phone.setRadioPower(turnOn);
1574 return true;
1575 } else {
1576 return false;
1577 }
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 }
1582
Wink Saville36469e72014-06-11 15:17:00 -07001583 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001584 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 public boolean enableDataConnectivity() {
1586 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001587
1588 final long identity = Binder.clearCallingIdentity();
1589 try {
1590 int subId = mSubscriptionController.getDefaultDataSubId();
1591 final Phone phone = getPhone(subId);
1592 if (phone != null) {
1593 phone.setUserDataEnabled(true);
1594 return true;
1595 } else {
1596 return false;
1597 }
1598 } finally {
1599 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
Wink Saville36469e72014-06-11 15:17:00 -07001603 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 public boolean disableDataConnectivity() {
1606 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001607
1608 final long identity = Binder.clearCallingIdentity();
1609 try {
1610 int subId = mSubscriptionController.getDefaultDataSubId();
1611 final Phone phone = getPhone(subId);
1612 if (phone != null) {
1613 phone.setUserDataEnabled(false);
1614 return true;
1615 } else {
1616 return false;
1617 }
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001624 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001625 final long identity = Binder.clearCallingIdentity();
1626 try {
1627 final Phone phone = getPhone(subId);
1628 if (phone != null) {
1629 return phone.isDataAllowed();
1630 } else {
1631 return false;
1632 }
1633 } finally {
1634 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 }
1637
1638 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001639 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001640 }
1641
pkanwarae03a6b2016-11-06 20:37:09 -08001642 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001643 enforceCallPermission();
1644
1645 final long identity = Binder.clearCallingIdentity();
1646 try {
1647 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1648 return;
1649 }
1650 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1651 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1652 } finally {
1653 Binder.restoreCallingIdentity(identity);
1654 }
pkanwar32d516d2016-10-14 19:37:38 -07001655 };
1656
Wink Savilleb564aae2014-10-23 10:18:09 -07001657 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001659
1660 final long identity = Binder.clearCallingIdentity();
1661 try {
1662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1663 return false;
1664 }
1665 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 }
1670
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001672 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
1674
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001675 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 Phone phone = PhoneFactory.getPhone(slotIndex);
1679 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1680 PhoneConstantConversions.convertCallState(phone.getState());
1681 } finally {
1682 Binder.restoreCallingIdentity(identity);
1683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 }
1685
Sanket Padawe356d7632015-06-22 14:03:32 -07001686 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001688 final long identity = Binder.clearCallingIdentity();
1689 try {
1690 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1691 if (phone != null) {
1692 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1693 } else {
1694 return PhoneConstantConversions.convertDataState(
1695 PhoneConstants.DataState.DISCONNECTED);
1696 }
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 }
1701
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001704 final long identity = Binder.clearCallingIdentity();
1705 try {
1706 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1707 if (phone != null) {
1708 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1709 } else {
1710 return TelephonyManager.DATA_ACTIVITY_NONE;
1711 }
1712 } finally {
1713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 }
1716
1717 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001718 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001719 mPhone.getContext().getSystemService(AppOpsManager.class)
1720 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001721 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001722 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001723 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001726 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001727 final long identity = Binder.clearCallingIdentity();
1728 try {
1729 if (DBG_LOC) log("getCellLocation: is active user");
1730 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001731 int subId = mSubscriptionController.getDefaultDataSubId();
1732 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1733 cl.fillInNotifierBundle(data);
Malcolm Chenaabec062018-02-28 15:00:40 -08001734 return data;
1735 } finally {
1736 Binder.restoreCallingIdentity(identity);
1737 }
Svetoslav64fad262015-04-14 14:35:21 -07001738 }
1739
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001741 public String getNetworkCountryIsoForPhone(int phoneId) {
1742 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1743 // registered cell info, so return a NULL country instead.
1744 final long identity = Binder.clearCallingIdentity();
1745 try {
1746 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001747 // Todo: fix this when we can get the actual cellular network info when the device
1748 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001749 if (TelephonyManager.NETWORK_TYPE_IWLAN
1750 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1751 return "";
1752 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001753 Phone phone = PhoneFactory.getPhone(phoneId);
1754 if (phone != null) {
1755 ServiceStateTracker sst = phone.getServiceStateTracker();
1756 if (sst != null) {
1757 LocaleTracker lt = sst.getLocaleTracker();
1758 if (lt != null) {
1759 return lt.getCurrentCountry();
1760 }
1761 }
1762 }
1763 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001764 } finally {
1765 Binder.restoreCallingIdentity(identity);
1766 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001767 }
1768
1769 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001771 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001772 }
1773
Sanket Padawe356d7632015-06-22 14:03:32 -07001774 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001775 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 mApp.enforceCallingOrSelfPermission(
1777 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001778
1779 final long identity = Binder.clearCallingIdentity();
1780 try {
1781 final Phone phone = getPhone(subId);
1782 if (phone != null) {
1783 phone.enableLocationUpdates();
1784 }
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
1789
1790 @Override
1791 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001792 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001793 }
1794
Sanket Padawe356d7632015-06-22 14:03:32 -07001795 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001796 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 mApp.enforceCallingOrSelfPermission(
1798 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001799
1800 final long identity = Binder.clearCallingIdentity();
1801 try {
1802 final Phone phone = getPhone(subId);
1803 if (phone != null) {
1804 phone.disableLocationUpdates();
1805 }
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Nathan Harold31d7ff32018-10-15 20:20:30 -07001811 /**
1812 * Returns the target SDK version number for a given package name.
1813 *
1814 * @return target SDK if the package is found or INT_MAX.
1815 */
1816 private int getTargetSdk(String packageName) {
1817 try {
1818 final ApplicationInfo ai =
1819 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1820 if (ai != null) return ai.targetSdkVersion;
1821 } catch (PackageManager.NameNotFoundException unexpected) {
1822 }
1823 return Integer.MAX_VALUE;
1824 }
1825
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 @Override
1827 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001828 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1829 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001830 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1831 throw new SecurityException(
1832 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1833 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001834
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1836 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1837 return null;
1838 }
Svetoslav64fad262015-04-14 14:35:21 -07001839
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001840 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841
Nathan Haroldf180aac2018-06-01 18:43:55 -07001842 List<CellInfo> info = getAllCellInfo(callingPackage);
1843 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844
Nathan Haroldf180aac2018-06-01 18:43:55 -07001845 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1846 for (CellInfo ci : info) {
1847 if (ci instanceof CellInfoGsm) {
1848 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1849 } else if (ci instanceof CellInfoWcdma) {
1850 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1851 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001852 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001853 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 }
1855
1856
1857 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001858 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001859 mPhone.getContext().getSystemService(AppOpsManager.class)
1860 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001861 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001862 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001863 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 }
1865
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001866 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001867 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001868 final long identity = Binder.clearCallingIdentity();
1869 try {
1870 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1871 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001872 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1873 CMD_GET_ALL_CELL_INFO,
1874 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaabec062018-02-28 15:00:40 -08001875 if (info != null) cellInfos.addAll(info);
1876 }
1877 return cellInfos;
1878 } finally {
1879 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 }
1881 }
1882
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001883 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001885 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001887
1888 final long identity = Binder.clearCallingIdentity();
1889 try {
1890 mPhone.setCellInfoListRate(rateInMillis, workSource);
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 }
1895
Shishir Agrawala9f32182016-04-12 12:00:16 -07001896 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001897 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001898 Phone phone = PhoneFactory.getPhone(slotIndex);
1899 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001900 return null;
1901 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001902 int subId = phone.getSubId();
1903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1904 mApp, subId, callingPackage, "getImeiForSlot")) {
1905 return null;
1906 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001907
1908 final long identity = Binder.clearCallingIdentity();
1909 try {
1910 return phone.getImei();
1911 } finally {
1912 Binder.restoreCallingIdentity(identity);
1913 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001914 }
1915
1916 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001917 public String getTypeAllocationCodeForSlot(int slotIndex) {
1918 Phone phone = PhoneFactory.getPhone(slotIndex);
1919 String tac = null;
1920 if (phone != null) {
1921 String imei = phone.getImei();
1922 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1923 }
1924 return tac;
1925 }
1926
1927 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001928 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001929 Phone phone = PhoneFactory.getPhone(slotIndex);
1930 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001931 return null;
1932 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001933 int subId = phone.getSubId();
1934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1935 mApp, subId, callingPackage, "getMeidForSlot")) {
1936 return null;
1937 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001938
1939 final long identity = Binder.clearCallingIdentity();
1940 try {
1941 return phone.getMeid();
1942 } finally {
1943 Binder.restoreCallingIdentity(identity);
1944 }
Jack Yu2af8d712017-03-15 17:14:14 -07001945 }
1946
1947 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001948 public String getManufacturerCodeForSlot(int slotIndex) {
1949 Phone phone = PhoneFactory.getPhone(slotIndex);
1950 String manufacturerCode = null;
1951 if (phone != null) {
1952 String meid = phone.getMeid();
1953 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1954 }
1955 return manufacturerCode;
1956 }
1957
1958 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001959 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001960 Phone phone = PhoneFactory.getPhone(slotIndex);
1961 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001962 return null;
1963 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001964 int subId = phone.getSubId();
1965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1966 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1967 return null;
1968 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001969
1970 final long identity = Binder.clearCallingIdentity();
1971 try {
1972 return phone.getDeviceSvn();
1973 } finally {
1974 Binder.restoreCallingIdentity(identity);
1975 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001976 }
1977
fionaxu43304da2017-11-27 22:51:16 -08001978 @Override
1979 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001980 final long identity = Binder.clearCallingIdentity();
1981 try {
1982 final Phone phone = getPhone(subId);
1983 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1984 } finally {
1985 Binder.restoreCallingIdentity(identity);
1986 }
fionaxu43304da2017-11-27 22:51:16 -08001987 }
1988
1989 @Override
1990 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001991 final long identity = Binder.clearCallingIdentity();
1992 try {
1993 final Phone phone = getPhone(subId);
1994 return phone == null ? null : phone.getCarrierName();
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
1997 }
fionaxu43304da2017-11-27 22:51:16 -08001998 }
1999
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 //
2001 // Internal helper methods.
2002 //
2003
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002004 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2006 *
2007 * @throws SecurityException if the caller does not have the required permission
2008 */
2009 private void enforceModifyPermission() {
2010 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2011 }
2012
2013 /**
2014 * Make sure the caller has the CALL_PHONE permission.
2015 *
2016 * @throws SecurityException if the caller does not have the required permission
2017 */
2018 private void enforceCallPermission() {
2019 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2020 }
2021
Stuart Scott8eef64f2015-04-08 15:13:54 -07002022 private void enforceConnectivityInternalPermission() {
2023 mApp.enforceCallingOrSelfPermission(
2024 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2025 "ConnectivityService");
2026 }
2027
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 private String createTelUrl(String number) {
2029 if (TextUtils.isEmpty(number)) {
2030 return null;
2031 }
2032
Jake Hambye994d462014-02-03 13:10:13 -08002033 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 }
2035
Ihab Awadf9e92732013-12-05 18:02:52 -08002036 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2038 }
2039
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002040 private static void logv(String msg) {
2041 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2042 }
2043
Ihab Awadf9e92732013-12-05 18:02:52 -08002044 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2046 }
2047
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002048 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002050 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002051 }
2052
Sanket Padawe356d7632015-06-22 14:03:32 -07002053 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002054 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 final Phone phone = PhoneFactory.getPhone(slotIndex);
2058 if (phone == null) {
2059 return PhoneConstants.PHONE_TYPE_NONE;
2060 } else {
2061 return phone.getPhoneType();
2062 }
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
2067
2068 /**
2069 * Returns the CDMA ERI icon index to display
2070 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002071 @Override
2072 public int getCdmaEriIconIndex(String callingPackage) {
2073 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002074 }
2075
Sanket Padawe356d7632015-06-22 14:03:32 -07002076 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002077 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002079 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002080 return -1;
2081 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002082
2083 final long identity = Binder.clearCallingIdentity();
2084 try {
2085 final Phone phone = getPhone(subId);
2086 if (phone != null) {
2087 return phone.getCdmaEriIconIndex();
2088 } else {
2089 return -1;
2090 }
2091 } finally {
2092 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 }
2095
2096 /**
2097 * Returns the CDMA ERI icon mode,
2098 * 0 - ON
2099 * 1 - FLASHING
2100 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002101 @Override
2102 public int getCdmaEriIconMode(String callingPackage) {
2103 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002104 }
2105
Sanket Padawe356d7632015-06-22 14:03:32 -07002106 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002107 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002109 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002110 return -1;
2111 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002112
2113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 final Phone phone = getPhone(subId);
2116 if (phone != null) {
2117 return phone.getCdmaEriIconMode();
2118 } else {
2119 return -1;
2120 }
2121 } finally {
2122 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 }
2125
2126 /**
2127 * Returns the CDMA ERI text,
2128 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002129 @Override
2130 public String getCdmaEriText(String callingPackage) {
2131 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002132 }
2133
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002135 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002137 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002138 return null;
2139 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002140
2141 final long identity = Binder.clearCallingIdentity();
2142 try {
2143 final Phone phone = getPhone(subId);
2144 if (phone != null) {
2145 return phone.getCdmaEriText();
2146 } else {
2147 return null;
2148 }
2149 } finally {
2150 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 }
2153
2154 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002155 * Returns the CDMA MDN.
2156 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002157 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002158 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2160 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002161
2162 final long identity = Binder.clearCallingIdentity();
2163 try {
2164 final Phone phone = getPhone(subId);
2165 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2166 return phone.getLine1Number();
2167 } else {
2168 return null;
2169 }
2170 } finally {
2171 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002172 }
2173 }
2174
2175 /**
2176 * Returns the CDMA MIN.
2177 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002178 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002179 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2181 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002182
2183 final long identity = Binder.clearCallingIdentity();
2184 try {
2185 final Phone phone = getPhone(subId);
2186 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2187 return phone.getCdmaMin();
2188 } else {
2189 return null;
2190 }
2191 } finally {
2192 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002193 }
2194 }
2195
2196 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 * Returns true if CDMA provisioning needs to run.
2198 */
2199 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 return mPhone.needsOtaServiceProvisioning();
2203 } finally {
2204 Binder.restoreCallingIdentity(identity);
2205 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 }
2207
2208 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002209 * Sets the voice mail number of a given subId.
2210 */
2211 @Override
2212 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002213 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002214
2215 final long identity = Binder.clearCallingIdentity();
2216 try {
2217 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2218 new Pair<String, String>(alphaTag, number), new Integer(subId));
2219 return success;
2220 } finally {
2221 Binder.restoreCallingIdentity(identity);
2222 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002223 }
2224
Ta-wei Yen87c49842016-05-13 21:19:52 -07002225 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002226 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2227 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2228 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2229 if (!TextUtils.equals(callingPackage, systemDialer)) {
2230 throw new SecurityException("caller must be system dialer");
2231 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002232
2233 final long identity = Binder.clearCallingIdentity();
2234 try {
2235 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2236 if (phoneAccountHandle == null) {
2237 return null;
2238 }
2239 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2240 } finally {
2241 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002242 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002243 }
2244
2245 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002246 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002247 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002249 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002250 return null;
2251 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002252
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002253 final long identity = Binder.clearCallingIdentity();
2254 try {
2255 return RemoteVvmTaskManager
2256 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2257 } finally {
2258 Binder.restoreCallingIdentity(identity);
2259 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002260 }
2261
2262 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002263 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2264 VisualVoicemailSmsFilterSettings settings) {
2265 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002266
2267 final long identity = Binder.clearCallingIdentity();
2268 try {
2269 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2270 mPhone.getContext(), callingPackage, subId, settings);
2271 } finally {
2272 Binder.restoreCallingIdentity(identity);
2273 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002274 }
2275
2276 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002277 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2278 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002279
2280 final long identity = Binder.clearCallingIdentity();
2281 try {
2282 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2283 mPhone.getContext(), callingPackage, subId);
2284 } finally {
2285 Binder.restoreCallingIdentity(identity);
2286 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002287 }
2288
2289 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002290 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2291 String callingPackage, int subId) {
2292 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002293
2294 final long identity = Binder.clearCallingIdentity();
2295 try {
2296 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2297 mPhone.getContext(), callingPackage, subId);
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
2300 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002301 }
2302
2303 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002304 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002305 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002306
2307 final long identity = Binder.clearCallingIdentity();
2308 try {
2309 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2310 mPhone.getContext(), subId);
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
2313 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002314 }
2315
2316 @Override
2317 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2318 String number, int port, String text, PendingIntent sentIntent) {
2319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002320 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002321 enforceSendSmsPermission();
2322 // Make the calls as the phone process.
2323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2326 if (port == 0) {
2327 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2328 sentIntent, null, false);
2329 } else {
2330 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2331 smsManager.sendDataMessageWithSelfPermissions(number, null,
2332 (short) port, data, sentIntent, null);
2333 }
2334 } finally {
2335 Binder.restoreCallingIdentity(identity);
2336 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002337 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002338 /**
fionaxu0152e512016-11-14 13:36:14 -08002339 * Sets the voice activation state of a given subId.
2340 */
2341 @Override
2342 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2344 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002345
2346 final long identity = Binder.clearCallingIdentity();
2347 try {
2348 final Phone phone = getPhone(subId);
2349 if (phone != null) {
2350 phone.setVoiceActivationState(activationState);
2351 } else {
2352 loge("setVoiceActivationState fails with invalid subId: " + subId);
2353 }
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002356 }
2357 }
2358
2359 /**
2360 * Sets the data activation state of a given subId.
2361 */
2362 @Override
2363 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2365 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002366
2367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 final Phone phone = getPhone(subId);
2370 if (phone != null) {
2371 phone.setDataActivationState(activationState);
2372 } else {
2373 loge("setVoiceActivationState fails with invalid subId: " + subId);
2374 }
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002377 }
2378 }
2379
2380 /**
2381 * Returns the voice activation state of a given subId.
2382 */
2383 @Override
2384 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002385 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002386
fionaxu0152e512016-11-14 13:36:14 -08002387 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 if (phone != null) {
2391 return phone.getVoiceActivationState();
2392 } else {
2393 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2394 }
2395 } finally {
2396 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002397 }
2398 }
2399
2400 /**
2401 * Returns the data activation state of a given subId.
2402 */
2403 @Override
2404 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002405 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002406
fionaxu0152e512016-11-14 13:36:14 -08002407 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 if (phone != null) {
2411 return phone.getDataActivationState();
2412 } else {
2413 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2414 }
2415 } finally {
2416 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002417 }
2418 }
2419
2420 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 * Returns the unread count of voicemails
2422 */
2423 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002424 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002425 }
2426
2427 /**
2428 * Returns the unread count of voicemails for a subId
2429 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002430 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002432 final long identity = Binder.clearCallingIdentity();
2433 try {
2434 final Phone phone = getPhone(subId);
2435 if (phone != null) {
2436 return phone.getVoiceMessageCount();
2437 } else {
2438 return 0;
2439 }
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444
2445 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002446 * returns true, if the device is in a state where both voice and data
2447 * are supported simultaneously. This can change based on location or network condition.
2448 */
2449 @Override
2450 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 final Phone phone = getPhone(subId);
2454 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2455 } finally {
2456 Binder.restoreCallingIdentity(identity);
2457 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002458 }
2459
2460 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002461 * Send the dialer code if called from the current default dialer or the caller has
2462 * carrier privilege.
2463 * @param inputCode The dialer code to send
2464 */
2465 @Override
2466 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2467 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2468 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2469 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002470 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2471 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002472 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002473
2474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 mPhone.sendDialerSpecialCode(inputCode);
2477 } finally {
2478 Binder.restoreCallingIdentity(identity);
2479 }
fionaxu235cc5e2017-03-06 22:25:57 -08002480 }
2481
2482 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002483 * Returns the data network type.
2484 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 *
2486 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2487 */
2488 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002489 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 final Phone phone = getPhone(getDefaultSubscription());
2493 if (phone != null) {
2494 return phone.getServiceState().getDataNetworkType();
2495 } else {
2496 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2497 }
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002500 }
Wink Saville36469e72014-06-11 15:17:00 -07002501 }
2502
Pengquan Meng0c05b502018-09-06 09:59:22 -07002503 @Override
2504 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002505 if (!isActiveSubscription(subId)) {
2506 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2507 }
2508
Pengquan Meng0c05b502018-09-06 09:59:22 -07002509 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2510 }
2511
Wink Saville36469e72014-06-11 15:17:00 -07002512 /**
2513 * Returns the network type for a subId
2514 */
2515 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002516 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002518 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002519 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2520 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002521
Malcolm Chenaabec062018-02-28 15:00:40 -08002522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 final Phone phone = getPhone(subId);
2525 if (phone != null) {
2526 return phone.getServiceState().getDataNetworkType();
2527 } else {
2528 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2529 }
2530 } finally {
2531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 }
2534
2535 /**
2536 * Returns the data network type
2537 */
2538 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002539 public int getDataNetworkType(String callingPackage) {
2540 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002541 }
2542
2543 /**
2544 * Returns the data network type for a subId
2545 */
2546 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002547 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002549 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2551 }
2552
Malcolm Chenaabec062018-02-28 15:00:40 -08002553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 return phone.getServiceState().getDataNetworkType();
2558 } else {
2559 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
2566 /**
Wink Saville36469e72014-06-11 15:17:00 -07002567 * Returns the Voice network type for a subId
2568 */
2569 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002570 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002572 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002573 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2574 }
2575
Malcolm Chenaabec062018-02-28 15:00:40 -08002576 final long identity = Binder.clearCallingIdentity();
2577 try {
2578 final Phone phone = getPhone(subId);
2579 if (phone != null) {
2580 return phone.getServiceState().getVoiceNetworkType();
2581 } else {
2582 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2583 }
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 }
2588
2589 /**
2590 * @return true if a ICC card is present
2591 */
2592 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002593 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002594 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2595 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002596 }
2597
2598 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002599 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002600 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002601 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002602 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 final Phone phone = PhoneFactory.getPhone(slotIndex);
2606 if (phone != null) {
2607 return phone.getIccCard().hasIccCard();
2608 } else {
2609 return false;
2610 }
2611 } finally {
2612 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 }
2615
2616 /**
2617 * Return if the current radio is LTE on CDMA. This
2618 * is a tri-state return value as for a period of time
2619 * the mode may be unknown.
2620 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002621 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002623 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002625 @Override
2626 public int getLteOnCdmaMode(String callingPackage) {
2627 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002628 }
2629
Sanket Padawe356d7632015-06-22 14:03:32 -07002630 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002631 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002633 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002634 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2635 }
2636
Malcolm Chenaabec062018-02-28 15:00:40 -08002637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 if (phone == null) {
2641 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2642 } else {
2643 return phone.getLteOnCdmaMode();
2644 }
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002647 }
Wink Saville36469e72014-06-11 15:17:00 -07002648 }
2649
2650 public void setPhone(Phone phone) {
2651 mPhone = phone;
2652 }
2653
2654 /**
2655 * {@hide}
2656 * Returns Default subId, 0 in the case of single standby.
2657 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002658 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002659 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002660 }
2661
Shishir Agrawala9f32182016-04-12 12:00:16 -07002662 private int getSlotForDefaultSubscription() {
2663 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2664 }
2665
Wink Savilleb564aae2014-10-23 10:18:09 -07002666 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002667 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002669
Pengquan Meng466e2482018-09-21 15:54:48 -07002670 private boolean isActiveSubscription(int subId) {
2671 return mSubscriptionController.isActiveSubId(subId);
2672 }
2673
Ihab Awadf2177b72013-11-25 13:33:23 -08002674 /**
2675 * @see android.telephony.TelephonyManager.WifiCallingChoices
2676 */
2677 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2681 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2682 getWhenToMakeWifiCallsDefaultPreference());
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002686 }
2687
2688 /**
2689 * @see android.telephony.TelephonyManager.WifiCallingChoices
2690 */
2691 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002692 final long identity = Binder.clearCallingIdentity();
2693 try {
2694 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2695 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2696 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
2699 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002700 }
2701
Sailesh Nepald1e68152013-12-12 19:08:02 -08002702 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002703 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002704 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002705 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002706
Shishir Agrawal566b7612013-10-28 14:41:00 -07002707 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002708 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2709 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2711 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002713
Malcolm Chenaabec062018-02-28 15:00:40 -08002714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 if (TextUtils.equals(ISDR_AID, aid)) {
2717 // Only allows LPA to open logical channel to ISD-R.
2718 ComponentInfo bestComponent =
2719 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2720 if (bestComponent == null
2721 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2722 loge("The calling package is not allowed to access ISD-R.");
2723 throw new SecurityException(
2724 "The calling package is not allowed to access ISD-R.");
2725 }
Derek Tan740e1672017-06-27 14:56:27 -07002726 }
Derek Tan740e1672017-06-27 14:56:27 -07002727
Malcolm Chenaabec062018-02-28 15:00:40 -08002728 if (DBG) {
2729 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2730 }
2731 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2732 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2733 if (DBG) log("iccOpenLogicalChannel: " + response);
2734 return response;
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
2737 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002738 }
2739
2740 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002741 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2743 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002744
Malcolm Chenaabec062018-02-28 15:00:40 -08002745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2748 if (channel < 0) {
2749 return false;
2750 }
2751 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2752 if (DBG) log("iccCloseLogicalChannel: " + success);
2753 return success;
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002756 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002757 }
2758
2759 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002760 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002761 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2763 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002764
Malcolm Chenaabec062018-02-28 15:00:40 -08002765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 if (DBG) {
2768 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2769 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2770 + p3 + " data=" + data);
2771 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002772
Malcolm Chenaabec062018-02-28 15:00:40 -08002773 if (channel < 0) {
2774 return "";
2775 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002776
Malcolm Chenaabec062018-02-28 15:00:40 -08002777 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2778 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2779 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002780
Malcolm Chenaabec062018-02-28 15:00:40 -08002781 // Append the returned status code to the end of the response payload.
2782 String s = Integer.toHexString(
2783 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2784 if (response.payload != null) {
2785 s = IccUtils.bytesToHexString(response.payload) + s;
2786 }
2787 return s;
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002790 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002791 }
Jake Hambye994d462014-02-03 13:10:13 -08002792
Evan Charltonc66da362014-05-16 14:06:40 -07002793 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002794 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2795 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2797 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002798 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002799
Malcolm Chenaabec062018-02-28 15:00:40 -08002800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2803 && TextUtils.equals(ISDR_AID, data)) {
2804 // Only allows LPA to select ISD-R.
2805 ComponentInfo bestComponent =
2806 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2807 if (bestComponent == null
2808 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2809 loge("The calling package is not allowed to select ISD-R.");
2810 throw new SecurityException(
2811 "The calling package is not allowed to select ISD-R.");
2812 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002813 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002814
Malcolm Chenaabec062018-02-28 15:00:40 -08002815 if (DBG) {
2816 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2817 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2818 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002819
Malcolm Chenaabec062018-02-28 15:00:40 -08002820 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2821 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2822 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002823
Malcolm Chenaabec062018-02-28 15:00:40 -08002824 // Append the returned status code to the end of the response payload.
2825 String s = Integer.toHexString(
2826 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2827 if (response.payload != null) {
2828 s = IccUtils.bytesToHexString(response.payload) + s;
2829 }
2830 return s;
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002833 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002834 }
2835
2836 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002837 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002838 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2840 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002841
Malcolm Chenaabec062018-02-28 15:00:40 -08002842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 if (DBG) {
2845 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2846 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2847 }
2848
2849 IccIoResult response =
2850 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2851 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2852 subId);
2853
2854 if (DBG) {
2855 log("Exchange SIM_IO [R]" + response);
2856 }
2857
2858 byte[] result = null;
2859 int length = 2;
2860 if (response.payload != null) {
2861 length = 2 + response.payload.length;
2862 result = new byte[length];
2863 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2864 } else {
2865 result = new byte[length];
2866 }
2867
2868 result[length - 1] = (byte) response.sw2;
2869 result[length - 2] = (byte) response.sw1;
2870 return result;
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002873 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002874 }
2875
Nathan Haroldb3014052017-01-25 15:57:32 -08002876 /**
2877 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2878 * on a particular subscription
2879 */
sqianb6e41952018-03-12 14:54:01 -07002880 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2882 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2883 return null;
2884 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002885 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2886 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2887 return null;
2888 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002889
2890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2893 if (response instanceof String[]) {
2894 return (String[]) response;
2895 }
2896 // Response is an Exception of some kind,
2897 // which is signalled to the user as a NULL retval
2898 return null;
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002901 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002902 }
2903
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002904 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002905 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2907 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002908
Malcolm Chenaabec062018-02-28 15:00:40 -08002909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2912 if (response.payload == null) {
2913 return "";
2914 }
Evan Charltonc66da362014-05-16 14:06:40 -07002915
Malcolm Chenaabec062018-02-28 15:00:40 -08002916 // Append the returned status code to the end of the response payload.
2917 String s = Integer.toHexString(
2918 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2919 s = IccUtils.bytesToHexString(response.payload) + s;
2920 return s;
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
2923 }
Evan Charltonc66da362014-05-16 14:06:40 -07002924 }
2925
Jake Hambye994d462014-02-03 13:10:13 -08002926 /**
2927 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2928 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2929 *
2930 * @param itemID the ID of the item to read
2931 * @return the NV item as a String, or null on error.
2932 */
2933 @Override
2934 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07002935 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2937 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08002938
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07002942 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08002943 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2944 return value;
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
2947 }
Jake Hambye994d462014-02-03 13:10:13 -08002948 }
2949
2950 /**
2951 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2952 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2953 *
2954 * @param itemID the ID of the item to read
2955 * @param itemValue the value to write, as a String
2956 * @return true on success; false on any failure
2957 */
2958 @Override
2959 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07002960 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08002961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2962 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08002963
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2967 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07002968 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08002969 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2970 return success;
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
2973 }
Jake Hambye994d462014-02-03 13:10:13 -08002974 }
2975
2976 /**
2977 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2978 * Used for device configuration by some CDMA operators.
2979 *
2980 * @param preferredRoamingList byte array containing the new PRL
2981 * @return true on success; false on any failure
2982 */
2983 @Override
2984 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2986 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08002987
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2991 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2992 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2993 return success;
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
Jake Hambye994d462014-02-03 13:10:13 -08002997 }
2998
2999 /**
3000 * Perform the specified type of NV config reset.
3001 * Used for device configuration by some CDMA operators.
3002 *
3003 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3004 * @return true on success; false on any failure
3005 */
3006 @Override
3007 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3009 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003010
3011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 if (DBG) log("nvResetConfig: type " + resetType);
3014 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3015 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3016 return success;
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
Jake Hambye994d462014-02-03 13:10:13 -08003020 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003021
Svet Ganovb320e182015-04-16 12:30:10 -07003022 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003023 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003024 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003025 return new String[0];
3026 }
3027
Malcolm Chenaabec062018-02-28 15:00:40 -08003028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 return mPhone.getPcscfAddress(apnType);
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
Wink Saville36469e72014-06-11 15:17:00 -07003034 }
3035
Brad Ebinger51f743a2017-01-23 13:50:20 -08003036 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003037 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3038 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003039 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003040 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003041 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003042
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 PhoneFactory.getImsResolver().enableIms(slotId);
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003049 }
3050
3051 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003052 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3053 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003054 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003055 public void disableIms(int slotId) {
3056 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003057
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 PhoneFactory.getImsResolver().disableIms(slotId);
3061 } finally {
3062 Binder.restoreCallingIdentity(identity);
3063 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003064 }
3065
3066 /**
3067 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3068 * feature or {@link null} if the service is not available. If the feature is available, the
3069 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3070 */
3071 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003072 IImsServiceFeatureCallback callback) {
3073 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003074
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003081 }
3082
3083 /**
3084 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3085 * feature during emergency calling or {@link null} if the service is not available. If the
3086 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3087 * listener for feature updates.
3088 */
3089 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3090 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003091
3092 final long identity = Binder.clearCallingIdentity();
3093 try {
3094 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3095 } finally {
3096 Binder.restoreCallingIdentity(identity);
3097 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003098 }
3099
Brad Ebinger5f64b052017-12-14 14:26:15 -08003100 /**
3101 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3102 * specified.
3103 */
3104 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3105 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003106
3107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003113 }
3114
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003115 /**
3116 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3117 * specified.
3118 */
3119 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3120 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003121
3122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003128 }
3129
Brad Ebinger884c07b2018-02-15 16:17:40 -08003130 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003131 * Sets the ImsService Package Name that Telephony will bind to.
3132 *
3133 * @param slotId the slot ID that the ImsService should bind for.
3134 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3135 * ImsService is the device default ImsService.
3136 * @param packageName The package name of the application that contains the ImsService to bind
3137 * to.
3138 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3139 * @hide
3140 */
3141 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003142 int[] subIds = SubscriptionManager.getSubId(slotId);
3143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3144 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3145 "setImsService");
3146
Malcolm Chenaabec062018-02-28 15:00:40 -08003147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3150 isCarrierImsService, packageName);
3151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003154 }
3155
3156 /**
3157 * Return the ImsService configuration.
3158 *
3159 * @param slotId The slot that the ImsService is associated with.
3160 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3161 * the device default.
3162 * @return the package name of the ImsService configuration.
3163 */
3164 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003165 int[] subIds = SubscriptionManager.getSubId(slotId);
3166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3167 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3168 "getImsService");
3169
Malcolm Chenaabec062018-02-28 15:00:40 -08003170 final long identity = Binder.clearCallingIdentity();
3171 try {
3172 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3173 isCarrierImsService);
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003177 }
3178
Wink Saville36469e72014-06-11 15:17:00 -07003179 public void setImsRegistrationState(boolean registered) {
3180 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003181
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 mPhone.setImsRegistrationState(registered);
3185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
Wink Saville36469e72014-06-11 15:17:00 -07003188 }
3189
3190 /**
Stuart Scott54788802015-03-30 13:18:01 -07003191 * Set the network selection mode to automatic.
3192 *
3193 */
3194 @Override
3195 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3197 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003198
Pengquan Meng466e2482018-09-21 15:54:48 -07003199 if (!isActiveSubscription(subId)) {
3200 return;
3201 }
3202
Malcolm Chenaabec062018-02-28 15:00:40 -08003203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3206 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
Stuart Scott54788802015-03-30 13:18:01 -07003210 }
3211
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003212 /**
3213 * Ask the radio to connect to the input network and change selection mode to manual.
3214 *
3215 * @param subId the id of the subscription.
3216 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3217 * the operator to attach to.
3218 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3219 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3220 * normal network selection next time.
3221 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003222 */
3223 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003224 public boolean setNetworkSelectionModeManual(
3225 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3227 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003228
3229 if (!isActiveSubscription(subId)) {
3230 return false;
3231 }
3232
Malcolm Chenaabec062018-02-28 15:00:40 -08003233 final long identity = Binder.clearCallingIdentity();
3234 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003235 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaabec062018-02-28 15:00:40 -08003236 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003237 if (DBG) {
3238 log("setNetworkSelectionModeManual: subId: " + subId
3239 + " operator: " + operatorInfo);
3240 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003241 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3242 } finally {
3243 Binder.restoreCallingIdentity(identity);
3244 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003245 }
3246
3247 /**
3248 * Scans for available networks.
3249 */
3250 @Override
3251 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3253 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003254
Pengquan Meng0c05b502018-09-06 09:59:22 -07003255 long identity = Binder.clearCallingIdentity();
Malcolm Chenaabec062018-02-28 15:00:40 -08003256 try {
3257 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003258 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaabec062018-02-28 15:00:40 -08003259 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08003260 } finally {
3261 Binder.restoreCallingIdentity(identity);
3262 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003263 }
3264
3265 /**
yinxub1bed742017-04-17 11:45:04 -07003266 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003267 *
yinxub1bed742017-04-17 11:45:04 -07003268 * @param subId id of the subscription
3269 * @param request contains the radio access networks with bands/channels to scan
3270 * @param messenger callback messenger for scan results or errors
3271 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003272 * @return the id of the requested scan which can be used to stop the scan.
3273 */
3274 @Override
3275 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3276 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3278 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003279
3280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 return mNetworkScanRequestTracker.startNetworkScan(
3283 request, messenger, binder, getPhone(subId));
3284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
yinxu504e1392017-04-12 16:03:22 -07003287 }
3288
3289 /**
3290 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003291 *
3292 * @param subId id of the subscription
3293 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003294 */
3295 @Override
3296 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3298 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003299
3300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
yinxu504e1392017-04-12 16:03:22 -07003306 }
3307
3308 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003309 * Get the calculated preferred network type.
3310 * Used for debugging incorrect network type.
3311 *
3312 * @return the preferred network type, defined in RILConstants.java.
3313 */
3314 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003315 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003317 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003318 return RILConstants.PREFERRED_NETWORK_MODE;
3319 }
3320
Malcolm Chenaabec062018-02-28 15:00:40 -08003321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 // FIXME: need to get SubId from somewhere.
3324 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
Junda Liu84d15a22014-07-02 11:21:04 -07003328 }
3329
3330 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003331 * Get the preferred network type.
3332 * Used for device configuration by some CDMA operators.
3333 *
3334 * @return the preferred network type, defined in RILConstants.java.
3335 */
3336 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003337 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3339 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003340
3341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 if (DBG) log("getPreferredNetworkType");
3344 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3345 int networkType = (result != null ? result[0] : -1);
3346 if (DBG) log("getPreferredNetworkType: " + networkType);
3347 return networkType;
3348 } finally {
3349 Binder.restoreCallingIdentity(identity);
3350 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003351 }
3352
3353 /**
3354 * Set the preferred network type.
3355 * Used for device configuration by some CDMA operators.
3356 *
3357 * @param networkType the preferred network type, defined in RILConstants.java.
3358 * @return true on success; false on any failure.
3359 */
3360 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003361 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3363 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003364
3365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3368 Boolean success = (Boolean) sendRequest(
3369 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3370 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3371 if (success) {
3372 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3373 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3374 }
3375 return success;
3376 } finally {
3377 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003378 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003379 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003380
3381 /**
Junda Liu475951f2014-11-07 16:45:03 -08003382 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3383 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3384 * tethering.
3385 *
3386 * @return 0: Not required. 1: required. 2: Not set.
3387 * @hide
3388 */
3389 @Override
3390 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003391 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003392
3393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3396 Settings.Global.TETHER_DUN_REQUIRED, 2);
3397 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3398 // config_tether_apndata.
3399 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3400 dunRequired = 1;
3401 }
3402 return dunRequired;
3403 } finally {
3404 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003405 }
Junda Liu475951f2014-11-07 16:45:03 -08003406 }
3407
3408 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003409 * Set mobile data enabled
3410 * Used by the user through settings etc to turn on/off mobile data
3411 *
3412 * @param enable {@code true} turn turn data on, else {@code false}
3413 */
3414 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003415 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3417 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003418
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 int phoneId = mSubscriptionController.getPhoneId(subId);
3422 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3423 Phone phone = PhoneFactory.getPhone(phoneId);
3424 if (phone != null) {
3425 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3426 phone.setUserDataEnabled(enable);
3427 } else {
3428 loge("setUserDataEnabled: no phone for subId=" + subId);
3429 }
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003432 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003433 }
3434
3435 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003436 * Get the user enabled state of Mobile Data.
3437 *
3438 * TODO: remove and use isUserDataEnabled.
3439 * This can't be removed now because some vendor codes
3440 * calls through ITelephony directly while they should
3441 * use TelephonyManager.
3442 *
3443 * @return true on enabled
3444 */
3445 @Override
3446 public boolean getDataEnabled(int subId) {
3447 return isUserDataEnabled(subId);
3448 }
3449
3450 /**
3451 * Get whether mobile data is enabled per user setting.
3452 *
3453 * There are other factors deciding whether mobile data is actually enabled, but they are
3454 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003455 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003456 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003457 *
3458 * @return {@code true} if data is enabled else {@code false}
3459 */
3460 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003461 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003462 try {
3463 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3464 null);
3465 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3467 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003468 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003469
3470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 int phoneId = mSubscriptionController.getPhoneId(subId);
3473 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3474 Phone phone = PhoneFactory.getPhone(phoneId);
3475 if (phone != null) {
3476 boolean retVal = phone.isUserDataEnabled();
3477 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3478 return retVal;
3479 } else {
3480 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3481 return false;
3482 }
3483 } finally {
3484 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003485 }
3486 }
3487
3488 /**
3489 * Get whether mobile data is enabled.
3490 *
3491 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3492 * whether mobile data is actually enabled.
3493 *
3494 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3495 *
3496 * @return {@code true} if data is enabled else {@code false}
3497 */
3498 @Override
3499 public boolean isDataEnabled(int subId) {
3500 try {
3501 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3502 null);
3503 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3505 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003506 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003507
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 int phoneId = mSubscriptionController.getPhoneId(subId);
3511 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3512 Phone phone = PhoneFactory.getPhone(phoneId);
3513 if (phone != null) {
3514 boolean retVal = phone.isDataEnabled();
3515 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3516 return retVal;
3517 } else {
3518 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3519 return false;
3520 }
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003523 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003524 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003525
3526 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003527 public int getCarrierPrivilegeStatus(int subId) {
3528 final Phone phone = getPhone(subId);
3529 if (phone == null) {
3530 loge("getCarrierPrivilegeStatus: Invalid subId");
3531 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3532 }
3533 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003534 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003535 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003536 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3537 }
3538 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003539 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003540 }
Junda Liu29340342014-07-10 15:23:27 -07003541
3542 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3544 final Phone phone = getPhone(subId);
3545 if (phone == null) {
3546 loge("getCarrierPrivilegeStatus: Invalid subId");
3547 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3548 }
3549 UiccProfile profile =
3550 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3551 if (profile == null) {
3552 loge("getCarrierPrivilegeStatus: No UICC");
3553 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3554 }
3555 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3556 }
3557
3558 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003559 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003560 if (TextUtils.isEmpty(pkgName))
3561 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003562 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003563 if (card == null) {
3564 loge("checkCarrierPrivilegesForPackage: No UICC");
3565 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3566 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003567 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3568 }
3569
3570 @Override
3571 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003572 if (TextUtils.isEmpty(pkgName))
3573 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003574 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3575 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3576 UiccCard card = UiccController.getInstance().getUiccCard(i);
3577 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003578 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003579 continue;
3580 }
3581
3582 result = card.getCarrierPrivilegeStatus(
3583 mPhone.getContext().getPackageManager(), pkgName);
3584 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3585 break;
3586 }
3587 }
3588
3589 return result;
Junda Liu29340342014-07-10 15:23:27 -07003590 }
Derek Tan89e89d42014-07-08 17:00:10 -07003591
3592 @Override
Junda Liue64de782015-04-16 17:19:16 -07003593 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3594 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3595 loge("phoneId " + phoneId + " is not valid.");
3596 return null;
3597 }
3598 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003599 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003600 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003601 return null ;
3602 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003603 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003604 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003605 }
3606
Amith Yamasani6e118872016-02-19 12:53:51 -08003607 @Override
3608 public List<String> getPackagesWithCarrierPrivileges() {
3609 PackageManager pm = mPhone.getContext().getPackageManager();
3610 List<String> privilegedPackages = new ArrayList<>();
3611 List<PackageInfo> packages = null;
3612 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3613 UiccCard card = UiccController.getInstance().getUiccCard(i);
3614 if (card == null) {
3615 // No UICC in that slot.
3616 continue;
3617 }
3618 if (card.hasCarrierPrivilegeRules()) {
3619 if (packages == null) {
3620 // Only check packages in user 0 for now
3621 packages = pm.getInstalledPackagesAsUser(
3622 PackageManager.MATCH_DISABLED_COMPONENTS
3623 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3624 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3625 }
3626 for (int p = packages.size() - 1; p >= 0; p--) {
3627 PackageInfo pkgInfo = packages.get(p);
3628 if (pkgInfo != null && pkgInfo.packageName != null
3629 && card.getCarrierPrivilegeStatus(pkgInfo)
3630 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3631 privilegedPackages.add(pkgInfo.packageName);
3632 }
3633 }
3634 }
3635 }
3636 return privilegedPackages;
3637 }
3638
Wink Savilleb564aae2014-10-23 10:18:09 -07003639 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003640 final Phone phone = getPhone(subId);
3641 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003642 if (card == null) {
3643 loge("getIccId: No UICC");
3644 return null;
3645 }
3646 String iccId = card.getIccId();
3647 if (TextUtils.isEmpty(iccId)) {
3648 loge("getIccId: ICC ID is null or empty.");
3649 return null;
3650 }
3651 return iccId;
3652 }
3653
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003654 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003655 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3656 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003657 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3658 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003659
Malcolm Chenaabec062018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 final String iccId = getIccId(subId);
3663 final Phone phone = getPhone(subId);
3664 if (phone == null) {
3665 return false;
3666 }
3667 final String subscriberId = phone.getSubscriberId();
3668
3669 if (DBG_MERGE) {
3670 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3671 + subscriberId + " to " + number);
3672 }
3673
3674 if (TextUtils.isEmpty(iccId)) {
3675 return false;
3676 }
3677
3678 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3679
3680 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3681 if (alphaTag == null) {
3682 editor.remove(alphaTagPrefKey);
3683 } else {
3684 editor.putString(alphaTagPrefKey, alphaTag);
3685 }
3686
3687 // Record both the line number and IMSI for this ICCID, since we need to
3688 // track all merged IMSIs based on line number
3689 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3690 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3691 if (number == null) {
3692 editor.remove(numberPrefKey);
3693 editor.remove(subscriberPrefKey);
3694 } else {
3695 editor.putString(numberPrefKey, number);
3696 editor.putString(subscriberPrefKey, subscriberId);
3697 }
3698
3699 editor.commit();
3700 return true;
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003703 }
Derek Tan7226c842014-07-02 17:42:23 -07003704 }
3705
3706 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003707 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003708 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003710 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003711 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003712 return null;
3713 }
Derek Tan97ebb422014-09-05 16:55:38 -07003714
Malcolm Chenaabec062018-02-28 15:00:40 -08003715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 String iccId = getIccId(subId);
3718 if (iccId != null) {
3719 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3720 if (DBG_MERGE) {
3721 log("getLine1NumberForDisplay returning "
3722 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3723 }
3724 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003725 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003726 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3727 return null;
3728 } finally {
3729 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003730 }
Derek Tan7226c842014-07-02 17:42:23 -07003731 }
3732
3733 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003734 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003736 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003737 return null;
3738 }
Derek Tan97ebb422014-09-05 16:55:38 -07003739
Malcolm Chenaabec062018-02-28 15:00:40 -08003740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 String iccId = getIccId(subId);
3743 if (iccId != null) {
3744 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3745 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3746 }
3747 return null;
3748 } finally {
3749 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003750 }
Derek Tan7226c842014-07-02 17:42:23 -07003751 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003752
3753 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003754 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003755 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3756 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003758 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3759 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003760 return null;
3761 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003762
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003763 final long identity = Binder.clearCallingIdentity();
3764 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003765 final Context context = mPhone.getContext();
3766 final TelephonyManager tele = TelephonyManager.from(context);
3767 final SubscriptionManager sub = SubscriptionManager.from(context);
3768
3769 // Figure out what subscribers are currently active
3770 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3771 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3772 // the process, where TelephonyManager was instantiated.
3773 // Otherwise AppOps check will fail.
3774
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003775 final int[] subIds = sub.getActiveSubscriptionIdList();
3776 for (int subId : subIds) {
3777 activeSubscriberIds.add(tele.getSubscriberId(subId));
3778 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003779
3780 // First pass, find a number override for an active subscriber
3781 String mergeNumber = null;
3782 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3783 for (String key : prefs.keySet()) {
3784 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3785 final String subscriberId = (String) prefs.get(key);
3786 if (activeSubscriberIds.contains(subscriberId)) {
3787 final String iccId = key.substring(
3788 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3789 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3790 mergeNumber = (String) prefs.get(numberKey);
3791 if (DBG_MERGE) {
3792 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3793 + " for active subscriber " + subscriberId);
3794 }
3795 if (!TextUtils.isEmpty(mergeNumber)) {
3796 break;
3797 }
3798 }
3799 }
3800 }
3801
3802 // Shortcut when no active merged subscribers
3803 if (TextUtils.isEmpty(mergeNumber)) {
3804 return null;
3805 }
3806
3807 // Second pass, find all subscribers under that line override
3808 final ArraySet<String> result = new ArraySet<>();
3809 for (String key : prefs.keySet()) {
3810 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3811 final String number = (String) prefs.get(key);
3812 if (mergeNumber.equals(number)) {
3813 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3814 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3815 final String subscriberId = (String) prefs.get(subscriberKey);
3816 if (!TextUtils.isEmpty(subscriberId)) {
3817 result.add(subscriberId);
3818 }
3819 }
3820 }
3821 }
3822
3823 final String[] resultArray = result.toArray(new String[result.size()]);
3824 Arrays.sort(resultArray);
3825 if (DBG_MERGE) {
3826 Slog.d(LOG_TAG,
3827 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3828 }
3829 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003830 } finally {
3831 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003832 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003833 }
3834
3835 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003836 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003837 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3838 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003839
3840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 final Phone phone = getPhone(subId);
3843 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3844 } finally {
3845 Binder.restoreCallingIdentity(identity);
3846 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003847 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003848
3849 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003850 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003851 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3852 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003853 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003854
3855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 final Phone phone = getPhone(subId);
3858 if (phone == null) {
3859 return false;
3860 }
3861 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3862 cdmaNonRoamingList);
3863 } finally {
3864 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003865 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003866 }
3867
3868 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003869 @Deprecated
3870 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3871 enforceModifyPermission();
3872
3873 int returnValue = 0;
3874 try {
vagdevie435a3e2018-08-15 16:01:53 -07003875 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003876 if(result.exception == null) {
3877 if (result.result != null) {
3878 byte[] responseData = (byte[])(result.result);
3879 if(responseData.length > oemResp.length) {
3880 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3881 responseData.length + "bytes. Buffer Size is " +
3882 oemResp.length + "bytes.");
3883 }
3884 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3885 returnValue = responseData.length;
3886 }
3887 } else {
3888 CommandException ex = (CommandException) result.exception;
3889 returnValue = ex.getCommandError().ordinal();
3890 if(returnValue > 0) returnValue *= -1;
3891 }
3892 } catch (RuntimeException e) {
3893 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3894 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3895 if(returnValue > 0) returnValue *= -1;
3896 }
3897
3898 return returnValue;
3899 }
3900
3901 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003902 public void setRadioCapability(RadioAccessFamily[] rafs) {
3903 try {
3904 ProxyController.getInstance().setRadioCapability(rafs);
3905 } catch (RuntimeException e) {
3906 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3907 }
3908 }
3909
3910 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003911 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003912 Phone phone = PhoneFactory.getPhone(phoneId);
3913 if (phone == null) {
3914 return RadioAccessFamily.RAF_UNKNOWN;
3915 }
3916 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003918 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003919 return RadioAccessFamily.RAF_UNKNOWN;
3920 }
3921
Malcolm Chenaabec062018-02-28 15:00:40 -08003922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3925 } finally {
3926 Binder.restoreCallingIdentity(identity);
3927 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003928 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003929
3930 @Override
3931 public void enableVideoCalling(boolean enable) {
3932 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003933
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003940 }
3941
3942 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003943 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3945 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3946 return false;
3947 }
Svet Ganovb320e182015-04-16 12:30:10 -07003948
Malcolm Chenaabec062018-02-28 15:00:40 -08003949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 // Check the user preference and the system-level IMS setting. Even if the user has
3952 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3953 // In the long run, we may instead need to check if there exists a connection service
3954 // which can support video calling.
3955 ImsManager imsManager =
3956 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3957 return imsManager.isVtEnabledByPlatform()
3958 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3959 && imsManager.isVtEnabledByUser();
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
3962 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003963 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003964
Andrew Leea1239f22015-03-02 17:44:07 -08003965 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08003966 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
3967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3968 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
3969 return false;
3970 }
3971
3972 final long identity = Binder.clearCallingIdentity();
3973 try {
3974 CarrierConfigManager configManager =
3975 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
3976 return configManager.getConfigForSubId(mPhone.getSubId())
3977 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
3978 } finally {
3979 Binder.restoreCallingIdentity(identity);
3980 }
Andrew Leea1239f22015-03-02 17:44:07 -08003981 }
3982
3983 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08003984 public boolean isWorldPhone(int subId, String callingPackage) {
3985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3986 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
3987 return false;
3988 }
3989
3990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 CarrierConfigManager configManager =
3993 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
3994 return configManager.getConfigForSubId(mPhone.getSubId())
3995 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
3996 } finally {
3997 Binder.restoreCallingIdentity(identity);
3998 }
Andrew Leea1239f22015-03-02 17:44:07 -08003999 }
4000
Andrew Lee9431b832015-03-09 18:46:45 -07004001 @Override
4002 public boolean isTtyModeSupported() {
4003 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004004 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004005 }
4006
4007 @Override
4008 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4012 } finally {
4013 Binder.restoreCallingIdentity(identity);
4014 }
Andrew Lee9431b832015-03-09 18:46:45 -07004015 }
4016
Hall Liu98187582018-01-22 19:15:32 -08004017 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004018 final long identity = Binder.clearCallingIdentity();
4019 try {
4020 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4021 mPhone.getSubId()).getBoolean(
4022 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4023 boolean isDeviceSupported =
4024 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4025 return isCarrierSupported && isDeviceSupported;
4026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
Hall Liu98187582018-01-22 19:15:32 -08004029 }
4030
Hall Liu3ad5f012018-04-06 16:23:39 -07004031 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 return isRttSupported() && Settings.Secure.getInt(
4035 mPhone.getContext().getContentResolver(),
4036 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4037 } finally {
4038 Binder.restoreCallingIdentity(identity);
4039 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004040 }
4041
Sanket Padawe7310cc72015-01-14 09:53:20 -08004042 /**
4043 * Returns the unique device ID of phone, for example, the IMEI for
4044 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4045 *
4046 * <p>Requires Permission:
4047 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4048 */
4049 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004050 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004051 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004052 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004053 return null;
4054 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004055 int subId = phone.getSubId();
4056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4057 mApp, subId, callingPackage, "getDeviceId")) {
4058 return null;
4059 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004060
4061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 return phone.getDeviceId();
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
4066 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004067 }
4068
Ping Sunc67b7c22016-03-02 19:16:45 +08004069 /**
4070 * {@hide}
4071 * Returns the IMS Registration Status on a particular subid
4072 *
4073 * @param subId
4074 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004075 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004076 Phone phone = getPhone(subId);
4077 if (phone != null) {
4078 return phone.isImsRegistered();
4079 } else {
4080 return false;
4081 }
4082 }
4083
Santos Cordon7a1885b2015-02-03 11:15:19 -08004084 @Override
4085 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
4091 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004092 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004093
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004094 /**
4095 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004096 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004097 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 Phone phone = getPhone(subId);
4101 if (phone != null) {
4102 return phone.isWifiCallingEnabled();
4103 } else {
4104 return false;
4105 }
4106 } finally {
4107 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004108 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004109 }
4110
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004111 /**
4112 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004113 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004114 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 Phone phone = getPhone(subId);
4118 if (phone != null) {
4119 return phone.isVolteEnabled();
4120 } else {
4121 return false;
4122 }
4123 } finally {
4124 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004125 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004126 }
Svet Ganovb320e182015-04-16 12:30:10 -07004127
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004128 /**
4129 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004130 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004131 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004132 final long identity = Binder.clearCallingIdentity();
4133 try {
4134 Phone phone = getPhone(subId);
4135 if (phone != null) {
4136 return phone.isVideoEnabled();
4137 } else {
4138 return false;
4139 }
4140 } finally {
4141 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004142 }
4143 }
4144
4145 /**
4146 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4147 * defined in {@link ImsRegistrationImplBase}.
4148 */
4149 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 Phone phone = getPhone(subId);
4153 if (phone != null) {
4154 return phone.getImsRegistrationTech();
4155 } else {
4156 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4157 }
4158 } finally {
4159 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004160 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004161 }
4162
Stuart Scott8eef64f2015-04-08 15:13:54 -07004163 @Override
4164 public void factoryReset(int subId) {
4165 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004166 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4167 return;
4168 }
4169
Svet Ganovcc087f82015-05-12 20:35:54 -07004170 final long identity = Binder.clearCallingIdentity();
4171 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004172 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4173 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004174 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004175 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004176 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4177 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004178 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004179 }
4180 } finally {
4181 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004182 }
4183 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004184
4185 @Override
4186 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 // We query all subscriptions instead of just the active ones, because
4190 // this might be called early on in the provisioning flow when the
4191 // subscriptions potentially aren't active yet.
4192 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4193 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004194 return null;
4195 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004196
Malcolm Chenaabec062018-02-28 15:00:40 -08004197 // This function may be called very early, say, from the setup wizard, at
4198 // which point we won't have a default subscription set. If that's the case
4199 // we just choose the first, which will be valid in "most cases".
4200 final int defaultSubId = getDefaultSubscription();
4201 SubscriptionInfo info = null;
4202 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4203 info = slist.get(0);
4204 } else {
4205 for (SubscriptionInfo item : slist) {
4206 if (item.getSubscriptionId() == defaultSubId) {
4207 info = item;
4208 break;
4209 }
4210 }
4211
4212 if (info == null) {
4213 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004214 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004215 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004216
Malcolm Chenaabec062018-02-28 15:00:40 -08004217 // Try and fetch the locale from the carrier properties or from the SIM language
4218 // preferences (EF-PL and EF-LI)...
4219 final int mcc = info.getMcc();
4220 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4221 String simLanguage = null;
4222 if (defaultPhone != null) {
4223 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4224 if (localeFromDefaultSim != null) {
4225 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4226 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4227 return localeFromDefaultSim.toLanguageTag();
4228 } else {
4229 simLanguage = localeFromDefaultSim.getLanguage();
4230 }
4231 }
4232 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004233
Malcolm Chenaabec062018-02-28 15:00:40 -08004234 // The SIM language preferences only store a language (e.g. fr = French), not an
4235 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4236 // the SIM and carrier preferences does not include a country we add the country
4237 // determined from the SIM MCC to provide an exact locale.
4238 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4239 simLanguage);
4240 if (mccLocale != null) {
4241 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4242 return mccLocale.toLanguageTag();
4243 }
4244
4245 if (DBG) log("No locale found - returning null");
4246 return null;
4247 } finally {
4248 Binder.restoreCallingIdentity(identity);
4249 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004250 }
4251
4252 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004253 return mSubscriptionController.getAllSubInfoList(
4254 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004255 }
4256
Malcolm Chenaabec062018-02-28 15:00:40 -08004257 /**
4258 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4259 */
4260 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4261 return mSubscriptionController.getActiveSubscriptionInfoList(
4262 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004263 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004264
Chenjie Yu1ba97252018-01-11 18:16:20 -08004265 private final ModemActivityInfo mLastModemActivityInfo =
4266 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4267
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004268 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004269 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4270 * representing the state of the modem.
4271 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004272 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4273 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004274 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004275 */
4276 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004277 public void requestModemActivityInfo(ResultReceiver result) {
4278 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004279 ModemActivityInfo ret = null;
vagdevie435a3e2018-08-15 16:01:53 -07004280 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Adam Lesinski903a54c2016-04-11 14:49:52 -07004281
Malcolm Chenaabec062018-02-28 15:00:40 -08004282 final long identity = Binder.clearCallingIdentity();
4283 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004284 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004285 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4286 CMD_GET_MODEM_ACTIVITY_INFO,
4287 null, workSource);
Siddharth Rayc339f892018-06-17 15:02:38 -07004288 if (isModemActivityInfoValid(info)) {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004289 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4290 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4291 mergedTxTimeMs[i] =
4292 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4293 }
4294 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4295 mLastModemActivityInfo.setSleepTimeMillis(
4296 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4297 mLastModemActivityInfo.setIdleTimeMillis(
4298 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4299 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4300 mLastModemActivityInfo.setRxTimeMillis(
4301 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4302 mLastModemActivityInfo.setEnergyUsed(
4303 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004304 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004305 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4306 mLastModemActivityInfo.getSleepTimeMillis(),
4307 mLastModemActivityInfo.getIdleTimeMillis(),
4308 mLastModemActivityInfo.getTxTimeMillis(),
4309 mLastModemActivityInfo.getRxTimeMillis(),
4310 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004311 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004312 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004313 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004314 result.send(0, bundle);
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004317 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004318 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004319
Siddharth Rayc339f892018-06-17 15:02:38 -07004320 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4321 // less than total activity duration.
4322 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4323 if (info == null) {
4324 return false;
4325 }
4326 int activityDurationMs =
4327 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4328 int totalTxTimeMs = 0;
4329 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4330 totalTxTimeMs += info.getTxTimeMillis()[i];
4331 }
4332 return (info.isValid()
4333 && (info.getSleepTimeMillis() <= activityDurationMs)
4334 && (info.getIdleTimeMillis() <= activityDurationMs)
4335 && (info.getRxTimeMillis() <= activityDurationMs)
4336 && (totalTxTimeMs <= activityDurationMs));
4337 }
4338
Jack Yu85bd38a2015-11-09 11:34:32 -08004339 /**
4340 * {@hide}
4341 * Returns the service state information on specified subscription.
4342 */
4343 @Override
4344 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004346 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004347 return null;
4348 }
4349
Malcolm Chenaabec062018-02-28 15:00:40 -08004350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 final Phone phone = getPhone(subId);
4353 if (phone == null) {
4354 return null;
4355 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004356
Malcolm Chenaabec062018-02-28 15:00:40 -08004357 return phone.getServiceState();
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004361 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004362
4363 /**
4364 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4365 *
4366 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4367 * voicemail ringtone.
4368 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4369 * PhoneAccount.
4370 */
4371 @Override
4372 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4376 if (phone == null) {
4377 phone = mPhone;
4378 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004379
Malcolm Chenaabec062018-02-28 15:00:40 -08004380 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004384 }
4385
4386 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004387 * Sets the per-account voicemail ringtone.
4388 *
4389 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4390 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4391 *
4392 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4393 * voicemail ringtone.
4394 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4395 * PhoneAccount.
4396 */
4397 @Override
4398 public void setVoicemailRingtoneUri(String callingPackage,
4399 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4400 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4401 if (!TextUtils.equals(callingPackage,
4402 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4404 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4405 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004406 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004407
4408 final long identity = Binder.clearCallingIdentity();
4409 try {
4410 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4411 if (phone == null) {
4412 phone = mPhone;
4413 }
4414 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004417 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004418 }
4419
4420 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004421 * Returns whether vibration is set for voicemail notification in Phone settings.
4422 *
4423 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4424 * voicemail vibration setting.
4425 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4426 */
4427 @Override
4428 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004429 final long identity = Binder.clearCallingIdentity();
4430 try {
4431 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4432 if (phone == null) {
4433 phone = mPhone;
4434 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004435
Malcolm Chenaabec062018-02-28 15:00:40 -08004436 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004440 }
4441
Youhan Wange64578a2016-05-02 15:32:42 -07004442 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004443 * Sets the per-account voicemail vibration.
4444 *
4445 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4446 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4447 *
4448 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4449 * voicemail vibration setting.
4450 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4451 * specific PhoneAccount.
4452 */
4453 @Override
4454 public void setVoicemailVibrationEnabled(String callingPackage,
4455 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4457 if (!TextUtils.equals(callingPackage,
4458 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4460 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4461 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004462 }
4463
Malcolm Chenaabec062018-02-28 15:00:40 -08004464 final long identity = Binder.clearCallingIdentity();
4465 try {
4466 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4467 if (phone == null) {
4468 phone = mPhone;
4469 }
4470 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4471 } finally {
4472 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004473 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004474 }
4475
4476 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004477 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4478 *
4479 * @throws SecurityException if the caller does not have the required permission
4480 */
4481 private void enforceReadPrivilegedPermission() {
4482 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4483 null);
4484 }
4485
4486 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004487 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4488 * permission.
4489 *
4490 * @throws SecurityException if the caller does not have the required permission
4491 */
4492 private void enforceSendSmsPermission() {
4493 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4494 }
4495
4496 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004497 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004498 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004499 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004500 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004501 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004502 final long identity = Binder.clearCallingIdentity();
4503 try {
4504 ComponentName componentName =
4505 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4506 if (componentName == null) {
4507 throw new SecurityException(
4508 "Caller not current active visual voicemail package[null]");
4509 }
4510 String vvmPackage = componentName.getPackageName();
4511 if (!callingPackage.equals(vvmPackage)) {
4512 throw new SecurityException("Caller not current active visual voicemail package["
4513 + vvmPackage + "]");
4514 }
4515 } finally {
4516 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004517 }
4518 }
4519
4520 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004521 * Return the application ID for the app type.
4522 *
4523 * @param subId the subscription ID that this request applies to.
4524 * @param appType the uicc app type.
4525 * @return Application ID for specificied app type, or null if no uicc.
4526 */
4527 @Override
4528 public String getAidForAppType(int subId, int appType) {
4529 enforceReadPrivilegedPermission();
4530 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004531
4532 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004533 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004534 if (phone == null) {
4535 return null;
4536 }
4537 String aid = null;
4538 try {
4539 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4540 .getApplicationByType(appType).getAid();
4541 } catch (Exception e) {
4542 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4543 }
4544 return aid;
4545 } finally {
4546 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004547 }
Youhan Wange64578a2016-05-02 15:32:42 -07004548 }
4549
Youhan Wang4001d252016-05-11 10:29:41 -07004550 /**
4551 * Return the Electronic Serial Number.
4552 *
4553 * @param subId the subscription ID that this request applies to.
4554 * @return ESN or null if error.
4555 */
4556 @Override
4557 public String getEsn(int subId) {
4558 enforceReadPrivilegedPermission();
4559 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004560
4561 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004562 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004563 if (phone == null) {
4564 return null;
4565 }
4566 String esn = null;
4567 try {
4568 esn = phone.getEsn();
4569 } catch (Exception e) {
4570 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4571 }
4572 return esn;
4573 } finally {
4574 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004575 }
Youhan Wang4001d252016-05-11 10:29:41 -07004576 }
4577
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004578 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004579 * Return the Preferred Roaming List Version.
4580 *
4581 * @param subId the subscription ID that this request applies to.
4582 * @return PRLVersion or null if error.
4583 */
4584 @Override
4585 public String getCdmaPrlVersion(int subId) {
4586 enforceReadPrivilegedPermission();
4587 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004588
4589 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004590 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004591 if (phone == null) {
4592 return null;
4593 }
4594 String cdmaPrlVersion = null;
4595 try {
4596 cdmaPrlVersion = phone.getCdmaPrlVersion();
4597 } catch (Exception e) {
4598 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4599 }
4600 return cdmaPrlVersion;
4601 } finally {
4602 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004603 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004604 }
4605
4606 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004607 * Get snapshot of Telephony histograms
4608 * @return List of Telephony histograms
4609 * @hide
4610 */
4611 @Override
4612 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4614 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004615
4616 final long identity = Binder.clearCallingIdentity();
4617 try {
4618 return RIL.getTelephonyRILTimingHistograms();
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004622 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004623
4624 /**
4625 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004626 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004627 * Require system privileges. In the future we may add this to carrier APIs.
4628 *
4629 * @return The number of carriers set successfully, should match length of carriers
4630 */
4631 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004632 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004633 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004634 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004635
Meng Wang9b7c4e92017-02-17 11:41:27 -08004636 if (carriers == null) {
4637 throw new NullPointerException("carriers cannot be null");
4638 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004639
Malcolm Chenaabec062018-02-28 15:00:40 -08004640 final long identity = Binder.clearCallingIdentity();
4641 try {
4642 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004643 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4644 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004645 return retVal[0];
4646 } finally {
4647 Binder.restoreCallingIdentity(identity);
4648 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004649 }
4650
4651 /**
4652 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004653 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004654 * Require system privileges. In the future we may add this to carrier APIs.
4655 *
4656 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4657 * means all carriers are allowed.
4658 */
4659 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004660 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004661 enforceReadPrivilegedPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004662 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08004663
4664 final long identity = Binder.clearCallingIdentity();
4665 try {
4666 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004667 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4668 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004672 }
4673
fionaxu59545b42016-05-25 15:53:37 -07004674 /**
4675 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4676 * @param subId the subscription ID that this action applies to.
4677 * @param enabled control enable or disable metered apns.
4678 * {@hide}
4679 */
4680 @Override
4681 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4682 enforceModifyPermission();
4683 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004684
4685 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004686 if (phone == null) {
4687 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4688 return;
4689 }
4690 try {
4691 phone.carrierActionSetMeteredApnsEnabled(enabled);
4692 } catch (Exception e) {
4693 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004694 } finally {
4695 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004696 }
4697 }
4698
4699 /**
4700 * Action set from carrier signalling broadcast receivers to enable/disable radio
4701 * @param subId the subscription ID that this action applies to.
4702 * @param enabled control enable or disable radio.
4703 * {@hide}
4704 */
4705 @Override
4706 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4707 enforceModifyPermission();
4708 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004709
4710 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004711 if (phone == null) {
4712 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4713 return;
4714 }
4715 try {
4716 phone.carrierActionSetRadioEnabled(enabled);
4717 } catch (Exception e) {
4718 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004719 } finally {
4720 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004721 }
4722 }
4723
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004724 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004725 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4726 * network status based on which carrier apps could apply actions accordingly,
4727 * enable/disable default url handler for example.
4728 *
4729 * @param subId the subscription ID that this action applies to.
4730 * @param report control start/stop reporting the default network status.
4731 * {@hide}
4732 */
4733 @Override
4734 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4735 enforceModifyPermission();
4736 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004737
4738 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004739 if (phone == null) {
4740 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4741 return;
4742 }
4743 try {
4744 phone.carrierActionReportDefaultNetworkStatus(report);
4745 } catch (Exception e) {
4746 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004747 } finally {
4748 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004749 }
4750 }
4751
4752 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004753 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4754 * bug report is being generated.
4755 */
4756 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004757 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004758 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4759 != PackageManager.PERMISSION_GRANTED) {
4760 writer.println("Permission Denial: can't dump Phone from pid="
4761 + Binder.getCallingPid()
4762 + ", uid=" + Binder.getCallingUid()
4763 + "without permission "
4764 + android.Manifest.permission.DUMP);
4765 return;
4766 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004767 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004768 }
Jack Yueb89b242016-06-22 13:27:47 -07004769
Brad Ebingerdac2f002018-04-03 15:17:52 -07004770 @Override
4771 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4772 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4773 throws RemoteException {
4774 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4775 }
4776
Jack Yueb89b242016-06-22 13:27:47 -07004777 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004778 * Get aggregated video call data usage since boot.
4779 *
4780 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4781 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004782 * {@hide}
4783 */
4784 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004785 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004786 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4787 null);
4788
Malcolm Chenaabec062018-02-28 15:00:40 -08004789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 // NetworkStatsService keeps tracking the active network interface and identity. It
4792 // records the delta with the corresponding network identity.
4793 // We just return the total video call data usage snapshot since boot.
4794 Phone phone = getPhone(subId);
4795 if (phone != null) {
4796 return phone.getVtDataUsage(perUidStats);
4797 }
4798 return null;
4799 } finally {
4800 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004801 }
Jack Yueb89b242016-06-22 13:27:47 -07004802 }
Jack Yu75ab2952016-07-08 14:29:33 -07004803
4804 /**
4805 * Policy control of data connection. Usually used when data limit is passed.
4806 * @param enabled True if enabling the data, otherwise disabling.
4807 * @param subId Subscription index
4808 * {@hide}
4809 */
4810 @Override
4811 public void setPolicyDataEnabled(boolean enabled, int subId) {
4812 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004813
4814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 Phone phone = getPhone(subId);
4817 if (phone != null) {
4818 phone.setPolicyDataEnabled(enabled);
4819 }
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004822 }
4823 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004824
4825 /**
4826 * Get Client request stats
4827 * @return List of Client Request Stats
4828 * @hide
4829 */
4830 @Override
4831 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004832 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004833 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004834 return null;
4835 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004836 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004837
Malcolm Chenaabec062018-02-28 15:00:40 -08004838 final long identity = Binder.clearCallingIdentity();
4839 try {
4840 if (phone != null) {
4841 return phone.getClientRequestStats();
4842 }
4843
4844 return null;
4845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004848 }
4849
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004850 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004851 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004852 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004853 }
Jack Yueb4124c2017-02-16 15:32:43 -08004854
4855 /**
Grace Chen70990072017-03-24 17:21:30 -07004856 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004857 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004858 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004859 * @param state State of SIM (power down, power up, pass through)
4860 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4861 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4862 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004863 *
4864 **/
4865 @Override
Grace Chen70990072017-03-24 17:21:30 -07004866 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004867 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004868 Phone phone = PhoneFactory.getPhone(slotIndex);
4869
vagdevie435a3e2018-08-15 16:01:53 -07004870 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4871
Malcolm Chenaabec062018-02-28 15:00:40 -08004872 final long identity = Binder.clearCallingIdentity();
4873 try {
4874 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07004875 phone.setSimPowerState(state, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004876 }
4877 } finally {
4878 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004879 }
4880 }
Shuo Qiandd210312017-04-12 22:11:33 +00004881
Tyler Gunn65d45c22017-06-05 11:22:26 -07004882 private boolean isUssdApiAllowed(int subId) {
4883 CarrierConfigManager configManager =
4884 (CarrierConfigManager) mPhone.getContext().getSystemService(
4885 Context.CARRIER_CONFIG_SERVICE);
4886 if (configManager == null) {
4887 return false;
4888 }
4889 PersistableBundle pb = configManager.getConfigForSubId(subId);
4890 if (pb == null) {
4891 return false;
4892 }
4893 return pb.getBoolean(
4894 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4895 }
4896
Shuo Qiandd210312017-04-12 22:11:33 +00004897 /**
4898 * Check if phone is in emergency callback mode
4899 * @return true if phone is in emergency callback mode
4900 * @param subId sub id
4901 */
goneil9c5f4872017-12-05 14:07:56 -08004902 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004903 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004904 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004905 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004906
4907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 if (phone != null) {
4910 return phone.isInEcm();
4911 } else {
4912 return false;
4913 }
4914 } finally {
4915 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004916 }
4917 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004918
4919 /**
4920 * Get the current signal strength information for the given subscription.
4921 * Because this information is not updated when the device is in a low power state
4922 * it should not be relied-upon to be current.
4923 * @param subId Subscription index
4924 * @return the most recent cached signal strength info from the modem
4925 */
4926 @Override
4927 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 Phone p = getPhone(subId);
4931 if (p == null) {
4932 return null;
4933 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004934
Malcolm Chenaabec062018-02-28 15:00:40 -08004935 return p.getSignalStrength();
4936 } finally {
4937 Binder.restoreCallingIdentity(identity);
4938 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004939 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004940
Pengquan Meng9140aec2018-08-22 14:49:57 -07004941 /**
chen xu907e5a22018-10-11 13:21:04 -07004942 * Get the current modem radio state for the given slot.
4943 * @param slotIndex slot index.
4944 * @param callingPackage the name of the package making the call.
4945 * @return the current radio power state from the modem
4946 */
4947 @Override
4948 public int getRadioPowerState(int slotIndex, String callingPackage) {
4949 Phone phone = PhoneFactory.getPhone(slotIndex);
4950 if (phone != null) {
4951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4952 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
4953 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
4954 }
4955
4956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 return phone.getRadioPowerState();
4959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
4962 }
4963 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
4964 }
4965
4966 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07004967 * Checks if data roaming is enabled on the subscription with id {@code subId}.
4968 *
4969 * <p>Requires one of the following permissions:
4970 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
4971 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
4972 * privileges.
4973 *
4974 * @param subId subscription id
4975 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
4976 * {@code false}.
4977 */
4978 @Override
4979 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07004980 boolean isEnabled = false;
4981 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07004982 try {
4983 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07004984 null /* message */);
4985 Phone phone = getPhone(subId);
4986 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07004987 } catch (Exception e) {
4988 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
4989 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07004990 } finally {
4991 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07004992 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07004993 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07004994 }
4995
4996
4997 /**
4998 * Enables/Disables the data roaming on the subscription with id {@code subId}.
4999 *
5000 * <p> Requires permission:
5001 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5002 * privileges.
5003 *
5004 * @param subId subscription id
5005 * @param isEnabled {@code true} means enable, {@code false} means disable.
5006 */
5007 @Override
5008 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5012 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005013
Pengquan Meng0c05b502018-09-06 09:59:22 -07005014 Phone phone = getPhone(subId);
5015 if (phone != null) {
5016 phone.setDataRoamingEnabled(isEnabled);
5017 }
5018 } finally {
5019 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005020 }
5021 }
5022
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005023 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005024 public boolean isManualNetworkSelectionAllowed(int subId) {
5025 boolean isAllowed = true;
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5029 mApp, subId, "isManualNetworkSelectionAllowed");
5030 Phone phone = getPhone(subId);
5031 if (phone != null) {
5032 isAllowed = phone.isCspPlmnEnabled();
5033 }
5034 } finally {
5035 Binder.restoreCallingIdentity(identity);
5036 }
5037 return isAllowed;
5038 }
5039
5040 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005041 public UiccSlotInfo[] getUiccSlotsInfo() {
5042 enforceReadPrivilegedPermission();
5043
Malcolm Chenaabec062018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005047 if (slots == null) {
5048 Rlog.i(LOG_TAG, "slots is null.");
5049 return null;
5050 }
5051
Malcolm Chenaabec062018-02-28 15:00:40 -08005052 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5053 for (int i = 0; i < slots.length; i++) {
5054 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005055 if (slot == null) {
5056 continue;
5057 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005058
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005059 String cardId;
5060 UiccCard card = slot.getUiccCard();
5061 if (card != null) {
5062 cardId = card.getCardId();
5063 } else {
5064 cardId = slot.getIccId();
5065 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005066
Malcolm Chenaabec062018-02-28 15:00:40 -08005067 int cardState = 0;
5068 switch (slot.getCardState()) {
5069 case CARDSTATE_ABSENT:
5070 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5071 break;
5072 case CARDSTATE_PRESENT:
5073 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5074 break;
5075 case CARDSTATE_ERROR:
5076 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5077 break;
5078 case CARDSTATE_RESTRICTED:
5079 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5080 break;
5081 default:
5082 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005083
Malcolm Chenaabec062018-02-28 15:00:40 -08005084 }
5085
5086 infos[i] = new UiccSlotInfo(
5087 slot.isActive(),
5088 slot.isEuicc(),
5089 cardId,
5090 cardState,
5091 slot.getPhoneId(),
5092 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005093 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005094 return infos;
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005097 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005098 }
5099
5100 @Override
5101 public boolean switchSlots(int[] physicalSlots) {
5102 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005103
5104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5107 } finally {
5108 Binder.restoreCallingIdentity(identity);
5109 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005110 }
Jack Yu4c988042018-02-27 15:30:01 -08005111
5112 @Override
5113 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5114 enforceModifyPermission();
5115 final Phone phone = getPhone(subId);
5116 if (phone == null) {
5117 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5118 return;
5119 }
5120
Malcolm Chenaabec062018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 phone.setRadioIndicationUpdateMode(filters, mode);
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
5126 }
Jack Yu4c988042018-02-27 15:30:01 -08005127 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005128
5129 /**
goneil47ffb6e2018-04-06 15:40:58 -07005130 * A test API to reload the UICC profile.
5131 *
5132 * <p>Requires that the calling app has permission
5133 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5134 * @hide
5135 */
5136 @Override
5137 public void refreshUiccProfile(int subId) {
5138 enforceModifyPermission();
5139
5140 final long identity = Binder.clearCallingIdentity();
5141 try {
5142 Phone phone = getPhone(subId);
5143 if (phone == null) {
5144 return;
5145 }
5146 UiccCard uiccCard = phone.getUiccCard();
5147 if (uiccCard == null) {
5148 return;
5149 }
5150 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5151 if (uiccProfile == null) {
5152 return;
5153 }
5154 uiccProfile.refresh();
5155 } finally {
5156 Binder.restoreCallingIdentity(identity);
5157 }
5158 }
5159
5160 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005161 * Returns false if the mobile data is disabled by default, otherwise return true.
5162 */
5163 private boolean getDefaultDataEnabled() {
5164 return "true".equalsIgnoreCase(
5165 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5166 }
5167
5168 /**
5169 * Returns true if the data roaming is enabled by default, i.e the system property
5170 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5171 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5172 */
5173 private boolean getDefaultDataRoamingEnabled(int subId) {
5174 final CarrierConfigManager configMgr = (CarrierConfigManager)
5175 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5176 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5177 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5178 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5179 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5180 return isDataRoamingEnabled;
5181 }
5182
5183 /**
5184 * Returns the default network type for the given {@code subId}, if the default network type is
5185 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5186 */
5187 private int getDefaultNetworkType(int subId) {
5188 return Integer.parseInt(
5189 TelephonyManager.getTelephonyProperty(
5190 mSubscriptionController.getPhoneId(subId),
5191 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5192 String.valueOf(Phone.PREFERRED_NT_MODE)));
5193 }
fionaxua13278b2018-03-21 00:08:13 -07005194
5195 @Override
5196 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5197 gid1, String gid2, String plmn, String spn) {
5198 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005199
5200 final long identity = Binder.clearCallingIdentity();
5201 try {
5202 final Phone phone = getPhone(subId);
5203 if (phone == null) {
5204 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5205 return;
5206 }
5207 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005210 }
fionaxua13278b2018-03-21 00:08:13 -07005211 }
5212
5213 @Override
5214 public int getCarrierIdListVersion(int subId) {
5215 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005216
5217 final long identity = Binder.clearCallingIdentity();
5218 try {
5219 final Phone phone = getPhone(subId);
5220 if (phone == null) {
5221 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5222 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5223 }
5224 return phone.getCarrierIdListVersion();
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005227 }
fionaxua13278b2018-03-21 00:08:13 -07005228 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005229
5230 @Override
5231 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5233 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5234 return -1;
5235 }
5236
5237 final long identity = Binder.clearCallingIdentity();
5238 try {
5239 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
5243 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005244
5245 @Override
5246 public int getCdmaRoamingMode(int subId) {
5247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5248 mApp, subId, "getCdmaRoamingMode");
5249
5250 final long identity = Binder.clearCallingIdentity();
5251 try {
5252 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
5256 }
5257
5258 @Override
5259 public boolean setCdmaRoamingMode(int subId, int mode) {
5260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5261 mApp, subId, "setCdmaRoamingMode");
5262
5263 final long identity = Binder.clearCallingIdentity();
5264 try {
5265 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5266 } finally {
5267 Binder.restoreCallingIdentity(identity);
5268 }
5269 }
5270
5271 @Override
5272 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5274 mApp, subId, "setCdmaSubscriptionMode");
5275
5276 final long identity = Binder.clearCallingIdentity();
5277 try {
5278 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5279 } finally {
5280 Binder.restoreCallingIdentity(identity);
5281 }
5282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005283}