blob: eb3298eeef1300806543e57410c79294ba7c9920 [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;
sqianc5eccab2018-10-19 18:46:41 -070057import android.telephony.emergency.EmergencyNumber;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070060import android.telephony.CellInfoGsm;
61import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070062import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070063import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070064import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080065import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070066import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080067import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070068import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070069import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080072import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070073import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080074import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070076import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000078import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070081import android.telephony.cdma.CdmaCellLocation;
82import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070083import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080084import android.telephony.ims.aidl.IImsConfig;
85import android.telephony.ims.aidl.IImsMmTelFeature;
86import android.telephony.ims.aidl.IImsRcsFeature;
87import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-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 Ebinger35c841c2018-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 Chen2c63d402018-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;
Makoto Onukida3bf792018-09-18 16:06:29 -0700120import com.android.internal.telephony.SmsApplication;
121import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800122import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800123import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700124import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.uicc.IccIoResult;
126import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800127import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700128import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800129import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800131import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000132import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700133import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700135import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800136import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700137import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700138import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800139
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700140import java.io.FileDescriptor;
141import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800144import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700145import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800146import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100147import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800148import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149
150/**
151 * Implementation of the ITelephony interface.
152 */
Santos Cordon117fee72014-05-16 17:56:12 -0700153public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154 private static final String LOG_TAG = "PhoneInterfaceManager";
155 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
156 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800157 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158
159 // Message codes used with mMainThreadHandler
160 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700161 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
162 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163 private static final int CMD_OPEN_CHANNEL = 9;
164 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
165 private static final int CMD_CLOSE_CHANNEL = 11;
166 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800167 private static final int CMD_NV_READ_ITEM = 13;
168 private static final int EVENT_NV_READ_ITEM_DONE = 14;
169 private static final int CMD_NV_WRITE_ITEM = 15;
170 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
171 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
172 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700173 private static final int CMD_RESET_MODEM_CONFIG = 19;
174 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800175 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
176 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
177 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
178 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800179 private static final int CMD_SEND_ENVELOPE = 25;
180 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000181 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
182 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700183 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
184 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
185 private static final int CMD_EXCHANGE_SIM_IO = 31;
186 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800187 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
188 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700189 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
190 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700191 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
192 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700193 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
194 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
195 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
196 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700197 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
198 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
199 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
200 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700201 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
203 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000204 private static final int CMD_SWITCH_SLOTS = 50;
205 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700206 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
207 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
208 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
209 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
210 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
211 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
212 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
213 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700214 private static final int CMD_GET_ALL_CELL_INFO = 60;
215 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
216 private static final int CMD_GET_CELL_LOCATION = 62;
217 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700218 private static final int CMD_MODEM_REBOOT = 64;
219 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800221 // Parameters of select command.
222 private static final int SELECT_COMMAND = 0xA4;
223 private static final int SELECT_P1 = 0x04;
224 private static final int SELECT_P2 = 0;
225 private static final int SELECT_P3 = 0x10;
226
Pengquan Meng85728fb2018-03-12 16:31:21 -0700227 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
228 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
229 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
230
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 /** The singleton instance. */
232 private static PhoneInterfaceManager sInstance;
233
Wink Saville3ab207e2014-11-20 13:07:20 -0800234 private PhoneGlobals mApp;
235 private Phone mPhone;
236 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700237 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800238 private AppOpsManager mAppOps;
239 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800240 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800241 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700242 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243
Derek Tan97ebb422014-09-05 16:55:38 -0700244 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
245 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800246 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700247
Derek Tan740e1672017-06-27 14:56:27 -0700248 // The AID of ISD-R.
249 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
250
yinxub1bed742017-04-17 11:45:04 -0700251 private NetworkScanRequestTracker mNetworkScanRequestTracker;
252
David Kelly5e06a7f2018-03-12 14:10:59 +0000253 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
254 private static final int MANUFACTURER_CODE_LENGTH = 8;
255
Derek Tan89e89d42014-07-08 17:00:10 -0700256 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700257 * A request object to use for transmitting data to an ICC.
258 */
259 private static final class IccAPDUArgument {
260 public int channel, cla, command, p1, p2, p3;
261 public String data;
262
263 public IccAPDUArgument(int channel, int cla, int command,
264 int p1, int p2, int p3, String data) {
265 this.channel = channel;
266 this.cla = cla;
267 this.command = command;
268 this.p1 = p1;
269 this.p2 = p2;
270 this.p3 = p3;
271 this.data = data;
272 }
273 }
274
275 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700276 * A request object to use for transmitting data to an ICC.
277 */
278 private static final class ManualNetworkSelectionArgument {
279 public OperatorInfo operatorInfo;
280 public boolean persistSelection;
281
282 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
283 this.operatorInfo = operatorInfo;
284 this.persistSelection = persistSelection;
285 }
286 }
287
288 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
290 * request after sending. The main thread will notify the request when it is complete.
291 */
292 private static final class MainThreadRequest {
293 /** The argument to use for the request */
294 public Object argument;
295 /** The result of the request that is run on the main thread */
296 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800297 // The subscriber id that this request applies to. Defaults to
298 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
299 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
Nathan Harold92bed182018-10-12 18:16:49 -0700301 // In cases where subId is unavailable, the caller needs to specify the phone.
302 public Phone phone;
303
vagdeviaf9a5b92018-08-15 16:01:53 -0700304 public WorkSource workSource;
305
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306 public MainThreadRequest(Object argument) {
307 this.argument = argument;
308 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800309
Nathan Harold92bed182018-10-12 18:16:49 -0700310 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
311 this.argument = argument;
312 if (phone != null) {
313 this.phone = phone;
314 }
315 this.workSource = workSource;
316 }
317
vagdeviaf9a5b92018-08-15 16:01:53 -0700318 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800319 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800320 if (subId != null) {
321 this.subId = subId;
322 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700323 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 }
326
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800327 private static final class IncomingThirdPartyCallArgs {
328 public final ComponentName component;
329 public final String callId;
330 public final String callerDisplayName;
331
332 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
333 String callerDisplayName) {
334 this.component = component;
335 this.callId = callId;
336 this.callerDisplayName = callerDisplayName;
337 }
338 }
339
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340 /**
341 * A handler that processes messages on the main thread in the phone process. Since many
342 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
343 * inbound binder threads to the main thread in the phone process. The Binder thread
344 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
345 * on, which will be notified when the operation completes and will contain the result of the
346 * request.
347 *
348 * <p>If a MainThreadRequest object is provided in the msg.obj field,
349 * note that request.result must be set to something non-null for the calling thread to
350 * unblock.
351 */
352 private final class MainThreadHandler extends Handler {
353 @Override
354 public void handleMessage(Message msg) {
355 MainThreadRequest request;
356 Message onCompleted;
357 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800358 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700359 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
361 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700362 case CMD_HANDLE_USSD_REQUEST: {
363 request = (MainThreadRequest) msg.obj;
364 final Phone phone = getPhoneFromRequest(request);
365 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
366 String ussdRequest = ussdObject.first;
367 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700368
Pengquan Menga1bb6272018-09-06 09:59:22 -0700369 if (!isUssdApiAllowed(request.subId)) {
370 // Carrier does not support use of this API, return failure.
371 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
372 UssdResponse response = new UssdResponse(ussdRequest, null);
373 Bundle returnData = new Bundle();
374 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
375 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700376
Pengquan Menga1bb6272018-09-06 09:59:22 -0700377 request.result = true;
378 notifyRequester(request);
379 return;
380 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700381
Pengquan Menga1bb6272018-09-06 09:59:22 -0700382 try {
383 request.result = phone != null
384 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
385 } catch (CallStateException cse) {
386 request.result = false;
387 }
388 // Wake up the requesting thread
389 notifyRequester(request);
390 break;
pkanwar32d516d2016-10-14 19:37:38 -0700391 }
392
Yorke Lee716f67e2015-06-17 15:39:16 -0700393 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700395 final Phone phone = getPhoneFromRequest(request);
396 request.result = phone != null ?
397 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
398 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700400 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700406 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800407 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700408 if (uiccCard == null) {
409 loge("iccTransmitApduLogicalChannel: No UICC");
410 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700412 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
414 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700415 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 iccArgument.channel, iccArgument.cla, iccArgument.command,
417 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700419 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700420 break;
421
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 ar = (AsyncResult) msg.obj;
424 request = (MainThreadRequest) ar.userObj;
425 if (ar.exception == null && ar.result != null) {
426 request.result = ar.result;
427 } else {
428 request.result = new IccIoResult(0x6F, 0, (byte[])null);
429 if (ar.result == null) {
430 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800431 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800433 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 } else {
435 loge("iccTransmitApduLogicalChannel: Unknown exception");
436 }
437 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 break;
440
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
442 request = (MainThreadRequest) msg.obj;
443 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800444 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 if (uiccCard == null) {
446 loge("iccTransmitApduBasicChannel: No UICC");
447 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700448 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 } else {
450 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
451 request);
452 uiccCard.iccTransmitApduBasicChannel(
453 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
454 iccArgument.p3, iccArgument.data, onCompleted);
455 }
456 break;
457
458 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
459 ar = (AsyncResult) msg.obj;
460 request = (MainThreadRequest) ar.userObj;
461 if (ar.exception == null && ar.result != null) {
462 request.result = ar.result;
463 } else {
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
465 if (ar.result == null) {
466 loge("iccTransmitApduBasicChannel: Empty response");
467 } else if (ar.exception instanceof CommandException) {
468 loge("iccTransmitApduBasicChannel: CommandException: " +
469 ar.exception);
470 } else {
471 loge("iccTransmitApduBasicChannel: Unknown exception");
472 }
473 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700474 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 break;
476
477 case CMD_EXCHANGE_SIM_IO:
478 request = (MainThreadRequest) msg.obj;
479 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800480 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 if (uiccCard == null) {
482 loge("iccExchangeSimIO: No UICC");
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 } else {
486 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
487 request);
488 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
489 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
490 iccArgument.data, onCompleted);
491 }
492 break;
493
494 case EVENT_EXCHANGE_SIM_IO_DONE:
495 ar = (AsyncResult) msg.obj;
496 request = (MainThreadRequest) ar.userObj;
497 if (ar.exception == null && ar.result != null) {
498 request.result = ar.result;
499 } else {
500 request.result = new IccIoResult(0x6f, 0, (byte[])null);
501 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 break;
504
Derek Tan4d5e5c12014-02-04 11:54:58 -0800505 case CMD_SEND_ENVELOPE:
506 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800507 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700508 if (uiccCard == null) {
509 loge("sendEnvelopeWithStatus: No UICC");
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700512 } else {
513 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
514 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
515 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800516 break;
517
518 case EVENT_SEND_ENVELOPE_DONE:
519 ar = (AsyncResult) msg.obj;
520 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700521 if (ar.exception == null && ar.result != null) {
522 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800523 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
525 if (ar.result == null) {
526 loge("sendEnvelopeWithStatus: Empty response");
527 } else if (ar.exception instanceof CommandException) {
528 loge("sendEnvelopeWithStatus: CommandException: " +
529 ar.exception);
530 } else {
531 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
532 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700534 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 break;
536
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 case CMD_OPEN_CHANNEL:
538 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800539 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800540 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 if (uiccCard == null) {
542 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800543 request.result = new IccOpenLogicalChannelResponse(-1,
544 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 } else {
547 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800548 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
549 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 break;
552
553 case EVENT_OPEN_CHANNEL_DONE:
554 ar = (AsyncResult) msg.obj;
555 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 int[] result = (int[]) ar.result;
559 int channelId = result[0];
560 byte[] selectResponse = null;
561 if (result.length > 1) {
562 selectResponse = new byte[result.length - 1];
563 for (int i = 1; i < result.length; ++i) {
564 selectResponse[i - 1] = (byte) result[i];
565 }
566 }
567 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700568 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 if (ar.result == null) {
571 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 if (ar.exception != null) {
574 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
575 }
576
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700577 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700578 if (ar.exception instanceof CommandException) {
579 CommandException.Error error =
580 ((CommandException) (ar.exception)).getCommandError();
581 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700583 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700584 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 }
586 }
587 openChannelResp = new IccOpenLogicalChannelResponse(
588 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700590 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 break;
593
594 case CMD_CLOSE_CHANNEL:
595 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800596 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 if (uiccCard == null) {
598 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900599 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 } else {
602 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
603 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
604 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 break;
606
607 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800608 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
609 break;
610
611 case CMD_NV_READ_ITEM:
612 request = (MainThreadRequest) msg.obj;
613 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700614 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800615 break;
616
617 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 ar = (AsyncResult) msg.obj;
619 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800620 if (ar.exception == null && ar.result != null) {
621 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800623 request.result = "";
624 if (ar.result == null) {
625 loge("nvReadItem: Empty response");
626 } else if (ar.exception instanceof CommandException) {
627 loge("nvReadItem: CommandException: " +
628 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800630 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 }
632 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
Jake Hambye994d462014-02-03 13:10:13 -0800636 case CMD_NV_WRITE_ITEM:
637 request = (MainThreadRequest) msg.obj;
638 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
639 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700640 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
641 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800642 break;
643
644 case EVENT_NV_WRITE_ITEM_DONE:
645 handleNullReturnEvent(msg, "nvWriteItem");
646 break;
647
648 case CMD_NV_WRITE_CDMA_PRL:
649 request = (MainThreadRequest) msg.obj;
650 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
651 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
652 break;
653
654 case EVENT_NV_WRITE_CDMA_PRL_DONE:
655 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
656 break;
657
chen xu6dac5ab2018-10-26 17:39:23 -0700658 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800659 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700660 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
661 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800662 break;
663
chen xu6dac5ab2018-10-26 17:39:23 -0700664 case EVENT_RESET_MODEM_CONFIG_DONE:
665 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800666 break;
667
Jake Hamby7c27be32014-03-03 13:25:59 -0800668 case CMD_GET_PREFERRED_NETWORK_TYPE:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700671 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800672 break;
673
674 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result; // Integer
679 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800680 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800681 if (ar.result == null) {
682 loge("getPreferredNetworkType: Empty response");
683 } else if (ar.exception instanceof CommandException) {
684 loge("getPreferredNetworkType: CommandException: " +
685 ar.exception);
686 } else {
687 loge("getPreferredNetworkType: Unknown exception");
688 }
689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800691 break;
692
693 case CMD_SET_PREFERRED_NETWORK_TYPE:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
696 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700697 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800698 break;
699
700 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
701 handleNullReturnEvent(msg, "setPreferredNetworkType");
702 break;
703
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000704 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
705 request = (MainThreadRequest)msg.obj;
706 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700707 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000708 break;
709
710 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
711 ar = (AsyncResult)msg.obj;
712 request = (MainThreadRequest)ar.userObj;
713 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000715 break;
716
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800717 case CMD_SET_VOICEMAIL_NUMBER:
718 request = (MainThreadRequest) msg.obj;
719 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
720 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800721 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
722 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800723 break;
724
725 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
726 handleNullReturnEvent(msg, "setVoicemailNumber");
727 break;
728
Stuart Scott54788802015-03-30 13:18:01 -0700729 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
732 request);
733 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
734 break;
735
736 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
737 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
738 break;
739
Shishir Agrawal302c8692015-06-19 13:49:39 -0700740 case CMD_PERFORM_NETWORK_SCAN:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
743 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
744 break;
745
746 case EVENT_PERFORM_NETWORK_SCAN_DONE:
747 ar = (AsyncResult) msg.obj;
748 request = (MainThreadRequest) ar.userObj;
749 CellNetworkScanResult cellScanResult;
750 if (ar.exception == null && ar.result != null) {
751 cellScanResult = new CellNetworkScanResult(
752 CellNetworkScanResult.STATUS_SUCCESS,
753 (List<OperatorInfo>) ar.result);
754 } else {
755 if (ar.result == null) {
756 loge("getCellNetworkScanResults: Empty response");
757 }
758 if (ar.exception != null) {
759 loge("getCellNetworkScanResults: Exception: " + ar.exception);
760 }
761 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
762 if (ar.exception instanceof CommandException) {
763 CommandException.Error error =
764 ((CommandException) (ar.exception)).getCommandError();
765 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
766 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
767 } else if (error == CommandException.Error.GENERIC_FAILURE) {
768 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
769 }
770 }
771 cellScanResult = new CellNetworkScanResult(errorCode, null);
772 }
773 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700775 break;
776
777 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
778 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700779 ManualNetworkSelectionArgument selArg =
780 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700781 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
782 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700783 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
784 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700785 break;
786
787 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
790 if (ar.exception == null) {
791 request.result = true;
792 } else {
793 request.result = false;
794 loge("setNetworkSelectionModeManual " + ar.exception);
795 }
796 notifyRequester(request);
797 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 break;
799
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700800 case CMD_GET_MODEM_ACTIVITY_INFO:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700803 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700804 break;
805
806 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null && ar.result != null) {
810 request.result = ar.result;
811 } else {
812 if (ar.result == null) {
813 loge("queryModemActivityInfo: Empty response");
814 } else if (ar.exception instanceof CommandException) {
815 loge("queryModemActivityInfo: CommandException: " +
816 ar.exception);
817 } else {
818 loge("queryModemActivityInfo: Unknown exception");
819 }
820 }
Amit Mahajand4766222016-01-28 15:28:28 -0800821 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
822 if (request.result == null) {
823 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
824 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700825 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700826 break;
827
Meng Wang1a7c35a2016-05-05 20:56:15 -0700828 case CMD_SET_ALLOWED_CARRIERS:
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
831 mPhone.setAllowedCarriers(
832 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700833 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700834 break;
835
836 case EVENT_SET_ALLOWED_CARRIERS_DONE:
837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null && ar.result != null) {
840 request.result = ar.result;
841 } else {
842 if (ar.result == null) {
843 loge("setAllowedCarriers: Empty response");
844 } else if (ar.exception instanceof CommandException) {
845 loge("setAllowedCarriers: CommandException: " +
846 ar.exception);
847 } else {
848 loge("setAllowedCarriers: Unknown exception");
849 }
850 }
851 // Result cannot be null. Return -1 on error.
852 if (request.result == null) {
853 request.result = new int[]{-1};
854 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700855 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700856 break;
857
858 case CMD_GET_ALLOWED_CARRIERS:
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700861 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700862 break;
863
864 case EVENT_GET_ALLOWED_CARRIERS_DONE:
865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
867 if (ar.exception == null && ar.result != null) {
868 request.result = ar.result;
869 } else {
870 if (ar.result == null) {
871 loge("getAllowedCarriers: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("getAllowedCarriers: CommandException: " +
874 ar.exception);
875 } else {
876 loge("getAllowedCarriers: Unknown exception");
877 }
878 }
879 // Result cannot be null. Return empty list of CarrierIdentifier.
880 if (request.result == null) {
881 request.result = new ArrayList<CarrierIdentifier>(0);
882 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 break;
885
Nathan Haroldb3014052017-01-25 15:57:32 -0800886 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result;
891 } else {
892 request.result = new IllegalArgumentException(
893 "Failed to retrieve Forbidden Plmns");
894 if (ar.result == null) {
895 loge("getForbiddenPlmns: Empty response");
896 } else {
897 loge("getForbiddenPlmns: Unknown exception");
898 }
899 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700900 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800901 break;
902
903 case CMD_GET_FORBIDDEN_PLMNS:
904 request = (MainThreadRequest) msg.obj;
905 uiccCard = getUiccCardFromRequest(request);
906 if (uiccCard == null) {
907 loge("getForbiddenPlmns() UiccCard is null");
908 request.result = new IllegalArgumentException(
909 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700910 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800911 break;
912 }
913 Integer appType = (Integer) request.argument;
914 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
915 if (uiccApp == null) {
916 loge("getForbiddenPlmns() no app with specified type -- "
917 + appType);
918 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700919 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800920 break;
921 } else {
922 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
923 + " specified type -- " + appType);
924 }
925 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
926 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
927 onCompleted);
928 break;
929
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000930 case CMD_SWITCH_SLOTS:
931 request = (MainThreadRequest) msg.obj;
932 int[] physicalSlots = (int[]) request.argument;
933 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
934 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
935 break;
936
937 case EVENT_SWITCH_SLOTS_DONE:
938 ar = (AsyncResult) msg.obj;
939 request = (MainThreadRequest) ar.userObj;
940 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700941 notifyRequester(request);
942 break;
943 case CMD_GET_NETWORK_SELECTION_MODE:
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
946 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
947 break;
948
949 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
950 ar = (AsyncResult) msg.obj;
951 request = (MainThreadRequest) ar.userObj;
952 if (ar.exception != null) {
953 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
954 } else {
955 int mode = ((int[]) ar.result)[0];
956 if (mode == 0) {
957 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
958 } else {
959 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
960 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000961 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700962 notifyRequester(request);
963 break;
964 case CMD_GET_CDMA_ROAMING_MODE:
965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
967 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
968 break;
969 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
972 if (ar.exception != null) {
973 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
974 } else {
975 request.result = ((int[]) ar.result)[0];
976 }
977 notifyRequester(request);
978 break;
979 case CMD_SET_CDMA_ROAMING_MODE:
980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
982 int mode = (int) request.argument;
983 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
984 break;
985 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 request.result = ar.exception == null;
989 notifyRequester(request);
990 break;
991 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
992 request = (MainThreadRequest) msg.obj;
993 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
994 int subscriptionMode = (int) request.argument;
995 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
996 break;
997 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 request.result = ar.exception == null;
1001 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001002 break;
1003
Nathan Harold3ff88932018-08-14 10:19:49 -07001004 case CMD_GET_ALL_CELL_INFO:
1005 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001006 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001007 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001008 break;
1009
1010 case EVENT_GET_ALL_CELL_INFO_DONE:
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001013 // If a timeout occurs, the response will be null
1014 request.result = (ar.exception == null && ar.result != null)
1015 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001016 synchronized (request) {
1017 request.notifyAll();
1018 }
1019 break;
1020
1021 case CMD_GET_CELL_LOCATION: {
1022 request = (MainThreadRequest) msg.obj;
1023 WorkSource ws = (WorkSource) request.argument;
1024 Phone phone = getPhoneFromRequest(request);
1025 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1026 break;
1027 }
1028
1029 case EVENT_GET_CELL_LOCATION_DONE: {
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 if (ar.exception == null) {
1033 request.result = ar.result;
1034 } else {
1035 Phone phone = getPhoneFromRequest(request);
1036 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1037 ? new CdmaCellLocation() : new GsmCellLocation();
1038 }
1039
1040 synchronized (request) {
1041 request.notifyAll();
1042 }
1043 break;
1044 }
1045
chen xu6dac5ab2018-10-26 17:39:23 -07001046 case CMD_MODEM_REBOOT:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1049 mPhone.rebootModem(onCompleted);
1050 break;
1051
1052 case EVENT_CMD_MODEM_REBOOT_DONE:
1053 handleNullReturnEvent(msg, "rebootModem");
1054 break;
1055
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001056 default:
1057 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1058 break;
1059 }
1060 }
Jake Hambye994d462014-02-03 13:10:13 -08001061
Pengquan Menga1bb6272018-09-06 09:59:22 -07001062 private void notifyRequester(MainThreadRequest request) {
1063 synchronized (request) {
1064 request.notifyAll();
1065 }
1066 }
1067
Jake Hambye994d462014-02-03 13:10:13 -08001068 private void handleNullReturnEvent(Message msg, String command) {
1069 AsyncResult ar = (AsyncResult) msg.obj;
1070 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1071 if (ar.exception == null) {
1072 request.result = true;
1073 } else {
1074 request.result = false;
1075 if (ar.exception instanceof CommandException) {
1076 loge(command + ": CommandException: " + ar.exception);
1077 } else {
1078 loge(command + ": Unknown exception");
1079 }
1080 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001081 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 }
1084
1085 /**
1086 * Posts the specified command to be executed on the main thread,
1087 * waits for the request to complete, and returns the result.
1088 * @see #sendRequestAsync
1089 */
1090 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001091 return sendRequest(
1092 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001093 }
1094
1095 /**
1096 * Posts the specified command to be executed on the main thread,
1097 * waits for the request to complete, and returns the result.
1098 * @see #sendRequestAsync
1099 */
1100 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1101 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001102 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001103 }
1104
1105 /**
1106 * Posts the specified command to be executed on the main thread,
1107 * waits for the request to complete, and returns the result.
1108 * @see #sendRequestAsync
1109 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001110 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001111 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001112 }
1113
1114 /**
1115 * Posts the specified command to be executed on the main thread,
1116 * waits for the request to complete, and returns the result.
1117 * @see #sendRequestAsync
1118 */
Nathan Harold92bed182018-10-12 18:16:49 -07001119 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1120 return sendRequest(command, argument, subId, null, workSource);
1121 }
1122
1123 /**
1124 * Posts the specified command to be executed on the main thread,
1125 * waits for the request to complete, and returns the result.
1126 * @see #sendRequestAsync
1127 */
1128 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1129 return sendRequest(
1130 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1131 }
1132
1133 /**
1134 * Posts the specified command to be executed on the main thread,
1135 * waits for the request to complete, and returns the result.
1136 * @see #sendRequestAsync
1137 */
1138 private Object sendRequest(
1139 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1141 throw new RuntimeException("This method will deadlock if called from the main thread.");
1142 }
1143
Nathan Harold92bed182018-10-12 18:16:49 -07001144 MainThreadRequest request = null;
1145 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1146 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1147 } else if (phone != null) {
1148 request = new MainThreadRequest(argument, phone, workSource);
1149 } else {
1150 request = new MainThreadRequest(argument, subId, workSource);
1151 }
1152
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001153 Message msg = mMainThreadHandler.obtainMessage(command, request);
1154 msg.sendToTarget();
1155
1156 // Wait for the request to complete
1157 synchronized (request) {
1158 while (request.result == null) {
1159 try {
1160 request.wait();
1161 } catch (InterruptedException e) {
1162 // Do nothing, go back and wait until the request is complete
1163 }
1164 }
1165 }
1166 return request.result;
1167 }
1168
1169 /**
1170 * Asynchronous ("fire and forget") version of sendRequest():
1171 * Posts the specified command to be executed on the main thread, and
1172 * returns immediately.
1173 * @see #sendRequest
1174 */
1175 private void sendRequestAsync(int command) {
1176 mMainThreadHandler.sendEmptyMessage(command);
1177 }
1178
1179 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001180 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1181 * @see {@link #sendRequest(int,Object)}
1182 */
1183 private void sendRequestAsync(int command, Object argument) {
1184 MainThreadRequest request = new MainThreadRequest(argument);
1185 Message msg = mMainThreadHandler.obtainMessage(command, request);
1186 msg.sendToTarget();
1187 }
1188
1189 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 * Initialize the singleton PhoneInterfaceManager instance.
1191 * This is only done once, at startup, from PhoneApp.onCreate().
1192 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001193 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 synchronized (PhoneInterfaceManager.class) {
1195 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001196 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 } else {
1198 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1199 }
1200 return sInstance;
1201 }
1202 }
1203
1204 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001205 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 mApp = app;
1207 mPhone = phone;
1208 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001209 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001210 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1211 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001212 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001213 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001214 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001215 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001216 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001217
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 publish();
1219 }
1220
1221 private void publish() {
1222 if (DBG) log("publish: " + this);
1223
1224 ServiceManager.addService("phone", this);
1225 }
1226
Stuart Scott584921c2015-01-15 17:10:34 -08001227 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001228 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1229 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001230 }
1231
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001232 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1233 Phone phone = getPhoneFromRequest(request);
1234 return phone == null ? null :
1235 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1236 }
1237
Wink Saville36469e72014-06-11 15:17:00 -07001238 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001239 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001240 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242
1243 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001244 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001245 }
1246
Wink Savilleb564aae2014-10-23 10:18:09 -07001247 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 if (DBG) log("dial: " + number);
1249 // No permission check needed here: This is just a wrapper around the
1250 // ACTION_DIAL intent, which is available to any app since it puts up
1251 // the UI before it does anything.
1252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001253 final long identity = Binder.clearCallingIdentity();
1254 try {
1255 String url = createTelUrl(number);
1256 if (url == null) {
1257 return;
1258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001260 // PENDING: should we just silently fail if phone is offhook or ringing?
1261 PhoneConstants.State state = mCM.getState(subId);
1262 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1263 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1264 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1265 mApp.startActivity(intent);
1266 }
1267 } finally {
1268 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001269 }
1270 }
1271
1272 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001273 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001274 }
1275
Wink Savilleb564aae2014-10-23 10:18:09 -07001276 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 if (DBG) log("call: " + number);
1278
1279 // This is just a wrapper around the ACTION_CALL intent, but we still
1280 // need to do a permission check since we're calling startActivity()
1281 // from the context of the phone app.
1282 enforceCallPermission();
1283
1284 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1285 != AppOpsManager.MODE_ALLOWED) {
1286 return;
1287 }
1288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001289 final long identity = Binder.clearCallingIdentity();
1290 try {
1291 String url = createTelUrl(number);
1292 if (url == null) {
1293 return;
1294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001296 boolean isValid = false;
1297 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1298 if (slist != null) {
1299 for (SubscriptionInfo subInfoRecord : slist) {
1300 if (subInfoRecord.getSubscriptionId() == subId) {
1301 isValid = true;
1302 break;
1303 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001304 }
Wink Saville08874612014-08-31 19:19:58 -07001305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001306 if (!isValid) {
1307 return;
1308 }
Wink Saville08874612014-08-31 19:19:58 -07001309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001310 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1311 intent.putExtra(SUBSCRIPTION_KEY, subId);
1312 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1313 mApp.startActivity(intent);
1314 } finally {
1315 Binder.restoreCallingIdentity(identity);
1316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 }
1318
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001321 }
1322
Wink Savilleb564aae2014-10-23 10:18:09 -07001323 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001324 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001325 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1326 }
1327
1328 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001329 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001330 }
1331
Wink Savilleb564aae2014-10-23 10:18:09 -07001332 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001333 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001334 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1335 }
1336
1337 /** {@hide} */
1338 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001339 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001340 }
1341
Wink Savilleb564aae2014-10-23 10:18:09 -07001342 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001344
1345 final long identity = Binder.clearCallingIdentity();
1346 try {
1347 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1348 checkSimPin.start();
1349 return checkSimPin.unlockSim(null, pin);
1350 } finally {
1351 Binder.restoreCallingIdentity(identity);
1352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001353 }
1354
Wink Saville9de0f752013-10-22 19:04:03 -07001355 /** {@hide} */
1356 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001357 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001358 }
1359
Wink Savilleb564aae2014-10-23 10:18:09 -07001360 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001362
1363 final long identity = Binder.clearCallingIdentity();
1364 try {
1365 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1366 checkSimPuk.start();
1367 return checkSimPuk.unlockSim(puk, pin);
1368 } finally {
1369 Binder.restoreCallingIdentity(identity);
1370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371 }
1372
1373 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001374 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 * a synchronous one.
1376 */
1377 private static class UnlockSim extends Thread {
1378
1379 private final IccCard mSimCard;
1380
1381 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001382 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1383 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384
1385 // For replies from SimCard interface
1386 private Handler mHandler;
1387
1388 // For async handler to identify request type
1389 private static final int SUPPLY_PIN_COMPLETE = 100;
1390
1391 public UnlockSim(IccCard simCard) {
1392 mSimCard = simCard;
1393 }
1394
1395 @Override
1396 public void run() {
1397 Looper.prepare();
1398 synchronized (UnlockSim.this) {
1399 mHandler = new Handler() {
1400 @Override
1401 public void handleMessage(Message msg) {
1402 AsyncResult ar = (AsyncResult) msg.obj;
1403 switch (msg.what) {
1404 case SUPPLY_PIN_COMPLETE:
1405 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1406 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001407 mRetryCount = msg.arg1;
1408 if (ar.exception != null) {
1409 if (ar.exception instanceof CommandException &&
1410 ((CommandException)(ar.exception)).getCommandError()
1411 == CommandException.Error.PASSWORD_INCORRECT) {
1412 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1413 } else {
1414 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1415 }
1416 } else {
1417 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 mDone = true;
1420 UnlockSim.this.notifyAll();
1421 }
1422 break;
1423 }
1424 }
1425 };
1426 UnlockSim.this.notifyAll();
1427 }
1428 Looper.loop();
1429 }
1430
1431 /*
1432 * Use PIN or PUK to unlock SIM card
1433 *
1434 * If PUK is null, unlock SIM card with PIN
1435 *
1436 * If PUK is not null, unlock SIM card with PUK and set PIN code
1437 */
Wink Saville9de0f752013-10-22 19:04:03 -07001438 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439
1440 while (mHandler == null) {
1441 try {
1442 wait();
1443 } catch (InterruptedException e) {
1444 Thread.currentThread().interrupt();
1445 }
1446 }
1447 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1448
1449 if (puk == null) {
1450 mSimCard.supplyPin(pin, callback);
1451 } else {
1452 mSimCard.supplyPuk(puk, pin, callback);
1453 }
1454
1455 while (!mDone) {
1456 try {
1457 Log.d(LOG_TAG, "wait for done");
1458 wait();
1459 } catch (InterruptedException e) {
1460 // Restore the interrupted status
1461 Thread.currentThread().interrupt();
1462 }
1463 }
1464 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001465 int[] resultArray = new int[2];
1466 resultArray[0] = mResult;
1467 resultArray[1] = mRetryCount;
1468 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 }
1470 }
1471
1472 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001473 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001474
1475 }
1476
Wink Savilleb564aae2014-10-23 10:18:09 -07001477 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 // No permission check needed here: this call is harmless, and it's
1479 // needed for the ServiceState.requestStateUpdate() call (which is
1480 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001481 final long identity = Binder.clearCallingIdentity();
1482 try {
1483 final Phone phone = getPhone(subId);
1484 if (phone != null) {
1485 phone.updateServiceLocation();
1486 }
1487 } finally {
1488 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 }
1491
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001492 @Override
1493 public boolean isRadioOn(String callingPackage) {
1494 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001495 }
1496
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001497 @Override
1498 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001500 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001501 return false;
1502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001503
1504 final long identity = Binder.clearCallingIdentity();
1505 try {
1506 return isRadioOnForSubscriber(subId);
1507 } finally {
1508 Binder.restoreCallingIdentity(identity);
1509 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001510 }
1511
1512 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001513 final long identity = Binder.clearCallingIdentity();
1514 try {
1515 final Phone phone = getPhone(subId);
1516 if (phone != null) {
1517 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1518 } else {
1519 return false;
1520 }
1521 } finally {
1522 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 }
1525
1526 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001527 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 }
Wink Saville36469e72014-06-11 15:17:00 -07001529
Wink Savilleb564aae2014-10-23 10:18:09 -07001530 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001532
1533 final long identity = Binder.clearCallingIdentity();
1534 try {
1535 final Phone phone = getPhone(subId);
1536 if (phone != null) {
1537 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1538 }
1539 } finally {
1540 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001541 }
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
1544 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001546 }
1547
Wink Savilleb564aae2014-10-23 10:18:09 -07001548 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001550
1551 final long identity = Binder.clearCallingIdentity();
1552 try {
1553 final Phone phone = getPhone(subId);
1554 if (phone == null) {
1555 return false;
1556 }
1557 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1558 toggleRadioOnOffForSubscriber(subId);
1559 }
1560 return true;
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
Wink Saville36469e72014-06-11 15:17:00 -07001565
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001566 public boolean needMobileRadioShutdown() {
1567 /*
1568 * If any of the Radios are available, it will need to be
1569 * shutdown. So return true if any Radio is available.
1570 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001571 final long identity = Binder.clearCallingIdentity();
1572 try {
1573 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1574 Phone phone = PhoneFactory.getPhone(i);
1575 if (phone != null && phone.isRadioAvailable()) return true;
1576 }
1577 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1578 return false;
1579 } finally {
1580 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001581 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001582 }
1583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001584 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001585 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001586 enforceModifyPermission();
1587
1588 final long identity = Binder.clearCallingIdentity();
1589 try {
1590 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1591 logv("Shutting down Phone " + i);
1592 shutdownRadioUsingPhoneId(i);
1593 }
1594 } finally {
1595 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001596 }
1597 }
1598
1599 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001600 Phone phone = PhoneFactory.getPhone(phoneId);
1601 if (phone != null && phone.isRadioAvailable()) {
1602 phone.shutdownRadio();
1603 }
1604 }
1605
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001608
1609 final long identity = Binder.clearCallingIdentity();
1610 try {
1611 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1612 if (defaultPhone != null) {
1613 defaultPhone.setRadioPower(turnOn);
1614 return true;
1615 } else {
1616 loge("There's no default phone.");
1617 return false;
1618 }
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001621 }
Wink Saville36469e72014-06-11 15:17:00 -07001622 }
1623
Wink Savilleb564aae2014-10-23 10:18:09 -07001624 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001626
1627 final long identity = Binder.clearCallingIdentity();
1628 try {
1629 final Phone phone = getPhone(subId);
1630 if (phone != null) {
1631 phone.setRadioPower(turnOn);
1632 return true;
1633 } else {
1634 return false;
1635 }
1636 } finally {
1637 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 }
1640
Wink Saville36469e72014-06-11 15:17:00 -07001641 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001642 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 public boolean enableDataConnectivity() {
1644 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001645
1646 final long identity = Binder.clearCallingIdentity();
1647 try {
1648 int subId = mSubscriptionController.getDefaultDataSubId();
1649 final Phone phone = getPhone(subId);
1650 if (phone != null) {
1651 phone.setUserDataEnabled(true);
1652 return true;
1653 } else {
1654 return false;
1655 }
1656 } finally {
1657 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
1660
Wink Saville36469e72014-06-11 15:17:00 -07001661 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001662 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 public boolean disableDataConnectivity() {
1664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001665
1666 final long identity = Binder.clearCallingIdentity();
1667 try {
1668 int subId = mSubscriptionController.getDefaultDataSubId();
1669 final Phone phone = getPhone(subId);
1670 if (phone != null) {
1671 phone.setUserDataEnabled(false);
1672 return true;
1673 } else {
1674 return false;
1675 }
1676 } finally {
1677 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 }
1680
Sanket Padawe356d7632015-06-22 14:03:32 -07001681 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001682 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001683 final long identity = Binder.clearCallingIdentity();
1684 try {
1685 final Phone phone = getPhone(subId);
1686 if (phone != null) {
1687 return phone.isDataAllowed();
1688 } else {
1689 return false;
1690 }
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
1695
1696 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001697 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001698 }
1699
pkanwarae03a6b2016-11-06 20:37:09 -08001700 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001701 enforceCallPermission();
1702
1703 final long identity = Binder.clearCallingIdentity();
1704 try {
1705 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1706 return;
1707 }
1708 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1709 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1710 } finally {
1711 Binder.restoreCallingIdentity(identity);
1712 }
pkanwar32d516d2016-10-14 19:37:38 -07001713 };
1714
Wink Savilleb564aae2014-10-23 10:18:09 -07001715 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1721 return false;
1722 }
1723 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 }
1728
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001730 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001731 }
1732
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001733 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 Phone phone = PhoneFactory.getPhone(slotIndex);
1737 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1738 PhoneConstantConversions.convertCallState(phone.getState());
1739 } finally {
1740 Binder.restoreCallingIdentity(identity);
1741 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 }
1743
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746 final long identity = Binder.clearCallingIdentity();
1747 try {
1748 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1749 if (phone != null) {
1750 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1751 } else {
1752 return PhoneConstantConversions.convertDataState(
1753 PhoneConstants.DataState.DISCONNECTED);
1754 }
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759
Sanket Padawe356d7632015-06-22 14:03:32 -07001760 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762 final long identity = Binder.clearCallingIdentity();
1763 try {
1764 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1765 if (phone != null) {
1766 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1767 } else {
1768 return TelephonyManager.DATA_ACTIVITY_NONE;
1769 }
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
1775 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001776 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001777 mPhone.getContext().getSystemService(AppOpsManager.class)
1778 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001779 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001780 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001781 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 }
1783
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001784 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 if (DBG_LOC) log("getCellLocation: is active user");
1788 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001789 int subId = mSubscriptionController.getDefaultDataSubId();
1790 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1791 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001792 return data;
1793 } finally {
1794 Binder.restoreCallingIdentity(identity);
1795 }
Svetoslav64fad262015-04-14 14:35:21 -07001796 }
1797
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001799 public String getNetworkCountryIsoForPhone(int phoneId) {
1800 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1801 // registered cell info, so return a NULL country instead.
1802 final long identity = Binder.clearCallingIdentity();
1803 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001804 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1805 // Get default phone in this case.
1806 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1807 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001808 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001809 // Todo: fix this when we can get the actual cellular network info when the device
1810 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001811 if (TelephonyManager.NETWORK_TYPE_IWLAN
1812 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1813 return "";
1814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001815 Phone phone = PhoneFactory.getPhone(phoneId);
1816 if (phone != null) {
1817 ServiceStateTracker sst = phone.getServiceStateTracker();
1818 if (sst != null) {
1819 LocaleTracker lt = sst.getLocaleTracker();
1820 if (lt != null) {
1821 return lt.getCurrentCountry();
1822 }
1823 }
1824 }
1825 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001826 } finally {
1827 Binder.restoreCallingIdentity(identity);
1828 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001829 }
1830
1831 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001833 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001834 }
1835
Sanket Padawe356d7632015-06-22 14:03:32 -07001836 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001837 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 mApp.enforceCallingOrSelfPermission(
1839 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001840
1841 final long identity = Binder.clearCallingIdentity();
1842 try {
1843 final Phone phone = getPhone(subId);
1844 if (phone != null) {
1845 phone.enableLocationUpdates();
1846 }
1847 } finally {
1848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 }
1851
1852 @Override
1853 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001854 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001855 }
1856
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001858 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 mApp.enforceCallingOrSelfPermission(
1860 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001861
1862 final long identity = Binder.clearCallingIdentity();
1863 try {
1864 final Phone phone = getPhone(subId);
1865 if (phone != null) {
1866 phone.disableLocationUpdates();
1867 }
1868 } finally {
1869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 }
1872
Nathan Harold31d7ff32018-10-15 20:20:30 -07001873 /**
1874 * Returns the target SDK version number for a given package name.
1875 *
1876 * @return target SDK if the package is found or INT_MAX.
1877 */
1878 private int getTargetSdk(String packageName) {
1879 try {
1880 final ApplicationInfo ai =
1881 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1882 if (ai != null) return ai.targetSdkVersion;
1883 } catch (PackageManager.NameNotFoundException unexpected) {
1884 }
1885 return Integer.MAX_VALUE;
1886 }
1887
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 @Override
1889 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001890 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1891 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001892 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1893 throw new SecurityException(
1894 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1895 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001896
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1898 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1899 return null;
1900 }
Svetoslav64fad262015-04-14 14:35:21 -07001901
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001902 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903
Nathan Haroldf180aac2018-06-01 18:43:55 -07001904 List<CellInfo> info = getAllCellInfo(callingPackage);
1905 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906
Nathan Haroldf180aac2018-06-01 18:43:55 -07001907 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1908 for (CellInfo ci : info) {
1909 if (ci instanceof CellInfoGsm) {
1910 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1911 } else if (ci instanceof CellInfoWcdma) {
1912 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001915 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 }
1917
1918
1919 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001920 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001921 mPhone.getContext().getSystemService(AppOpsManager.class)
1922 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001923 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001924 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001925 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 }
1927
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001928 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001929 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1933 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001934 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001935 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001936 if (info != null) cellInfos.addAll(info);
1937 }
1938 return cellInfos;
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942 }
1943
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001944 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001946 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001947 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948
1949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 mPhone.setCellInfoListRate(rateInMillis, workSource);
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
Shishir Agrawala9f32182016-04-12 12:00:16 -07001957 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001958 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001959 Phone phone = PhoneFactory.getPhone(slotIndex);
1960 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001961 return null;
1962 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001963 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001964 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1965 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001966 return null;
1967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968
1969 final long identity = Binder.clearCallingIdentity();
1970 try {
1971 return phone.getImei();
1972 } finally {
1973 Binder.restoreCallingIdentity(identity);
1974 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001975 }
1976
1977 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001978 public String getTypeAllocationCodeForSlot(int slotIndex) {
1979 Phone phone = PhoneFactory.getPhone(slotIndex);
1980 String tac = null;
1981 if (phone != null) {
1982 String imei = phone.getImei();
1983 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1984 }
1985 return tac;
1986 }
1987
1988 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001989 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001990 Phone phone = PhoneFactory.getPhone(slotIndex);
1991 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001992 return null;
1993 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001994 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001995 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1996 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001997 return null;
1998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999
2000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 return phone.getMeid();
2003 } finally {
2004 Binder.restoreCallingIdentity(identity);
2005 }
Jack Yu2af8d712017-03-15 17:14:14 -07002006 }
2007
2008 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002009 public String getManufacturerCodeForSlot(int slotIndex) {
2010 Phone phone = PhoneFactory.getPhone(slotIndex);
2011 String manufacturerCode = null;
2012 if (phone != null) {
2013 String meid = phone.getMeid();
2014 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2015 }
2016 return manufacturerCode;
2017 }
2018
2019 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002020 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002021 Phone phone = PhoneFactory.getPhone(slotIndex);
2022 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002023 return null;
2024 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002025 int subId = phone.getSubId();
2026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2027 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2028 return null;
2029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030
2031 final long identity = Binder.clearCallingIdentity();
2032 try {
2033 return phone.getDeviceSvn();
2034 } finally {
2035 Binder.restoreCallingIdentity(identity);
2036 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002037 }
2038
fionaxu43304da2017-11-27 22:51:16 -08002039 @Override
2040 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041 final long identity = Binder.clearCallingIdentity();
2042 try {
2043 final Phone phone = getPhone(subId);
2044 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
2047 }
fionaxu43304da2017-11-27 22:51:16 -08002048 }
2049
2050 @Override
2051 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002052 final long identity = Binder.clearCallingIdentity();
2053 try {
2054 final Phone phone = getPhone(subId);
2055 return phone == null ? null : phone.getCarrierName();
2056 } finally {
2057 Binder.restoreCallingIdentity(identity);
2058 }
fionaxu43304da2017-11-27 22:51:16 -08002059 }
2060
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 //
2062 // Internal helper methods.
2063 //
2064
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002065 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2067 *
2068 * @throws SecurityException if the caller does not have the required permission
2069 */
2070 private void enforceModifyPermission() {
2071 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2072 }
2073
2074 /**
2075 * Make sure the caller has the CALL_PHONE permission.
2076 *
2077 * @throws SecurityException if the caller does not have the required permission
2078 */
2079 private void enforceCallPermission() {
2080 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2081 }
2082
Stuart Scott8eef64f2015-04-08 15:13:54 -07002083 private void enforceConnectivityInternalPermission() {
2084 mApp.enforceCallingOrSelfPermission(
2085 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2086 "ConnectivityService");
2087 }
2088
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 private String createTelUrl(String number) {
2090 if (TextUtils.isEmpty(number)) {
2091 return null;
2092 }
2093
Jake Hambye994d462014-02-03 13:10:13 -08002094 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 }
2096
Ihab Awadf9e92732013-12-05 18:02:52 -08002097 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2099 }
2100
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002101 private static void logv(String msg) {
2102 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2103 }
2104
Ihab Awadf9e92732013-12-05 18:02:52 -08002105 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2107 }
2108
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002109 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002111 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002112 }
2113
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002115 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002116 final long identity = Binder.clearCallingIdentity();
2117 try {
2118 final Phone phone = PhoneFactory.getPhone(slotIndex);
2119 if (phone == null) {
2120 return PhoneConstants.PHONE_TYPE_NONE;
2121 } else {
2122 return phone.getPhoneType();
2123 }
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
2129 /**
2130 * Returns the CDMA ERI icon index to display
2131 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002132 @Override
2133 public int getCdmaEriIconIndex(String callingPackage) {
2134 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002135 }
2136
Sanket Padawe356d7632015-06-22 14:03:32 -07002137 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002138 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002139 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002140 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002141 return -1;
2142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002143
2144 final long identity = Binder.clearCallingIdentity();
2145 try {
2146 final Phone phone = getPhone(subId);
2147 if (phone != null) {
2148 return phone.getCdmaEriIconIndex();
2149 } else {
2150 return -1;
2151 }
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002154 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 }
2156
2157 /**
2158 * Returns the CDMA ERI icon mode,
2159 * 0 - ON
2160 * 1 - FLASHING
2161 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002162 @Override
2163 public int getCdmaEriIconMode(String callingPackage) {
2164 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002165 }
2166
Sanket Padawe356d7632015-06-22 14:03:32 -07002167 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002168 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002169 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002170 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002171 return -1;
2172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002173
2174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 final Phone phone = getPhone(subId);
2177 if (phone != null) {
2178 return phone.getCdmaEriIconMode();
2179 } else {
2180 return -1;
2181 }
2182 } finally {
2183 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
2187 /**
2188 * Returns the CDMA ERI text,
2189 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002190 @Override
2191 public String getCdmaEriText(String callingPackage) {
2192 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002193 }
2194
Sanket Padawe356d7632015-06-22 14:03:32 -07002195 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002196 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002198 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002199 return null;
2200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002201
2202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 final Phone phone = getPhone(subId);
2205 if (phone != null) {
2206 return phone.getCdmaEriText();
2207 } else {
2208 return null;
2209 }
2210 } finally {
2211 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 }
2214
2215 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002216 * Returns the CDMA MDN.
2217 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002218 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002219 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2221 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222
2223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 final Phone phone = getPhone(subId);
2226 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2227 return phone.getLine1Number();
2228 } else {
2229 return null;
2230 }
2231 } finally {
2232 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002233 }
2234 }
2235
2236 /**
2237 * Returns the CDMA MIN.
2238 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002240 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2242 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243
2244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 final Phone phone = getPhone(subId);
2247 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2248 return phone.getCdmaMin();
2249 } else {
2250 return null;
2251 }
2252 } finally {
2253 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002254 }
2255 }
2256
2257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 * Returns true if CDMA provisioning needs to run.
2259 */
2260 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261 final long identity = Binder.clearCallingIdentity();
2262 try {
2263 return mPhone.needsOtaServiceProvisioning();
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
2266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
2269 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002270 * Sets the voice mail number of a given subId.
2271 */
2272 @Override
2273 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002274 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275
2276 final long identity = Binder.clearCallingIdentity();
2277 try {
2278 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2279 new Pair<String, String>(alphaTag, number), new Integer(subId));
2280 return success;
2281 } finally {
2282 Binder.restoreCallingIdentity(identity);
2283 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002284 }
2285
Ta-wei Yen87c49842016-05-13 21:19:52 -07002286 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002287 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2288 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2289 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2290 if (!TextUtils.equals(callingPackage, systemDialer)) {
2291 throw new SecurityException("caller must be system dialer");
2292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293
2294 final long identity = Binder.clearCallingIdentity();
2295 try {
2296 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2297 if (phoneAccountHandle == null) {
2298 return null;
2299 }
2300 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2301 } finally {
2302 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002303 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002304 }
2305
2306 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002307 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002308 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002310 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002311 return null;
2312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002314 final long identity = Binder.clearCallingIdentity();
2315 try {
2316 return RemoteVvmTaskManager
2317 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
2320 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002321 }
2322
2323 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002324 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2325 VisualVoicemailSmsFilterSettings settings) {
2326 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2331 mPhone.getContext(), callingPackage, subId, settings);
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
2334 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002335 }
2336
2337 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002338 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2339 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340
2341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2344 mPhone.getContext(), callingPackage, subId);
2345 } finally {
2346 Binder.restoreCallingIdentity(identity);
2347 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002348 }
2349
2350 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002351 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2352 String callingPackage, int subId) {
2353 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002354
2355 final long identity = Binder.clearCallingIdentity();
2356 try {
2357 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2358 mPhone.getContext(), callingPackage, subId);
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
2361 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002362 }
2363
2364 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002365 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002366 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367
2368 final long identity = Binder.clearCallingIdentity();
2369 try {
2370 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2371 mPhone.getContext(), subId);
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
2374 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002375 }
2376
2377 @Override
2378 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2379 String number, int port, String text, PendingIntent sentIntent) {
2380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002381 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002382 enforceSendSmsPermission();
2383 // Make the calls as the phone process.
2384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2387 if (port == 0) {
2388 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2389 sentIntent, null, false);
2390 } else {
2391 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2392 smsManager.sendDataMessageWithSelfPermissions(number, null,
2393 (short) port, data, sentIntent, null);
2394 }
2395 } finally {
2396 Binder.restoreCallingIdentity(identity);
2397 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002398 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002399 /**
fionaxu0152e512016-11-14 13:36:14 -08002400 * Sets the voice activation state of a given subId.
2401 */
2402 @Override
2403 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2405 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002406
2407 final long identity = Binder.clearCallingIdentity();
2408 try {
2409 final Phone phone = getPhone(subId);
2410 if (phone != null) {
2411 phone.setVoiceActivationState(activationState);
2412 } else {
2413 loge("setVoiceActivationState fails with invalid subId: " + subId);
2414 }
2415 } finally {
2416 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002417 }
2418 }
2419
2420 /**
2421 * Sets the data activation state of a given subId.
2422 */
2423 @Override
2424 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2426 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427
2428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 final Phone phone = getPhone(subId);
2431 if (phone != null) {
2432 phone.setDataActivationState(activationState);
2433 } else {
2434 loge("setVoiceActivationState fails with invalid subId: " + subId);
2435 }
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002438 }
2439 }
2440
2441 /**
2442 * Returns the voice activation state of a given subId.
2443 */
2444 @Override
2445 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002446 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447
fionaxu0152e512016-11-14 13:36:14 -08002448 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 if (phone != null) {
2452 return phone.getVoiceActivationState();
2453 } else {
2454 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2455 }
2456 } finally {
2457 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002458 }
2459 }
2460
2461 /**
2462 * Returns the data activation state of a given subId.
2463 */
2464 @Override
2465 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002466 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467
fionaxu0152e512016-11-14 13:36:14 -08002468 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 final long identity = Binder.clearCallingIdentity();
2470 try {
2471 if (phone != null) {
2472 return phone.getDataActivationState();
2473 } else {
2474 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2475 }
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002478 }
2479 }
2480
2481 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 * Returns the unread count of voicemails
2483 */
2484 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002485 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002486 }
2487
2488 /**
2489 * Returns the unread count of voicemails for a subId
2490 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002491 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002492 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493 final long identity = Binder.clearCallingIdentity();
2494 try {
2495 final Phone phone = getPhone(subId);
2496 if (phone != null) {
2497 return phone.getVoiceMessageCount();
2498 } else {
2499 return 0;
2500 }
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
2505
2506 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002507 * returns true, if the device is in a state where both voice and data
2508 * are supported simultaneously. This can change based on location or network condition.
2509 */
2510 @Override
2511 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 final Phone phone = getPhone(subId);
2515 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
2518 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002519 }
2520
2521 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002522 * Send the dialer code if called from the current default dialer or the caller has
2523 * carrier privilege.
2524 * @param inputCode The dialer code to send
2525 */
2526 @Override
2527 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2529 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2530 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002531 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2532 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534
2535 final long identity = Binder.clearCallingIdentity();
2536 try {
2537 mPhone.sendDialerSpecialCode(inputCode);
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
2540 }
fionaxu235cc5e2017-03-06 22:25:57 -08002541 }
2542
2543 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002544 * Returns the data network type.
2545 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 *
2547 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2548 */
2549 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002550 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 final Phone phone = getPhone(getDefaultSubscription());
2554 if (phone != null) {
2555 return phone.getServiceState().getDataNetworkType();
2556 } else {
2557 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2558 }
2559 } finally {
2560 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002561 }
Wink Saville36469e72014-06-11 15:17:00 -07002562 }
2563
Pengquan Menga1bb6272018-09-06 09:59:22 -07002564 @Override
2565 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002566 if (!isActiveSubscription(subId)) {
2567 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2568 }
2569
Pengquan Menga1bb6272018-09-06 09:59:22 -07002570 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2571 }
2572
Brad Ebinger35c841c2018-10-01 10:40:55 -07002573 @Override
2574 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2575 String callingPackage) throws RemoteException {
2576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2577 "addImsRegistrationCallback")) {
2578 return;
2579 }
2580 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2581 final long token = Binder.clearCallingIdentity();
2582 try {
2583 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2584 .addRegistrationCallbackForSubscription(c, subId);
2585 } finally {
2586 Binder.restoreCallingIdentity(token);
2587 }
2588 }
2589
2590 @Override
2591 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2592 String callingPackage) {
2593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2594 "removeImsRegistrationCallback")) {
2595 return;
2596 }
2597 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2598 Binder.withCleanCallingIdentity(() ->
2599 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2600 .removeRegistrationCallbackForSubscription(c, subId));
2601 }
2602
2603 @Override
2604 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2605 String callingPackage) throws RemoteException {
2606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2607 "addMmTelCapabilityCallback")) {
2608 return;
2609 }
2610 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2611 final long token = Binder.clearCallingIdentity();
2612 try {
2613 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2614 .addCapabilitiesCallbackForSubscription(c, subId);
2615 } finally {
2616 Binder.restoreCallingIdentity(token);
2617 }
2618 }
2619
2620 @Override
2621 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2622 String callingPackage) {
2623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2624 "removeMmTelCapabilityCallback")) {
2625 return;
2626 }
2627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2628 Binder.withCleanCallingIdentity(() ->
2629 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2630 .removeCapabilitiesCallbackForSubscription(c, subId));
2631 }
2632
2633 @Override
2634 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2636 "isCapable")) {
2637 return false;
2638 }
2639 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2640 final long token = Binder.clearCallingIdentity();
2641 try {
2642 return ImsManager.getInstance(mPhone.getContext(),
2643 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2644 } catch (ImsException e) {
2645 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2646 return false;
2647 } finally {
2648 Binder.restoreCallingIdentity(token);
2649 }
2650 }
2651
2652 @Override
2653 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2655 "isAvailable")) {
2656 return false;
2657 }
2658 final long token = Binder.clearCallingIdentity();
2659 try {
2660 Phone phone = getPhone(subId);
2661 if (phone == null) return false;
2662 return phone.isImsCapabilityAvailable(capability, regTech);
2663 } finally {
2664 Binder.restoreCallingIdentity(token);
2665 }
2666 }
2667
2668 @Override
2669 public boolean isAdvancedCallingSettingEnabled(int subId) {
2670 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2671 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2672 final long token = Binder.clearCallingIdentity();
2673 try {
2674 return ImsManager.getInstance(mPhone.getContext(),
2675 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2676 } finally {
2677 Binder.restoreCallingIdentity(token);
2678 }
2679 }
2680
2681 @Override
2682 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2684 "setAdvancedCallingSetting");
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2688 ImsManager.getInstance(mPhone.getContext(),
2689 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
2692 }
2693 }
2694
2695 @Override
2696 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2698 "isVtSettingEnabled")) {
2699 return false;
2700 }
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2704 return ImsManager.getInstance(mPhone.getContext(),
2705 getSlotIndexOrException(subId)).isVtEnabledByUser();
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
2709 }
2710
2711 @Override
2712 public void setVtSetting(int subId, boolean isEnabled) {
2713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2714 "setVtSetting");
2715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2718 ImsManager.getInstance(mPhone.getContext(),
2719 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
2722 }
2723 }
2724
2725 @Override
2726 public boolean isVoWiFiSettingEnabled(int subId) {
2727 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2728 final long identity = Binder.clearCallingIdentity();
2729 try {
2730 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2731 return ImsManager.getInstance(mPhone.getContext(),
2732 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2733 } finally {
2734 Binder.restoreCallingIdentity(identity);
2735 }
2736 }
2737
2738 @Override
2739 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2741 "setVoWiFiSetting");
2742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2745 ImsManager.getInstance(mPhone.getContext(),
2746 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
2749 }
2750 }
2751
2752 @Override
2753 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2754 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2758 return ImsManager.getInstance(mPhone.getContext(),
2759 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2760 } finally {
2761 Binder.restoreCallingIdentity(identity);
2762 }
2763 }
2764
2765 @Override
2766 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2768 "setVoWiFiRoamingSetting");
2769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2772 ImsManager.getInstance(mPhone.getContext(),
2773 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
2776 }
2777 }
2778
2779 @Override
2780 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2782 "setVoWiFiNonPersistent");
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2786 ImsManager.getInstance(mPhone.getContext(),
2787 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
2790 }
2791 }
2792
2793 @Override
2794 public int getVoWiFiModeSetting(int subId) {
2795 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2796 final long identity = Binder.clearCallingIdentity();
2797 try {
2798 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2799 return ImsManager.getInstance(mPhone.getContext(),
2800 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2801 } finally {
2802 Binder.restoreCallingIdentity(identity);
2803 }
2804 }
2805
2806 @Override
2807 public void setVoWiFiModeSetting(int subId, int mode) {
2808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2809 "setVoWiFiModeSetting");
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2813 ImsManager.getInstance(mPhone.getContext(),
2814 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
2818 }
2819
2820 @Override
2821 public int getVoWiFiRoamingModeSetting(int subId) {
2822 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2826 return ImsManager.getInstance(mPhone.getContext(),
2827 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
2830 }
2831 }
2832
2833 @Override
2834 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2836 "setVoWiFiRoamingModeSetting");
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2840 ImsManager.getInstance(mPhone.getContext(),
2841 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
2844 }
2845 }
2846
2847 @Override
2848 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2850 "setRttCapabilityEnabled");
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2854 ImsManager.getInstance(mPhone.getContext(),
2855 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
2859 }
2860
2861 @Override
2862 public boolean isTtyOverVolteEnabled(int subId) {
2863 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2867 return ImsManager.getInstance(mPhone.getContext(),
2868 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
2871 }
2872 }
2873
2874 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2875 int slotId = SubscriptionManager.getSlotIndex(subId);
2876 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2877 throw new IllegalArgumentException("Invalid Subscription Id.");
2878 }
2879 return slotId;
2880 }
2881
Wink Saville36469e72014-06-11 15:17:00 -07002882 /**
2883 * Returns the network type for a subId
2884 */
2885 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002886 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002888 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002889 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2890 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 final Phone phone = getPhone(subId);
2895 if (phone != null) {
2896 return phone.getServiceState().getDataNetworkType();
2897 } else {
2898 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2899 }
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002903 }
2904
2905 /**
2906 * Returns the data network type
2907 */
2908 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002909 public int getDataNetworkType(String callingPackage) {
2910 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002911 }
2912
2913 /**
2914 * Returns the data network type for a subId
2915 */
2916 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002917 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002919 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002920 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2921 }
2922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 final Phone phone = getPhone(subId);
2926 if (phone != null) {
2927 return phone.getServiceState().getDataNetworkType();
2928 } else {
2929 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2930 }
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 }
2935
2936 /**
Wink Saville36469e72014-06-11 15:17:00 -07002937 * Returns the Voice network type for a subId
2938 */
2939 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002940 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002942 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002943 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2944 }
2945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 final Phone phone = getPhone(subId);
2949 if (phone != null) {
2950 return phone.getServiceState().getVoiceNetworkType();
2951 } else {
2952 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2953 }
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 }
2958
2959 /**
2960 * @return true if a ICC card is present
2961 */
2962 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002963 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002964 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2965 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002966 }
2967
2968 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002969 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002970 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002971 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002972 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973 final long identity = Binder.clearCallingIdentity();
2974 try {
2975 final Phone phone = PhoneFactory.getPhone(slotIndex);
2976 if (phone != null) {
2977 return phone.getIccCard().hasIccCard();
2978 } else {
2979 return false;
2980 }
2981 } finally {
2982 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984 }
2985
2986 /**
2987 * Return if the current radio is LTE on CDMA. This
2988 * is a tri-state return value as for a period of time
2989 * the mode may be unknown.
2990 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002991 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002993 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002994 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002995 @Override
2996 public int getLteOnCdmaMode(String callingPackage) {
2997 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002998 }
2999
Sanket Padawe356d7632015-06-22 14:03:32 -07003000 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003001 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003003 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003004 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3005 }
3006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007 final long identity = Binder.clearCallingIdentity();
3008 try {
3009 final Phone phone = getPhone(subId);
3010 if (phone == null) {
3011 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3012 } else {
3013 return phone.getLteOnCdmaMode();
3014 }
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003017 }
Wink Saville36469e72014-06-11 15:17:00 -07003018 }
3019
3020 public void setPhone(Phone phone) {
3021 mPhone = phone;
3022 }
3023
3024 /**
3025 * {@hide}
3026 * Returns Default subId, 0 in the case of single standby.
3027 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003028 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003029 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003030 }
3031
Shishir Agrawala9f32182016-04-12 12:00:16 -07003032 private int getSlotForDefaultSubscription() {
3033 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3034 }
3035
Wink Savilleb564aae2014-10-23 10:18:09 -07003036 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003037 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003038 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003039
Pengquan Menge92a50d2018-09-21 15:54:48 -07003040 private boolean isActiveSubscription(int subId) {
3041 return mSubscriptionController.isActiveSubId(subId);
3042 }
3043
Ihab Awadf2177b72013-11-25 13:33:23 -08003044 /**
3045 * @see android.telephony.TelephonyManager.WifiCallingChoices
3046 */
3047 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3051 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3052 getWhenToMakeWifiCallsDefaultPreference());
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003056 }
3057
3058 /**
3059 * @see android.telephony.TelephonyManager.WifiCallingChoices
3060 */
3061 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3065 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3066 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003070 }
3071
Sailesh Nepald1e68152013-12-12 19:08:02 -08003072 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003073 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003074 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003075 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003076
Shishir Agrawal566b7612013-10-28 14:41:00 -07003077 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003078 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3079 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3081 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 if (TextUtils.equals(ISDR_AID, aid)) {
3087 // Only allows LPA to open logical channel to ISD-R.
3088 ComponentInfo bestComponent =
3089 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3090 if (bestComponent == null
3091 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3092 loge("The calling package is not allowed to access ISD-R.");
3093 throw new SecurityException(
3094 "The calling package is not allowed to access ISD-R.");
3095 }
Derek Tan740e1672017-06-27 14:56:27 -07003096 }
Derek Tan740e1672017-06-27 14:56:27 -07003097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003098 if (DBG) {
3099 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3100 }
3101 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3102 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3103 if (DBG) log("iccOpenLogicalChannel: " + response);
3104 return response;
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003108 }
3109
3110 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003111 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3113 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3118 if (channel < 0) {
3119 return false;
3120 }
3121 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3122 if (DBG) log("iccCloseLogicalChannel: " + success);
3123 return success;
3124 } finally {
3125 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003126 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003127 }
3128
3129 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003130 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003131 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3133 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 if (DBG) {
3138 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3139 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3140 + p3 + " data=" + data);
3141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003143 if (channel < 0) {
3144 return "";
3145 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3148 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3149 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003150
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 // Append the returned status code to the end of the response payload.
3152 String s = Integer.toHexString(
3153 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3154 if (response.payload != null) {
3155 s = IccUtils.bytesToHexString(response.payload) + s;
3156 }
3157 return s;
3158 } finally {
3159 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003160 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003161 }
Jake Hambye994d462014-02-03 13:10:13 -08003162
Evan Charltonc66da362014-05-16 14:06:40 -07003163 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003164 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3165 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3167 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 final long identity = Binder.clearCallingIdentity();
3171 try {
3172 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3173 && TextUtils.equals(ISDR_AID, data)) {
3174 // Only allows LPA to select 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 select ISD-R.");
3180 throw new SecurityException(
3181 "The calling package is not allowed to select ISD-R.");
3182 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003183 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185 if (DBG) {
3186 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3187 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3188 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3191 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3192 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 // Append the returned status code to the end of the response payload.
3195 String s = Integer.toHexString(
3196 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3197 if (response.payload != null) {
3198 s = IccUtils.bytesToHexString(response.payload) + s;
3199 }
3200 return s;
3201 } finally {
3202 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003203 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003204 }
3205
3206 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003207 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003208 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3210 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 if (DBG) {
3215 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3216 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3217 }
3218
3219 IccIoResult response =
3220 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3221 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3222 subId);
3223
3224 if (DBG) {
3225 log("Exchange SIM_IO [R]" + response);
3226 }
3227
3228 byte[] result = null;
3229 int length = 2;
3230 if (response.payload != null) {
3231 length = 2 + response.payload.length;
3232 result = new byte[length];
3233 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3234 } else {
3235 result = new byte[length];
3236 }
3237
3238 result[length - 1] = (byte) response.sw2;
3239 result[length - 2] = (byte) response.sw1;
3240 return result;
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003243 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003244 }
3245
Nathan Haroldb3014052017-01-25 15:57:32 -08003246 /**
3247 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3248 * on a particular subscription
3249 */
sqianb6e41952018-03-12 14:54:01 -07003250 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3252 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3253 return null;
3254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255
3256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 if (appType != TelephonyManager.APPTYPE_USIM
3259 && appType != TelephonyManager.APPTYPE_SIM) {
3260 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3261 return null;
3262 }
3263 Object response = sendRequest(
3264 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3265 if (response instanceof String[]) {
3266 return (String[]) response;
3267 }
3268 // Response is an Exception of some kind,
3269 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003270 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271 } finally {
3272 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003273 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003274 }
3275
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003276 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003277 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3279 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3284 if (response.payload == null) {
3285 return "";
3286 }
Evan Charltonc66da362014-05-16 14:06:40 -07003287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288 // Append the returned status code to the end of the response payload.
3289 String s = Integer.toHexString(
3290 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3291 s = IccUtils.bytesToHexString(response.payload) + s;
3292 return s;
3293 } finally {
3294 Binder.restoreCallingIdentity(identity);
3295 }
Evan Charltonc66da362014-05-16 14:06:40 -07003296 }
3297
Jake Hambye994d462014-02-03 13:10:13 -08003298 /**
3299 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3300 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3301 *
3302 * @param itemID the ID of the item to read
3303 * @return the NV item as a String, or null on error.
3304 */
3305 @Override
3306 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003307 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3309 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003314 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3316 return value;
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
Jake Hambye994d462014-02-03 13:10:13 -08003320 }
3321
3322 /**
3323 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3324 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3325 *
3326 * @param itemID the ID of the item to read
3327 * @param itemValue the value to write, as a String
3328 * @return true on success; false on any failure
3329 */
3330 @Override
3331 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003332 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3334 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335
3336 final long identity = Binder.clearCallingIdentity();
3337 try {
3338 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3339 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003340 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3342 return success;
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
Jake Hambye994d462014-02-03 13:10:13 -08003346 }
3347
3348 /**
3349 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3350 * Used for device configuration by some CDMA operators.
3351 *
3352 * @param preferredRoamingList byte array containing the new PRL
3353 * @return true on success; false on any failure
3354 */
3355 @Override
3356 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3358 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3363 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3364 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3365 return success;
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
Jake Hambye994d462014-02-03 13:10:13 -08003369 }
3370
3371 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003372 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003373 * Used for device configuration by some CDMA operators.
3374 *
chen xu6dac5ab2018-10-26 17:39:23 -07003375 * @param slotIndex - device slot.
3376 *
Jake Hambye994d462014-02-03 13:10:13 -08003377 * @return true on success; false on any failure
3378 */
3379 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003380 public boolean resetModemConfig(int slotIndex) {
3381 Phone phone = PhoneFactory.getPhone(slotIndex);
3382 if (phone != null) {
3383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3384 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003385
chen xu6dac5ab2018-10-26 17:39:23 -07003386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3389 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3390 return success;
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394 }
chen xu6dac5ab2018-10-26 17:39:23 -07003395 return false;
3396 }
3397
3398 /**
3399 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3400 *
3401 * @param slotIndex - device slot.
3402 *
3403 * @return true on success; false on any failure
3404 */
3405 @Override
3406 public boolean rebootModem(int slotIndex) {
3407 Phone phone = PhoneFactory.getPhone(slotIndex);
3408 if (phone != null) {
3409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3410 mApp, phone.getSubId(), "rebootModem");
3411
3412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3415 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3416 return success;
3417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
3420 }
3421 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003422 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003423
Svet Ganovb320e182015-04-16 12:30:10 -07003424 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003426 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003427 return new String[0];
3428 }
3429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003430 final long identity = Binder.clearCallingIdentity();
3431 try {
3432 return mPhone.getPcscfAddress(apnType);
3433 } finally {
3434 Binder.restoreCallingIdentity(identity);
3435 }
Wink Saville36469e72014-06-11 15:17:00 -07003436 }
3437
Brad Ebinger51f743a2017-01-23 13:50:20 -08003438 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003439 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3440 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003441 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003442 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003443 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 PhoneFactory.getImsResolver().enableIms(slotId);
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003451 }
3452
3453 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003454 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3455 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003456 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003457 public void disableIms(int slotId) {
3458 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003459
3460 final long identity = Binder.clearCallingIdentity();
3461 try {
3462 PhoneFactory.getImsResolver().disableIms(slotId);
3463 } finally {
3464 Binder.restoreCallingIdentity(identity);
3465 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003466 }
3467
3468 /**
3469 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3470 * feature or {@link null} if the service is not available. If the feature is available, the
3471 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3472 */
3473 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003474 IImsServiceFeatureCallback callback) {
3475 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003476
3477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3480 } finally {
3481 Binder.restoreCallingIdentity(identity);
3482 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003483 }
3484
3485 /**
3486 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3487 * feature during emergency calling or {@link null} if the service is not available. If the
3488 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3489 * listener for feature updates.
3490 */
3491 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493
3494 final long identity = Binder.clearCallingIdentity();
3495 try {
3496 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003500 }
3501
Brad Ebinger5f64b052017-12-14 14:26:15 -08003502 /**
3503 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3504 * specified.
3505 */
3506 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003508
3509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003515 }
3516
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003517 /**
3518 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3519 * specified.
3520 */
3521 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3522 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523
3524 final long identity = Binder.clearCallingIdentity();
3525 try {
3526 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003530 }
3531
Brad Ebinger884c07b2018-02-15 16:17:40 -08003532 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003533 * Sets the ImsService Package Name that Telephony will bind to.
3534 *
3535 * @param slotId the slot ID that the ImsService should bind for.
3536 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3537 * ImsService is the device default ImsService.
3538 * @param packageName The package name of the application that contains the ImsService to bind
3539 * to.
3540 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3541 * @hide
3542 */
3543 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003544 int[] subIds = SubscriptionManager.getSubId(slotId);
3545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3546 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3547 "setImsService");
3548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3552 isCarrierImsService, packageName);
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003556 }
3557
3558 /**
3559 * Return the ImsService configuration.
3560 *
3561 * @param slotId The slot that the ImsService is associated with.
3562 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3563 * the device default.
3564 * @return the package name of the ImsService configuration.
3565 */
3566 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003567 int[] subIds = SubscriptionManager.getSubId(slotId);
3568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3569 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3570 "getImsService");
3571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3575 isCarrierImsService);
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003579 }
3580
Wink Saville36469e72014-06-11 15:17:00 -07003581 public void setImsRegistrationState(boolean registered) {
3582 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583
3584 final long identity = Binder.clearCallingIdentity();
3585 try {
3586 mPhone.setImsRegistrationState(registered);
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
Wink Saville36469e72014-06-11 15:17:00 -07003590 }
3591
3592 /**
Stuart Scott54788802015-03-30 13:18:01 -07003593 * Set the network selection mode to automatic.
3594 *
3595 */
3596 @Override
3597 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3599 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003600
Pengquan Menge92a50d2018-09-21 15:54:48 -07003601 if (!isActiveSubscription(subId)) {
3602 return;
3603 }
3604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605 final long identity = Binder.clearCallingIdentity();
3606 try {
3607 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3608 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
3611 }
Stuart Scott54788802015-03-30 13:18:01 -07003612 }
3613
Pengquan Mengea84e042018-09-20 14:57:26 -07003614 /**
3615 * Ask the radio to connect to the input network and change selection mode to manual.
3616 *
3617 * @param subId the id of the subscription.
3618 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3619 * the operator to attach to.
3620 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3621 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3622 * normal network selection next time.
3623 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003624 */
3625 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003626 public boolean setNetworkSelectionModeManual(
3627 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3629 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003630
3631 if (!isActiveSubscription(subId)) {
3632 return false;
3633 }
3634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635 final long identity = Binder.clearCallingIdentity();
3636 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003637 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003639 if (DBG) {
3640 log("setNetworkSelectionModeManual: subId: " + subId
3641 + " operator: " + operatorInfo);
3642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003647 }
3648
3649 /**
3650 * Scans for available networks.
3651 */
3652 @Override
3653 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3655 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656
Pengquan Menga1bb6272018-09-06 09:59:22 -07003657 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658 try {
3659 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003660 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003665 }
3666
3667 /**
yinxub1bed742017-04-17 11:45:04 -07003668 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003669 *
yinxub1bed742017-04-17 11:45:04 -07003670 * @param subId id of the subscription
3671 * @param request contains the radio access networks with bands/channels to scan
3672 * @param messenger callback messenger for scan results or errors
3673 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003674 * @return the id of the requested scan which can be used to stop the scan.
3675 */
3676 @Override
3677 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3678 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3680 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681
3682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 return mNetworkScanRequestTracker.startNetworkScan(
3685 request, messenger, binder, getPhone(subId));
3686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
yinxu504e1392017-04-12 16:03:22 -07003689 }
3690
3691 /**
3692 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003693 *
3694 * @param subId id of the subscription
3695 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003696 */
3697 @Override
3698 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3700 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701
3702 final long identity = Binder.clearCallingIdentity();
3703 try {
3704 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
yinxu504e1392017-04-12 16:03:22 -07003708 }
3709
3710 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003711 * Get the calculated preferred network type.
3712 * Used for debugging incorrect network type.
3713 *
3714 * @return the preferred network type, defined in RILConstants.java.
3715 */
3716 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003717 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003719 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003720 return RILConstants.PREFERRED_NETWORK_MODE;
3721 }
3722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 // FIXME: need to get SubId from somewhere.
3726 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
Junda Liu84d15a22014-07-02 11:21:04 -07003730 }
3731
3732 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003733 * Get the preferred network type.
3734 * Used for device configuration by some CDMA operators.
3735 *
3736 * @return the preferred network type, defined in RILConstants.java.
3737 */
3738 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003739 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3741 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 if (DBG) log("getPreferredNetworkType");
3746 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3747 int networkType = (result != null ? result[0] : -1);
3748 if (DBG) log("getPreferredNetworkType: " + networkType);
3749 return networkType;
3750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003753 }
3754
3755 /**
3756 * Set the preferred network type.
3757 * Used for device configuration by some CDMA operators.
3758 *
3759 * @param networkType the preferred network type, defined in RILConstants.java.
3760 * @return true on success; false on any failure.
3761 */
3762 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003763 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3765 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766
3767 final long identity = Binder.clearCallingIdentity();
3768 try {
3769 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3770 Boolean success = (Boolean) sendRequest(
3771 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3772 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3773 if (success) {
3774 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3775 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3776 }
3777 return success;
3778 } finally {
3779 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003780 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003781 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003782
3783 /**
Junda Liu475951f2014-11-07 16:45:03 -08003784 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3785 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3786 * tethering.
3787 *
3788 * @return 0: Not required. 1: required. 2: Not set.
3789 * @hide
3790 */
3791 @Override
3792 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003793 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794
3795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3798 Settings.Global.TETHER_DUN_REQUIRED, 2);
3799 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3800 // config_tether_apndata.
3801 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3802 dunRequired = 1;
3803 }
3804 return dunRequired;
3805 } finally {
3806 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003807 }
Junda Liu475951f2014-11-07 16:45:03 -08003808 }
3809
3810 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003811 * Set mobile data enabled
3812 * Used by the user through settings etc to turn on/off mobile data
3813 *
3814 * @param enable {@code true} turn turn data on, else {@code false}
3815 */
3816 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003817 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3819 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820
3821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 int phoneId = mSubscriptionController.getPhoneId(subId);
3824 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3825 Phone phone = PhoneFactory.getPhone(phoneId);
3826 if (phone != null) {
3827 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3828 phone.setUserDataEnabled(enable);
3829 } else {
3830 loge("setUserDataEnabled: no phone for subId=" + subId);
3831 }
3832 } finally {
3833 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003834 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003835 }
3836
3837 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003838 * Get the user enabled state of Mobile Data.
3839 *
3840 * TODO: remove and use isUserDataEnabled.
3841 * This can't be removed now because some vendor codes
3842 * calls through ITelephony directly while they should
3843 * use TelephonyManager.
3844 *
3845 * @return true on enabled
3846 */
3847 @Override
3848 public boolean getDataEnabled(int subId) {
3849 return isUserDataEnabled(subId);
3850 }
3851
3852 /**
3853 * Get whether mobile data is enabled per user setting.
3854 *
3855 * There are other factors deciding whether mobile data is actually enabled, but they are
3856 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003857 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003858 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003859 *
3860 * @return {@code true} if data is enabled else {@code false}
3861 */
3862 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003863 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003864 try {
3865 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3866 null);
3867 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3869 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871
3872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 int phoneId = mSubscriptionController.getPhoneId(subId);
3875 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3876 Phone phone = PhoneFactory.getPhone(phoneId);
3877 if (phone != null) {
3878 boolean retVal = phone.isUserDataEnabled();
3879 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3880 return retVal;
3881 } else {
3882 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3883 return false;
3884 }
3885 } finally {
3886 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003887 }
3888 }
3889
3890 /**
3891 * Get whether mobile data is enabled.
3892 *
3893 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3894 * whether mobile data is actually enabled.
3895 *
3896 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3897 *
3898 * @return {@code true} if data is enabled else {@code false}
3899 */
3900 @Override
3901 public boolean isDataEnabled(int subId) {
3902 try {
3903 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3904 null);
3905 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3907 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909
3910 final long identity = Binder.clearCallingIdentity();
3911 try {
3912 int phoneId = mSubscriptionController.getPhoneId(subId);
3913 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3914 Phone phone = PhoneFactory.getPhone(phoneId);
3915 if (phone != null) {
3916 boolean retVal = phone.isDataEnabled();
3917 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3918 return retVal;
3919 } else {
3920 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3921 return false;
3922 }
3923 } finally {
3924 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003925 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003926 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003927
3928 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003929 public int getCarrierPrivilegeStatus(int subId) {
3930 final Phone phone = getPhone(subId);
3931 if (phone == null) {
3932 loge("getCarrierPrivilegeStatus: Invalid subId");
3933 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3934 }
3935 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003936 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003937 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003938 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3939 }
3940 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003941 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003942 }
Junda Liu29340342014-07-10 15:23:27 -07003943
3944 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003945 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3946 final Phone phone = getPhone(subId);
3947 if (phone == null) {
3948 loge("getCarrierPrivilegeStatus: Invalid subId");
3949 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3950 }
3951 UiccProfile profile =
3952 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3953 if (profile == null) {
3954 loge("getCarrierPrivilegeStatus: No UICC");
3955 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3956 }
3957 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3958 }
3959
3960 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003961 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003962 if (TextUtils.isEmpty(pkgName))
3963 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003964 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003965 if (card == null) {
3966 loge("checkCarrierPrivilegesForPackage: No UICC");
3967 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3968 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003969 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3970 }
3971
3972 @Override
3973 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003974 if (TextUtils.isEmpty(pkgName))
3975 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003976 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3977 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3978 UiccCard card = UiccController.getInstance().getUiccCard(i);
3979 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003980 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003981 continue;
3982 }
3983
3984 result = card.getCarrierPrivilegeStatus(
3985 mPhone.getContext().getPackageManager(), pkgName);
3986 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3987 break;
3988 }
3989 }
3990
3991 return result;
Junda Liu29340342014-07-10 15:23:27 -07003992 }
Derek Tan89e89d42014-07-08 17:00:10 -07003993
3994 @Override
Junda Liue64de782015-04-16 17:19:16 -07003995 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3996 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3997 loge("phoneId " + phoneId + " is not valid.");
3998 return null;
3999 }
4000 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004001 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004002 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004003 return null ;
4004 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004005 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004006 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004007 }
4008
Amith Yamasani6e118872016-02-19 12:53:51 -08004009 @Override
4010 public List<String> getPackagesWithCarrierPrivileges() {
4011 PackageManager pm = mPhone.getContext().getPackageManager();
4012 List<String> privilegedPackages = new ArrayList<>();
4013 List<PackageInfo> packages = null;
4014 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4015 UiccCard card = UiccController.getInstance().getUiccCard(i);
4016 if (card == null) {
4017 // No UICC in that slot.
4018 continue;
4019 }
4020 if (card.hasCarrierPrivilegeRules()) {
4021 if (packages == null) {
4022 // Only check packages in user 0 for now
4023 packages = pm.getInstalledPackagesAsUser(
4024 PackageManager.MATCH_DISABLED_COMPONENTS
4025 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4026 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4027 }
4028 for (int p = packages.size() - 1; p >= 0; p--) {
4029 PackageInfo pkgInfo = packages.get(p);
4030 if (pkgInfo != null && pkgInfo.packageName != null
4031 && card.getCarrierPrivilegeStatus(pkgInfo)
4032 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4033 privilegedPackages.add(pkgInfo.packageName);
4034 }
4035 }
4036 }
4037 }
4038 return privilegedPackages;
4039 }
4040
Wink Savilleb564aae2014-10-23 10:18:09 -07004041 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004042 final Phone phone = getPhone(subId);
4043 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004044 if (card == null) {
4045 loge("getIccId: No UICC");
4046 return null;
4047 }
4048 String iccId = card.getIccId();
4049 if (TextUtils.isEmpty(iccId)) {
4050 loge("getIccId: ICC ID is null or empty.");
4051 return null;
4052 }
4053 return iccId;
4054 }
4055
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004056 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004057 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4058 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004059 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4060 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062 final long identity = Binder.clearCallingIdentity();
4063 try {
4064 final String iccId = getIccId(subId);
4065 final Phone phone = getPhone(subId);
4066 if (phone == null) {
4067 return false;
4068 }
4069 final String subscriberId = phone.getSubscriberId();
4070
4071 if (DBG_MERGE) {
4072 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4073 + subscriberId + " to " + number);
4074 }
4075
4076 if (TextUtils.isEmpty(iccId)) {
4077 return false;
4078 }
4079
4080 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4081
4082 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4083 if (alphaTag == null) {
4084 editor.remove(alphaTagPrefKey);
4085 } else {
4086 editor.putString(alphaTagPrefKey, alphaTag);
4087 }
4088
4089 // Record both the line number and IMSI for this ICCID, since we need to
4090 // track all merged IMSIs based on line number
4091 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4092 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4093 if (number == null) {
4094 editor.remove(numberPrefKey);
4095 editor.remove(subscriberPrefKey);
4096 } else {
4097 editor.putString(numberPrefKey, number);
4098 editor.putString(subscriberPrefKey, subscriberId);
4099 }
4100
4101 editor.commit();
4102 return true;
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004105 }
Derek Tan7226c842014-07-02 17:42:23 -07004106 }
4107
4108 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004109 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004110 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004112 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004113 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004114 return null;
4115 }
Derek Tan97ebb422014-09-05 16:55:38 -07004116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 String iccId = getIccId(subId);
4120 if (iccId != null) {
4121 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4122 if (DBG_MERGE) {
4123 log("getLine1NumberForDisplay returning "
4124 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4125 }
4126 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4129 return null;
4130 } finally {
4131 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004132 }
Derek Tan7226c842014-07-02 17:42:23 -07004133 }
4134
4135 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004136 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004138 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004139 return null;
4140 }
Derek Tan97ebb422014-09-05 16:55:38 -07004141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 String iccId = getIccId(subId);
4145 if (iccId != null) {
4146 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4147 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4148 }
4149 return null;
4150 } finally {
4151 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004152 }
Derek Tan7226c842014-07-02 17:42:23 -07004153 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004154
4155 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004156 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004157 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4158 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004160 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4161 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004162 return null;
4163 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004164
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004165 final long identity = Binder.clearCallingIdentity();
4166 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004167 final Context context = mPhone.getContext();
4168 final TelephonyManager tele = TelephonyManager.from(context);
4169 final SubscriptionManager sub = SubscriptionManager.from(context);
4170
4171 // Figure out what subscribers are currently active
4172 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4173 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4174 // the process, where TelephonyManager was instantiated.
4175 // Otherwise AppOps check will fail.
4176
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004177 final int[] subIds = sub.getActiveSubscriptionIdList();
4178 for (int subId : subIds) {
4179 activeSubscriberIds.add(tele.getSubscriberId(subId));
4180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181
4182 // First pass, find a number override for an active subscriber
4183 String mergeNumber = null;
4184 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4185 for (String key : prefs.keySet()) {
4186 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4187 final String subscriberId = (String) prefs.get(key);
4188 if (activeSubscriberIds.contains(subscriberId)) {
4189 final String iccId = key.substring(
4190 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4191 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4192 mergeNumber = (String) prefs.get(numberKey);
4193 if (DBG_MERGE) {
4194 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4195 + " for active subscriber " + subscriberId);
4196 }
4197 if (!TextUtils.isEmpty(mergeNumber)) {
4198 break;
4199 }
4200 }
4201 }
4202 }
4203
4204 // Shortcut when no active merged subscribers
4205 if (TextUtils.isEmpty(mergeNumber)) {
4206 return null;
4207 }
4208
4209 // Second pass, find all subscribers under that line override
4210 final ArraySet<String> result = new ArraySet<>();
4211 for (String key : prefs.keySet()) {
4212 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4213 final String number = (String) prefs.get(key);
4214 if (mergeNumber.equals(number)) {
4215 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4216 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4217 final String subscriberId = (String) prefs.get(subscriberKey);
4218 if (!TextUtils.isEmpty(subscriberId)) {
4219 result.add(subscriberId);
4220 }
4221 }
4222 }
4223 }
4224
4225 final String[] resultArray = result.toArray(new String[result.size()]);
4226 Arrays.sort(resultArray);
4227 if (DBG_MERGE) {
4228 Slog.d(LOG_TAG,
4229 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4230 }
4231 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004232 } finally {
4233 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004234 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004235 }
4236
4237 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004238 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004239 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4240 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004241
4242 final long identity = Binder.clearCallingIdentity();
4243 try {
4244 final Phone phone = getPhone(subId);
4245 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004249 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004250
4251 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004252 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004253 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4254 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004255 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256
4257 final long identity = Binder.clearCallingIdentity();
4258 try {
4259 final Phone phone = getPhone(subId);
4260 if (phone == null) {
4261 return false;
4262 }
4263 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4264 cdmaNonRoamingList);
4265 } finally {
4266 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004267 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004268 }
4269
4270 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004271 @Deprecated
4272 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4273 enforceModifyPermission();
4274
4275 int returnValue = 0;
4276 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004277 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004278 if(result.exception == null) {
4279 if (result.result != null) {
4280 byte[] responseData = (byte[])(result.result);
4281 if(responseData.length > oemResp.length) {
4282 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4283 responseData.length + "bytes. Buffer Size is " +
4284 oemResp.length + "bytes.");
4285 }
4286 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4287 returnValue = responseData.length;
4288 }
4289 } else {
4290 CommandException ex = (CommandException) result.exception;
4291 returnValue = ex.getCommandError().ordinal();
4292 if(returnValue > 0) returnValue *= -1;
4293 }
4294 } catch (RuntimeException e) {
4295 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4296 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4297 if(returnValue > 0) returnValue *= -1;
4298 }
4299
4300 return returnValue;
4301 }
4302
4303 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004304 public void setRadioCapability(RadioAccessFamily[] rafs) {
4305 try {
4306 ProxyController.getInstance().setRadioCapability(rafs);
4307 } catch (RuntimeException e) {
4308 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4309 }
4310 }
4311
4312 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004313 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004314 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004315 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004316 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004317 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 final long identity = Binder.clearCallingIdentity();
4320 try {
chen xub97461a2018-10-26 14:17:57 -07004321 TelephonyPermissions
4322 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4323 mApp, phone.getSubId(), "getRadioAccessFamily");
4324 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
chen xub97461a2018-10-26 14:17:57 -07004328 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004329 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004330
4331 @Override
4332 public void enableVideoCalling(boolean enable) {
4333 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334
4335 final long identity = Binder.clearCallingIdentity();
4336 try {
4337 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004341 }
4342
4343 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004344 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4346 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4347 return false;
4348 }
Svet Ganovb320e182015-04-16 12:30:10 -07004349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 // Check the user preference and the system-level IMS setting. Even if the user has
4353 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4354 // In the long run, we may instead need to check if there exists a connection service
4355 // which can support video calling.
4356 ImsManager imsManager =
4357 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4358 return imsManager.isVtEnabledByPlatform()
4359 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4360 && imsManager.isVtEnabledByUser();
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004364 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004365
Andrew Leea1239f22015-03-02 17:44:07 -08004366 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4369 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4370 return false;
4371 }
4372
4373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 CarrierConfigManager configManager =
4376 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4377 return configManager.getConfigForSubId(mPhone.getSubId())
4378 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
Andrew Leea1239f22015-03-02 17:44:07 -08004382 }
4383
4384 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385 public boolean isWorldPhone(int subId, String callingPackage) {
4386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4387 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4388 return false;
4389 }
4390
4391 final long identity = Binder.clearCallingIdentity();
4392 try {
4393 CarrierConfigManager configManager =
4394 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4395 return configManager.getConfigForSubId(mPhone.getSubId())
4396 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
Andrew Leea1239f22015-03-02 17:44:07 -08004400 }
4401
Andrew Lee9431b832015-03-09 18:46:45 -07004402 @Override
4403 public boolean isTtyModeSupported() {
4404 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004405 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004406 }
4407
4408 @Override
4409 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 final long identity = Binder.clearCallingIdentity();
4411 try {
4412 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
4415 }
Andrew Lee9431b832015-03-09 18:46:45 -07004416 }
4417
Hall Liu98187582018-01-22 19:15:32 -08004418 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4422 mPhone.getSubId()).getBoolean(
4423 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4424 boolean isDeviceSupported =
4425 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4426 return isCarrierSupported && isDeviceSupported;
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
Hall Liu98187582018-01-22 19:15:32 -08004430 }
4431
Hall Liu3ad5f012018-04-06 16:23:39 -07004432 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 final long identity = Binder.clearCallingIdentity();
4434 try {
4435 return isRttSupported() && Settings.Secure.getInt(
4436 mPhone.getContext().getContentResolver(),
4437 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4438 } finally {
4439 Binder.restoreCallingIdentity(identity);
4440 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004441 }
4442
Sanket Padawe7310cc72015-01-14 09:53:20 -08004443 /**
4444 * Returns the unique device ID of phone, for example, the IMEI for
4445 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4446 *
4447 * <p>Requires Permission:
4448 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4449 */
4450 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004451 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004452 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004453 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004454 return null;
4455 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004456 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004457 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4458 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004459 return null;
4460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
4464 return phone.getDeviceId();
4465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004468 }
4469
Ping Sunc67b7c22016-03-02 19:16:45 +08004470 /**
4471 * {@hide}
4472 * Returns the IMS Registration Status on a particular subid
4473 *
4474 * @param subId
4475 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004476 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004477 Phone phone = getPhone(subId);
4478 if (phone != null) {
4479 return phone.isImsRegistered();
4480 } else {
4481 return false;
4482 }
4483 }
4484
Santos Cordon7a1885b2015-02-03 11:15:19 -08004485 @Override
4486 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 final long identity = Binder.clearCallingIdentity();
4488 try {
4489 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004493 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004494
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004495 /**
4496 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004497 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004498 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 final long identity = Binder.clearCallingIdentity();
4500 try {
4501 Phone phone = getPhone(subId);
4502 if (phone != null) {
4503 return phone.isWifiCallingEnabled();
4504 } else {
4505 return false;
4506 }
4507 } finally {
4508 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004509 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004510 }
4511
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004512 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004513 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004514 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004515 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 final long identity = Binder.clearCallingIdentity();
4517 try {
4518 Phone phone = getPhone(subId);
4519 if (phone != null) {
4520 return phone.isVideoEnabled();
4521 } else {
4522 return false;
4523 }
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004526 }
4527 }
4528
4529 /**
4530 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4531 * defined in {@link ImsRegistrationImplBase}.
4532 */
4533 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 final long identity = Binder.clearCallingIdentity();
4535 try {
4536 Phone phone = getPhone(subId);
4537 if (phone != null) {
4538 return phone.getImsRegistrationTech();
4539 } else {
4540 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4541 }
4542 } finally {
4543 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004544 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004545 }
4546
Stuart Scott8eef64f2015-04-08 15:13:54 -07004547 @Override
4548 public void factoryReset(int subId) {
4549 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004550 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4551 return;
4552 }
4553
Svet Ganovcc087f82015-05-12 20:35:54 -07004554 final long identity = Binder.clearCallingIdentity();
4555 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004556 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4557 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004558 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004559 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004560 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4561 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004562 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004563 }
4564 } finally {
4565 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004566 }
4567 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004568
4569 @Override
4570 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 final long identity = Binder.clearCallingIdentity();
4572 try {
4573 // We query all subscriptions instead of just the active ones, because
4574 // this might be called early on in the provisioning flow when the
4575 // subscriptions potentially aren't active yet.
4576 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4577 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004578 return null;
4579 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 // This function may be called very early, say, from the setup wizard, at
4582 // which point we won't have a default subscription set. If that's the case
4583 // we just choose the first, which will be valid in "most cases".
4584 final int defaultSubId = getDefaultSubscription();
4585 SubscriptionInfo info = null;
4586 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4587 info = slist.get(0);
4588 } else {
4589 for (SubscriptionInfo item : slist) {
4590 if (item.getSubscriptionId() == defaultSubId) {
4591 info = item;
4592 break;
4593 }
4594 }
4595
4596 if (info == null) {
4597 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004598 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004599 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 // Try and fetch the locale from the carrier properties or from the SIM language
4602 // preferences (EF-PL and EF-LI)...
4603 final int mcc = info.getMcc();
4604 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4605 String simLanguage = null;
4606 if (defaultPhone != null) {
4607 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4608 if (localeFromDefaultSim != null) {
4609 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4610 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4611 return localeFromDefaultSim.toLanguageTag();
4612 } else {
4613 simLanguage = localeFromDefaultSim.getLanguage();
4614 }
4615 }
4616 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004618 // The SIM language preferences only store a language (e.g. fr = French), not an
4619 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4620 // the SIM and carrier preferences does not include a country we add the country
4621 // determined from the SIM MCC to provide an exact locale.
4622 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4623 simLanguage);
4624 if (mccLocale != null) {
4625 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4626 return mccLocale.toLanguageTag();
4627 }
4628
4629 if (DBG) log("No locale found - returning null");
4630 return null;
4631 } finally {
4632 Binder.restoreCallingIdentity(identity);
4633 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004634 }
4635
4636 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 return mSubscriptionController.getAllSubInfoList(
4638 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004639 }
4640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 /**
4642 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4643 */
4644 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4645 return mSubscriptionController.getActiveSubscriptionInfoList(
4646 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004647 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004648
Chenjie Yu1ba97252018-01-11 18:16:20 -08004649 private final ModemActivityInfo mLastModemActivityInfo =
4650 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4651
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004652 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004653 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4654 * representing the state of the modem.
4655 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004656 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4657 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004658 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004659 */
4660 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004661 public void requestModemActivityInfo(ResultReceiver result) {
4662 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004663 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664
4665 final long identity = Binder.clearCallingIdentity();
4666 try {
4667 ModemActivityInfo ret = null;
4668 synchronized (mLastModemActivityInfo) {
4669 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4670 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004671 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004672 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4674 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4675 mergedTxTimeMs[i] =
4676 info.getTxTimeMillis()[i]
4677 + mLastModemActivityInfo.getTxTimeMillis()[i];
4678 }
4679 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4680 mLastModemActivityInfo.setSleepTimeMillis(
4681 info.getSleepTimeMillis()
4682 + mLastModemActivityInfo.getSleepTimeMillis());
4683 mLastModemActivityInfo.setIdleTimeMillis(
4684 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4685 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4686 mLastModemActivityInfo.setRxTimeMillis(
4687 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4688 mLastModemActivityInfo.setEnergyUsed(
4689 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4692 mLastModemActivityInfo.getSleepTimeMillis(),
4693 mLastModemActivityInfo.getIdleTimeMillis(),
4694 mLastModemActivityInfo.getTxTimeMillis(),
4695 mLastModemActivityInfo.getRxTimeMillis(),
4696 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 Bundle bundle = new Bundle();
4699 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4700 result.send(0, bundle);
4701 } finally {
4702 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004703 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004704 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004705
Siddharth Rayb8114062018-06-17 15:02:38 -07004706 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4707 // less than total activity duration.
4708 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4709 if (info == null) {
4710 return false;
4711 }
4712 int activityDurationMs =
4713 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4714 int totalTxTimeMs = 0;
4715 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4716 totalTxTimeMs += info.getTxTimeMillis()[i];
4717 }
4718 return (info.isValid()
4719 && (info.getSleepTimeMillis() <= activityDurationMs)
4720 && (info.getIdleTimeMillis() <= activityDurationMs)
4721 && (info.getRxTimeMillis() <= activityDurationMs)
4722 && (totalTxTimeMs <= activityDurationMs));
4723 }
4724
Jack Yu85bd38a2015-11-09 11:34:32 -08004725 /**
4726 * {@hide}
4727 * Returns the service state information on specified subscription.
4728 */
4729 @Override
4730 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004731 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004732 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004733 return null;
4734 }
4735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736 final long identity = Binder.clearCallingIdentity();
4737 try {
4738 final Phone phone = getPhone(subId);
4739 if (phone == null) {
4740 return null;
4741 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 return phone.getServiceState();
4744 } finally {
4745 Binder.restoreCallingIdentity(identity);
4746 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004747 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004748
4749 /**
4750 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4751 *
4752 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4753 * voicemail ringtone.
4754 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4755 * PhoneAccount.
4756 */
4757 @Override
4758 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4762 if (phone == null) {
4763 phone = mPhone;
4764 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4767 } finally {
4768 Binder.restoreCallingIdentity(identity);
4769 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004770 }
4771
4772 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004773 * Sets the per-account voicemail ringtone.
4774 *
4775 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4776 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4777 *
4778 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4779 * voicemail ringtone.
4780 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4781 * PhoneAccount.
4782 */
4783 @Override
4784 public void setVoicemailRingtoneUri(String callingPackage,
4785 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4787 if (!TextUtils.equals(callingPackage,
4788 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4790 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4791 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793
4794 final long identity = Binder.clearCallingIdentity();
4795 try {
4796 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4797 if (phone == null) {
4798 phone = mPhone;
4799 }
4800 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4801 } finally {
4802 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004803 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004804 }
4805
4806 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004807 * Returns whether vibration is set for voicemail notification in Phone settings.
4808 *
4809 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4810 * voicemail vibration setting.
4811 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4812 */
4813 @Override
4814 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 final long identity = Binder.clearCallingIdentity();
4816 try {
4817 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4818 if (phone == null) {
4819 phone = mPhone;
4820 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4823 } finally {
4824 Binder.restoreCallingIdentity(identity);
4825 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004826 }
4827
Youhan Wange64578a2016-05-02 15:32:42 -07004828 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004829 * Sets the per-account voicemail vibration.
4830 *
4831 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4832 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4833 *
4834 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4835 * voicemail vibration setting.
4836 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4837 * specific PhoneAccount.
4838 */
4839 @Override
4840 public void setVoicemailVibrationEnabled(String callingPackage,
4841 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4842 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4843 if (!TextUtils.equals(callingPackage,
4844 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4846 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4847 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004848 }
4849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4853 if (phone == null) {
4854 phone = mPhone;
4855 }
4856 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4857 } finally {
4858 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004859 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004860 }
4861
4862 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004863 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4864 *
4865 * @throws SecurityException if the caller does not have the required permission
4866 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004867 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004869 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004870 }
4871
4872 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004873 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4874 * permission.
4875 *
4876 * @throws SecurityException if the caller does not have the required permission
4877 */
4878 private void enforceSendSmsPermission() {
4879 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4880 }
4881
4882 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004883 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004884 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004885 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004886 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004887 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
4890 ComponentName componentName =
4891 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4892 if (componentName == null) {
4893 throw new SecurityException(
4894 "Caller not current active visual voicemail package[null]");
4895 }
4896 String vvmPackage = componentName.getPackageName();
4897 if (!callingPackage.equals(vvmPackage)) {
4898 throw new SecurityException("Caller not current active visual voicemail package["
4899 + vvmPackage + "]");
4900 }
4901 } finally {
4902 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004903 }
4904 }
4905
4906 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004907 * Return the application ID for the app type.
4908 *
4909 * @param subId the subscription ID that this request applies to.
4910 * @param appType the uicc app type.
4911 * @return Application ID for specificied app type, or null if no uicc.
4912 */
4913 @Override
4914 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004915 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07004916 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917
4918 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004919 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004920 if (phone == null) {
4921 return null;
4922 }
4923 String aid = null;
4924 try {
4925 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4926 .getApplicationByType(appType).getAid();
4927 } catch (Exception e) {
4928 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4929 }
4930 return aid;
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004933 }
Youhan Wange64578a2016-05-02 15:32:42 -07004934 }
4935
Youhan Wang4001d252016-05-11 10:29:41 -07004936 /**
4937 * Return the Electronic Serial Number.
4938 *
4939 * @param subId the subscription ID that this request applies to.
4940 * @return ESN or null if error.
4941 */
4942 @Override
4943 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004944 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07004945 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946
4947 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004948 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 if (phone == null) {
4950 return null;
4951 }
4952 String esn = null;
4953 try {
4954 esn = phone.getEsn();
4955 } catch (Exception e) {
4956 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4957 }
4958 return esn;
4959 } finally {
4960 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004961 }
Youhan Wang4001d252016-05-11 10:29:41 -07004962 }
4963
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004964 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004965 * Return the Preferred Roaming List Version.
4966 *
4967 * @param subId the subscription ID that this request applies to.
4968 * @return PRLVersion or null if error.
4969 */
4970 @Override
4971 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07004973 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974
4975 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004976 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 if (phone == null) {
4978 return null;
4979 }
4980 String cdmaPrlVersion = null;
4981 try {
4982 cdmaPrlVersion = phone.getCdmaPrlVersion();
4983 } catch (Exception e) {
4984 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4985 }
4986 return cdmaPrlVersion;
4987 } finally {
4988 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004989 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004990 }
4991
4992 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004993 * Get snapshot of Telephony histograms
4994 * @return List of Telephony histograms
4995 * @hide
4996 */
4997 @Override
4998 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5000 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001
5002 final long identity = Binder.clearCallingIdentity();
5003 try {
5004 return RIL.getTelephonyRILTimingHistograms();
5005 } finally {
5006 Binder.restoreCallingIdentity(identity);
5007 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005008 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005009
5010 /**
5011 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005012 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005013 * Require system privileges. In the future we may add this to carrier APIs.
5014 *
5015 * @return The number of carriers set successfully, should match length of carriers
5016 */
5017 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005018 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005019 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005021
Meng Wang9b7c4e92017-02-17 11:41:27 -08005022 if (carriers == null) {
5023 throw new NullPointerException("carriers cannot be null");
5024 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005029 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5030 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 return retVal[0];
5032 } finally {
5033 Binder.restoreCallingIdentity(identity);
5034 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005035 }
5036
5037 /**
5038 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005039 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005040 * Require system privileges. In the future we may add this to carrier APIs.
5041 *
5042 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5043 * means all carriers are allowed.
5044 */
5045 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005046 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005047 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005048 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049
5050 final long identity = Binder.clearCallingIdentity();
5051 try {
5052 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005053 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5054 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005055 } finally {
5056 Binder.restoreCallingIdentity(identity);
5057 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005058 }
5059
fionaxu59545b42016-05-25 15:53:37 -07005060 /**
5061 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5062 * @param subId the subscription ID that this action applies to.
5063 * @param enabled control enable or disable metered apns.
5064 * {@hide}
5065 */
5066 @Override
5067 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5068 enforceModifyPermission();
5069 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070
5071 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005072 if (phone == null) {
5073 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5074 return;
5075 }
5076 try {
5077 phone.carrierActionSetMeteredApnsEnabled(enabled);
5078 } catch (Exception e) {
5079 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 } finally {
5081 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005082 }
5083 }
5084
5085 /**
5086 * Action set from carrier signalling broadcast receivers to enable/disable radio
5087 * @param subId the subscription ID that this action applies to.
5088 * @param enabled control enable or disable radio.
5089 * {@hide}
5090 */
5091 @Override
5092 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5093 enforceModifyPermission();
5094 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095
5096 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005097 if (phone == null) {
5098 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5099 return;
5100 }
5101 try {
5102 phone.carrierActionSetRadioEnabled(enabled);
5103 } catch (Exception e) {
5104 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 } finally {
5106 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005107 }
5108 }
5109
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005110 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005111 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5112 * network status based on which carrier apps could apply actions accordingly,
5113 * enable/disable default url handler for example.
5114 *
5115 * @param subId the subscription ID that this action applies to.
5116 * @param report control start/stop reporting the default network status.
5117 * {@hide}
5118 */
5119 @Override
5120 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5121 enforceModifyPermission();
5122 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123
5124 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005125 if (phone == null) {
5126 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5127 return;
5128 }
5129 try {
5130 phone.carrierActionReportDefaultNetworkStatus(report);
5131 } catch (Exception e) {
5132 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005135 }
5136 }
5137
5138 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005139 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5140 * bug report is being generated.
5141 */
5142 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005143 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005144 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5145 != PackageManager.PERMISSION_GRANTED) {
5146 writer.println("Permission Denial: can't dump Phone from pid="
5147 + Binder.getCallingPid()
5148 + ", uid=" + Binder.getCallingUid()
5149 + "without permission "
5150 + android.Manifest.permission.DUMP);
5151 return;
5152 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005153 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005154 }
Jack Yueb89b242016-06-22 13:27:47 -07005155
Brad Ebingerdac2f002018-04-03 15:17:52 -07005156 @Override
5157 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5158 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5159 throws RemoteException {
5160 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5161 }
5162
Jack Yueb89b242016-06-22 13:27:47 -07005163 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005164 * Get aggregated video call data usage since boot.
5165 *
5166 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5167 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005168 * {@hide}
5169 */
5170 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005171 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005172 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5173 null);
5174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 final long identity = Binder.clearCallingIdentity();
5176 try {
5177 // NetworkStatsService keeps tracking the active network interface and identity. It
5178 // records the delta with the corresponding network identity.
5179 // We just return the total video call data usage snapshot since boot.
5180 Phone phone = getPhone(subId);
5181 if (phone != null) {
5182 return phone.getVtDataUsage(perUidStats);
5183 }
5184 return null;
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005187 }
Jack Yueb89b242016-06-22 13:27:47 -07005188 }
Jack Yu75ab2952016-07-08 14:29:33 -07005189
5190 /**
5191 * Policy control of data connection. Usually used when data limit is passed.
5192 * @param enabled True if enabling the data, otherwise disabling.
5193 * @param subId Subscription index
5194 * {@hide}
5195 */
5196 @Override
5197 public void setPolicyDataEnabled(boolean enabled, int subId) {
5198 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199
5200 final long identity = Binder.clearCallingIdentity();
5201 try {
5202 Phone phone = getPhone(subId);
5203 if (phone != null) {
5204 phone.setPolicyDataEnabled(enabled);
5205 }
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005208 }
5209 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005210
5211 /**
5212 * Get Client request stats
5213 * @return List of Client Request Stats
5214 * @hide
5215 */
5216 @Override
5217 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005219 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005220 return null;
5221 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005222 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 if (phone != null) {
5227 return phone.getClientRequestStats();
5228 }
5229
5230 return null;
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005234 }
5235
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005236 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005237 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005238 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005239 }
Jack Yueb4124c2017-02-16 15:32:43 -08005240
5241 /**
Grace Chen70990072017-03-24 17:21:30 -07005242 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005243 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005244 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005245 * @param state State of SIM (power down, power up, pass through)
5246 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5247 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5248 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005249 *
5250 **/
5251 @Override
Grace Chen70990072017-03-24 17:21:30 -07005252 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005253 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005254 Phone phone = PhoneFactory.getPhone(slotIndex);
5255
vagdeviaf9a5b92018-08-15 16:01:53 -07005256 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 final long identity = Binder.clearCallingIdentity();
5259 try {
5260 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005261 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 }
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005265 }
5266 }
Shuo Qiandd210312017-04-12 22:11:33 +00005267
Tyler Gunn65d45c22017-06-05 11:22:26 -07005268 private boolean isUssdApiAllowed(int subId) {
5269 CarrierConfigManager configManager =
5270 (CarrierConfigManager) mPhone.getContext().getSystemService(
5271 Context.CARRIER_CONFIG_SERVICE);
5272 if (configManager == null) {
5273 return false;
5274 }
5275 PersistableBundle pb = configManager.getConfigForSubId(subId);
5276 if (pb == null) {
5277 return false;
5278 }
5279 return pb.getBoolean(
5280 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5281 }
5282
Shuo Qiandd210312017-04-12 22:11:33 +00005283 /**
5284 * Check if phone is in emergency callback mode
5285 * @return true if phone is in emergency callback mode
5286 * @param subId sub id
5287 */
goneil9c5f4872017-12-05 14:07:56 -08005288 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005289 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005290 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005291 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292
5293 final long identity = Binder.clearCallingIdentity();
5294 try {
5295 if (phone != null) {
5296 return phone.isInEcm();
5297 } else {
5298 return false;
5299 }
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005302 }
5303 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005304
5305 /**
5306 * Get the current signal strength information for the given subscription.
5307 * Because this information is not updated when the device is in a low power state
5308 * it should not be relied-upon to be current.
5309 * @param subId Subscription index
5310 * @return the most recent cached signal strength info from the modem
5311 */
5312 @Override
5313 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005314 final long identity = Binder.clearCallingIdentity();
5315 try {
5316 Phone p = getPhone(subId);
5317 if (p == null) {
5318 return null;
5319 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 return p.getSignalStrength();
5322 } finally {
5323 Binder.restoreCallingIdentity(identity);
5324 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005325 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005326
Pengquan Meng77b7f132018-08-22 14:49:57 -07005327 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005328 * Get the current modem radio state for the given slot.
5329 * @param slotIndex slot index.
5330 * @param callingPackage the name of the package making the call.
5331 * @return the current radio power state from the modem
5332 */
5333 @Override
5334 public int getRadioPowerState(int slotIndex, String callingPackage) {
5335 Phone phone = PhoneFactory.getPhone(slotIndex);
5336 if (phone != null) {
5337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5338 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5339 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5340 }
5341
5342 final long identity = Binder.clearCallingIdentity();
5343 try {
5344 return phone.getRadioPowerState();
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
5348 }
5349 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5350 }
5351
5352 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005353 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5354 *
5355 * <p>Requires one of the following permissions:
5356 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5357 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5358 * privileges.
5359 *
5360 * @param subId subscription id
5361 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5362 * {@code false}.
5363 */
5364 @Override
5365 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005366 boolean isEnabled = false;
5367 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005368 try {
5369 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005370 null /* message */);
5371 Phone phone = getPhone(subId);
5372 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005373 } catch (Exception e) {
5374 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5375 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005376 } finally {
5377 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005378 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005379 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005380 }
5381
5382
5383 /**
5384 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5385 *
5386 * <p> Requires permission:
5387 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5388 * privileges.
5389 *
5390 * @param subId subscription id
5391 * @param isEnabled {@code true} means enable, {@code false} means disable.
5392 */
5393 @Override
5394 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005395 final long identity = Binder.clearCallingIdentity();
5396 try {
5397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5398 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005399
Pengquan Menga1bb6272018-09-06 09:59:22 -07005400 Phone phone = getPhone(subId);
5401 if (phone != null) {
5402 phone.setDataRoamingEnabled(isEnabled);
5403 }
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005406 }
5407 }
5408
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005409 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005410 public boolean isManualNetworkSelectionAllowed(int subId) {
5411 boolean isAllowed = true;
5412 final long identity = Binder.clearCallingIdentity();
5413 try {
5414 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5415 mApp, subId, "isManualNetworkSelectionAllowed");
5416 Phone phone = getPhone(subId);
5417 if (phone != null) {
5418 isAllowed = phone.isCspPlmnEnabled();
5419 }
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
5423 return isAllowed;
5424 }
5425
5426 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005427 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005428 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5433 if (slots == null) {
5434 Rlog.i(LOG_TAG, "slots is null.");
5435 return null;
5436 }
5437
5438 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5439 for (int i = 0; i < slots.length; i++) {
5440 UiccSlot slot = slots[i];
5441 if (slot == null) {
5442 continue;
5443 }
5444
5445 String cardId;
5446 UiccCard card = slot.getUiccCard();
5447 if (card != null) {
5448 cardId = card.getCardId();
5449 } else {
5450 cardId = slot.getIccId();
5451 }
5452
5453 int cardState = 0;
5454 switch (slot.getCardState()) {
5455 case CARDSTATE_ABSENT:
5456 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5457 break;
5458 case CARDSTATE_PRESENT:
5459 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5460 break;
5461 case CARDSTATE_ERROR:
5462 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5463 break;
5464 case CARDSTATE_RESTRICTED:
5465 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5466 break;
5467 default:
5468 break;
5469
5470 }
5471
5472 infos[i] = new UiccSlotInfo(
5473 slot.isActive(),
5474 slot.isEuicc(),
5475 cardId,
5476 cardState,
5477 slot.getPhoneId(),
5478 slot.isExtendedApduSupported());
5479 }
5480 return infos;
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005483 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005484 }
5485
5486 @Override
5487 public boolean switchSlots(int[] physicalSlots) {
5488 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489
5490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005496 }
Jack Yu4c988042018-02-27 15:30:01 -08005497
5498 @Override
5499 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5500 enforceModifyPermission();
5501 final Phone phone = getPhone(subId);
5502 if (phone == null) {
5503 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5504 return;
5505 }
5506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 phone.setRadioIndicationUpdateMode(filters, mode);
5510 } finally {
5511 Binder.restoreCallingIdentity(identity);
5512 }
Jack Yu4c988042018-02-27 15:30:01 -08005513 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005514
5515 /**
goneil47ffb6e2018-04-06 15:40:58 -07005516 * A test API to reload the UICC profile.
5517 *
5518 * <p>Requires that the calling app has permission
5519 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5520 * @hide
5521 */
5522 @Override
5523 public void refreshUiccProfile(int subId) {
5524 enforceModifyPermission();
5525
5526 final long identity = Binder.clearCallingIdentity();
5527 try {
5528 Phone phone = getPhone(subId);
5529 if (phone == null) {
5530 return;
5531 }
5532 UiccCard uiccCard = phone.getUiccCard();
5533 if (uiccCard == null) {
5534 return;
5535 }
5536 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5537 if (uiccProfile == null) {
5538 return;
5539 }
5540 uiccProfile.refresh();
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
5544 }
5545
5546 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005547 * Returns false if the mobile data is disabled by default, otherwise return true.
5548 */
5549 private boolean getDefaultDataEnabled() {
5550 return "true".equalsIgnoreCase(
5551 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5552 }
5553
5554 /**
5555 * Returns true if the data roaming is enabled by default, i.e the system property
5556 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5557 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5558 */
5559 private boolean getDefaultDataRoamingEnabled(int subId) {
5560 final CarrierConfigManager configMgr = (CarrierConfigManager)
5561 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5562 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5563 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5564 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5565 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5566 return isDataRoamingEnabled;
5567 }
5568
5569 /**
5570 * Returns the default network type for the given {@code subId}, if the default network type is
5571 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5572 */
5573 private int getDefaultNetworkType(int subId) {
5574 return Integer.parseInt(
5575 TelephonyManager.getTelephonyProperty(
5576 mSubscriptionController.getPhoneId(subId),
5577 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5578 String.valueOf(Phone.PREFERRED_NT_MODE)));
5579 }
fionaxua13278b2018-03-21 00:08:13 -07005580
5581 @Override
5582 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5583 gid1, String gid2, String plmn, String spn) {
5584 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585
5586 final long identity = Binder.clearCallingIdentity();
5587 try {
5588 final Phone phone = getPhone(subId);
5589 if (phone == null) {
5590 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5591 return;
5592 }
5593 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005596 }
fionaxua13278b2018-03-21 00:08:13 -07005597 }
5598
5599 @Override
5600 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005601 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602
5603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 final Phone phone = getPhone(subId);
5606 if (phone == null) {
5607 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5608 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5609 }
5610 return phone.getCarrierIdListVersion();
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005613 }
fionaxua13278b2018-03-21 00:08:13 -07005614 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005615
5616 @Override
5617 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5619 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5620 return -1;
5621 }
5622
5623 final long identity = Binder.clearCallingIdentity();
5624 try {
5625 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
5629 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005630
5631 @Override
5632 public int getCdmaRoamingMode(int subId) {
5633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5634 mApp, subId, "getCdmaRoamingMode");
5635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
5642 }
5643
5644 @Override
5645 public boolean setCdmaRoamingMode(int subId, int mode) {
5646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5647 mApp, subId, "setCdmaRoamingMode");
5648
5649 final long identity = Binder.clearCallingIdentity();
5650 try {
5651 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5652 } finally {
5653 Binder.restoreCallingIdentity(identity);
5654 }
5655 }
5656
5657 @Override
5658 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5660 mApp, subId, "setCdmaSubscriptionMode");
5661
5662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
5668 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005669
5670 private void ensureUserRunning(int userId) {
5671 if (!mUserManager.isUserRunning(userId)) {
5672 throw new IllegalStateException("User " + userId + " does not exist or not running");
5673 }
5674 }
5675
5676 /**
5677 * Returns a list of SMS apps on a given user.
5678 *
5679 * Only the shell user (UID 2000 or 0) can call it.
5680 * Target user must be running.
5681 */
5682 @Override
5683 public String[] getSmsApps(int userId) {
5684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5685 ensureUserRunning(userId);
5686
5687 final Collection<SmsApplicationData> apps =
5688 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5689
5690 String[] ret = new String[apps.size()];
5691 int i = 0;
5692 for (SmsApplicationData app : apps) {
5693 ret[i++] = app.mPackageName;
5694 }
5695 return ret;
5696 }
5697
5698 /**
5699 * Returns the default SMS app package name on a given user.
5700 *
5701 * Only the shell user (UID 2000 or 0) can call it.
5702 * Target user must be running.
5703 */
5704 @Override
5705 public String getDefaultSmsApp(int userId) {
5706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5707 ensureUserRunning(userId);
5708
5709 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5710 /* updateIfNeeded= */ true, userId);
5711 return cn == null ? null : cn.getPackageName();
5712 }
5713
5714 /**
5715 * Set a package as the default SMS app on a given user.
5716 *
5717 * Only the shell user (UID 2000 or 0) can call it.
5718 * Target user must be running.
5719 */
5720 @Override
5721 public void setDefaultSmsApp(int userId, String packageName) {
5722 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5723 ensureUserRunning(userId);
5724
5725 boolean found = false;
5726 for (String pkg : getSmsApps(userId)) {
5727 if (TextUtils.equals(packageName, pkg)) {
5728 found = true;
5729 break;
5730 }
5731 }
5732 if (!found) {
5733 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5734 }
5735
5736 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5737 }
sqianc5eccab2018-10-19 18:46:41 -07005738
5739 @Override
5740 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5741 String callingPackage) {
5742 // TODO connect with internal content
5743 return null;
5744 }
5745
5746 @Override
5747 public boolean isCurrentEmergencyNumber(String number) {
5748 // TODO connect with internal content
5749 return false;
5750 }
chen xud6b45bd2018-10-30 22:27:10 -07005751
5752 @Override
5753 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5754 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5755 Phone phone = getPhone(subId);
5756 if (phone == null) {
5757 return null;
5758 }
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
5761 UiccProfile profile = UiccController.getInstance()
5762 .getUiccProfileForPhone(phone.getPhoneId());
5763 if (profile != null) {
5764 return profile.getCertsFromCarrierPrivilegeAccessRules();
5765 }
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
5769 return null;
5770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005771}