blob: 0bbf1d260ac1f55c6dbe28563f42e32780226aad [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 Ebinger4c460712018-10-01 10:40:55 -070082import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080083import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070084import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080085import android.telephony.ims.aidl.IImsMmTelFeature;
86import android.telephony.ims.aidl.IImsRcsFeature;
87import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070088import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080089import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080095
Brad Ebinger4c460712018-10-01 10:40:55 -070096import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070097import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080098import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070099import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700100import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700101import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700102import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700103import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800106import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700107import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100108import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700109import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700112import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800113import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700114import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700115import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700116import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700117import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700118import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700119import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800120import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800121import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700122import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.uicc.IccIoResult;
124import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800125import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700126import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800127import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800129import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000130import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700131import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800132import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700133import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800134import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700135import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700136import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800137
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700138import java.io.FileDescriptor;
139import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800140import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800142import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800143import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100144import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800145import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146
147/**
148 * Implementation of the ITelephony interface.
149 */
Santos Cordon117fee72014-05-16 17:56:12 -0700150public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 private static final String LOG_TAG = "PhoneInterfaceManager";
152 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
153 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800154 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155
156 // Message codes used with mMainThreadHandler
157 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700158 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
159 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160 private static final int CMD_OPEN_CHANNEL = 9;
161 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
162 private static final int CMD_CLOSE_CHANNEL = 11;
163 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800164 private static final int CMD_NV_READ_ITEM = 13;
165 private static final int EVENT_NV_READ_ITEM_DONE = 14;
166 private static final int CMD_NV_WRITE_ITEM = 15;
167 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
168 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
169 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700170 private static final int CMD_RESET_MODEM_CONFIG = 19;
171 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800172 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
173 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
174 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
175 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800176 private static final int CMD_SEND_ENVELOPE = 25;
177 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000178 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
179 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700180 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
181 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
182 private static final int CMD_EXCHANGE_SIM_IO = 31;
183 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800184 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
185 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700186 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
187 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700188 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
189 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700190 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
191 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
192 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
193 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700194 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
195 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
196 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
197 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700198 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
200 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000201 private static final int CMD_SWITCH_SLOTS = 50;
202 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700203 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
204 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
205 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
206 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
207 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
208 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
209 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
210 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700211 private static final int CMD_GET_ALL_CELL_INFO = 60;
212 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
213 private static final int CMD_GET_CELL_LOCATION = 62;
214 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700215 private static final int CMD_MODEM_REBOOT = 64;
216 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800218 // Parameters of select command.
219 private static final int SELECT_COMMAND = 0xA4;
220 private static final int SELECT_P1 = 0x04;
221 private static final int SELECT_P2 = 0;
222 private static final int SELECT_P3 = 0x10;
223
Pengquan Meng85728fb2018-03-12 16:31:21 -0700224 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
225 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
226 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
227
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228 /** The singleton instance. */
229 private static PhoneInterfaceManager sInstance;
230
Wink Saville3ab207e2014-11-20 13:07:20 -0800231 private PhoneGlobals mApp;
232 private Phone mPhone;
233 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700234 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800235 private AppOpsManager mAppOps;
236 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800237 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800238 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700239 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
Derek Tan97ebb422014-09-05 16:55:38 -0700241 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
242 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800243 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700244
Derek Tan740e1672017-06-27 14:56:27 -0700245 // The AID of ISD-R.
246 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
247
yinxub1bed742017-04-17 11:45:04 -0700248 private NetworkScanRequestTracker mNetworkScanRequestTracker;
249
David Kelly5e06a7f2018-03-12 14:10:59 +0000250 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
251 private static final int MANUFACTURER_CODE_LENGTH = 8;
252
Derek Tan89e89d42014-07-08 17:00:10 -0700253 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700254 * A request object to use for transmitting data to an ICC.
255 */
256 private static final class IccAPDUArgument {
257 public int channel, cla, command, p1, p2, p3;
258 public String data;
259
260 public IccAPDUArgument(int channel, int cla, int command,
261 int p1, int p2, int p3, String data) {
262 this.channel = channel;
263 this.cla = cla;
264 this.command = command;
265 this.p1 = p1;
266 this.p2 = p2;
267 this.p3 = p3;
268 this.data = data;
269 }
270 }
271
272 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700273 * A request object to use for transmitting data to an ICC.
274 */
275 private static final class ManualNetworkSelectionArgument {
276 public OperatorInfo operatorInfo;
277 public boolean persistSelection;
278
279 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
280 this.operatorInfo = operatorInfo;
281 this.persistSelection = persistSelection;
282 }
283 }
284
285 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
287 * request after sending. The main thread will notify the request when it is complete.
288 */
289 private static final class MainThreadRequest {
290 /** The argument to use for the request */
291 public Object argument;
292 /** The result of the request that is run on the main thread */
293 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800294 // The subscriber id that this request applies to. Defaults to
295 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
296 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297
Nathan Harold92bed182018-10-12 18:16:49 -0700298 // In cases where subId is unavailable, the caller needs to specify the phone.
299 public Phone phone;
300
vagdevie435a3e2018-08-15 16:01:53 -0700301 public WorkSource workSource;
302
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 public MainThreadRequest(Object argument) {
304 this.argument = argument;
305 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800306
Nathan Harold92bed182018-10-12 18:16:49 -0700307 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
308 this.argument = argument;
309 if (phone != null) {
310 this.phone = phone;
311 }
312 this.workSource = workSource;
313 }
314
vagdevie435a3e2018-08-15 16:01:53 -0700315 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800316 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800317 if (subId != null) {
318 this.subId = subId;
319 }
vagdevie435a3e2018-08-15 16:01:53 -0700320 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 }
323
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800324 private static final class IncomingThirdPartyCallArgs {
325 public final ComponentName component;
326 public final String callId;
327 public final String callerDisplayName;
328
329 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
330 String callerDisplayName) {
331 this.component = component;
332 this.callId = callId;
333 this.callerDisplayName = callerDisplayName;
334 }
335 }
336
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 /**
338 * A handler that processes messages on the main thread in the phone process. Since many
339 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
340 * inbound binder threads to the main thread in the phone process. The Binder thread
341 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
342 * on, which will be notified when the operation completes and will contain the result of the
343 * request.
344 *
345 * <p>If a MainThreadRequest object is provided in the msg.obj field,
346 * note that request.result must be set to something non-null for the calling thread to
347 * unblock.
348 */
349 private final class MainThreadHandler extends Handler {
350 @Override
351 public void handleMessage(Message msg) {
352 MainThreadRequest request;
353 Message onCompleted;
354 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800355 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700356 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
358 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700359 case CMD_HANDLE_USSD_REQUEST: {
360 request = (MainThreadRequest) msg.obj;
361 final Phone phone = getPhoneFromRequest(request);
362 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
363 String ussdRequest = ussdObject.first;
364 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700365
Pengquan Meng0c05b502018-09-06 09:59:22 -0700366 if (!isUssdApiAllowed(request.subId)) {
367 // Carrier does not support use of this API, return failure.
368 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
369 UssdResponse response = new UssdResponse(ussdRequest, null);
370 Bundle returnData = new Bundle();
371 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
372 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700373
Pengquan Meng0c05b502018-09-06 09:59:22 -0700374 request.result = true;
375 notifyRequester(request);
376 return;
377 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700378
Pengquan Meng0c05b502018-09-06 09:59:22 -0700379 try {
380 request.result = phone != null
381 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
382 } catch (CallStateException cse) {
383 request.result = false;
384 }
385 // Wake up the requesting thread
386 notifyRequester(request);
387 break;
pkanwar32d516d2016-10-14 19:37:38 -0700388 }
389
Yorke Lee716f67e2015-06-17 15:39:16 -0700390 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700392 final Phone phone = getPhoneFromRequest(request);
393 request.result = phone != null ?
394 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
395 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700397 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700402 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700403 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800404 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700405 if (uiccCard == null) {
406 loge("iccTransmitApduLogicalChannel: No UICC");
407 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700408 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700409 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700410 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
411 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700412 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 iccArgument.channel, iccArgument.cla, iccArgument.command,
414 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700415 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700416 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 break;
418
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700420 ar = (AsyncResult) msg.obj;
421 request = (MainThreadRequest) ar.userObj;
422 if (ar.exception == null && ar.result != null) {
423 request.result = ar.result;
424 } else {
425 request.result = new IccIoResult(0x6F, 0, (byte[])null);
426 if (ar.result == null) {
427 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800428 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800430 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 } else {
432 loge("iccTransmitApduLogicalChannel: Unknown exception");
433 }
434 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700435 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 break;
437
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
439 request = (MainThreadRequest) msg.obj;
440 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800441 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 if (uiccCard == null) {
443 loge("iccTransmitApduBasicChannel: No UICC");
444 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700445 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 } else {
447 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
448 request);
449 uiccCard.iccTransmitApduBasicChannel(
450 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
451 iccArgument.p3, iccArgument.data, onCompleted);
452 }
453 break;
454
455 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
456 ar = (AsyncResult) msg.obj;
457 request = (MainThreadRequest) ar.userObj;
458 if (ar.exception == null && ar.result != null) {
459 request.result = ar.result;
460 } else {
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
462 if (ar.result == null) {
463 loge("iccTransmitApduBasicChannel: Empty response");
464 } else if (ar.exception instanceof CommandException) {
465 loge("iccTransmitApduBasicChannel: CommandException: " +
466 ar.exception);
467 } else {
468 loge("iccTransmitApduBasicChannel: Unknown exception");
469 }
470 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700471 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 break;
473
474 case CMD_EXCHANGE_SIM_IO:
475 request = (MainThreadRequest) msg.obj;
476 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800477 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 if (uiccCard == null) {
479 loge("iccExchangeSimIO: No UICC");
480 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 } else {
483 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
484 request);
485 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
486 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
487 iccArgument.data, onCompleted);
488 }
489 break;
490
491 case EVENT_EXCHANGE_SIM_IO_DONE:
492 ar = (AsyncResult) msg.obj;
493 request = (MainThreadRequest) ar.userObj;
494 if (ar.exception == null && ar.result != null) {
495 request.result = ar.result;
496 } else {
497 request.result = new IccIoResult(0x6f, 0, (byte[])null);
498 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700499 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 break;
501
Derek Tan4d5e5c12014-02-04 11:54:58 -0800502 case CMD_SEND_ENVELOPE:
503 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800504 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700505 if (uiccCard == null) {
506 loge("sendEnvelopeWithStatus: No UICC");
507 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700508 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700509 } else {
510 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
511 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
512 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800513 break;
514
515 case EVENT_SEND_ENVELOPE_DONE:
516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800520 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
522 if (ar.result == null) {
523 loge("sendEnvelopeWithStatus: Empty response");
524 } else if (ar.exception instanceof CommandException) {
525 loge("sendEnvelopeWithStatus: CommandException: " +
526 ar.exception);
527 } else {
528 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
529 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700531 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800532 break;
533
Shishir Agrawal566b7612013-10-28 14:41:00 -0700534 case CMD_OPEN_CHANNEL:
535 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800536 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800537 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 if (uiccCard == null) {
539 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800540 request.result = new IccOpenLogicalChannelResponse(-1,
541 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800545 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
546 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 break;
549
550 case EVENT_OPEN_CHANNEL_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 int[] result = (int[]) ar.result;
556 int channelId = result[0];
557 byte[] selectResponse = null;
558 if (result.length > 1) {
559 selectResponse = new byte[result.length - 1];
560 for (int i = 1; i < result.length; ++i) {
561 selectResponse[i - 1] = (byte) result[i];
562 }
563 }
564 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700565 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 if (ar.result == null) {
568 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 if (ar.exception != null) {
571 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
572 }
573
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700574 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700575 if (ar.exception instanceof CommandException) {
576 CommandException.Error error =
577 ((CommandException) (ar.exception)).getCommandError();
578 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700579 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700580 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700581 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 }
583 }
584 openChannelResp = new IccOpenLogicalChannelResponse(
585 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700587 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
591 case CMD_CLOSE_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 if (uiccCard == null) {
595 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900596 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 } else {
599 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
600 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
601 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
604 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800605 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
606 break;
607
608 case CMD_NV_READ_ITEM:
609 request = (MainThreadRequest) msg.obj;
610 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700611 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800612 break;
613
614 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 ar = (AsyncResult) msg.obj;
616 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800617 if (ar.exception == null && ar.result != null) {
618 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800620 request.result = "";
621 if (ar.result == null) {
622 loge("nvReadItem: Empty response");
623 } else if (ar.exception instanceof CommandException) {
624 loge("nvReadItem: CommandException: " +
625 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800627 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 }
629 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 break;
632
Jake Hambye994d462014-02-03 13:10:13 -0800633 case CMD_NV_WRITE_ITEM:
634 request = (MainThreadRequest) msg.obj;
635 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
636 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700637 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
638 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800639 break;
640
641 case EVENT_NV_WRITE_ITEM_DONE:
642 handleNullReturnEvent(msg, "nvWriteItem");
643 break;
644
645 case CMD_NV_WRITE_CDMA_PRL:
646 request = (MainThreadRequest) msg.obj;
647 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
648 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
649 break;
650
651 case EVENT_NV_WRITE_CDMA_PRL_DONE:
652 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
653 break;
654
chen xu1cc0abe2018-10-26 17:39:23 -0700655 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800656 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700657 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
658 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800659 break;
660
chen xu1cc0abe2018-10-26 17:39:23 -0700661 case EVENT_RESET_MODEM_CONFIG_DONE:
662 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800663 break;
664
Jake Hamby7c27be32014-03-03 13:25:59 -0800665 case CMD_GET_PREFERRED_NETWORK_TYPE:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700668 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800669 break;
670
671 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
672 ar = (AsyncResult) msg.obj;
673 request = (MainThreadRequest) ar.userObj;
674 if (ar.exception == null && ar.result != null) {
675 request.result = ar.result; // Integer
676 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800677 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800678 if (ar.result == null) {
679 loge("getPreferredNetworkType: Empty response");
680 } else if (ar.exception instanceof CommandException) {
681 loge("getPreferredNetworkType: CommandException: " +
682 ar.exception);
683 } else {
684 loge("getPreferredNetworkType: Unknown exception");
685 }
686 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700687 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800688 break;
689
690 case CMD_SET_PREFERRED_NETWORK_TYPE:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
693 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700694 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800695 break;
696
697 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
698 handleNullReturnEvent(msg, "setPreferredNetworkType");
699 break;
700
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000701 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
702 request = (MainThreadRequest)msg.obj;
703 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700704 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000705 break;
706
707 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
708 ar = (AsyncResult)msg.obj;
709 request = (MainThreadRequest)ar.userObj;
710 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700711 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000712 break;
713
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800714 case CMD_SET_VOICEMAIL_NUMBER:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
717 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800718 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
719 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800720 break;
721
722 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
723 handleNullReturnEvent(msg, "setVoicemailNumber");
724 break;
725
Stuart Scott54788802015-03-30 13:18:01 -0700726 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
729 request);
730 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
731 break;
732
733 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
734 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
735 break;
736
Shishir Agrawal302c8692015-06-19 13:49:39 -0700737 case CMD_PERFORM_NETWORK_SCAN:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
740 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
741 break;
742
743 case EVENT_PERFORM_NETWORK_SCAN_DONE:
744 ar = (AsyncResult) msg.obj;
745 request = (MainThreadRequest) ar.userObj;
746 CellNetworkScanResult cellScanResult;
747 if (ar.exception == null && ar.result != null) {
748 cellScanResult = new CellNetworkScanResult(
749 CellNetworkScanResult.STATUS_SUCCESS,
750 (List<OperatorInfo>) ar.result);
751 } else {
752 if (ar.result == null) {
753 loge("getCellNetworkScanResults: Empty response");
754 }
755 if (ar.exception != null) {
756 loge("getCellNetworkScanResults: Exception: " + ar.exception);
757 }
758 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
759 if (ar.exception instanceof CommandException) {
760 CommandException.Error error =
761 ((CommandException) (ar.exception)).getCommandError();
762 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
763 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
764 } else if (error == CommandException.Error.GENERIC_FAILURE) {
765 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
766 }
767 }
768 cellScanResult = new CellNetworkScanResult(errorCode, null);
769 }
770 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700771 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700772 break;
773
774 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
775 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700776 ManualNetworkSelectionArgument selArg =
777 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700778 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
779 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700780 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
781 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700782 break;
783
784 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700785 ar = (AsyncResult) msg.obj;
786 request = (MainThreadRequest) ar.userObj;
787 if (ar.exception == null) {
788 request.result = true;
789 } else {
790 request.result = false;
791 loge("setNetworkSelectionModeManual " + ar.exception);
792 }
793 notifyRequester(request);
794 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 break;
796
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700797 case CMD_GET_MODEM_ACTIVITY_INFO:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700800 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700801 break;
802
803 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 if (ar.exception == null && ar.result != null) {
807 request.result = ar.result;
808 } else {
809 if (ar.result == null) {
810 loge("queryModemActivityInfo: Empty response");
811 } else if (ar.exception instanceof CommandException) {
812 loge("queryModemActivityInfo: CommandException: " +
813 ar.exception);
814 } else {
815 loge("queryModemActivityInfo: Unknown exception");
816 }
817 }
Amit Mahajand4766222016-01-28 15:28:28 -0800818 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
819 if (request.result == null) {
820 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
821 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700822 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700823 break;
824
Meng Wang1a7c35a2016-05-05 20:56:15 -0700825 case CMD_SET_ALLOWED_CARRIERS:
826 request = (MainThreadRequest) msg.obj;
827 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
828 mPhone.setAllowedCarriers(
829 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700830 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700831 break;
832
833 case EVENT_SET_ALLOWED_CARRIERS_DONE:
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null && ar.result != null) {
837 request.result = ar.result;
838 } else {
839 if (ar.result == null) {
840 loge("setAllowedCarriers: Empty response");
841 } else if (ar.exception instanceof CommandException) {
842 loge("setAllowedCarriers: CommandException: " +
843 ar.exception);
844 } else {
845 loge("setAllowedCarriers: Unknown exception");
846 }
847 }
848 // Result cannot be null. Return -1 on error.
849 if (request.result == null) {
850 request.result = new int[]{-1};
851 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700852 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 break;
854
855 case CMD_GET_ALLOWED_CARRIERS:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700858 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700859 break;
860
861 case EVENT_GET_ALLOWED_CARRIERS_DONE:
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null && ar.result != null) {
865 request.result = ar.result;
866 } else {
867 if (ar.result == null) {
868 loge("getAllowedCarriers: Empty response");
869 } else if (ar.exception instanceof CommandException) {
870 loge("getAllowedCarriers: CommandException: " +
871 ar.exception);
872 } else {
873 loge("getAllowedCarriers: Unknown exception");
874 }
875 }
876 // Result cannot be null. Return empty list of CarrierIdentifier.
877 if (request.result == null) {
878 request.result = new ArrayList<CarrierIdentifier>(0);
879 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700880 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 break;
882
Nathan Haroldb3014052017-01-25 15:57:32 -0800883 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
889 request.result = new IllegalArgumentException(
890 "Failed to retrieve Forbidden Plmns");
891 if (ar.result == null) {
892 loge("getForbiddenPlmns: Empty response");
893 } else {
894 loge("getForbiddenPlmns: Unknown exception");
895 }
896 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700897 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800898 break;
899
900 case CMD_GET_FORBIDDEN_PLMNS:
901 request = (MainThreadRequest) msg.obj;
902 uiccCard = getUiccCardFromRequest(request);
903 if (uiccCard == null) {
904 loge("getForbiddenPlmns() UiccCard is null");
905 request.result = new IllegalArgumentException(
906 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700907 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800908 break;
909 }
910 Integer appType = (Integer) request.argument;
911 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
912 if (uiccApp == null) {
913 loge("getForbiddenPlmns() no app with specified type -- "
914 + appType);
915 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700916 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800917 break;
918 } else {
919 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
920 + " specified type -- " + appType);
921 }
922 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
923 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
924 onCompleted);
925 break;
926
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000927 case CMD_SWITCH_SLOTS:
928 request = (MainThreadRequest) msg.obj;
929 int[] physicalSlots = (int[]) request.argument;
930 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
931 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
932 break;
933
934 case EVENT_SWITCH_SLOTS_DONE:
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700938 notifyRequester(request);
939 break;
940 case CMD_GET_NETWORK_SELECTION_MODE:
941 request = (MainThreadRequest) msg.obj;
942 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
943 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
944 break;
945
946 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
947 ar = (AsyncResult) msg.obj;
948 request = (MainThreadRequest) ar.userObj;
949 if (ar.exception != null) {
950 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
951 } else {
952 int mode = ((int[]) ar.result)[0];
953 if (mode == 0) {
954 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
955 } else {
956 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
957 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000958 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700959 notifyRequester(request);
960 break;
961 case CMD_GET_CDMA_ROAMING_MODE:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
964 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
965 break;
966 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 if (ar.exception != null) {
970 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
971 } else {
972 request.result = ((int[]) ar.result)[0];
973 }
974 notifyRequester(request);
975 break;
976 case CMD_SET_CDMA_ROAMING_MODE:
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
979 int mode = (int) request.argument;
980 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
981 break;
982 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 request.result = ar.exception == null;
986 notifyRequester(request);
987 break;
988 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
991 int subscriptionMode = (int) request.argument;
992 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
993 break;
994 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 request.result = ar.exception == null;
998 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000999 break;
1000
Nathan Harold3ff88932018-08-14 10:19:49 -07001001 case CMD_GET_ALL_CELL_INFO:
1002 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001003 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001004 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001005 break;
1006
1007 case EVENT_GET_ALL_CELL_INFO_DONE:
1008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001010 // If a timeout occurs, the response will be null
1011 request.result = (ar.exception == null && ar.result != null)
1012 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001013 synchronized (request) {
1014 request.notifyAll();
1015 }
1016 break;
1017
1018 case CMD_GET_CELL_LOCATION: {
1019 request = (MainThreadRequest) msg.obj;
1020 WorkSource ws = (WorkSource) request.argument;
1021 Phone phone = getPhoneFromRequest(request);
1022 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1023 break;
1024 }
1025
1026 case EVENT_GET_CELL_LOCATION_DONE: {
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 if (ar.exception == null) {
1030 request.result = ar.result;
1031 } else {
1032 Phone phone = getPhoneFromRequest(request);
1033 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1034 ? new CdmaCellLocation() : new GsmCellLocation();
1035 }
1036
1037 synchronized (request) {
1038 request.notifyAll();
1039 }
1040 break;
1041 }
1042
chen xu1cc0abe2018-10-26 17:39:23 -07001043 case CMD_MODEM_REBOOT:
1044 request = (MainThreadRequest) msg.obj;
1045 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1046 mPhone.rebootModem(onCompleted);
1047 break;
1048
1049 case EVENT_CMD_MODEM_REBOOT_DONE:
1050 handleNullReturnEvent(msg, "rebootModem");
1051 break;
1052
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001053 default:
1054 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1055 break;
1056 }
1057 }
Jake Hambye994d462014-02-03 13:10:13 -08001058
Pengquan Meng0c05b502018-09-06 09:59:22 -07001059 private void notifyRequester(MainThreadRequest request) {
1060 synchronized (request) {
1061 request.notifyAll();
1062 }
1063 }
1064
Jake Hambye994d462014-02-03 13:10:13 -08001065 private void handleNullReturnEvent(Message msg, String command) {
1066 AsyncResult ar = (AsyncResult) msg.obj;
1067 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null) {
1069 request.result = true;
1070 } else {
1071 request.result = false;
1072 if (ar.exception instanceof CommandException) {
1073 loge(command + ": CommandException: " + ar.exception);
1074 } else {
1075 loge(command + ": Unknown exception");
1076 }
1077 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001078 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001080 }
1081
1082 /**
1083 * Posts the specified command to be executed on the main thread,
1084 * waits for the request to complete, and returns the result.
1085 * @see #sendRequestAsync
1086 */
1087 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001088 return sendRequest(
1089 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001090 }
1091
1092 /**
1093 * Posts the specified command to be executed on the main thread,
1094 * waits for the request to complete, and returns the result.
1095 * @see #sendRequestAsync
1096 */
1097 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1098 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001099 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001100 }
1101
1102 /**
1103 * Posts the specified command to be executed on the main thread,
1104 * waits for the request to complete, and returns the result.
1105 * @see #sendRequestAsync
1106 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001107 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001108 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001109 }
1110
1111 /**
1112 * Posts the specified command to be executed on the main thread,
1113 * waits for the request to complete, and returns the result.
1114 * @see #sendRequestAsync
1115 */
Nathan Harold92bed182018-10-12 18:16:49 -07001116 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1117 return sendRequest(command, argument, subId, null, workSource);
1118 }
1119
1120 /**
1121 * Posts the specified command to be executed on the main thread,
1122 * waits for the request to complete, and returns the result.
1123 * @see #sendRequestAsync
1124 */
1125 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1126 return sendRequest(
1127 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1128 }
1129
1130 /**
1131 * Posts the specified command to be executed on the main thread,
1132 * waits for the request to complete, and returns the result.
1133 * @see #sendRequestAsync
1134 */
1135 private Object sendRequest(
1136 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001137 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1138 throw new RuntimeException("This method will deadlock if called from the main thread.");
1139 }
1140
Nathan Harold92bed182018-10-12 18:16:49 -07001141 MainThreadRequest request = null;
1142 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1143 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1144 } else if (phone != null) {
1145 request = new MainThreadRequest(argument, phone, workSource);
1146 } else {
1147 request = new MainThreadRequest(argument, subId, workSource);
1148 }
1149
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 Message msg = mMainThreadHandler.obtainMessage(command, request);
1151 msg.sendToTarget();
1152
1153 // Wait for the request to complete
1154 synchronized (request) {
1155 while (request.result == null) {
1156 try {
1157 request.wait();
1158 } catch (InterruptedException e) {
1159 // Do nothing, go back and wait until the request is complete
1160 }
1161 }
1162 }
1163 return request.result;
1164 }
1165
1166 /**
1167 * Asynchronous ("fire and forget") version of sendRequest():
1168 * Posts the specified command to be executed on the main thread, and
1169 * returns immediately.
1170 * @see #sendRequest
1171 */
1172 private void sendRequestAsync(int command) {
1173 mMainThreadHandler.sendEmptyMessage(command);
1174 }
1175
1176 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001177 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1178 * @see {@link #sendRequest(int,Object)}
1179 */
1180 private void sendRequestAsync(int command, Object argument) {
1181 MainThreadRequest request = new MainThreadRequest(argument);
1182 Message msg = mMainThreadHandler.obtainMessage(command, request);
1183 msg.sendToTarget();
1184 }
1185
1186 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001187 * Initialize the singleton PhoneInterfaceManager instance.
1188 * This is only done once, at startup, from PhoneApp.onCreate().
1189 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001190 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 synchronized (PhoneInterfaceManager.class) {
1192 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001193 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 } else {
1195 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1196 }
1197 return sInstance;
1198 }
1199 }
1200
1201 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001202 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203 mApp = app;
1204 mPhone = phone;
1205 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001206 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1208 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001209 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001210 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001211 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001212 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001213 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001214
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001215 publish();
1216 }
1217
1218 private void publish() {
1219 if (DBG) log("publish: " + this);
1220
1221 ServiceManager.addService("phone", this);
1222 }
1223
Stuart Scott584921c2015-01-15 17:10:34 -08001224 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001225 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1226 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001227 }
1228
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001229 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1230 Phone phone = getPhoneFromRequest(request);
1231 return phone == null ? null :
1232 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1233 }
1234
Wink Saville36469e72014-06-11 15:17:00 -07001235 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001236 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001237 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001239
1240 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001241 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001242 }
1243
Wink Savilleb564aae2014-10-23 10:18:09 -07001244 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 if (DBG) log("dial: " + number);
1246 // No permission check needed here: This is just a wrapper around the
1247 // ACTION_DIAL intent, which is available to any app since it puts up
1248 // the UI before it does anything.
1249
Malcolm Chend965c8b2018-02-28 15:00:40 -08001250 final long identity = Binder.clearCallingIdentity();
1251 try {
1252 String url = createTelUrl(number);
1253 if (url == null) {
1254 return;
1255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001256
Malcolm Chend965c8b2018-02-28 15:00:40 -08001257 // PENDING: should we just silently fail if phone is offhook or ringing?
1258 PhoneConstants.State state = mCM.getState(subId);
1259 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1260 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1261 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1262 mApp.startActivity(intent);
1263 }
1264 } finally {
1265 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 }
1267 }
1268
1269 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001270 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001271 }
1272
Wink Savilleb564aae2014-10-23 10:18:09 -07001273 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 if (DBG) log("call: " + number);
1275
1276 // This is just a wrapper around the ACTION_CALL intent, but we still
1277 // need to do a permission check since we're calling startActivity()
1278 // from the context of the phone app.
1279 enforceCallPermission();
1280
1281 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1282 != AppOpsManager.MODE_ALLOWED) {
1283 return;
1284 }
1285
Malcolm Chend965c8b2018-02-28 15:00:40 -08001286 final long identity = Binder.clearCallingIdentity();
1287 try {
1288 String url = createTelUrl(number);
1289 if (url == null) {
1290 return;
1291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292
Malcolm Chend965c8b2018-02-28 15:00:40 -08001293 boolean isValid = false;
1294 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1295 if (slist != null) {
1296 for (SubscriptionInfo subInfoRecord : slist) {
1297 if (subInfoRecord.getSubscriptionId() == subId) {
1298 isValid = true;
1299 break;
1300 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001301 }
Wink Saville08874612014-08-31 19:19:58 -07001302 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001303 if (!isValid) {
1304 return;
1305 }
Wink Saville08874612014-08-31 19:19:58 -07001306
Malcolm Chend965c8b2018-02-28 15:00:40 -08001307 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1308 intent.putExtra(SUBSCRIPTION_KEY, subId);
1309 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1310 mApp.startActivity(intent);
1311 } finally {
1312 Binder.restoreCallingIdentity(identity);
1313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 }
1315
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001317 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001318 }
1319
Wink Savilleb564aae2014-10-23 10:18:09 -07001320 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001321 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001322 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1323 }
1324
1325 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001326 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001327 }
1328
Wink Savilleb564aae2014-10-23 10:18:09 -07001329 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001330 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001331 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1332 }
1333
1334 /** {@hide} */
1335 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001336 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001337 }
1338
Wink Savilleb564aae2014-10-23 10:18:09 -07001339 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001340 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001341
1342 final long identity = Binder.clearCallingIdentity();
1343 try {
1344 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1345 checkSimPin.start();
1346 return checkSimPin.unlockSim(null, pin);
1347 } finally {
1348 Binder.restoreCallingIdentity(identity);
1349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 }
1351
Wink Saville9de0f752013-10-22 19:04:03 -07001352 /** {@hide} */
1353 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001354 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001355 }
1356
Wink Savilleb564aae2014-10-23 10:18:09 -07001357 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001359
1360 final long identity = Binder.clearCallingIdentity();
1361 try {
1362 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1363 checkSimPuk.start();
1364 return checkSimPuk.unlockSim(puk, pin);
1365 } finally {
1366 Binder.restoreCallingIdentity(identity);
1367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 }
1369
1370 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001371 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372 * a synchronous one.
1373 */
1374 private static class UnlockSim extends Thread {
1375
1376 private final IccCard mSimCard;
1377
1378 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001379 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1380 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381
1382 // For replies from SimCard interface
1383 private Handler mHandler;
1384
1385 // For async handler to identify request type
1386 private static final int SUPPLY_PIN_COMPLETE = 100;
1387
1388 public UnlockSim(IccCard simCard) {
1389 mSimCard = simCard;
1390 }
1391
1392 @Override
1393 public void run() {
1394 Looper.prepare();
1395 synchronized (UnlockSim.this) {
1396 mHandler = new Handler() {
1397 @Override
1398 public void handleMessage(Message msg) {
1399 AsyncResult ar = (AsyncResult) msg.obj;
1400 switch (msg.what) {
1401 case SUPPLY_PIN_COMPLETE:
1402 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1403 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001404 mRetryCount = msg.arg1;
1405 if (ar.exception != null) {
1406 if (ar.exception instanceof CommandException &&
1407 ((CommandException)(ar.exception)).getCommandError()
1408 == CommandException.Error.PASSWORD_INCORRECT) {
1409 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1410 } else {
1411 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1412 }
1413 } else {
1414 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 mDone = true;
1417 UnlockSim.this.notifyAll();
1418 }
1419 break;
1420 }
1421 }
1422 };
1423 UnlockSim.this.notifyAll();
1424 }
1425 Looper.loop();
1426 }
1427
1428 /*
1429 * Use PIN or PUK to unlock SIM card
1430 *
1431 * If PUK is null, unlock SIM card with PIN
1432 *
1433 * If PUK is not null, unlock SIM card with PUK and set PIN code
1434 */
Wink Saville9de0f752013-10-22 19:04:03 -07001435 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001436
1437 while (mHandler == null) {
1438 try {
1439 wait();
1440 } catch (InterruptedException e) {
1441 Thread.currentThread().interrupt();
1442 }
1443 }
1444 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1445
1446 if (puk == null) {
1447 mSimCard.supplyPin(pin, callback);
1448 } else {
1449 mSimCard.supplyPuk(puk, pin, callback);
1450 }
1451
1452 while (!mDone) {
1453 try {
1454 Log.d(LOG_TAG, "wait for done");
1455 wait();
1456 } catch (InterruptedException e) {
1457 // Restore the interrupted status
1458 Thread.currentThread().interrupt();
1459 }
1460 }
1461 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001462 int[] resultArray = new int[2];
1463 resultArray[0] = mResult;
1464 resultArray[1] = mRetryCount;
1465 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 }
1467 }
1468
1469 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001470 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001471
1472 }
1473
Wink Savilleb564aae2014-10-23 10:18:09 -07001474 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 // No permission check needed here: this call is harmless, and it's
1476 // needed for the ServiceState.requestStateUpdate() call (which is
1477 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001478 final long identity = Binder.clearCallingIdentity();
1479 try {
1480 final Phone phone = getPhone(subId);
1481 if (phone != null) {
1482 phone.updateServiceLocation();
1483 }
1484 } finally {
1485 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 }
1488
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001489 @Override
1490 public boolean isRadioOn(String callingPackage) {
1491 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001492 }
1493
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001494 @Override
1495 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001497 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001498 return false;
1499 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001500
1501 final long identity = Binder.clearCallingIdentity();
1502 try {
1503 return isRadioOnForSubscriber(subId);
1504 } finally {
1505 Binder.restoreCallingIdentity(identity);
1506 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001507 }
1508
1509 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001510 final long identity = Binder.clearCallingIdentity();
1511 try {
1512 final Phone phone = getPhone(subId);
1513 if (phone != null) {
1514 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1515 } else {
1516 return false;
1517 }
1518 } finally {
1519 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001521 }
1522
1523 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001524 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 }
Wink Saville36469e72014-06-11 15:17:00 -07001526
Wink Savilleb564aae2014-10-23 10:18:09 -07001527 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001529
1530 final long identity = Binder.clearCallingIdentity();
1531 try {
1532 final Phone phone = getPhone(subId);
1533 if (phone != null) {
1534 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1535 }
1536 } finally {
1537 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001538 }
Wink Saville36469e72014-06-11 15:17:00 -07001539 }
1540
1541 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001543 }
1544
Wink Savilleb564aae2014-10-23 10:18:09 -07001545 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001546 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001547
1548 final long identity = Binder.clearCallingIdentity();
1549 try {
1550 final Phone phone = getPhone(subId);
1551 if (phone == null) {
1552 return false;
1553 }
1554 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1555 toggleRadioOnOffForSubscriber(subId);
1556 }
1557 return true;
1558 } finally {
1559 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 }
Wink Saville36469e72014-06-11 15:17:00 -07001562
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001563 public boolean needMobileRadioShutdown() {
1564 /*
1565 * If any of the Radios are available, it will need to be
1566 * shutdown. So return true if any Radio is available.
1567 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001568 final long identity = Binder.clearCallingIdentity();
1569 try {
1570 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1571 Phone phone = PhoneFactory.getPhone(i);
1572 if (phone != null && phone.isRadioAvailable()) return true;
1573 }
1574 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1575 return false;
1576 } finally {
1577 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001578 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001579 }
1580
Malcolm Chend965c8b2018-02-28 15:00:40 -08001581 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001582 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001583 enforceModifyPermission();
1584
1585 final long identity = Binder.clearCallingIdentity();
1586 try {
1587 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1588 logv("Shutting down Phone " + i);
1589 shutdownRadioUsingPhoneId(i);
1590 }
1591 } finally {
1592 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001593 }
1594 }
1595
1596 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001597 Phone phone = PhoneFactory.getPhone(phoneId);
1598 if (phone != null && phone.isRadioAvailable()) {
1599 phone.shutdownRadio();
1600 }
1601 }
1602
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001604 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001605
1606 final long identity = Binder.clearCallingIdentity();
1607 try {
1608 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1609 if (defaultPhone != null) {
1610 defaultPhone.setRadioPower(turnOn);
1611 return true;
1612 } else {
1613 loge("There's no default phone.");
1614 return false;
1615 }
1616 } finally {
1617 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001618 }
Wink Saville36469e72014-06-11 15:17:00 -07001619 }
1620
Wink Savilleb564aae2014-10-23 10:18:09 -07001621 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001623
1624 final long identity = Binder.clearCallingIdentity();
1625 try {
1626 final Phone phone = getPhone(subId);
1627 if (phone != null) {
1628 phone.setRadioPower(turnOn);
1629 return true;
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
Wink Saville36469e72014-06-11 15:17:00 -07001638 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001639 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 public boolean enableDataConnectivity() {
1641 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001642
1643 final long identity = Binder.clearCallingIdentity();
1644 try {
1645 int subId = mSubscriptionController.getDefaultDataSubId();
1646 final Phone phone = getPhone(subId);
1647 if (phone != null) {
1648 phone.setUserDataEnabled(true);
1649 return true;
1650 } else {
1651 return false;
1652 }
1653 } finally {
1654 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 }
1657
Wink Saville36469e72014-06-11 15:17:00 -07001658 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001659 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 public boolean disableDataConnectivity() {
1661 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001662
1663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 int subId = mSubscriptionController.getDefaultDataSubId();
1666 final Phone phone = getPhone(subId);
1667 if (phone != null) {
1668 phone.setUserDataEnabled(false);
1669 return true;
1670 } else {
1671 return false;
1672 }
1673 } finally {
1674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 }
1677
Sanket Padawe356d7632015-06-22 14:03:32 -07001678 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001679 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001680 final long identity = Binder.clearCallingIdentity();
1681 try {
1682 final Phone phone = getPhone(subId);
1683 if (phone != null) {
1684 return phone.isDataAllowed();
1685 } else {
1686 return false;
1687 }
1688 } finally {
1689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 }
1692
1693 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001694 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001695 }
1696
pkanwarae03a6b2016-11-06 20:37:09 -08001697 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001698 enforceCallPermission();
1699
1700 final long identity = Binder.clearCallingIdentity();
1701 try {
1702 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1703 return;
1704 }
1705 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1706 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1707 } finally {
1708 Binder.restoreCallingIdentity(identity);
1709 }
pkanwar32d516d2016-10-14 19:37:38 -07001710 };
1711
Wink Savilleb564aae2014-10-23 10:18:09 -07001712 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001714
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1718 return false;
1719 }
1720 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001727 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001728 }
1729
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001730 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001731 final long identity = Binder.clearCallingIdentity();
1732 try {
1733 Phone phone = PhoneFactory.getPhone(slotIndex);
1734 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1735 PhoneConstantConversions.convertCallState(phone.getState());
1736 } finally {
1737 Binder.restoreCallingIdentity(identity);
1738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 }
1740
Sanket Padawe356d7632015-06-22 14:03:32 -07001741 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1746 if (phone != null) {
1747 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1748 } else {
1749 return PhoneConstantConversions.convertDataState(
1750 PhoneConstants.DataState.DISCONNECTED);
1751 }
1752 } finally {
1753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 }
1756
Sanket Padawe356d7632015-06-22 14:03:32 -07001757 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001759 final long identity = Binder.clearCallingIdentity();
1760 try {
1761 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1762 if (phone != null) {
1763 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1764 } else {
1765 return TelephonyManager.DATA_ACTIVITY_NONE;
1766 }
1767 } finally {
1768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
1772 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001773 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001774 mPhone.getContext().getSystemService(AppOpsManager.class)
1775 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001776 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001777 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001778 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 }
1780
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001781 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001782 final long identity = Binder.clearCallingIdentity();
1783 try {
1784 if (DBG_LOC) log("getCellLocation: is active user");
1785 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001786 int subId = mSubscriptionController.getDefaultDataSubId();
1787 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1788 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001789 return data;
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
1792 }
Svetoslav64fad262015-04-14 14:35:21 -07001793 }
1794
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001796 public String getNetworkCountryIsoForPhone(int phoneId) {
1797 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1798 // registered cell info, so return a NULL country instead.
1799 final long identity = Binder.clearCallingIdentity();
1800 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001801 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1802 // Get default phone in this case.
1803 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1804 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001805 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001806 // Todo: fix this when we can get the actual cellular network info when the device
1807 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001808 if (TelephonyManager.NETWORK_TYPE_IWLAN
1809 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1810 return "";
1811 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001812 Phone phone = PhoneFactory.getPhone(phoneId);
1813 if (phone != null) {
1814 ServiceStateTracker sst = phone.getServiceStateTracker();
1815 if (sst != null) {
1816 LocaleTracker lt = sst.getLocaleTracker();
1817 if (lt != null) {
1818 return lt.getCurrentCountry();
1819 }
1820 }
1821 }
1822 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001823 } finally {
1824 Binder.restoreCallingIdentity(identity);
1825 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001826 }
1827
1828 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001830 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001831 }
1832
Sanket Padawe356d7632015-06-22 14:03:32 -07001833 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001834 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 mApp.enforceCallingOrSelfPermission(
1836 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001837
1838 final long identity = Binder.clearCallingIdentity();
1839 try {
1840 final Phone phone = getPhone(subId);
1841 if (phone != null) {
1842 phone.enableLocationUpdates();
1843 }
1844 } finally {
1845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 }
1848
1849 @Override
1850 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001851 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001852 }
1853
Sanket Padawe356d7632015-06-22 14:03:32 -07001854 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001855 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 mApp.enforceCallingOrSelfPermission(
1857 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001858
1859 final long identity = Binder.clearCallingIdentity();
1860 try {
1861 final Phone phone = getPhone(subId);
1862 if (phone != null) {
1863 phone.disableLocationUpdates();
1864 }
1865 } finally {
1866 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 }
1869
Nathan Harold31d7ff32018-10-15 20:20:30 -07001870 /**
1871 * Returns the target SDK version number for a given package name.
1872 *
1873 * @return target SDK if the package is found or INT_MAX.
1874 */
1875 private int getTargetSdk(String packageName) {
1876 try {
1877 final ApplicationInfo ai =
1878 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1879 if (ai != null) return ai.targetSdkVersion;
1880 } catch (PackageManager.NameNotFoundException unexpected) {
1881 }
1882 return Integer.MAX_VALUE;
1883 }
1884
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 @Override
1886 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001887 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1888 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001889 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1890 throw new SecurityException(
1891 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1892 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001893
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1895 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1896 return null;
1897 }
Svetoslav64fad262015-04-14 14:35:21 -07001898
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001899 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900
Nathan Haroldf180aac2018-06-01 18:43:55 -07001901 List<CellInfo> info = getAllCellInfo(callingPackage);
1902 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903
Nathan Haroldf180aac2018-06-01 18:43:55 -07001904 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1905 for (CellInfo ci : info) {
1906 if (ci instanceof CellInfoGsm) {
1907 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1908 } else if (ci instanceof CellInfoWcdma) {
1909 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001912 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
1915
1916 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001917 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001918 mPhone.getContext().getSystemService(AppOpsManager.class)
1919 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001920 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001921 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001922 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 }
1924
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001925 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1930 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001931 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001932 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001933 if (info != null) cellInfos.addAll(info);
1934 }
1935 return cellInfos;
1936 } finally {
1937 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939 }
1940
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001941 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001943 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001944 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001945
1946 final long identity = Binder.clearCallingIdentity();
1947 try {
1948 mPhone.setCellInfoListRate(rateInMillis, workSource);
1949 } finally {
1950 Binder.restoreCallingIdentity(identity);
1951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
Shishir Agrawala9f32182016-04-12 12:00:16 -07001954 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001955 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001956 Phone phone = PhoneFactory.getPhone(slotIndex);
1957 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001958 return null;
1959 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001960 int subId = phone.getSubId();
1961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1962 mApp, subId, callingPackage, "getImeiForSlot")) {
1963 return null;
1964 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001965
1966 final long identity = Binder.clearCallingIdentity();
1967 try {
1968 return phone.getImei();
1969 } finally {
1970 Binder.restoreCallingIdentity(identity);
1971 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001972 }
1973
1974 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001975 public String getTypeAllocationCodeForSlot(int slotIndex) {
1976 Phone phone = PhoneFactory.getPhone(slotIndex);
1977 String tac = null;
1978 if (phone != null) {
1979 String imei = phone.getImei();
1980 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1981 }
1982 return tac;
1983 }
1984
1985 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001986 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001987 Phone phone = PhoneFactory.getPhone(slotIndex);
1988 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001989 return null;
1990 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001991 int subId = phone.getSubId();
1992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1993 mApp, subId, callingPackage, "getMeidForSlot")) {
1994 return null;
1995 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001996
1997 final long identity = Binder.clearCallingIdentity();
1998 try {
1999 return phone.getMeid();
2000 } finally {
2001 Binder.restoreCallingIdentity(identity);
2002 }
Jack Yu2af8d712017-03-15 17:14:14 -07002003 }
2004
2005 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002006 public String getManufacturerCodeForSlot(int slotIndex) {
2007 Phone phone = PhoneFactory.getPhone(slotIndex);
2008 String manufacturerCode = null;
2009 if (phone != null) {
2010 String meid = phone.getMeid();
2011 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2012 }
2013 return manufacturerCode;
2014 }
2015
2016 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002017 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002018 Phone phone = PhoneFactory.getPhone(slotIndex);
2019 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002020 return null;
2021 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002022 int subId = phone.getSubId();
2023 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2024 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2025 return null;
2026 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002027
2028 final long identity = Binder.clearCallingIdentity();
2029 try {
2030 return phone.getDeviceSvn();
2031 } finally {
2032 Binder.restoreCallingIdentity(identity);
2033 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002034 }
2035
fionaxu43304da2017-11-27 22:51:16 -08002036 @Override
2037 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002038 final long identity = Binder.clearCallingIdentity();
2039 try {
2040 final Phone phone = getPhone(subId);
2041 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
fionaxu43304da2017-11-27 22:51:16 -08002045 }
2046
2047 @Override
2048 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002049 final long identity = Binder.clearCallingIdentity();
2050 try {
2051 final Phone phone = getPhone(subId);
2052 return phone == null ? null : phone.getCarrierName();
2053 } finally {
2054 Binder.restoreCallingIdentity(identity);
2055 }
fionaxu43304da2017-11-27 22:51:16 -08002056 }
2057
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 //
2059 // Internal helper methods.
2060 //
2061
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002062 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2064 *
2065 * @throws SecurityException if the caller does not have the required permission
2066 */
2067 private void enforceModifyPermission() {
2068 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2069 }
2070
2071 /**
2072 * Make sure the caller has the CALL_PHONE permission.
2073 *
2074 * @throws SecurityException if the caller does not have the required permission
2075 */
2076 private void enforceCallPermission() {
2077 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2078 }
2079
Stuart Scott8eef64f2015-04-08 15:13:54 -07002080 private void enforceConnectivityInternalPermission() {
2081 mApp.enforceCallingOrSelfPermission(
2082 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2083 "ConnectivityService");
2084 }
2085
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 private String createTelUrl(String number) {
2087 if (TextUtils.isEmpty(number)) {
2088 return null;
2089 }
2090
Jake Hambye994d462014-02-03 13:10:13 -08002091 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 }
2093
Ihab Awadf9e92732013-12-05 18:02:52 -08002094 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2096 }
2097
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002098 private static void logv(String msg) {
2099 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2100 }
2101
Ihab Awadf9e92732013-12-05 18:02:52 -08002102 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2104 }
2105
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002106 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002108 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002109 }
2110
Sanket Padawe356d7632015-06-22 14:03:32 -07002111 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002112 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 final Phone phone = PhoneFactory.getPhone(slotIndex);
2116 if (phone == null) {
2117 return PhoneConstants.PHONE_TYPE_NONE;
2118 } else {
2119 return phone.getPhoneType();
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 icon index to display
2128 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002129 @Override
2130 public int getCdmaEriIconIndex(String callingPackage) {
2131 return getCdmaEriIconIndexForSubscriber(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 int getCdmaEriIconIndexForSubscriber(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, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002138 return -1;
2139 }
Malcolm Chend965c8b2018-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.getCdmaEriIconIndex();
2146 } else {
2147 return -1;
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 /**
2155 * Returns the CDMA ERI icon mode,
2156 * 0 - ON
2157 * 1 - FLASHING
2158 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002159 @Override
2160 public int getCdmaEriIconMode(String callingPackage) {
2161 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002162 }
2163
Sanket Padawe356d7632015-06-22 14:03:32 -07002164 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002165 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002166 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002167 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002168 return -1;
2169 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002170
2171 final long identity = Binder.clearCallingIdentity();
2172 try {
2173 final Phone phone = getPhone(subId);
2174 if (phone != null) {
2175 return phone.getCdmaEriIconMode();
2176 } else {
2177 return -1;
2178 }
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
2184 /**
2185 * Returns the CDMA ERI text,
2186 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002187 @Override
2188 public String getCdmaEriText(String callingPackage) {
2189 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002190 }
2191
Sanket Padawe356d7632015-06-22 14:03:32 -07002192 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002193 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002195 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002196 return null;
2197 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002198
2199 final long identity = Binder.clearCallingIdentity();
2200 try {
2201 final Phone phone = getPhone(subId);
2202 if (phone != null) {
2203 return phone.getCdmaEriText();
2204 } else {
2205 return null;
2206 }
2207 } finally {
2208 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
2212 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002213 * Returns the CDMA MDN.
2214 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002215 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002216 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2218 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002219
2220 final long identity = Binder.clearCallingIdentity();
2221 try {
2222 final Phone phone = getPhone(subId);
2223 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2224 return phone.getLine1Number();
2225 } else {
2226 return null;
2227 }
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002230 }
2231 }
2232
2233 /**
2234 * Returns the CDMA MIN.
2235 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002237 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2239 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002240
2241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 final Phone phone = getPhone(subId);
2244 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2245 return phone.getCdmaMin();
2246 } else {
2247 return null;
2248 }
2249 } finally {
2250 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002251 }
2252 }
2253
2254 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 * Returns true if CDMA provisioning needs to run.
2256 */
2257 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002258 final long identity = Binder.clearCallingIdentity();
2259 try {
2260 return mPhone.needsOtaServiceProvisioning();
2261 } finally {
2262 Binder.restoreCallingIdentity(identity);
2263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 }
2265
2266 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002267 * Sets the voice mail number of a given subId.
2268 */
2269 @Override
2270 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002271 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002272
2273 final long identity = Binder.clearCallingIdentity();
2274 try {
2275 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2276 new Pair<String, String>(alphaTag, number), new Integer(subId));
2277 return success;
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
2280 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002281 }
2282
Ta-wei Yen87c49842016-05-13 21:19:52 -07002283 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002284 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2285 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2286 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2287 if (!TextUtils.equals(callingPackage, systemDialer)) {
2288 throw new SecurityException("caller must be system dialer");
2289 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002290
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
2293 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2294 if (phoneAccountHandle == null) {
2295 return null;
2296 }
2297 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002300 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002301 }
2302
2303 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002304 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002305 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002307 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002308 return null;
2309 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002310
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002311 final long identity = Binder.clearCallingIdentity();
2312 try {
2313 return RemoteVvmTaskManager
2314 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2315 } finally {
2316 Binder.restoreCallingIdentity(identity);
2317 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002318 }
2319
2320 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002321 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2322 VisualVoicemailSmsFilterSettings settings) {
2323 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2328 mPhone.getContext(), callingPackage, subId, settings);
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
2331 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002332 }
2333
2334 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002335 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2336 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002337
2338 final long identity = Binder.clearCallingIdentity();
2339 try {
2340 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2341 mPhone.getContext(), callingPackage, subId);
2342 } finally {
2343 Binder.restoreCallingIdentity(identity);
2344 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002345 }
2346
2347 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002348 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2349 String callingPackage, int subId) {
2350 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002351
2352 final long identity = Binder.clearCallingIdentity();
2353 try {
2354 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2355 mPhone.getContext(), callingPackage, subId);
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
2358 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002359 }
2360
2361 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002362 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002363 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002364
2365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2368 mPhone.getContext(), subId);
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
2371 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002372 }
2373
2374 @Override
2375 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2376 String number, int port, String text, PendingIntent sentIntent) {
2377 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002378 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002379 enforceSendSmsPermission();
2380 // Make the calls as the phone process.
2381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2384 if (port == 0) {
2385 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2386 sentIntent, null, false);
2387 } else {
2388 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2389 smsManager.sendDataMessageWithSelfPermissions(number, null,
2390 (short) port, data, sentIntent, null);
2391 }
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
2394 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002395 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002396 /**
fionaxu0152e512016-11-14 13:36:14 -08002397 * Sets the voice activation state of a given subId.
2398 */
2399 @Override
2400 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2402 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002403
2404 final long identity = Binder.clearCallingIdentity();
2405 try {
2406 final Phone phone = getPhone(subId);
2407 if (phone != null) {
2408 phone.setVoiceActivationState(activationState);
2409 } else {
2410 loge("setVoiceActivationState fails with invalid subId: " + subId);
2411 }
2412 } finally {
2413 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002414 }
2415 }
2416
2417 /**
2418 * Sets the data activation state of a given subId.
2419 */
2420 @Override
2421 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2423 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002424
2425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 final Phone phone = getPhone(subId);
2428 if (phone != null) {
2429 phone.setDataActivationState(activationState);
2430 } else {
2431 loge("setVoiceActivationState fails with invalid subId: " + subId);
2432 }
2433 } finally {
2434 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002435 }
2436 }
2437
2438 /**
2439 * Returns the voice activation state of a given subId.
2440 */
2441 @Override
2442 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002443 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002444
fionaxu0152e512016-11-14 13:36:14 -08002445 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 if (phone != null) {
2449 return phone.getVoiceActivationState();
2450 } else {
2451 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2452 }
2453 } finally {
2454 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002455 }
2456 }
2457
2458 /**
2459 * Returns the data activation state of a given subId.
2460 */
2461 @Override
2462 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002463 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002464
fionaxu0152e512016-11-14 13:36:14 -08002465 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002466 final long identity = Binder.clearCallingIdentity();
2467 try {
2468 if (phone != null) {
2469 return phone.getDataActivationState();
2470 } else {
2471 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2472 }
2473 } finally {
2474 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002475 }
2476 }
2477
2478 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 * Returns the unread count of voicemails
2480 */
2481 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002482 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002483 }
2484
2485 /**
2486 * Returns the unread count of voicemails for a subId
2487 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002488 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002489 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 final Phone phone = getPhone(subId);
2493 if (phone != null) {
2494 return phone.getVoiceMessageCount();
2495 } else {
2496 return 0;
2497 }
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
2503 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002504 * returns true, if the device is in a state where both voice and data
2505 * are supported simultaneously. This can change based on location or network condition.
2506 */
2507 @Override
2508 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 final Phone phone = getPhone(subId);
2512 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2513 } finally {
2514 Binder.restoreCallingIdentity(identity);
2515 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002516 }
2517
2518 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002519 * Send the dialer code if called from the current default dialer or the caller has
2520 * carrier privilege.
2521 * @param inputCode The dialer code to send
2522 */
2523 @Override
2524 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2525 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2526 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2527 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002528 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2529 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002530 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002531
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 mPhone.sendDialerSpecialCode(inputCode);
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
2537 }
fionaxu235cc5e2017-03-06 22:25:57 -08002538 }
2539
2540 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002541 * Returns the data network type.
2542 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543 *
2544 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2545 */
2546 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002547 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 final Phone phone = getPhone(getDefaultSubscription());
2551 if (phone != null) {
2552 return phone.getServiceState().getDataNetworkType();
2553 } else {
2554 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2555 }
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002558 }
Wink Saville36469e72014-06-11 15:17:00 -07002559 }
2560
Pengquan Meng0c05b502018-09-06 09:59:22 -07002561 @Override
2562 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002563 if (!isActiveSubscription(subId)) {
2564 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2565 }
2566
Pengquan Meng0c05b502018-09-06 09:59:22 -07002567 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2568 }
2569
Brad Ebinger4c460712018-10-01 10:40:55 -07002570 @Override
2571 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2572 String callingPackage) throws RemoteException {
2573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2574 "addImsRegistrationCallback")) {
2575 return;
2576 }
2577 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2578 final long token = Binder.clearCallingIdentity();
2579 try {
2580 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2581 .addRegistrationCallbackForSubscription(c, subId);
2582 } finally {
2583 Binder.restoreCallingIdentity(token);
2584 }
2585 }
2586
2587 @Override
2588 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2589 String callingPackage) {
2590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2591 "removeImsRegistrationCallback")) {
2592 return;
2593 }
2594 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2595 Binder.withCleanCallingIdentity(() ->
2596 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2597 .removeRegistrationCallbackForSubscription(c, subId));
2598 }
2599
2600 @Override
2601 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2602 String callingPackage) throws RemoteException {
2603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2604 "addMmTelCapabilityCallback")) {
2605 return;
2606 }
2607 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2608 final long token = Binder.clearCallingIdentity();
2609 try {
2610 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2611 .addCapabilitiesCallbackForSubscription(c, subId);
2612 } finally {
2613 Binder.restoreCallingIdentity(token);
2614 }
2615 }
2616
2617 @Override
2618 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2619 String callingPackage) {
2620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2621 "removeMmTelCapabilityCallback")) {
2622 return;
2623 }
2624 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2625 Binder.withCleanCallingIdentity(() ->
2626 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2627 .removeCapabilitiesCallbackForSubscription(c, subId));
2628 }
2629
2630 @Override
2631 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2633 "isCapable")) {
2634 return false;
2635 }
2636 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2637 final long token = Binder.clearCallingIdentity();
2638 try {
2639 return ImsManager.getInstance(mPhone.getContext(),
2640 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2641 } catch (ImsException e) {
2642 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2643 return false;
2644 } finally {
2645 Binder.restoreCallingIdentity(token);
2646 }
2647 }
2648
2649 @Override
2650 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2652 "isAvailable")) {
2653 return false;
2654 }
2655 final long token = Binder.clearCallingIdentity();
2656 try {
2657 Phone phone = getPhone(subId);
2658 if (phone == null) return false;
2659 return phone.isImsCapabilityAvailable(capability, regTech);
2660 } finally {
2661 Binder.restoreCallingIdentity(token);
2662 }
2663 }
2664
2665 @Override
2666 public boolean isAdvancedCallingSettingEnabled(int subId) {
2667 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2669 final long token = Binder.clearCallingIdentity();
2670 try {
2671 return ImsManager.getInstance(mPhone.getContext(),
2672 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2673 } finally {
2674 Binder.restoreCallingIdentity(token);
2675 }
2676 }
2677
2678 @Override
2679 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2681 "setAdvancedCallingSetting");
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2685 ImsManager.getInstance(mPhone.getContext(),
2686 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
2689 }
2690 }
2691
2692 @Override
2693 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2695 "isVtSettingEnabled")) {
2696 return false;
2697 }
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2701 return ImsManager.getInstance(mPhone.getContext(),
2702 getSlotIndexOrException(subId)).isVtEnabledByUser();
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
2706 }
2707
2708 @Override
2709 public void setVtSetting(int subId, boolean isEnabled) {
2710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2711 "setVtSetting");
2712 final long identity = Binder.clearCallingIdentity();
2713 try {
2714 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2715 ImsManager.getInstance(mPhone.getContext(),
2716 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
2719 }
2720 }
2721
2722 @Override
2723 public boolean isVoWiFiSettingEnabled(int subId) {
2724 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2728 return ImsManager.getInstance(mPhone.getContext(),
2729 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
2732 }
2733 }
2734
2735 @Override
2736 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2738 "setVoWiFiSetting");
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2742 ImsManager.getInstance(mPhone.getContext(),
2743 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
2746 }
2747 }
2748
2749 @Override
2750 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2751 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2755 return ImsManager.getInstance(mPhone.getContext(),
2756 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2757 } finally {
2758 Binder.restoreCallingIdentity(identity);
2759 }
2760 }
2761
2762 @Override
2763 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2765 "setVoWiFiRoamingSetting");
2766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2769 ImsManager.getInstance(mPhone.getContext(),
2770 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
2773 }
2774 }
2775
2776 @Override
2777 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2779 "setVoWiFiNonPersistent");
2780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2783 ImsManager.getInstance(mPhone.getContext(),
2784 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
2787 }
2788 }
2789
2790 @Override
2791 public int getVoWiFiModeSetting(int subId) {
2792 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2793 final long identity = Binder.clearCallingIdentity();
2794 try {
2795 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2796 return ImsManager.getInstance(mPhone.getContext(),
2797 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
2800 }
2801 }
2802
2803 @Override
2804 public void setVoWiFiModeSetting(int subId, int mode) {
2805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2806 "setVoWiFiModeSetting");
2807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2810 ImsManager.getInstance(mPhone.getContext(),
2811 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
2814 }
2815 }
2816
2817 @Override
2818 public int getVoWiFiRoamingModeSetting(int subId) {
2819 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2823 return ImsManager.getInstance(mPhone.getContext(),
2824 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
2827 }
2828 }
2829
2830 @Override
2831 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2833 "setVoWiFiRoamingModeSetting");
2834 final long identity = Binder.clearCallingIdentity();
2835 try {
2836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2837 ImsManager.getInstance(mPhone.getContext(),
2838 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
2841 }
2842 }
2843
2844 @Override
2845 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2847 "setRttCapabilityEnabled");
2848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2851 ImsManager.getInstance(mPhone.getContext(),
2852 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2853 } finally {
2854 Binder.restoreCallingIdentity(identity);
2855 }
2856 }
2857
2858 @Override
2859 public boolean isTtyOverVolteEnabled(int subId) {
2860 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2864 return ImsManager.getInstance(mPhone.getContext(),
2865 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2866 } finally {
2867 Binder.restoreCallingIdentity(identity);
2868 }
2869 }
2870
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002871 @Override
2872 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2873 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2877 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2878 .getConfigInterface().addConfigCallback(callback);
2879 } catch (ImsException e) {
2880 throw new IllegalArgumentException(e.getMessage());
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
2883 }
2884 }
2885
2886 @Override
2887 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2888 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
2889 final long identity = Binder.clearCallingIdentity();
2890 try {
2891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2892 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2893 .getConfigInterface().removeConfigCallback(callback);
2894 } catch (ImsException e) {
2895 throw new IllegalArgumentException(e.getMessage());
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
2898 }
2899 }
2900
2901 @Override
2902 public int getImsProvisioningInt(int subId, int key) {
2903 enforceReadPrivilegedPermission("getImsProvisioningInt");
2904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2907 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2908 .getConfigInterface().getConfigInt(key);
2909 } catch (ImsException e) {
2910 throw new IllegalArgumentException(e.getMessage());
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
2913 }
2914 }
2915
2916 @Override
2917 public String getImsProvisioningString(int subId, int key) {
2918 enforceReadPrivilegedPermission("getImsProvisioningString");
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2922 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2923 .getConfigInterface().getConfigString(key);
2924 } catch (ImsException e) {
2925 throw new IllegalArgumentException(e.getMessage());
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
2929 }
2930
2931 @Override
2932 public int setImsProvisioningInt(int subId, int key, int value) {
2933 enforceReadPrivilegedPermission("setImsProvisioningInt");
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2937 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2938 .getConfigInterface().setConfig(key, value);
2939 } catch (ImsException e) {
2940 throw new IllegalArgumentException(e.getMessage());
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
2943 }
2944 }
2945
2946 @Override
2947 public int setImsProvisioningString(int subId, int key, String value) {
2948 enforceReadPrivilegedPermission("setImsProvisioningString");
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2952 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2953 .getConfigInterface().setConfig(key, value);
2954 } catch (ImsException e) {
2955 throw new IllegalArgumentException(e.getMessage());
2956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
2959 }
2960
Brad Ebinger4c460712018-10-01 10:40:55 -07002961 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2962 int slotId = SubscriptionManager.getSlotIndex(subId);
2963 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2964 throw new IllegalArgumentException("Invalid Subscription Id.");
2965 }
2966 return slotId;
2967 }
2968
Wink Saville36469e72014-06-11 15:17:00 -07002969 /**
2970 * Returns the network type for a subId
2971 */
2972 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002973 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002975 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002976 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2977 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002978
Malcolm Chend965c8b2018-02-28 15:00:40 -08002979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 final Phone phone = getPhone(subId);
2982 if (phone != null) {
2983 return phone.getServiceState().getDataNetworkType();
2984 } else {
2985 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2986 }
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 }
2991
2992 /**
2993 * Returns the data network type
2994 */
2995 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002996 public int getDataNetworkType(String callingPackage) {
2997 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002998 }
2999
3000 /**
3001 * Returns the data network type for a subId
3002 */
3003 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003004 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003006 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003007 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3008 }
3009
Malcolm Chend965c8b2018-02-28 15:00:40 -08003010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 final Phone phone = getPhone(subId);
3013 if (phone != null) {
3014 return phone.getServiceState().getDataNetworkType();
3015 } else {
3016 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3017 }
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 }
3022
3023 /**
Wink Saville36469e72014-06-11 15:17:00 -07003024 * Returns the Voice network type for a subId
3025 */
3026 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003027 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003028 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003029 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003030 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3031 }
3032
Malcolm Chend965c8b2018-02-28 15:00:40 -08003033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 final Phone phone = getPhone(subId);
3036 if (phone != null) {
3037 return phone.getServiceState().getVoiceNetworkType();
3038 } else {
3039 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3040 }
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003043 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003044 }
3045
3046 /**
3047 * @return true if a ICC card is present
3048 */
3049 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003050 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003051 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3052 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003053 }
3054
3055 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003056 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003057 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003058 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003059 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 final Phone phone = PhoneFactory.getPhone(slotIndex);
3063 if (phone != null) {
3064 return phone.getIccCard().hasIccCard();
3065 } else {
3066 return false;
3067 }
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003070 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 }
3072
3073 /**
3074 * Return if the current radio is LTE on CDMA. This
3075 * is a tri-state return value as for a period of time
3076 * the mode may be unknown.
3077 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003078 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003079 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003080 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003082 @Override
3083 public int getLteOnCdmaMode(String callingPackage) {
3084 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003085 }
3086
Sanket Padawe356d7632015-06-22 14:03:32 -07003087 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003088 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003090 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003091 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3092 }
3093
Malcolm Chend965c8b2018-02-28 15:00:40 -08003094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 final Phone phone = getPhone(subId);
3097 if (phone == null) {
3098 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3099 } else {
3100 return phone.getLteOnCdmaMode();
3101 }
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003104 }
Wink Saville36469e72014-06-11 15:17:00 -07003105 }
3106
3107 public void setPhone(Phone phone) {
3108 mPhone = phone;
3109 }
3110
3111 /**
3112 * {@hide}
3113 * Returns Default subId, 0 in the case of single standby.
3114 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003115 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003116 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003117 }
3118
Shishir Agrawala9f32182016-04-12 12:00:16 -07003119 private int getSlotForDefaultSubscription() {
3120 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3121 }
3122
Wink Savilleb564aae2014-10-23 10:18:09 -07003123 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003124 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003125 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003126
Pengquan Meng466e2482018-09-21 15:54:48 -07003127 private boolean isActiveSubscription(int subId) {
3128 return mSubscriptionController.isActiveSubId(subId);
3129 }
3130
Ihab Awadf2177b72013-11-25 13:33:23 -08003131 /**
3132 * @see android.telephony.TelephonyManager.WifiCallingChoices
3133 */
3134 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3138 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3139 getWhenToMakeWifiCallsDefaultPreference());
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003143 }
3144
3145 /**
3146 * @see android.telephony.TelephonyManager.WifiCallingChoices
3147 */
3148 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3152 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3153 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003157 }
3158
Sailesh Nepald1e68152013-12-12 19:08:02 -08003159 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003160 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003161 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003162 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003163
Shishir Agrawal566b7612013-10-28 14:41:00 -07003164 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003165 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3166 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3168 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003169 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003170
Malcolm Chend965c8b2018-02-28 15:00:40 -08003171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 if (TextUtils.equals(ISDR_AID, aid)) {
3174 // Only allows LPA to open logical channel to ISD-R.
3175 ComponentInfo bestComponent =
3176 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3177 if (bestComponent == null
3178 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3179 loge("The calling package is not allowed to access ISD-R.");
3180 throw new SecurityException(
3181 "The calling package is not allowed to access ISD-R.");
3182 }
Derek Tan740e1672017-06-27 14:56:27 -07003183 }
Derek Tan740e1672017-06-27 14:56:27 -07003184
Malcolm Chend965c8b2018-02-28 15:00:40 -08003185 if (DBG) {
3186 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3187 }
3188 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3189 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3190 if (DBG) log("iccOpenLogicalChannel: " + response);
3191 return response;
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003195 }
3196
3197 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003198 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3200 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003201
Malcolm Chend965c8b2018-02-28 15:00:40 -08003202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3205 if (channel < 0) {
3206 return false;
3207 }
3208 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3209 if (DBG) log("iccCloseLogicalChannel: " + success);
3210 return success;
3211 } finally {
3212 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003213 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003214 }
3215
3216 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003217 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003218 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3220 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003221
Malcolm Chend965c8b2018-02-28 15:00:40 -08003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 if (DBG) {
3225 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3226 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3227 + p3 + " data=" + data);
3228 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003229
Malcolm Chend965c8b2018-02-28 15:00:40 -08003230 if (channel < 0) {
3231 return "";
3232 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003233
Malcolm Chend965c8b2018-02-28 15:00:40 -08003234 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3235 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3236 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003237
Malcolm Chend965c8b2018-02-28 15:00:40 -08003238 // Append the returned status code to the end of the response payload.
3239 String s = Integer.toHexString(
3240 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3241 if (response.payload != null) {
3242 s = IccUtils.bytesToHexString(response.payload) + s;
3243 }
3244 return s;
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003247 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003248 }
Jake Hambye994d462014-02-03 13:10:13 -08003249
Evan Charltonc66da362014-05-16 14:06:40 -07003250 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003251 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3252 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3254 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003255 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003256
Malcolm Chend965c8b2018-02-28 15:00:40 -08003257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3260 && TextUtils.equals(ISDR_AID, data)) {
3261 // Only allows LPA to select ISD-R.
3262 ComponentInfo bestComponent =
3263 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3264 if (bestComponent == null
3265 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3266 loge("The calling package is not allowed to select ISD-R.");
3267 throw new SecurityException(
3268 "The calling package is not allowed to select ISD-R.");
3269 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003270 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003271
Malcolm Chend965c8b2018-02-28 15:00:40 -08003272 if (DBG) {
3273 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3274 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3275 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003276
Malcolm Chend965c8b2018-02-28 15:00:40 -08003277 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3278 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3279 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003280
Malcolm Chend965c8b2018-02-28 15:00:40 -08003281 // Append the returned status code to the end of the response payload.
3282 String s = Integer.toHexString(
3283 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3284 if (response.payload != null) {
3285 s = IccUtils.bytesToHexString(response.payload) + s;
3286 }
3287 return s;
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003290 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003291 }
3292
3293 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003294 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003295 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3297 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003298
Malcolm Chend965c8b2018-02-28 15:00:40 -08003299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 if (DBG) {
3302 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3303 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3304 }
3305
3306 IccIoResult response =
3307 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3308 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3309 subId);
3310
3311 if (DBG) {
3312 log("Exchange SIM_IO [R]" + response);
3313 }
3314
3315 byte[] result = null;
3316 int length = 2;
3317 if (response.payload != null) {
3318 length = 2 + response.payload.length;
3319 result = new byte[length];
3320 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3321 } else {
3322 result = new byte[length];
3323 }
3324
3325 result[length - 1] = (byte) response.sw2;
3326 result[length - 2] = (byte) response.sw1;
3327 return result;
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003330 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003331 }
3332
Nathan Haroldb3014052017-01-25 15:57:32 -08003333 /**
3334 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3335 * on a particular subscription
3336 */
sqianb6e41952018-03-12 14:54:01 -07003337 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3339 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3340 return null;
3341 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003342
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 if (appType != TelephonyManager.APPTYPE_USIM
3346 && appType != TelephonyManager.APPTYPE_SIM) {
3347 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3348 return null;
3349 }
3350 Object response = sendRequest(
3351 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3352 if (response instanceof String[]) {
3353 return (String[]) response;
3354 }
3355 // Response is an Exception of some kind,
3356 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003357 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003358 } finally {
3359 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003360 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003361 }
3362
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003363 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003364 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3366 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003367
Malcolm Chend965c8b2018-02-28 15:00:40 -08003368 final long identity = Binder.clearCallingIdentity();
3369 try {
3370 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3371 if (response.payload == null) {
3372 return "";
3373 }
Evan Charltonc66da362014-05-16 14:06:40 -07003374
Malcolm Chend965c8b2018-02-28 15:00:40 -08003375 // Append the returned status code to the end of the response payload.
3376 String s = Integer.toHexString(
3377 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3378 s = IccUtils.bytesToHexString(response.payload) + s;
3379 return s;
3380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
Evan Charltonc66da362014-05-16 14:06:40 -07003383 }
3384
Jake Hambye994d462014-02-03 13:10:13 -08003385 /**
3386 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3387 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3388 *
3389 * @param itemID the ID of the item to read
3390 * @return the NV item as a String, or null on error.
3391 */
3392 @Override
3393 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003394 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3396 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003397
3398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003401 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003402 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3403 return value;
3404 } finally {
3405 Binder.restoreCallingIdentity(identity);
3406 }
Jake Hambye994d462014-02-03 13:10:13 -08003407 }
3408
3409 /**
3410 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3411 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3412 *
3413 * @param itemID the ID of the item to read
3414 * @param itemValue the value to write, as a String
3415 * @return true on success; false on any failure
3416 */
3417 @Override
3418 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003419 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3421 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003422
3423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3426 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003427 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003428 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3429 return success;
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
Jake Hambye994d462014-02-03 13:10:13 -08003433 }
3434
3435 /**
3436 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3437 * Used for device configuration by some CDMA operators.
3438 *
3439 * @param preferredRoamingList byte array containing the new PRL
3440 * @return true on success; false on any failure
3441 */
3442 @Override
3443 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3445 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003446
3447 final long identity = Binder.clearCallingIdentity();
3448 try {
3449 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3450 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3451 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3452 return success;
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
Jake Hambye994d462014-02-03 13:10:13 -08003456 }
3457
3458 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003459 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003460 * Used for device configuration by some CDMA operators.
3461 *
chen xu1cc0abe2018-10-26 17:39:23 -07003462 * @param slotIndex - device slot.
3463 *
Jake Hambye994d462014-02-03 13:10:13 -08003464 * @return true on success; false on any failure
3465 */
3466 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003467 public boolean resetModemConfig(int slotIndex) {
3468 Phone phone = PhoneFactory.getPhone(slotIndex);
3469 if (phone != null) {
3470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3471 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003472
chen xu1cc0abe2018-10-26 17:39:23 -07003473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3476 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3477 return success;
3478 } finally {
3479 Binder.restoreCallingIdentity(identity);
3480 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003481 }
chen xu1cc0abe2018-10-26 17:39:23 -07003482 return false;
3483 }
3484
3485 /**
3486 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3487 *
3488 * @param slotIndex - device slot.
3489 *
3490 * @return true on success; false on any failure
3491 */
3492 @Override
3493 public boolean rebootModem(int slotIndex) {
3494 Phone phone = PhoneFactory.getPhone(slotIndex);
3495 if (phone != null) {
3496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3497 mApp, phone.getSubId(), "rebootModem");
3498
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3502 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3503 return success;
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
3506 }
3507 }
3508 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003509 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003510
Svet Ganovb320e182015-04-16 12:30:10 -07003511 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003512 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003513 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003514 return new String[0];
3515 }
3516
Malcolm Chend965c8b2018-02-28 15:00:40 -08003517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 return mPhone.getPcscfAddress(apnType);
3520 } finally {
3521 Binder.restoreCallingIdentity(identity);
3522 }
Wink Saville36469e72014-06-11 15:17:00 -07003523 }
3524
Brad Ebinger51f743a2017-01-23 13:50:20 -08003525 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003526 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3527 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003528 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003529 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003530 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003531
3532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 PhoneFactory.getImsResolver().enableIms(slotId);
3535 } finally {
3536 Binder.restoreCallingIdentity(identity);
3537 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003538 }
3539
3540 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003541 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3542 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003543 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003544 public void disableIms(int slotId) {
3545 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003546
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 PhoneFactory.getImsResolver().disableIms(slotId);
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003553 }
3554
3555 /**
3556 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3557 * feature or {@link null} if the service is not available. If the feature is available, the
3558 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3559 */
3560 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003561 IImsServiceFeatureCallback callback) {
3562 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003563
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3567 } finally {
3568 Binder.restoreCallingIdentity(identity);
3569 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003570 }
3571
3572 /**
3573 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3574 * feature during emergency calling or {@link null} if the service is not available. If the
3575 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3576 * listener for feature updates.
3577 */
3578 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3579 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003580
3581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3584 } finally {
3585 Binder.restoreCallingIdentity(identity);
3586 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003587 }
3588
Brad Ebinger5f64b052017-12-14 14:26:15 -08003589 /**
3590 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3591 * specified.
3592 */
3593 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3594 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
3601 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003602 }
3603
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003604 /**
3605 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3606 * specified.
3607 */
3608 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3609 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003610
3611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003617 }
3618
Brad Ebinger884c07b2018-02-15 16:17:40 -08003619 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003620 * Sets the ImsService Package Name that Telephony will bind to.
3621 *
3622 * @param slotId the slot ID that the ImsService should bind for.
3623 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3624 * ImsService is the device default ImsService.
3625 * @param packageName The package name of the application that contains the ImsService to bind
3626 * to.
3627 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3628 * @hide
3629 */
3630 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003631 int[] subIds = SubscriptionManager.getSubId(slotId);
3632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3633 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3634 "setImsService");
3635
Malcolm Chend965c8b2018-02-28 15:00:40 -08003636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3639 isCarrierImsService, packageName);
3640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003643 }
3644
3645 /**
3646 * Return the ImsService configuration.
3647 *
3648 * @param slotId The slot that the ImsService is associated with.
3649 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3650 * the device default.
3651 * @return the package name of the ImsService configuration.
3652 */
3653 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003654 int[] subIds = SubscriptionManager.getSubId(slotId);
3655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3656 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3657 "getImsService");
3658
Malcolm Chend965c8b2018-02-28 15:00:40 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3662 isCarrierImsService);
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003666 }
3667
Wink Saville36469e72014-06-11 15:17:00 -07003668 public void setImsRegistrationState(boolean registered) {
3669 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003670
3671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 mPhone.setImsRegistrationState(registered);
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
Wink Saville36469e72014-06-11 15:17:00 -07003677 }
3678
3679 /**
Stuart Scott54788802015-03-30 13:18:01 -07003680 * Set the network selection mode to automatic.
3681 *
3682 */
3683 @Override
3684 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3686 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003687
Pengquan Meng466e2482018-09-21 15:54:48 -07003688 if (!isActiveSubscription(subId)) {
3689 return;
3690 }
3691
Malcolm Chend965c8b2018-02-28 15:00:40 -08003692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3695 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
Stuart Scott54788802015-03-30 13:18:01 -07003699 }
3700
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003701 /**
3702 * Ask the radio to connect to the input network and change selection mode to manual.
3703 *
3704 * @param subId the id of the subscription.
3705 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3706 * the operator to attach to.
3707 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3708 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3709 * normal network selection next time.
3710 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003711 */
3712 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003713 public boolean setNetworkSelectionModeManual(
3714 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3716 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003717
3718 if (!isActiveSubscription(subId)) {
3719 return false;
3720 }
3721
Malcolm Chend965c8b2018-02-28 15:00:40 -08003722 final long identity = Binder.clearCallingIdentity();
3723 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003724 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003725 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003726 if (DBG) {
3727 log("setNetworkSelectionModeManual: subId: " + subId
3728 + " operator: " + operatorInfo);
3729 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003730 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003734 }
3735
3736 /**
3737 * Scans for available networks.
3738 */
3739 @Override
3740 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3742 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003743
Pengquan Meng0c05b502018-09-06 09:59:22 -07003744 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003745 try {
3746 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003747 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003748 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003749 } finally {
3750 Binder.restoreCallingIdentity(identity);
3751 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003752 }
3753
3754 /**
yinxub1bed742017-04-17 11:45:04 -07003755 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003756 *
yinxub1bed742017-04-17 11:45:04 -07003757 * @param subId id of the subscription
3758 * @param request contains the radio access networks with bands/channels to scan
3759 * @param messenger callback messenger for scan results or errors
3760 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003761 * @return the id of the requested scan which can be used to stop the scan.
3762 */
3763 @Override
3764 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3765 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3767 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003768
3769 final long identity = Binder.clearCallingIdentity();
3770 try {
3771 return mNetworkScanRequestTracker.startNetworkScan(
3772 request, messenger, binder, getPhone(subId));
3773 } finally {
3774 Binder.restoreCallingIdentity(identity);
3775 }
yinxu504e1392017-04-12 16:03:22 -07003776 }
3777
3778 /**
3779 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003780 *
3781 * @param subId id of the subscription
3782 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003783 */
3784 @Override
3785 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3787 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003788
3789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3792 } finally {
3793 Binder.restoreCallingIdentity(identity);
3794 }
yinxu504e1392017-04-12 16:03:22 -07003795 }
3796
3797 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003798 * Get the calculated preferred network type.
3799 * Used for debugging incorrect network type.
3800 *
3801 * @return the preferred network type, defined in RILConstants.java.
3802 */
3803 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003804 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003806 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003807 return RILConstants.PREFERRED_NETWORK_MODE;
3808 }
3809
Malcolm Chend965c8b2018-02-28 15:00:40 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 // FIXME: need to get SubId from somewhere.
3813 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3814 } finally {
3815 Binder.restoreCallingIdentity(identity);
3816 }
Junda Liu84d15a22014-07-02 11:21:04 -07003817 }
3818
3819 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003820 * Get the preferred network type.
3821 * Used for device configuration by some CDMA operators.
3822 *
3823 * @return the preferred network type, defined in RILConstants.java.
3824 */
3825 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003826 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3828 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003829
3830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 if (DBG) log("getPreferredNetworkType");
3833 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3834 int networkType = (result != null ? result[0] : -1);
3835 if (DBG) log("getPreferredNetworkType: " + networkType);
3836 return networkType;
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
3839 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003840 }
3841
3842 /**
3843 * Set the preferred network type.
3844 * Used for device configuration by some CDMA operators.
3845 *
3846 * @param networkType the preferred network type, defined in RILConstants.java.
3847 * @return true on success; false on any failure.
3848 */
3849 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003850 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3852 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003853
3854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3857 Boolean success = (Boolean) sendRequest(
3858 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3859 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3860 if (success) {
3861 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3862 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3863 }
3864 return success;
3865 } finally {
3866 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003867 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003868 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003869
3870 /**
Junda Liu475951f2014-11-07 16:45:03 -08003871 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003872 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003873 * tethering.
3874 *
3875 * @return 0: Not required. 1: required. 2: Not set.
3876 * @hide
3877 */
3878 @Override
3879 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003880 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003881
3882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3885 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07003886 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08003887 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3888 dunRequired = 1;
3889 }
3890 return dunRequired;
3891 } finally {
3892 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003893 }
Junda Liu475951f2014-11-07 16:45:03 -08003894 }
3895
3896 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003897 * Set mobile data enabled
3898 * Used by the user through settings etc to turn on/off mobile data
3899 *
3900 * @param enable {@code true} turn turn data on, else {@code false}
3901 */
3902 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003903 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3905 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003906
3907 final long identity = Binder.clearCallingIdentity();
3908 try {
3909 int phoneId = mSubscriptionController.getPhoneId(subId);
3910 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3911 Phone phone = PhoneFactory.getPhone(phoneId);
3912 if (phone != null) {
3913 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3914 phone.setUserDataEnabled(enable);
3915 } else {
3916 loge("setUserDataEnabled: no phone for subId=" + subId);
3917 }
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003920 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003921 }
3922
3923 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003924 * Get the user enabled state of Mobile Data.
3925 *
3926 * TODO: remove and use isUserDataEnabled.
3927 * This can't be removed now because some vendor codes
3928 * calls through ITelephony directly while they should
3929 * use TelephonyManager.
3930 *
3931 * @return true on enabled
3932 */
3933 @Override
3934 public boolean getDataEnabled(int subId) {
3935 return isUserDataEnabled(subId);
3936 }
3937
3938 /**
3939 * Get whether mobile data is enabled per user setting.
3940 *
3941 * There are other factors deciding whether mobile data is actually enabled, but they are
3942 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003943 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003944 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003945 *
3946 * @return {@code true} if data is enabled else {@code false}
3947 */
3948 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003949 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003950 try {
3951 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3952 null);
3953 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3955 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003956 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 int phoneId = mSubscriptionController.getPhoneId(subId);
3961 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3962 Phone phone = PhoneFactory.getPhone(phoneId);
3963 if (phone != null) {
3964 boolean retVal = phone.isUserDataEnabled();
3965 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3966 return retVal;
3967 } else {
3968 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3969 return false;
3970 }
3971 } finally {
3972 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003973 }
3974 }
3975
3976 /**
3977 * Get whether mobile data is enabled.
3978 *
3979 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3980 * whether mobile data is actually enabled.
3981 *
3982 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3983 *
3984 * @return {@code true} if data is enabled else {@code false}
3985 */
3986 @Override
3987 public boolean isDataEnabled(int subId) {
3988 try {
3989 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3990 null);
3991 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3993 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003994 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003995
3996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 int phoneId = mSubscriptionController.getPhoneId(subId);
3999 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4000 Phone phone = PhoneFactory.getPhone(phoneId);
4001 if (phone != null) {
4002 boolean retVal = phone.isDataEnabled();
4003 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4004 return retVal;
4005 } else {
4006 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4007 return false;
4008 }
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004011 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004012 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004013
4014 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004015 public int getCarrierPrivilegeStatus(int subId) {
4016 final Phone phone = getPhone(subId);
4017 if (phone == null) {
4018 loge("getCarrierPrivilegeStatus: Invalid subId");
4019 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4020 }
4021 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004022 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004023 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004024 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4025 }
4026 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004027 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004028 }
Junda Liu29340342014-07-10 15:23:27 -07004029
4030 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004031 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4032 final Phone phone = getPhone(subId);
4033 if (phone == null) {
4034 loge("getCarrierPrivilegeStatus: Invalid subId");
4035 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4036 }
4037 UiccProfile profile =
4038 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4039 if (profile == null) {
4040 loge("getCarrierPrivilegeStatus: No UICC");
4041 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4042 }
4043 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4044 }
4045
4046 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004047 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004048 if (TextUtils.isEmpty(pkgName))
4049 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004050 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004051 if (card == null) {
4052 loge("checkCarrierPrivilegesForPackage: No UICC");
4053 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4054 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004055 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4056 }
4057
4058 @Override
4059 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004060 if (TextUtils.isEmpty(pkgName))
4061 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004062 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4063 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4064 UiccCard card = UiccController.getInstance().getUiccCard(i);
4065 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004066 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004067 continue;
4068 }
4069
4070 result = card.getCarrierPrivilegeStatus(
4071 mPhone.getContext().getPackageManager(), pkgName);
4072 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4073 break;
4074 }
4075 }
4076
4077 return result;
Junda Liu29340342014-07-10 15:23:27 -07004078 }
Derek Tan89e89d42014-07-08 17:00:10 -07004079
4080 @Override
Junda Liue64de782015-04-16 17:19:16 -07004081 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4082 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4083 loge("phoneId " + phoneId + " is not valid.");
4084 return null;
4085 }
4086 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004087 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004088 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004089 return null ;
4090 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004091 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004092 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004093 }
4094
Amith Yamasani6e118872016-02-19 12:53:51 -08004095 @Override
4096 public List<String> getPackagesWithCarrierPrivileges() {
4097 PackageManager pm = mPhone.getContext().getPackageManager();
4098 List<String> privilegedPackages = new ArrayList<>();
4099 List<PackageInfo> packages = null;
4100 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4101 UiccCard card = UiccController.getInstance().getUiccCard(i);
4102 if (card == null) {
4103 // No UICC in that slot.
4104 continue;
4105 }
4106 if (card.hasCarrierPrivilegeRules()) {
4107 if (packages == null) {
4108 // Only check packages in user 0 for now
4109 packages = pm.getInstalledPackagesAsUser(
4110 PackageManager.MATCH_DISABLED_COMPONENTS
4111 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4112 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4113 }
4114 for (int p = packages.size() - 1; p >= 0; p--) {
4115 PackageInfo pkgInfo = packages.get(p);
4116 if (pkgInfo != null && pkgInfo.packageName != null
4117 && card.getCarrierPrivilegeStatus(pkgInfo)
4118 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4119 privilegedPackages.add(pkgInfo.packageName);
4120 }
4121 }
4122 }
4123 }
4124 return privilegedPackages;
4125 }
4126
Wink Savilleb564aae2014-10-23 10:18:09 -07004127 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004128 final Phone phone = getPhone(subId);
4129 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004130 if (card == null) {
4131 loge("getIccId: No UICC");
4132 return null;
4133 }
4134 String iccId = card.getIccId();
4135 if (TextUtils.isEmpty(iccId)) {
4136 loge("getIccId: ICC ID is null or empty.");
4137 return null;
4138 }
4139 return iccId;
4140 }
4141
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004142 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004143 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4144 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004145 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4146 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004147
Malcolm Chend965c8b2018-02-28 15:00:40 -08004148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 final String iccId = getIccId(subId);
4151 final Phone phone = getPhone(subId);
4152 if (phone == null) {
4153 return false;
4154 }
4155 final String subscriberId = phone.getSubscriberId();
4156
4157 if (DBG_MERGE) {
4158 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4159 + subscriberId + " to " + number);
4160 }
4161
4162 if (TextUtils.isEmpty(iccId)) {
4163 return false;
4164 }
4165
4166 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4167
4168 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4169 if (alphaTag == null) {
4170 editor.remove(alphaTagPrefKey);
4171 } else {
4172 editor.putString(alphaTagPrefKey, alphaTag);
4173 }
4174
4175 // Record both the line number and IMSI for this ICCID, since we need to
4176 // track all merged IMSIs based on line number
4177 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4178 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4179 if (number == null) {
4180 editor.remove(numberPrefKey);
4181 editor.remove(subscriberPrefKey);
4182 } else {
4183 editor.putString(numberPrefKey, number);
4184 editor.putString(subscriberPrefKey, subscriberId);
4185 }
4186
4187 editor.commit();
4188 return true;
4189 } finally {
4190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004191 }
Derek Tan7226c842014-07-02 17:42:23 -07004192 }
4193
4194 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004195 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004196 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004198 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004199 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004200 return null;
4201 }
Derek Tan97ebb422014-09-05 16:55:38 -07004202
Malcolm Chend965c8b2018-02-28 15:00:40 -08004203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 String iccId = getIccId(subId);
4206 if (iccId != null) {
4207 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4208 if (DBG_MERGE) {
4209 log("getLine1NumberForDisplay returning "
4210 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4211 }
4212 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004213 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004214 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4215 return null;
4216 } finally {
4217 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004218 }
Derek Tan7226c842014-07-02 17:42:23 -07004219 }
4220
4221 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004222 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004224 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004225 return null;
4226 }
Derek Tan97ebb422014-09-05 16:55:38 -07004227
Malcolm Chend965c8b2018-02-28 15:00:40 -08004228 final long identity = Binder.clearCallingIdentity();
4229 try {
4230 String iccId = getIccId(subId);
4231 if (iccId != null) {
4232 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4233 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4234 }
4235 return null;
4236 } finally {
4237 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004238 }
Derek Tan7226c842014-07-02 17:42:23 -07004239 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004240
4241 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004242 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004243 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4244 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004246 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4247 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004248 return null;
4249 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004250
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004251 final long identity = Binder.clearCallingIdentity();
4252 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004253 final Context context = mPhone.getContext();
4254 final TelephonyManager tele = TelephonyManager.from(context);
4255 final SubscriptionManager sub = SubscriptionManager.from(context);
4256
4257 // Figure out what subscribers are currently active
4258 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4259 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4260 // the process, where TelephonyManager was instantiated.
4261 // Otherwise AppOps check will fail.
4262
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004263 final int[] subIds = sub.getActiveSubscriptionIdList();
4264 for (int subId : subIds) {
4265 activeSubscriberIds.add(tele.getSubscriberId(subId));
4266 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004267
4268 // First pass, find a number override for an active subscriber
4269 String mergeNumber = null;
4270 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4271 for (String key : prefs.keySet()) {
4272 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4273 final String subscriberId = (String) prefs.get(key);
4274 if (activeSubscriberIds.contains(subscriberId)) {
4275 final String iccId = key.substring(
4276 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4277 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4278 mergeNumber = (String) prefs.get(numberKey);
4279 if (DBG_MERGE) {
4280 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4281 + " for active subscriber " + subscriberId);
4282 }
4283 if (!TextUtils.isEmpty(mergeNumber)) {
4284 break;
4285 }
4286 }
4287 }
4288 }
4289
4290 // Shortcut when no active merged subscribers
4291 if (TextUtils.isEmpty(mergeNumber)) {
4292 return null;
4293 }
4294
4295 // Second pass, find all subscribers under that line override
4296 final ArraySet<String> result = new ArraySet<>();
4297 for (String key : prefs.keySet()) {
4298 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4299 final String number = (String) prefs.get(key);
4300 if (mergeNumber.equals(number)) {
4301 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4302 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4303 final String subscriberId = (String) prefs.get(subscriberKey);
4304 if (!TextUtils.isEmpty(subscriberId)) {
4305 result.add(subscriberId);
4306 }
4307 }
4308 }
4309 }
4310
4311 final String[] resultArray = result.toArray(new String[result.size()]);
4312 Arrays.sort(resultArray);
4313 if (DBG_MERGE) {
4314 Slog.d(LOG_TAG,
4315 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4316 }
4317 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004318 } finally {
4319 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004320 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004321 }
4322
4323 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004324 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4326 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004327
4328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 final Phone phone = getPhone(subId);
4331 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4332 } finally {
4333 Binder.restoreCallingIdentity(identity);
4334 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004335 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004336
4337 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004338 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004339 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4340 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004341 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004342
4343 final long identity = Binder.clearCallingIdentity();
4344 try {
4345 final Phone phone = getPhone(subId);
4346 if (phone == null) {
4347 return false;
4348 }
4349 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4350 cdmaNonRoamingList);
4351 } finally {
4352 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004353 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004354 }
4355
4356 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004357 @Deprecated
4358 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4359 enforceModifyPermission();
4360
4361 int returnValue = 0;
4362 try {
vagdevie435a3e2018-08-15 16:01:53 -07004363 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004364 if(result.exception == null) {
4365 if (result.result != null) {
4366 byte[] responseData = (byte[])(result.result);
4367 if(responseData.length > oemResp.length) {
4368 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4369 responseData.length + "bytes. Buffer Size is " +
4370 oemResp.length + "bytes.");
4371 }
4372 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4373 returnValue = responseData.length;
4374 }
4375 } else {
4376 CommandException ex = (CommandException) result.exception;
4377 returnValue = ex.getCommandError().ordinal();
4378 if(returnValue > 0) returnValue *= -1;
4379 }
4380 } catch (RuntimeException e) {
4381 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4382 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4383 if(returnValue > 0) returnValue *= -1;
4384 }
4385
4386 return returnValue;
4387 }
4388
4389 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004390 public void setRadioCapability(RadioAccessFamily[] rafs) {
4391 try {
4392 ProxyController.getInstance().setRadioCapability(rafs);
4393 } catch (RuntimeException e) {
4394 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4395 }
4396 }
4397
4398 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004399 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004400 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004401 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004402 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004403 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004404 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004405 final long identity = Binder.clearCallingIdentity();
4406 try {
chen xufeeed752018-10-26 14:17:57 -07004407 TelephonyPermissions
4408 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4409 mApp, phone.getSubId(), "getRadioAccessFamily");
4410 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
chen xufeeed752018-10-26 14:17:57 -07004414 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004415 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004416
4417 @Override
4418 public void enableVideoCalling(boolean enable) {
4419 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004420
4421 final long identity = Binder.clearCallingIdentity();
4422 try {
4423 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004427 }
4428
4429 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004430 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004431 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4432 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4433 return false;
4434 }
Svet Ganovb320e182015-04-16 12:30:10 -07004435
Malcolm Chend965c8b2018-02-28 15:00:40 -08004436 final long identity = Binder.clearCallingIdentity();
4437 try {
4438 // Check the user preference and the system-level IMS setting. Even if the user has
4439 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4440 // In the long run, we may instead need to check if there exists a connection service
4441 // which can support video calling.
4442 ImsManager imsManager =
4443 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4444 return imsManager.isVtEnabledByPlatform()
4445 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4446 && imsManager.isVtEnabledByUser();
4447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004450 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004451
Andrew Leea1239f22015-03-02 17:44:07 -08004452 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004453 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4454 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4455 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4456 return false;
4457 }
4458
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
4461 CarrierConfigManager configManager =
4462 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4463 return configManager.getConfigForSubId(mPhone.getSubId())
4464 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
Andrew Leea1239f22015-03-02 17:44:07 -08004468 }
4469
4470 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004471 public boolean isWorldPhone(int subId, String callingPackage) {
4472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4473 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4474 return false;
4475 }
4476
4477 final long identity = Binder.clearCallingIdentity();
4478 try {
4479 CarrierConfigManager configManager =
4480 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4481 return configManager.getConfigForSubId(mPhone.getSubId())
4482 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
Andrew Leea1239f22015-03-02 17:44:07 -08004486 }
4487
Andrew Lee9431b832015-03-09 18:46:45 -07004488 @Override
4489 public boolean isTtyModeSupported() {
4490 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004491 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004492 }
4493
4494 @Override
4495 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
Andrew Lee9431b832015-03-09 18:46:45 -07004502 }
4503
Hall Liuf6668912018-10-31 17:05:23 -07004504 /**
4505 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4506 * support for the feature and device firmware support.
4507 *
4508 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4509 */
4510 @Override
4511 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004512 final long identity = Binder.clearCallingIdentity();
4513 try {
4514 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4515 mPhone.getSubId()).getBoolean(
4516 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4517 boolean isDeviceSupported =
4518 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4519 return isCarrierSupported && isDeviceSupported;
4520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
Hall Liu98187582018-01-22 19:15:32 -08004523 }
4524
Hall Liuf6668912018-10-31 17:05:23 -07004525 /**
4526 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4527 * both also support RTT.
4528 */
4529 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004530 final long identity = Binder.clearCallingIdentity();
4531 try {
Hall Liuf6668912018-10-31 17:05:23 -07004532 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004533 mPhone.getContext().getContentResolver(),
4534 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004538 }
4539
Sanket Padawe7310cc72015-01-14 09:53:20 -08004540 /**
4541 * Returns the unique device ID of phone, for example, the IMEI for
4542 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4543 *
4544 * <p>Requires Permission:
4545 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4546 */
4547 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004548 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004549 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004550 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004551 return null;
4552 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004553 int subId = phone.getSubId();
4554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4555 mApp, subId, callingPackage, "getDeviceId")) {
4556 return null;
4557 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004558
4559 final long identity = Binder.clearCallingIdentity();
4560 try {
4561 return phone.getDeviceId();
4562 } finally {
4563 Binder.restoreCallingIdentity(identity);
4564 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004565 }
4566
Ping Sunc67b7c22016-03-02 19:16:45 +08004567 /**
4568 * {@hide}
4569 * Returns the IMS Registration Status on a particular subid
4570 *
4571 * @param subId
4572 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004573 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004574 Phone phone = getPhone(subId);
4575 if (phone != null) {
4576 return phone.isImsRegistered();
4577 } else {
4578 return false;
4579 }
4580 }
4581
Santos Cordon7a1885b2015-02-03 11:15:19 -08004582 @Override
4583 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004584 final long identity = Binder.clearCallingIdentity();
4585 try {
4586 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4587 } finally {
4588 Binder.restoreCallingIdentity(identity);
4589 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004590 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004591
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004592 /**
4593 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004594 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004595 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004596 final long identity = Binder.clearCallingIdentity();
4597 try {
4598 Phone phone = getPhone(subId);
4599 if (phone != null) {
4600 return phone.isWifiCallingEnabled();
4601 } else {
4602 return false;
4603 }
4604 } finally {
4605 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004606 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004607 }
4608
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004609 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004610 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004611 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004612 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 Phone phone = getPhone(subId);
4616 if (phone != null) {
4617 return phone.isVideoEnabled();
4618 } else {
4619 return false;
4620 }
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004623 }
4624 }
4625
4626 /**
4627 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4628 * defined in {@link ImsRegistrationImplBase}.
4629 */
4630 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004631 final long identity = Binder.clearCallingIdentity();
4632 try {
4633 Phone phone = getPhone(subId);
4634 if (phone != null) {
4635 return phone.getImsRegistrationTech();
4636 } else {
4637 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4638 }
4639 } finally {
4640 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004641 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004642 }
4643
Stuart Scott8eef64f2015-04-08 15:13:54 -07004644 @Override
4645 public void factoryReset(int subId) {
4646 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004647 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4648 return;
4649 }
4650
Svet Ganovcc087f82015-05-12 20:35:54 -07004651 final long identity = Binder.clearCallingIdentity();
4652 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004653 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4654 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004655 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004656 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004657 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4658 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004659 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004660 }
4661 } finally {
4662 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004663 }
4664 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004665
4666 @Override
4667 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004668 final long identity = Binder.clearCallingIdentity();
4669 try {
4670 // We query all subscriptions instead of just the active ones, because
4671 // this might be called early on in the provisioning flow when the
4672 // subscriptions potentially aren't active yet.
4673 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4674 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004675 return null;
4676 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004677
Malcolm Chend965c8b2018-02-28 15:00:40 -08004678 // This function may be called very early, say, from the setup wizard, at
4679 // which point we won't have a default subscription set. If that's the case
4680 // we just choose the first, which will be valid in "most cases".
4681 final int defaultSubId = getDefaultSubscription();
4682 SubscriptionInfo info = null;
4683 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4684 info = slist.get(0);
4685 } else {
4686 for (SubscriptionInfo item : slist) {
4687 if (item.getSubscriptionId() == defaultSubId) {
4688 info = item;
4689 break;
4690 }
4691 }
4692
4693 if (info == null) {
4694 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004695 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004696 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004697
Malcolm Chend965c8b2018-02-28 15:00:40 -08004698 // Try and fetch the locale from the carrier properties or from the SIM language
4699 // preferences (EF-PL and EF-LI)...
4700 final int mcc = info.getMcc();
4701 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4702 String simLanguage = null;
4703 if (defaultPhone != null) {
4704 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4705 if (localeFromDefaultSim != null) {
4706 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4707 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4708 return localeFromDefaultSim.toLanguageTag();
4709 } else {
4710 simLanguage = localeFromDefaultSim.getLanguage();
4711 }
4712 }
4713 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004714
Malcolm Chend965c8b2018-02-28 15:00:40 -08004715 // The SIM language preferences only store a language (e.g. fr = French), not an
4716 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4717 // the SIM and carrier preferences does not include a country we add the country
4718 // determined from the SIM MCC to provide an exact locale.
4719 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4720 simLanguage);
4721 if (mccLocale != null) {
4722 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4723 return mccLocale.toLanguageTag();
4724 }
4725
4726 if (DBG) log("No locale found - returning null");
4727 return null;
4728 } finally {
4729 Binder.restoreCallingIdentity(identity);
4730 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004731 }
4732
4733 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004734 return mSubscriptionController.getAllSubInfoList(
4735 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004736 }
4737
Malcolm Chend965c8b2018-02-28 15:00:40 -08004738 /**
4739 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4740 */
4741 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4742 return mSubscriptionController.getActiveSubscriptionInfoList(
4743 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004744 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004745
Chenjie Yu1ba97252018-01-11 18:16:20 -08004746 private final ModemActivityInfo mLastModemActivityInfo =
4747 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4748
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004749 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004750 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4751 * representing the state of the modem.
4752 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004753 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4754 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004755 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004756 */
4757 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004758 public void requestModemActivityInfo(ResultReceiver result) {
4759 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004760 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004761
4762 final long identity = Binder.clearCallingIdentity();
4763 try {
4764 ModemActivityInfo ret = null;
4765 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004766 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4767 CMD_GET_MODEM_ACTIVITY_INFO,
4768 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004769 if (isModemActivityInfoValid(info)) {
4770 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4771 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4772 mergedTxTimeMs[i] =
4773 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4774 }
4775 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4776 mLastModemActivityInfo.setSleepTimeMillis(
4777 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4778 mLastModemActivityInfo.setIdleTimeMillis(
4779 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4780 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4781 mLastModemActivityInfo.setRxTimeMillis(
4782 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4783 mLastModemActivityInfo.setEnergyUsed(
4784 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004785 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004786 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4787 mLastModemActivityInfo.getSleepTimeMillis(),
4788 mLastModemActivityInfo.getIdleTimeMillis(),
4789 mLastModemActivityInfo.getTxTimeMillis(),
4790 mLastModemActivityInfo.getRxTimeMillis(),
4791 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004792 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004793 Bundle bundle = new Bundle();
4794 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4795 result.send(0, bundle);
4796 } finally {
4797 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004798 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004799 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004800
Siddharth Rayf5d29552018-06-17 15:02:38 -07004801 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4802 // less than total activity duration.
4803 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4804 if (info == null) {
4805 return false;
4806 }
4807 int activityDurationMs =
4808 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4809 int totalTxTimeMs = 0;
4810 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4811 totalTxTimeMs += info.getTxTimeMillis()[i];
4812 }
4813 return (info.isValid()
4814 && (info.getSleepTimeMillis() <= activityDurationMs)
4815 && (info.getIdleTimeMillis() <= activityDurationMs)
4816 && (info.getRxTimeMillis() <= activityDurationMs)
4817 && (totalTxTimeMs <= activityDurationMs));
4818 }
4819
Jack Yu85bd38a2015-11-09 11:34:32 -08004820 /**
4821 * {@hide}
4822 * Returns the service state information on specified subscription.
4823 */
4824 @Override
4825 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004827 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004828 return null;
4829 }
4830
Malcolm Chend965c8b2018-02-28 15:00:40 -08004831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 final Phone phone = getPhone(subId);
4834 if (phone == null) {
4835 return null;
4836 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004837
Malcolm Chend965c8b2018-02-28 15:00:40 -08004838 return phone.getServiceState();
4839 } finally {
4840 Binder.restoreCallingIdentity(identity);
4841 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004842 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004843
4844 /**
4845 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4846 *
4847 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4848 * voicemail ringtone.
4849 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4850 * PhoneAccount.
4851 */
4852 @Override
4853 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4857 if (phone == null) {
4858 phone = mPhone;
4859 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004860
Malcolm Chend965c8b2018-02-28 15:00:40 -08004861 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004865 }
4866
4867 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004868 * Sets the per-account voicemail ringtone.
4869 *
4870 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4871 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4872 *
4873 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4874 * voicemail ringtone.
4875 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4876 * PhoneAccount.
4877 */
4878 @Override
4879 public void setVoicemailRingtoneUri(String callingPackage,
4880 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4881 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4882 if (!TextUtils.equals(callingPackage,
4883 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4885 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4886 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004887 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004888
4889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4892 if (phone == null) {
4893 phone = mPhone;
4894 }
4895 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004898 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004899 }
4900
4901 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004902 * Returns whether vibration is set for voicemail notification in Phone settings.
4903 *
4904 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4905 * voicemail vibration setting.
4906 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4907 */
4908 @Override
4909 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4913 if (phone == null) {
4914 phone = mPhone;
4915 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004916
Malcolm Chend965c8b2018-02-28 15:00:40 -08004917 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004921 }
4922
Youhan Wange64578a2016-05-02 15:32:42 -07004923 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004924 * Sets the per-account voicemail vibration.
4925 *
4926 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4927 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4928 *
4929 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4930 * voicemail vibration setting.
4931 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4932 * specific PhoneAccount.
4933 */
4934 @Override
4935 public void setVoicemailVibrationEnabled(String callingPackage,
4936 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4937 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4938 if (!TextUtils.equals(callingPackage,
4939 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4941 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4942 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004943 }
4944
Malcolm Chend965c8b2018-02-28 15:00:40 -08004945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4948 if (phone == null) {
4949 phone = mPhone;
4950 }
4951 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4952 } finally {
4953 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004954 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004955 }
4956
4957 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004958 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4959 *
4960 * @throws SecurityException if the caller does not have the required permission
4961 */
Brad Ebinger4c460712018-10-01 10:40:55 -07004962 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004963 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07004964 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004965 }
4966
4967 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004968 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4969 * permission.
4970 *
4971 * @throws SecurityException if the caller does not have the required permission
4972 */
4973 private void enforceSendSmsPermission() {
4974 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4975 }
4976
4977 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004978 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004979 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004980 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004981 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004982 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 ComponentName componentName =
4986 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4987 if (componentName == null) {
4988 throw new SecurityException(
4989 "Caller not current active visual voicemail package[null]");
4990 }
4991 String vvmPackage = componentName.getPackageName();
4992 if (!callingPackage.equals(vvmPackage)) {
4993 throw new SecurityException("Caller not current active visual voicemail package["
4994 + vvmPackage + "]");
4995 }
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004998 }
4999 }
5000
5001 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005002 * Return the application ID for the app type.
5003 *
5004 * @param subId the subscription ID that this request applies to.
5005 * @param appType the uicc app type.
5006 * @return Application ID for specificied app type, or null if no uicc.
5007 */
5008 @Override
5009 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005010 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005011 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005012
5013 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005014 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005015 if (phone == null) {
5016 return null;
5017 }
5018 String aid = null;
5019 try {
5020 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5021 .getApplicationByType(appType).getAid();
5022 } catch (Exception e) {
5023 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5024 }
5025 return aid;
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005028 }
Youhan Wange64578a2016-05-02 15:32:42 -07005029 }
5030
Youhan Wang4001d252016-05-11 10:29:41 -07005031 /**
5032 * Return the Electronic Serial Number.
5033 *
5034 * @param subId the subscription ID that this request applies to.
5035 * @return ESN or null if error.
5036 */
5037 @Override
5038 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005039 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005040 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005041
5042 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005043 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005044 if (phone == null) {
5045 return null;
5046 }
5047 String esn = null;
5048 try {
5049 esn = phone.getEsn();
5050 } catch (Exception e) {
5051 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5052 }
5053 return esn;
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005056 }
Youhan Wang4001d252016-05-11 10:29:41 -07005057 }
5058
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005059 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005060 * Return the Preferred Roaming List Version.
5061 *
5062 * @param subId the subscription ID that this request applies to.
5063 * @return PRLVersion or null if error.
5064 */
5065 @Override
5066 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005067 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005068 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005069
5070 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005071 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005072 if (phone == null) {
5073 return null;
5074 }
5075 String cdmaPrlVersion = null;
5076 try {
5077 cdmaPrlVersion = phone.getCdmaPrlVersion();
5078 } catch (Exception e) {
5079 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5080 }
5081 return cdmaPrlVersion;
5082 } finally {
5083 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005084 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005085 }
5086
5087 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005088 * Get snapshot of Telephony histograms
5089 * @return List of Telephony histograms
5090 * @hide
5091 */
5092 @Override
5093 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5095 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005096
5097 final long identity = Binder.clearCallingIdentity();
5098 try {
5099 return RIL.getTelephonyRILTimingHistograms();
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005103 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005104
5105 /**
5106 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005107 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005108 * Require system privileges. In the future we may add this to carrier APIs.
5109 *
5110 * @return The number of carriers set successfully, should match length of carriers
5111 */
5112 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005113 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005114 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005115 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005116
Meng Wang9b7c4e92017-02-17 11:41:27 -08005117 if (carriers == null) {
5118 throw new NullPointerException("carriers cannot be null");
5119 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005120
Malcolm Chend965c8b2018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005124 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5125 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005126 return retVal[0];
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
5129 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005130 }
5131
5132 /**
5133 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005134 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005135 * Require system privileges. In the future we may add this to carrier APIs.
5136 *
5137 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5138 * means all carriers are allowed.
5139 */
5140 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005141 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005142 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005143 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005144
5145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005148 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5149 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005153 }
5154
fionaxu59545b42016-05-25 15:53:37 -07005155 /**
5156 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5157 * @param subId the subscription ID that this action applies to.
5158 * @param enabled control enable or disable metered apns.
5159 * {@hide}
5160 */
5161 @Override
5162 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5163 enforceModifyPermission();
5164 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005165
5166 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005167 if (phone == null) {
5168 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5169 return;
5170 }
5171 try {
5172 phone.carrierActionSetMeteredApnsEnabled(enabled);
5173 } catch (Exception e) {
5174 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005175 } finally {
5176 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005177 }
5178 }
5179
5180 /**
5181 * Action set from carrier signalling broadcast receivers to enable/disable radio
5182 * @param subId the subscription ID that this action applies to.
5183 * @param enabled control enable or disable radio.
5184 * {@hide}
5185 */
5186 @Override
5187 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5188 enforceModifyPermission();
5189 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005190
5191 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005192 if (phone == null) {
5193 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5194 return;
5195 }
5196 try {
5197 phone.carrierActionSetRadioEnabled(enabled);
5198 } catch (Exception e) {
5199 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005200 } finally {
5201 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005202 }
5203 }
5204
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005205 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005206 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5207 * network status based on which carrier apps could apply actions accordingly,
5208 * enable/disable default url handler for example.
5209 *
5210 * @param subId the subscription ID that this action applies to.
5211 * @param report control start/stop reporting the default network status.
5212 * {@hide}
5213 */
5214 @Override
5215 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5216 enforceModifyPermission();
5217 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005218
5219 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005220 if (phone == null) {
5221 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5222 return;
5223 }
5224 try {
5225 phone.carrierActionReportDefaultNetworkStatus(report);
5226 } catch (Exception e) {
5227 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005228 } finally {
5229 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005230 }
5231 }
5232
5233 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005234 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5235 * bug report is being generated.
5236 */
5237 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005238 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005239 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5240 != PackageManager.PERMISSION_GRANTED) {
5241 writer.println("Permission Denial: can't dump Phone from pid="
5242 + Binder.getCallingPid()
5243 + ", uid=" + Binder.getCallingUid()
5244 + "without permission "
5245 + android.Manifest.permission.DUMP);
5246 return;
5247 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005248 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005249 }
Jack Yueb89b242016-06-22 13:27:47 -07005250
Brad Ebingerdac2f002018-04-03 15:17:52 -07005251 @Override
5252 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5253 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5254 throws RemoteException {
5255 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5256 }
5257
Jack Yueb89b242016-06-22 13:27:47 -07005258 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005259 * Get aggregated video call data usage since boot.
5260 *
5261 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5262 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005263 * {@hide}
5264 */
5265 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005266 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005267 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5268 null);
5269
Malcolm Chend965c8b2018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 // NetworkStatsService keeps tracking the active network interface and identity. It
5273 // records the delta with the corresponding network identity.
5274 // We just return the total video call data usage snapshot since boot.
5275 Phone phone = getPhone(subId);
5276 if (phone != null) {
5277 return phone.getVtDataUsage(perUidStats);
5278 }
5279 return null;
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005282 }
Jack Yueb89b242016-06-22 13:27:47 -07005283 }
Jack Yu75ab2952016-07-08 14:29:33 -07005284
5285 /**
5286 * Policy control of data connection. Usually used when data limit is passed.
5287 * @param enabled True if enabling the data, otherwise disabling.
5288 * @param subId Subscription index
5289 * {@hide}
5290 */
5291 @Override
5292 public void setPolicyDataEnabled(boolean enabled, int subId) {
5293 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005294
5295 final long identity = Binder.clearCallingIdentity();
5296 try {
5297 Phone phone = getPhone(subId);
5298 if (phone != null) {
5299 phone.setPolicyDataEnabled(enabled);
5300 }
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005303 }
5304 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005305
5306 /**
5307 * Get Client request stats
5308 * @return List of Client Request Stats
5309 * @hide
5310 */
5311 @Override
5312 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005314 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005315 return null;
5316 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005317 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005318
Malcolm Chend965c8b2018-02-28 15:00:40 -08005319 final long identity = Binder.clearCallingIdentity();
5320 try {
5321 if (phone != null) {
5322 return phone.getClientRequestStats();
5323 }
5324
5325 return null;
5326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005329 }
5330
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005331 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005332 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005333 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005334 }
Jack Yueb4124c2017-02-16 15:32:43 -08005335
5336 /**
Grace Chen70990072017-03-24 17:21:30 -07005337 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005338 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005339 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005340 * @param state State of SIM (power down, power up, pass through)
5341 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5342 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5343 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005344 *
5345 **/
5346 @Override
Grace Chen70990072017-03-24 17:21:30 -07005347 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005348 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005349 Phone phone = PhoneFactory.getPhone(slotIndex);
5350
vagdevie435a3e2018-08-15 16:01:53 -07005351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5352
Malcolm Chend965c8b2018-02-28 15:00:40 -08005353 final long identity = Binder.clearCallingIdentity();
5354 try {
5355 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005356 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005357 }
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005360 }
5361 }
Shuo Qiandd210312017-04-12 22:11:33 +00005362
Tyler Gunn65d45c22017-06-05 11:22:26 -07005363 private boolean isUssdApiAllowed(int subId) {
5364 CarrierConfigManager configManager =
5365 (CarrierConfigManager) mPhone.getContext().getSystemService(
5366 Context.CARRIER_CONFIG_SERVICE);
5367 if (configManager == null) {
5368 return false;
5369 }
5370 PersistableBundle pb = configManager.getConfigForSubId(subId);
5371 if (pb == null) {
5372 return false;
5373 }
5374 return pb.getBoolean(
5375 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5376 }
5377
Shuo Qiandd210312017-04-12 22:11:33 +00005378 /**
5379 * Check if phone is in emergency callback mode
5380 * @return true if phone is in emergency callback mode
5381 * @param subId sub id
5382 */
goneil9c5f4872017-12-05 14:07:56 -08005383 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005384 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005385 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005386 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005387
5388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 if (phone != null) {
5391 return phone.isInEcm();
5392 } else {
5393 return false;
5394 }
5395 } finally {
5396 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005397 }
5398 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005399
5400 /**
5401 * Get the current signal strength information for the given subscription.
5402 * Because this information is not updated when the device is in a low power state
5403 * it should not be relied-upon to be current.
5404 * @param subId Subscription index
5405 * @return the most recent cached signal strength info from the modem
5406 */
5407 @Override
5408 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005409 final long identity = Binder.clearCallingIdentity();
5410 try {
5411 Phone p = getPhone(subId);
5412 if (p == null) {
5413 return null;
5414 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005415
Malcolm Chend965c8b2018-02-28 15:00:40 -08005416 return p.getSignalStrength();
5417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005420 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005421
Pengquan Meng9140aec2018-08-22 14:49:57 -07005422 /**
chen xu907e5a22018-10-11 13:21:04 -07005423 * Get the current modem radio state for the given slot.
5424 * @param slotIndex slot index.
5425 * @param callingPackage the name of the package making the call.
5426 * @return the current radio power state from the modem
5427 */
5428 @Override
5429 public int getRadioPowerState(int slotIndex, String callingPackage) {
5430 Phone phone = PhoneFactory.getPhone(slotIndex);
5431 if (phone != null) {
5432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5433 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5434 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5435 }
5436
5437 final long identity = Binder.clearCallingIdentity();
5438 try {
5439 return phone.getRadioPowerState();
5440 } finally {
5441 Binder.restoreCallingIdentity(identity);
5442 }
5443 }
5444 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5445 }
5446
5447 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005448 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5449 *
5450 * <p>Requires one of the following permissions:
5451 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5452 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5453 * privileges.
5454 *
5455 * @param subId subscription id
5456 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5457 * {@code false}.
5458 */
5459 @Override
5460 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005461 boolean isEnabled = false;
5462 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005463 try {
5464 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005465 null /* message */);
5466 Phone phone = getPhone(subId);
5467 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005468 } catch (Exception e) {
5469 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5470 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005471 } finally {
5472 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005473 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005474 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005475 }
5476
5477
5478 /**
5479 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5480 *
5481 * <p> Requires permission:
5482 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5483 * privileges.
5484 *
5485 * @param subId subscription id
5486 * @param isEnabled {@code true} means enable, {@code false} means disable.
5487 */
5488 @Override
5489 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5493 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005494
Pengquan Meng0c05b502018-09-06 09:59:22 -07005495 Phone phone = getPhone(subId);
5496 if (phone != null) {
5497 phone.setDataRoamingEnabled(isEnabled);
5498 }
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005501 }
5502 }
5503
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005504 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005505 public boolean isManualNetworkSelectionAllowed(int subId) {
5506 boolean isAllowed = true;
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5510 mApp, subId, "isManualNetworkSelectionAllowed");
5511 Phone phone = getPhone(subId);
5512 if (phone != null) {
5513 isAllowed = phone.isCspPlmnEnabled();
5514 }
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
5518 return isAllowed;
5519 }
5520
5521 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005522 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005523 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005524
Malcolm Chend965c8b2018-02-28 15:00:40 -08005525 final long identity = Binder.clearCallingIdentity();
5526 try {
5527 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5528 if (slots == null) {
5529 Rlog.i(LOG_TAG, "slots is null.");
5530 return null;
5531 }
5532
5533 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5534 for (int i = 0; i < slots.length; i++) {
5535 UiccSlot slot = slots[i];
5536 if (slot == null) {
5537 continue;
5538 }
5539
5540 String cardId;
5541 UiccCard card = slot.getUiccCard();
5542 if (card != null) {
5543 cardId = card.getCardId();
5544 } else {
5545 cardId = slot.getIccId();
5546 }
5547
5548 int cardState = 0;
5549 switch (slot.getCardState()) {
5550 case CARDSTATE_ABSENT:
5551 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5552 break;
5553 case CARDSTATE_PRESENT:
5554 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5555 break;
5556 case CARDSTATE_ERROR:
5557 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5558 break;
5559 case CARDSTATE_RESTRICTED:
5560 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5561 break;
5562 default:
5563 break;
5564
5565 }
5566
5567 infos[i] = new UiccSlotInfo(
5568 slot.isActive(),
5569 slot.isEuicc(),
5570 cardId,
5571 cardState,
5572 slot.getPhoneId(),
5573 slot.isExtendedApduSupported());
5574 }
5575 return infos;
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005578 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005579 }
5580
5581 @Override
5582 public boolean switchSlots(int[] physicalSlots) {
5583 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005584
5585 final long identity = Binder.clearCallingIdentity();
5586 try {
5587 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005591 }
Jack Yu4c988042018-02-27 15:30:01 -08005592
5593 @Override
5594 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5595 enforceModifyPermission();
5596 final Phone phone = getPhone(subId);
5597 if (phone == null) {
5598 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5599 return;
5600 }
5601
Malcolm Chend965c8b2018-02-28 15:00:40 -08005602 final long identity = Binder.clearCallingIdentity();
5603 try {
5604 phone.setRadioIndicationUpdateMode(filters, mode);
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
Jack Yu4c988042018-02-27 15:30:01 -08005608 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005609
5610 /**
goneil47ffb6e2018-04-06 15:40:58 -07005611 * A test API to reload the UICC profile.
5612 *
5613 * <p>Requires that the calling app has permission
5614 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5615 * @hide
5616 */
5617 @Override
5618 public void refreshUiccProfile(int subId) {
5619 enforceModifyPermission();
5620
5621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 Phone phone = getPhone(subId);
5624 if (phone == null) {
5625 return;
5626 }
5627 UiccCard uiccCard = phone.getUiccCard();
5628 if (uiccCard == null) {
5629 return;
5630 }
5631 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5632 if (uiccProfile == null) {
5633 return;
5634 }
5635 uiccProfile.refresh();
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
5638 }
5639 }
5640
5641 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005642 * Returns false if the mobile data is disabled by default, otherwise return true.
5643 */
5644 private boolean getDefaultDataEnabled() {
5645 return "true".equalsIgnoreCase(
5646 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5647 }
5648
5649 /**
5650 * Returns true if the data roaming is enabled by default, i.e the system property
5651 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5652 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5653 */
5654 private boolean getDefaultDataRoamingEnabled(int subId) {
5655 final CarrierConfigManager configMgr = (CarrierConfigManager)
5656 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5657 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5658 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5659 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5660 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5661 return isDataRoamingEnabled;
5662 }
5663
5664 /**
5665 * Returns the default network type for the given {@code subId}, if the default network type is
5666 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5667 */
5668 private int getDefaultNetworkType(int subId) {
5669 return Integer.parseInt(
5670 TelephonyManager.getTelephonyProperty(
5671 mSubscriptionController.getPhoneId(subId),
5672 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5673 String.valueOf(Phone.PREFERRED_NT_MODE)));
5674 }
fionaxua13278b2018-03-21 00:08:13 -07005675
5676 @Override
5677 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5678 gid1, String gid2, String plmn, String spn) {
5679 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005680
5681 final long identity = Binder.clearCallingIdentity();
5682 try {
5683 final Phone phone = getPhone(subId);
5684 if (phone == null) {
5685 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5686 return;
5687 }
5688 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5689 } finally {
5690 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005691 }
fionaxua13278b2018-03-21 00:08:13 -07005692 }
5693
5694 @Override
5695 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005696 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005697
5698 final long identity = Binder.clearCallingIdentity();
5699 try {
5700 final Phone phone = getPhone(subId);
5701 if (phone == null) {
5702 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5703 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5704 }
5705 return phone.getCarrierIdListVersion();
5706 } finally {
5707 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005708 }
fionaxua13278b2018-03-21 00:08:13 -07005709 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005710
5711 @Override
5712 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5714 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5715 return -1;
5716 }
5717
5718 final long identity = Binder.clearCallingIdentity();
5719 try {
5720 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5721 } finally {
5722 Binder.restoreCallingIdentity(identity);
5723 }
5724 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005725
5726 @Override
5727 public int getCdmaRoamingMode(int subId) {
5728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5729 mApp, subId, "getCdmaRoamingMode");
5730
5731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5734 } finally {
5735 Binder.restoreCallingIdentity(identity);
5736 }
5737 }
5738
5739 @Override
5740 public boolean setCdmaRoamingMode(int subId, int mode) {
5741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5742 mApp, subId, "setCdmaRoamingMode");
5743
5744 final long identity = Binder.clearCallingIdentity();
5745 try {
5746 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
5750 }
5751
5752 @Override
5753 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5755 mApp, subId, "setCdmaSubscriptionMode");
5756
5757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5760 } finally {
5761 Binder.restoreCallingIdentity(identity);
5762 }
5763 }
chen xu7ee67862018-10-30 22:27:10 -07005764
5765 @Override
5766 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5767 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5768 Phone phone = getPhone(subId);
5769 if (phone == null) {
5770 return null;
5771 }
5772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 UiccProfile profile = UiccController.getInstance()
5775 .getUiccProfileForPhone(phone.getPhoneId());
5776 if (profile != null) {
5777 return profile.getCertsFromCarrierPrivilegeAccessRules();
5778 }
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
5781 }
5782 return null;
5783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005784}