blob: 6ce87846a97b9ec861d7254343e5ce90f54e10c0 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070028import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080043import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070046import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070047import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070049import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070050import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080052import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070053import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080054import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080055import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070056import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070057import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070059import android.telephony.CellInfoGsm;
60import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070061import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070063import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080064import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070065import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080066import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070067import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070068import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070069import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080071import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070072import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080073import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070075import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070076import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000077import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070078import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070079import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070080import android.telephony.cdma.CdmaCellLocation;
calvinpaneed9ae82018-11-01 19:43:06 +080081import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070082import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-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 Ebinger4c460712018-10-01 10:40:55 -070088import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080089import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080095
Brad Ebinger4c460712018-10-01 10:40:55 -070096import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070097import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080098import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070099import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700100import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700101import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700102import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700103import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800106import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700107import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100108import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700109import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700112import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800113import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700114import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700115import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700116import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700117import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700118import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700119import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800120import 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;
sqian2fff4a32018-11-05 14:18:37 -0800145import 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 xu1cc0abe2018-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 Meng0c05b502018-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 xu1cc0abe2018-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 Chenf144d942018-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
vagdevie435a3e2018-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
vagdevie435a3e2018-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 }
vagdevie435a3e2018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-09-06 09:59:22 -0700377 request.result = true;
378 notifyRequester(request);
379 return;
380 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700381
Pengquan Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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);
vagdevie435a3e2018-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 Meng0c05b502018-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;
vagdevie435a3e2018-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 xu1cc0abe2018-10-26 17:39:23 -0700658 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800659 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-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 xu1cc0abe2018-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 Meng0c05b502018-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);
vagdevie435a3e2018-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 Meng0c05b502018-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 Meng0c05b502018-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 Mengdd9ac822018-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);
vagdevie435a3e2018-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 Meng0c05b502018-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,
vagdevie435a3e2018-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 Meng0c05b502018-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);
vagdevie435a3e2018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 xu1cc0abe2018-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 Meng0c05b502018-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 Meng0c05b502018-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);
vagdevie435a3e2018-08-15 16:01:53 -07001093 }
1094
1095 /**
1096 * Posts the specified command to be executed on the main thread,
1097 * waits for the request to complete, and returns the result.
1098 * @see #sendRequestAsync
1099 */
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);
vagdevie435a3e2018-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 Chenf144d942018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08001306 if (!isValid) {
1307 return;
1308 }
Wink Saville08874612014-08-31 19:19:58 -07001309
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08001584 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001585 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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();
1964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1965 mApp, subId, callingPackage, "getImeiForSlot")) {
1966 return null;
1967 }
Malcolm Chend965c8b2018-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();
1995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1996 mApp, subId, callingPackage, "getMeidForSlot")) {
1997 return null;
1998 }
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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
calvinpaneed9ae82018-11-01 19:43:06 +08002061 @Override
2062 public int getSubscriptionMNOCarrierId(int subId) {
2063 final long identity = Binder.clearCallingIdentity();
2064 try {
2065 final Phone phone = getPhone(subId);
2066 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2067 } finally {
2068 Binder.restoreCallingIdentity(identity);
2069 }
2070 }
2071
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 //
2073 // Internal helper methods.
2074 //
2075
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002076 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2078 *
2079 * @throws SecurityException if the caller does not have the required permission
2080 */
2081 private void enforceModifyPermission() {
2082 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2083 }
2084
2085 /**
2086 * Make sure the caller has the CALL_PHONE permission.
2087 *
2088 * @throws SecurityException if the caller does not have the required permission
2089 */
2090 private void enforceCallPermission() {
2091 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2092 }
2093
Stuart Scott8eef64f2015-04-08 15:13:54 -07002094 private void enforceConnectivityInternalPermission() {
2095 mApp.enforceCallingOrSelfPermission(
2096 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2097 "ConnectivityService");
2098 }
2099
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 private String createTelUrl(String number) {
2101 if (TextUtils.isEmpty(number)) {
2102 return null;
2103 }
2104
Jake Hambye994d462014-02-03 13:10:13 -08002105 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 }
2107
Ihab Awadf9e92732013-12-05 18:02:52 -08002108 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2110 }
2111
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002112 private static void logv(String msg) {
2113 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2114 }
2115
Ihab Awadf9e92732013-12-05 18:02:52 -08002116 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2118 }
2119
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002120 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002122 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002123 }
2124
Sanket Padawe356d7632015-06-22 14:03:32 -07002125 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002126 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002127 final long identity = Binder.clearCallingIdentity();
2128 try {
2129 final Phone phone = PhoneFactory.getPhone(slotIndex);
2130 if (phone == null) {
2131 return PhoneConstants.PHONE_TYPE_NONE;
2132 } else {
2133 return phone.getPhoneType();
2134 }
2135 } finally {
2136 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 }
2139
2140 /**
2141 * Returns the CDMA ERI icon index to display
2142 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002143 @Override
2144 public int getCdmaEriIconIndex(String callingPackage) {
2145 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002146 }
2147
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002149 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002151 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002152 return -1;
2153 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002154
2155 final long identity = Binder.clearCallingIdentity();
2156 try {
2157 final Phone phone = getPhone(subId);
2158 if (phone != null) {
2159 return phone.getCdmaEriIconIndex();
2160 } else {
2161 return -1;
2162 }
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
2167
2168 /**
2169 * Returns the CDMA ERI icon mode,
2170 * 0 - ON
2171 * 1 - FLASHING
2172 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002173 @Override
2174 public int getCdmaEriIconMode(String callingPackage) {
2175 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002176 }
2177
Sanket Padawe356d7632015-06-22 14:03:32 -07002178 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002179 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002181 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002182 return -1;
2183 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002184
2185 final long identity = Binder.clearCallingIdentity();
2186 try {
2187 final Phone phone = getPhone(subId);
2188 if (phone != null) {
2189 return phone.getCdmaEriIconMode();
2190 } else {
2191 return -1;
2192 }
2193 } finally {
2194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 }
2197
2198 /**
2199 * Returns the CDMA ERI text,
2200 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002201 @Override
2202 public String getCdmaEriText(String callingPackage) {
2203 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002204 }
2205
Sanket Padawe356d7632015-06-22 14:03:32 -07002206 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002207 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002209 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002210 return null;
2211 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002212
2213 final long identity = Binder.clearCallingIdentity();
2214 try {
2215 final Phone phone = getPhone(subId);
2216 if (phone != null) {
2217 return phone.getCdmaEriText();
2218 } else {
2219 return null;
2220 }
2221 } finally {
2222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 }
2225
2226 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002227 * Returns the CDMA MDN.
2228 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002229 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002230 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2232 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002233
2234 final long identity = Binder.clearCallingIdentity();
2235 try {
2236 final Phone phone = getPhone(subId);
2237 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2238 return phone.getLine1Number();
2239 } else {
2240 return null;
2241 }
2242 } finally {
2243 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002244 }
2245 }
2246
2247 /**
2248 * Returns the CDMA MIN.
2249 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002251 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2253 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002254
2255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 final Phone phone = getPhone(subId);
2258 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2259 return phone.getCdmaMin();
2260 } else {
2261 return null;
2262 }
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002265 }
2266 }
2267
2268 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 * Returns true if CDMA provisioning needs to run.
2270 */
2271 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002272 final long identity = Binder.clearCallingIdentity();
2273 try {
2274 return mPhone.needsOtaServiceProvisioning();
2275 } finally {
2276 Binder.restoreCallingIdentity(identity);
2277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 }
2279
2280 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002281 * Sets the voice mail number of a given subId.
2282 */
2283 @Override
2284 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002285 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002286
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2290 new Pair<String, String>(alphaTag, number), new Integer(subId));
2291 return success;
2292 } finally {
2293 Binder.restoreCallingIdentity(identity);
2294 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002295 }
2296
Ta-wei Yen87c49842016-05-13 21:19:52 -07002297 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002298 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2299 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2300 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2301 if (!TextUtils.equals(callingPackage, systemDialer)) {
2302 throw new SecurityException("caller must be system dialer");
2303 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002304
2305 final long identity = Binder.clearCallingIdentity();
2306 try {
2307 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2308 if (phoneAccountHandle == null) {
2309 return null;
2310 }
2311 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2312 } finally {
2313 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002314 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002315 }
2316
2317 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002318 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002321 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002322 return null;
2323 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002324
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 return RemoteVvmTaskManager
2328 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
2331 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002332 }
2333
2334 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002335 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2336 VisualVoicemailSmsFilterSettings settings) {
2337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002338
2339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2342 mPhone.getContext(), callingPackage, subId, settings);
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
2345 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002346 }
2347
2348 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002349 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2350 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002351
2352 final long identity = Binder.clearCallingIdentity();
2353 try {
2354 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2355 mPhone.getContext(), callingPackage, subId);
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
2358 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002359 }
2360
2361 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002362 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2363 String callingPackage, int subId) {
2364 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002365
2366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2369 mPhone.getContext(), callingPackage, subId);
2370 } finally {
2371 Binder.restoreCallingIdentity(identity);
2372 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002373 }
2374
2375 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002376 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002377 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002378
2379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2382 mPhone.getContext(), subId);
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
2385 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002386 }
2387
2388 @Override
2389 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2390 String number, int port, String text, PendingIntent sentIntent) {
2391 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002392 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002393 enforceSendSmsPermission();
2394 // Make the calls as the phone process.
2395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2398 if (port == 0) {
2399 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2400 sentIntent, null, false);
2401 } else {
2402 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2403 smsManager.sendDataMessageWithSelfPermissions(number, null,
2404 (short) port, data, sentIntent, null);
2405 }
2406 } finally {
2407 Binder.restoreCallingIdentity(identity);
2408 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002409 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002410 /**
fionaxu0152e512016-11-14 13:36:14 -08002411 * Sets the voice activation state of a given subId.
2412 */
2413 @Override
2414 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2416 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002417
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 final Phone phone = getPhone(subId);
2421 if (phone != null) {
2422 phone.setVoiceActivationState(activationState);
2423 } else {
2424 loge("setVoiceActivationState fails with invalid subId: " + subId);
2425 }
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002428 }
2429 }
2430
2431 /**
2432 * Sets the data activation state of a given subId.
2433 */
2434 @Override
2435 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2437 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002438
2439 final long identity = Binder.clearCallingIdentity();
2440 try {
2441 final Phone phone = getPhone(subId);
2442 if (phone != null) {
2443 phone.setDataActivationState(activationState);
2444 } else {
2445 loge("setVoiceActivationState fails with invalid subId: " + subId);
2446 }
2447 } finally {
2448 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002449 }
2450 }
2451
2452 /**
2453 * Returns the voice activation state of a given subId.
2454 */
2455 @Override
2456 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002457 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002458
fionaxu0152e512016-11-14 13:36:14 -08002459 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002460 final long identity = Binder.clearCallingIdentity();
2461 try {
2462 if (phone != null) {
2463 return phone.getVoiceActivationState();
2464 } else {
2465 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2466 }
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002469 }
2470 }
2471
2472 /**
2473 * Returns the data activation state of a given subId.
2474 */
2475 @Override
2476 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002477 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002478
fionaxu0152e512016-11-14 13:36:14 -08002479 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 if (phone != null) {
2483 return phone.getDataActivationState();
2484 } else {
2485 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2486 }
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002489 }
2490 }
2491
2492 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 * Returns the unread count of voicemails
2494 */
2495 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002497 }
2498
2499 /**
2500 * Returns the unread count of voicemails for a subId
2501 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002502 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002503 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 final Phone phone = getPhone(subId);
2507 if (phone != null) {
2508 return phone.getVoiceMessageCount();
2509 } else {
2510 return 0;
2511 }
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
2517 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002518 * returns true, if the device is in a state where both voice and data
2519 * are supported simultaneously. This can change based on location or network condition.
2520 */
2521 @Override
2522 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002523 final long identity = Binder.clearCallingIdentity();
2524 try {
2525 final Phone phone = getPhone(subId);
2526 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2527 } finally {
2528 Binder.restoreCallingIdentity(identity);
2529 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002530 }
2531
2532 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002533 * Send the dialer code if called from the current default dialer or the caller has
2534 * carrier privilege.
2535 * @param inputCode The dialer code to send
2536 */
2537 @Override
2538 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2539 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2540 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2541 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002542 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2543 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002544 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002545
2546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 mPhone.sendDialerSpecialCode(inputCode);
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
2551 }
fionaxu235cc5e2017-03-06 22:25:57 -08002552 }
2553
2554 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002555 * Returns the data network type.
2556 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 *
2558 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2559 */
2560 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002561 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002562 final long identity = Binder.clearCallingIdentity();
2563 try {
2564 final Phone phone = getPhone(getDefaultSubscription());
2565 if (phone != null) {
2566 return phone.getServiceState().getDataNetworkType();
2567 } else {
2568 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2569 }
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002572 }
Wink Saville36469e72014-06-11 15:17:00 -07002573 }
2574
Pengquan Meng0c05b502018-09-06 09:59:22 -07002575 @Override
2576 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002577 if (!isActiveSubscription(subId)) {
2578 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2579 }
2580
Pengquan Meng0c05b502018-09-06 09:59:22 -07002581 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2582 }
2583
Brad Ebinger4c460712018-10-01 10:40:55 -07002584 @Override
2585 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2586 String callingPackage) throws RemoteException {
2587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2588 "addImsRegistrationCallback")) {
2589 return;
2590 }
2591 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2592 final long token = Binder.clearCallingIdentity();
2593 try {
2594 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2595 .addRegistrationCallbackForSubscription(c, subId);
2596 } finally {
2597 Binder.restoreCallingIdentity(token);
2598 }
2599 }
2600
2601 @Override
2602 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2603 String callingPackage) {
2604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2605 "removeImsRegistrationCallback")) {
2606 return;
2607 }
2608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2609 Binder.withCleanCallingIdentity(() ->
2610 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2611 .removeRegistrationCallbackForSubscription(c, subId));
2612 }
2613
2614 @Override
2615 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2616 String callingPackage) throws RemoteException {
2617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2618 "addMmTelCapabilityCallback")) {
2619 return;
2620 }
2621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2622 final long token = Binder.clearCallingIdentity();
2623 try {
2624 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2625 .addCapabilitiesCallbackForSubscription(c, subId);
2626 } finally {
2627 Binder.restoreCallingIdentity(token);
2628 }
2629 }
2630
2631 @Override
2632 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2633 String callingPackage) {
2634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2635 "removeMmTelCapabilityCallback")) {
2636 return;
2637 }
2638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2639 Binder.withCleanCallingIdentity(() ->
2640 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2641 .removeCapabilitiesCallbackForSubscription(c, subId));
2642 }
2643
2644 @Override
2645 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2647 "isCapable")) {
2648 return false;
2649 }
2650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2651 final long token = Binder.clearCallingIdentity();
2652 try {
2653 return ImsManager.getInstance(mPhone.getContext(),
2654 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2655 } catch (ImsException e) {
2656 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2657 return false;
2658 } finally {
2659 Binder.restoreCallingIdentity(token);
2660 }
2661 }
2662
2663 @Override
2664 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2666 "isAvailable")) {
2667 return false;
2668 }
2669 final long token = Binder.clearCallingIdentity();
2670 try {
2671 Phone phone = getPhone(subId);
2672 if (phone == null) return false;
2673 return phone.isImsCapabilityAvailable(capability, regTech);
2674 } finally {
2675 Binder.restoreCallingIdentity(token);
2676 }
2677 }
2678
2679 @Override
2680 public boolean isAdvancedCallingSettingEnabled(int subId) {
2681 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2682 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2683 final long token = Binder.clearCallingIdentity();
2684 try {
2685 return ImsManager.getInstance(mPhone.getContext(),
2686 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2687 } finally {
2688 Binder.restoreCallingIdentity(token);
2689 }
2690 }
2691
2692 @Override
2693 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2695 "setAdvancedCallingSetting");
2696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2699 ImsManager.getInstance(mPhone.getContext(),
2700 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2701 } finally {
2702 Binder.restoreCallingIdentity(identity);
2703 }
2704 }
2705
2706 @Override
2707 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2709 "isVtSettingEnabled")) {
2710 return false;
2711 }
2712 final long identity = Binder.clearCallingIdentity();
2713 try {
2714 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2715 return ImsManager.getInstance(mPhone.getContext(),
2716 getSlotIndexOrException(subId)).isVtEnabledByUser();
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
2719 }
2720 }
2721
2722 @Override
2723 public void setVtSetting(int subId, boolean isEnabled) {
2724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2725 "setVtSetting");
2726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2729 ImsManager.getInstance(mPhone.getContext(),
2730 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2731 } finally {
2732 Binder.restoreCallingIdentity(identity);
2733 }
2734 }
2735
2736 @Override
2737 public boolean isVoWiFiSettingEnabled(int subId) {
2738 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2742 return ImsManager.getInstance(mPhone.getContext(),
2743 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
2746 }
2747 }
2748
2749 @Override
2750 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2752 "setVoWiFiSetting");
2753 final long identity = Binder.clearCallingIdentity();
2754 try {
2755 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2756 ImsManager.getInstance(mPhone.getContext(),
2757 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2758 } finally {
2759 Binder.restoreCallingIdentity(identity);
2760 }
2761 }
2762
2763 @Override
2764 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2765 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2769 return ImsManager.getInstance(mPhone.getContext(),
2770 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
2773 }
2774 }
2775
2776 @Override
2777 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2779 "setVoWiFiRoamingSetting");
2780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2783 ImsManager.getInstance(mPhone.getContext(),
2784 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
2787 }
2788 }
2789
2790 @Override
2791 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2793 "setVoWiFiNonPersistent");
2794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2797 ImsManager.getInstance(mPhone.getContext(),
2798 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
2802 }
2803
2804 @Override
2805 public int getVoWiFiModeSetting(int subId) {
2806 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2810 return ImsManager.getInstance(mPhone.getContext(),
2811 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
2814 }
2815 }
2816
2817 @Override
2818 public void setVoWiFiModeSetting(int subId, int mode) {
2819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2820 "setVoWiFiModeSetting");
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2824 ImsManager.getInstance(mPhone.getContext(),
2825 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
2828 }
2829 }
2830
2831 @Override
2832 public int getVoWiFiRoamingModeSetting(int subId) {
2833 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2834 final long identity = Binder.clearCallingIdentity();
2835 try {
2836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2837 return ImsManager.getInstance(mPhone.getContext(),
2838 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
2841 }
2842 }
2843
2844 @Override
2845 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2847 "setVoWiFiRoamingModeSetting");
2848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2851 ImsManager.getInstance(mPhone.getContext(),
2852 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2853 } finally {
2854 Binder.restoreCallingIdentity(identity);
2855 }
2856 }
2857
2858 @Override
2859 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2861 "setRttCapabilityEnabled");
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2865 ImsManager.getInstance(mPhone.getContext(),
2866 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
2870 }
2871
2872 @Override
2873 public boolean isTtyOverVolteEnabled(int subId) {
2874 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2878 return ImsManager.getInstance(mPhone.getContext(),
2879 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
2882 }
2883 }
2884
2885 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2886 int slotId = SubscriptionManager.getSlotIndex(subId);
2887 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2888 throw new IllegalArgumentException("Invalid Subscription Id.");
2889 }
2890 return slotId;
2891 }
2892
Wink Saville36469e72014-06-11 15:17:00 -07002893 /**
2894 * Returns the network type for a subId
2895 */
2896 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002897 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002899 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002900 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2901 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002902
Malcolm Chend965c8b2018-02-28 15:00:40 -08002903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 final Phone phone = getPhone(subId);
2906 if (phone != null) {
2907 return phone.getServiceState().getDataNetworkType();
2908 } else {
2909 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2910 }
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002914 }
2915
2916 /**
2917 * Returns the data network type
2918 */
2919 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002920 public int getDataNetworkType(String callingPackage) {
2921 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002922 }
2923
2924 /**
2925 * Returns the data network type for a subId
2926 */
2927 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002928 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002930 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002931 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2932 }
2933
Malcolm Chend965c8b2018-02-28 15:00:40 -08002934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 final Phone phone = getPhone(subId);
2937 if (phone != null) {
2938 return phone.getServiceState().getDataNetworkType();
2939 } else {
2940 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2941 }
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 }
2946
2947 /**
Wink Saville36469e72014-06-11 15:17:00 -07002948 * Returns the Voice network type for a subId
2949 */
2950 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002951 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002953 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002954 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2955 }
2956
Malcolm Chend965c8b2018-02-28 15:00:40 -08002957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 final Phone phone = getPhone(subId);
2960 if (phone != null) {
2961 return phone.getServiceState().getVoiceNetworkType();
2962 } else {
2963 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2964 }
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002968 }
2969
2970 /**
2971 * @return true if a ICC card is present
2972 */
2973 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002974 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002975 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2976 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002977 }
2978
2979 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002980 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002981 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002982 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002983 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 final Phone phone = PhoneFactory.getPhone(slotIndex);
2987 if (phone != null) {
2988 return phone.getIccCard().hasIccCard();
2989 } else {
2990 return false;
2991 }
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002995 }
2996
2997 /**
2998 * Return if the current radio is LTE on CDMA. This
2999 * is a tri-state return value as for a period of time
3000 * the mode may be unknown.
3001 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003002 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003003 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003004 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003006 @Override
3007 public int getLteOnCdmaMode(String callingPackage) {
3008 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003009 }
3010
Sanket Padawe356d7632015-06-22 14:03:32 -07003011 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003012 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003014 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003015 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3016 }
3017
Malcolm Chend965c8b2018-02-28 15:00:40 -08003018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 final Phone phone = getPhone(subId);
3021 if (phone == null) {
3022 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3023 } else {
3024 return phone.getLteOnCdmaMode();
3025 }
3026 } finally {
3027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003028 }
Wink Saville36469e72014-06-11 15:17:00 -07003029 }
3030
3031 public void setPhone(Phone phone) {
3032 mPhone = phone;
3033 }
3034
3035 /**
3036 * {@hide}
3037 * Returns Default subId, 0 in the case of single standby.
3038 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003039 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003040 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003041 }
3042
Shishir Agrawala9f32182016-04-12 12:00:16 -07003043 private int getSlotForDefaultSubscription() {
3044 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3045 }
3046
Wink Savilleb564aae2014-10-23 10:18:09 -07003047 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003048 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003050
Pengquan Meng466e2482018-09-21 15:54:48 -07003051 private boolean isActiveSubscription(int subId) {
3052 return mSubscriptionController.isActiveSubId(subId);
3053 }
3054
Ihab Awadf2177b72013-11-25 13:33:23 -08003055 /**
3056 * @see android.telephony.TelephonyManager.WifiCallingChoices
3057 */
3058 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3062 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3063 getWhenToMakeWifiCallsDefaultPreference());
3064 } finally {
3065 Binder.restoreCallingIdentity(identity);
3066 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003067 }
3068
3069 /**
3070 * @see android.telephony.TelephonyManager.WifiCallingChoices
3071 */
3072 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3076 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3077 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003081 }
3082
Sailesh Nepald1e68152013-12-12 19:08:02 -08003083 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003084 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003085 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003086 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003087
Shishir Agrawal566b7612013-10-28 14:41:00 -07003088 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003089 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3090 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3092 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003093 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003094
Malcolm Chend965c8b2018-02-28 15:00:40 -08003095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 if (TextUtils.equals(ISDR_AID, aid)) {
3098 // Only allows LPA to open logical channel to ISD-R.
3099 ComponentInfo bestComponent =
3100 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3101 if (bestComponent == null
3102 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3103 loge("The calling package is not allowed to access ISD-R.");
3104 throw new SecurityException(
3105 "The calling package is not allowed to access ISD-R.");
3106 }
Derek Tan740e1672017-06-27 14:56:27 -07003107 }
Derek Tan740e1672017-06-27 14:56:27 -07003108
Malcolm Chend965c8b2018-02-28 15:00:40 -08003109 if (DBG) {
3110 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3111 }
3112 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3113 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3114 if (DBG) log("iccOpenLogicalChannel: " + response);
3115 return response;
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003119 }
3120
3121 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003122 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3124 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003125
Malcolm Chend965c8b2018-02-28 15:00:40 -08003126 final long identity = Binder.clearCallingIdentity();
3127 try {
3128 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3129 if (channel < 0) {
3130 return false;
3131 }
3132 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3133 if (DBG) log("iccCloseLogicalChannel: " + success);
3134 return success;
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003137 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003138 }
3139
3140 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003141 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003142 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3144 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003145
Malcolm Chend965c8b2018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 if (DBG) {
3149 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3150 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3151 + p3 + " data=" + data);
3152 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003153
Malcolm Chend965c8b2018-02-28 15:00:40 -08003154 if (channel < 0) {
3155 return "";
3156 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003157
Malcolm Chend965c8b2018-02-28 15:00:40 -08003158 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3159 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3160 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003161
Malcolm Chend965c8b2018-02-28 15:00:40 -08003162 // Append the returned status code to the end of the response payload.
3163 String s = Integer.toHexString(
3164 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3165 if (response.payload != null) {
3166 s = IccUtils.bytesToHexString(response.payload) + s;
3167 }
3168 return s;
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003171 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003172 }
Jake Hambye994d462014-02-03 13:10:13 -08003173
Evan Charltonc66da362014-05-16 14:06:40 -07003174 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003175 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3176 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3178 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003179 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003180
Malcolm Chend965c8b2018-02-28 15:00:40 -08003181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3184 && TextUtils.equals(ISDR_AID, data)) {
3185 // Only allows LPA to select ISD-R.
3186 ComponentInfo bestComponent =
3187 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3188 if (bestComponent == null
3189 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3190 loge("The calling package is not allowed to select ISD-R.");
3191 throw new SecurityException(
3192 "The calling package is not allowed to select ISD-R.");
3193 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003194 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003195
Malcolm Chend965c8b2018-02-28 15:00:40 -08003196 if (DBG) {
3197 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3198 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3199 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003200
Malcolm Chend965c8b2018-02-28 15:00:40 -08003201 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3202 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3203 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003204
Malcolm Chend965c8b2018-02-28 15:00:40 -08003205 // Append the returned status code to the end of the response payload.
3206 String s = Integer.toHexString(
3207 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3208 if (response.payload != null) {
3209 s = IccUtils.bytesToHexString(response.payload) + s;
3210 }
3211 return s;
3212 } finally {
3213 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003214 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003215 }
3216
3217 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003218 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003219 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3221 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003222
Malcolm Chend965c8b2018-02-28 15:00:40 -08003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 if (DBG) {
3226 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3227 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3228 }
3229
3230 IccIoResult response =
3231 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3232 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3233 subId);
3234
3235 if (DBG) {
3236 log("Exchange SIM_IO [R]" + response);
3237 }
3238
3239 byte[] result = null;
3240 int length = 2;
3241 if (response.payload != null) {
3242 length = 2 + response.payload.length;
3243 result = new byte[length];
3244 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3245 } else {
3246 result = new byte[length];
3247 }
3248
3249 result[length - 1] = (byte) response.sw2;
3250 result[length - 2] = (byte) response.sw1;
3251 return result;
3252 } finally {
3253 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003254 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003255 }
3256
Nathan Haroldb3014052017-01-25 15:57:32 -08003257 /**
3258 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3259 * on a particular subscription
3260 */
sqianb6e41952018-03-12 14:54:01 -07003261 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3263 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3264 return null;
3265 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003266
3267 final long identity = Binder.clearCallingIdentity();
3268 try {
3269 if (appType != TelephonyManager.APPTYPE_USIM
3270 && appType != TelephonyManager.APPTYPE_SIM) {
3271 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3272 return null;
3273 }
3274 Object response = sendRequest(
3275 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3276 if (response instanceof String[]) {
3277 return (String[]) response;
3278 }
3279 // Response is an Exception of some kind,
3280 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003281 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003282 } finally {
3283 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003284 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003285 }
3286
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003287 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003288 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3290 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003291
Malcolm Chend965c8b2018-02-28 15:00:40 -08003292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3295 if (response.payload == null) {
3296 return "";
3297 }
Evan Charltonc66da362014-05-16 14:06:40 -07003298
Malcolm Chend965c8b2018-02-28 15:00:40 -08003299 // Append the returned status code to the end of the response payload.
3300 String s = Integer.toHexString(
3301 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3302 s = IccUtils.bytesToHexString(response.payload) + s;
3303 return s;
3304 } finally {
3305 Binder.restoreCallingIdentity(identity);
3306 }
Evan Charltonc66da362014-05-16 14:06:40 -07003307 }
3308
Jake Hambye994d462014-02-03 13:10:13 -08003309 /**
3310 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3311 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3312 *
3313 * @param itemID the ID of the item to read
3314 * @return the NV item as a String, or null on error.
3315 */
3316 @Override
3317 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3320 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003321
3322 final long identity = Binder.clearCallingIdentity();
3323 try {
3324 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003325 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003326 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3327 return value;
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
3330 }
Jake Hambye994d462014-02-03 13:10:13 -08003331 }
3332
3333 /**
3334 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3335 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3336 *
3337 * @param itemID the ID of the item to read
3338 * @param itemValue the value to write, as a String
3339 * @return true on success; false on any failure
3340 */
3341 @Override
3342 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3345 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003346
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3350 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003351 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003352 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3353 return success;
3354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
Jake Hambye994d462014-02-03 13:10:13 -08003357 }
3358
3359 /**
3360 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3361 * Used for device configuration by some CDMA operators.
3362 *
3363 * @param preferredRoamingList byte array containing the new PRL
3364 * @return true on success; false on any failure
3365 */
3366 @Override
3367 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3369 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003370
3371 final long identity = Binder.clearCallingIdentity();
3372 try {
3373 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3374 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3375 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3376 return success;
3377 } finally {
3378 Binder.restoreCallingIdentity(identity);
3379 }
Jake Hambye994d462014-02-03 13:10:13 -08003380 }
3381
3382 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003383 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003384 * Used for device configuration by some CDMA operators.
3385 *
chen xu1cc0abe2018-10-26 17:39:23 -07003386 * @param slotIndex - device slot.
3387 *
Jake Hambye994d462014-02-03 13:10:13 -08003388 * @return true on success; false on any failure
3389 */
3390 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003391 public boolean resetModemConfig(int slotIndex) {
3392 Phone phone = PhoneFactory.getPhone(slotIndex);
3393 if (phone != null) {
3394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3395 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003396
chen xu1cc0abe2018-10-26 17:39:23 -07003397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3400 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3401 return success;
3402 } finally {
3403 Binder.restoreCallingIdentity(identity);
3404 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003405 }
chen xu1cc0abe2018-10-26 17:39:23 -07003406 return false;
3407 }
3408
3409 /**
3410 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3411 *
3412 * @param slotIndex - device slot.
3413 *
3414 * @return true on success; false on any failure
3415 */
3416 @Override
3417 public boolean rebootModem(int slotIndex) {
3418 Phone phone = PhoneFactory.getPhone(slotIndex);
3419 if (phone != null) {
3420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3421 mApp, phone.getSubId(), "rebootModem");
3422
3423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3426 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3427 return success;
3428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
3431 }
3432 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003433 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003434
Svet Ganovb320e182015-04-16 12:30:10 -07003435 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003437 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003438 return new String[0];
3439 }
3440
Malcolm Chend965c8b2018-02-28 15:00:40 -08003441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 return mPhone.getPcscfAddress(apnType);
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
Wink Saville36469e72014-06-11 15:17:00 -07003447 }
3448
Brad Ebinger51f743a2017-01-23 13:50:20 -08003449 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003450 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3451 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003452 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003453 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003454 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003455
3456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 PhoneFactory.getImsResolver().enableIms(slotId);
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
3461 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003462 }
3463
3464 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003465 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3466 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003467 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003468 public void disableIms(int slotId) {
3469 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003470
3471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 PhoneFactory.getImsResolver().disableIms(slotId);
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
3476 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003477 }
3478
3479 /**
3480 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3481 * feature or {@link null} if the service is not available. If the feature is available, the
3482 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3483 */
3484 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003485 IImsServiceFeatureCallback callback) {
3486 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003487
3488 final long identity = Binder.clearCallingIdentity();
3489 try {
3490 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3491 } finally {
3492 Binder.restoreCallingIdentity(identity);
3493 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003494 }
3495
3496 /**
3497 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3498 * feature during emergency calling or {@link null} if the service is not available. If the
3499 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3500 * listener for feature updates.
3501 */
3502 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3503 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003504
3505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
3510 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003511 }
3512
Brad Ebinger5f64b052017-12-14 14:26:15 -08003513 /**
3514 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3515 * specified.
3516 */
3517 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3518 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003519
3520 final long identity = Binder.clearCallingIdentity();
3521 try {
3522 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003526 }
3527
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003528 /**
3529 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3530 * specified.
3531 */
3532 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3533 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003534
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003541 }
3542
Brad Ebinger884c07b2018-02-15 16:17:40 -08003543 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003544 * Sets the ImsService Package Name that Telephony will bind to.
3545 *
3546 * @param slotId the slot ID that the ImsService should bind for.
3547 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3548 * ImsService is the device default ImsService.
3549 * @param packageName The package name of the application that contains the ImsService to bind
3550 * to.
3551 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3552 * @hide
3553 */
3554 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003555 int[] subIds = SubscriptionManager.getSubId(slotId);
3556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3557 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3558 "setImsService");
3559
Malcolm Chend965c8b2018-02-28 15:00:40 -08003560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3563 isCarrierImsService, packageName);
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
3566 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003567 }
3568
3569 /**
3570 * Return the ImsService configuration.
3571 *
3572 * @param slotId The slot that the ImsService is associated with.
3573 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3574 * the device default.
3575 * @return the package name of the ImsService configuration.
3576 */
3577 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003578 int[] subIds = SubscriptionManager.getSubId(slotId);
3579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3580 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3581 "getImsService");
3582
Malcolm Chend965c8b2018-02-28 15:00:40 -08003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3586 isCarrierImsService);
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003590 }
3591
Wink Saville36469e72014-06-11 15:17:00 -07003592 public void setImsRegistrationState(boolean registered) {
3593 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003594
3595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 mPhone.setImsRegistrationState(registered);
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
3600 }
Wink Saville36469e72014-06-11 15:17:00 -07003601 }
3602
3603 /**
Stuart Scott54788802015-03-30 13:18:01 -07003604 * Set the network selection mode to automatic.
3605 *
3606 */
3607 @Override
3608 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3610 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003611
Pengquan Meng466e2482018-09-21 15:54:48 -07003612 if (!isActiveSubscription(subId)) {
3613 return;
3614 }
3615
Malcolm Chend965c8b2018-02-28 15:00:40 -08003616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3619 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3620 } finally {
3621 Binder.restoreCallingIdentity(identity);
3622 }
Stuart Scott54788802015-03-30 13:18:01 -07003623 }
3624
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003625 /**
3626 * Ask the radio to connect to the input network and change selection mode to manual.
3627 *
3628 * @param subId the id of the subscription.
3629 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3630 * the operator to attach to.
3631 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3632 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3633 * normal network selection next time.
3634 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003635 */
3636 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003637 public boolean setNetworkSelectionModeManual(
3638 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3640 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003641
3642 if (!isActiveSubscription(subId)) {
3643 return false;
3644 }
3645
Malcolm Chend965c8b2018-02-28 15:00:40 -08003646 final long identity = Binder.clearCallingIdentity();
3647 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003648 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003649 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003650 if (DBG) {
3651 log("setNetworkSelectionModeManual: subId: " + subId
3652 + " operator: " + operatorInfo);
3653 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003654 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003658 }
3659
3660 /**
3661 * Scans for available networks.
3662 */
3663 @Override
3664 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3666 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003667
Pengquan Meng0c05b502018-09-06 09:59:22 -07003668 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003669 try {
3670 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003671 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003672 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003676 }
3677
3678 /**
yinxub1bed742017-04-17 11:45:04 -07003679 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003680 *
yinxub1bed742017-04-17 11:45:04 -07003681 * @param subId id of the subscription
3682 * @param request contains the radio access networks with bands/channels to scan
3683 * @param messenger callback messenger for scan results or errors
3684 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003685 * @return the id of the requested scan which can be used to stop the scan.
3686 */
3687 @Override
3688 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3689 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3691 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003692
3693 final long identity = Binder.clearCallingIdentity();
3694 try {
3695 return mNetworkScanRequestTracker.startNetworkScan(
3696 request, messenger, binder, getPhone(subId));
3697 } finally {
3698 Binder.restoreCallingIdentity(identity);
3699 }
yinxu504e1392017-04-12 16:03:22 -07003700 }
3701
3702 /**
3703 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003704 *
3705 * @param subId id of the subscription
3706 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003707 */
3708 @Override
3709 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3711 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003712
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
yinxu504e1392017-04-12 16:03:22 -07003719 }
3720
3721 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003722 * Get the calculated preferred network type.
3723 * Used for debugging incorrect network type.
3724 *
3725 * @return the preferred network type, defined in RILConstants.java.
3726 */
3727 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003728 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003730 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003731 return RILConstants.PREFERRED_NETWORK_MODE;
3732 }
3733
Malcolm Chend965c8b2018-02-28 15:00:40 -08003734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 // FIXME: need to get SubId from somewhere.
3737 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3738 } finally {
3739 Binder.restoreCallingIdentity(identity);
3740 }
Junda Liu84d15a22014-07-02 11:21:04 -07003741 }
3742
3743 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003744 * Get the preferred network type.
3745 * Used for device configuration by some CDMA operators.
3746 *
3747 * @return the preferred network type, defined in RILConstants.java.
3748 */
3749 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003750 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3752 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003753
3754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 if (DBG) log("getPreferredNetworkType");
3757 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3758 int networkType = (result != null ? result[0] : -1);
3759 if (DBG) log("getPreferredNetworkType: " + networkType);
3760 return networkType;
3761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003764 }
3765
3766 /**
3767 * Set the preferred network type.
3768 * Used for device configuration by some CDMA operators.
3769 *
3770 * @param networkType the preferred network type, defined in RILConstants.java.
3771 * @return true on success; false on any failure.
3772 */
3773 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003774 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3776 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003777
3778 final long identity = Binder.clearCallingIdentity();
3779 try {
3780 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3781 Boolean success = (Boolean) sendRequest(
3782 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3783 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3784 if (success) {
3785 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3786 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3787 }
3788 return success;
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003791 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003792 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003793
3794 /**
Junda Liu475951f2014-11-07 16:45:03 -08003795 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003796 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003797 * tethering.
3798 *
3799 * @return 0: Not required. 1: required. 2: Not set.
3800 * @hide
3801 */
3802 @Override
3803 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003804 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003805
3806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3809 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07003810 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08003811 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3812 dunRequired = 1;
3813 }
3814 return dunRequired;
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003817 }
Junda Liu475951f2014-11-07 16:45:03 -08003818 }
3819
3820 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003821 * Set mobile data enabled
3822 * Used by the user through settings etc to turn on/off mobile data
3823 *
3824 * @param enable {@code true} turn turn data on, else {@code false}
3825 */
3826 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003827 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3829 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003830
3831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 int phoneId = mSubscriptionController.getPhoneId(subId);
3834 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3835 Phone phone = PhoneFactory.getPhone(phoneId);
3836 if (phone != null) {
3837 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3838 phone.setUserDataEnabled(enable);
3839 } else {
3840 loge("setUserDataEnabled: no phone for subId=" + subId);
3841 }
3842 } finally {
3843 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003844 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003845 }
3846
3847 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003848 * Get the user enabled state of Mobile Data.
3849 *
3850 * TODO: remove and use isUserDataEnabled.
3851 * This can't be removed now because some vendor codes
3852 * calls through ITelephony directly while they should
3853 * use TelephonyManager.
3854 *
3855 * @return true on enabled
3856 */
3857 @Override
3858 public boolean getDataEnabled(int subId) {
3859 return isUserDataEnabled(subId);
3860 }
3861
3862 /**
3863 * Get whether mobile data is enabled per user setting.
3864 *
3865 * There are other factors deciding whether mobile data is actually enabled, but they are
3866 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003867 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003868 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003869 *
3870 * @return {@code true} if data is enabled else {@code false}
3871 */
3872 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003873 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003874 try {
3875 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3876 null);
3877 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3879 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003880 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003881
3882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 int phoneId = mSubscriptionController.getPhoneId(subId);
3885 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3886 Phone phone = PhoneFactory.getPhone(phoneId);
3887 if (phone != null) {
3888 boolean retVal = phone.isUserDataEnabled();
3889 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3890 return retVal;
3891 } else {
3892 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3893 return false;
3894 }
3895 } finally {
3896 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003897 }
3898 }
3899
3900 /**
3901 * Get whether mobile data is enabled.
3902 *
3903 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3904 * whether mobile data is actually enabled.
3905 *
3906 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3907 *
3908 * @return {@code true} if data is enabled else {@code false}
3909 */
3910 @Override
3911 public boolean isDataEnabled(int subId) {
3912 try {
3913 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3914 null);
3915 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3917 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003918 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003919
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 int phoneId = mSubscriptionController.getPhoneId(subId);
3923 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3924 Phone phone = PhoneFactory.getPhone(phoneId);
3925 if (phone != null) {
3926 boolean retVal = phone.isDataEnabled();
3927 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3928 return retVal;
3929 } else {
3930 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3931 return false;
3932 }
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003935 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003936 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003937
3938 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003939 public int getCarrierPrivilegeStatus(int subId) {
3940 final Phone phone = getPhone(subId);
3941 if (phone == null) {
3942 loge("getCarrierPrivilegeStatus: Invalid subId");
3943 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3944 }
3945 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003946 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003947 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003948 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3949 }
3950 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003951 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003952 }
Junda Liu29340342014-07-10 15:23:27 -07003953
3954 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003955 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3956 final Phone phone = getPhone(subId);
3957 if (phone == null) {
3958 loge("getCarrierPrivilegeStatus: Invalid subId");
3959 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3960 }
3961 UiccProfile profile =
3962 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3963 if (profile == null) {
3964 loge("getCarrierPrivilegeStatus: No UICC");
3965 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3966 }
3967 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3968 }
3969
3970 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003971 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003972 if (TextUtils.isEmpty(pkgName))
3973 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003974 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003975 if (card == null) {
3976 loge("checkCarrierPrivilegesForPackage: No UICC");
3977 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3978 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003979 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3980 }
3981
3982 @Override
3983 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003984 if (TextUtils.isEmpty(pkgName))
3985 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003986 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3987 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3988 UiccCard card = UiccController.getInstance().getUiccCard(i);
3989 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003990 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003991 continue;
3992 }
3993
3994 result = card.getCarrierPrivilegeStatus(
3995 mPhone.getContext().getPackageManager(), pkgName);
3996 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3997 break;
3998 }
3999 }
4000
4001 return result;
Junda Liu29340342014-07-10 15:23:27 -07004002 }
Derek Tan89e89d42014-07-08 17:00:10 -07004003
4004 @Override
Junda Liue64de782015-04-16 17:19:16 -07004005 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4006 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4007 loge("phoneId " + phoneId + " is not valid.");
4008 return null;
4009 }
4010 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004011 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004012 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004013 return null ;
4014 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004015 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004016 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004017 }
4018
Amith Yamasani6e118872016-02-19 12:53:51 -08004019 @Override
4020 public List<String> getPackagesWithCarrierPrivileges() {
4021 PackageManager pm = mPhone.getContext().getPackageManager();
4022 List<String> privilegedPackages = new ArrayList<>();
4023 List<PackageInfo> packages = null;
4024 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4025 UiccCard card = UiccController.getInstance().getUiccCard(i);
4026 if (card == null) {
4027 // No UICC in that slot.
4028 continue;
4029 }
4030 if (card.hasCarrierPrivilegeRules()) {
4031 if (packages == null) {
4032 // Only check packages in user 0 for now
4033 packages = pm.getInstalledPackagesAsUser(
4034 PackageManager.MATCH_DISABLED_COMPONENTS
4035 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4036 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4037 }
4038 for (int p = packages.size() - 1; p >= 0; p--) {
4039 PackageInfo pkgInfo = packages.get(p);
4040 if (pkgInfo != null && pkgInfo.packageName != null
4041 && card.getCarrierPrivilegeStatus(pkgInfo)
4042 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4043 privilegedPackages.add(pkgInfo.packageName);
4044 }
4045 }
4046 }
4047 }
4048 return privilegedPackages;
4049 }
4050
Wink Savilleb564aae2014-10-23 10:18:09 -07004051 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004052 final Phone phone = getPhone(subId);
4053 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004054 if (card == null) {
4055 loge("getIccId: No UICC");
4056 return null;
4057 }
4058 String iccId = card.getIccId();
4059 if (TextUtils.isEmpty(iccId)) {
4060 loge("getIccId: ICC ID is null or empty.");
4061 return null;
4062 }
4063 return iccId;
4064 }
4065
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004066 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004067 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4068 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004069 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4070 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004071
Malcolm Chend965c8b2018-02-28 15:00:40 -08004072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 final String iccId = getIccId(subId);
4075 final Phone phone = getPhone(subId);
4076 if (phone == null) {
4077 return false;
4078 }
4079 final String subscriberId = phone.getSubscriberId();
4080
4081 if (DBG_MERGE) {
4082 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4083 + subscriberId + " to " + number);
4084 }
4085
4086 if (TextUtils.isEmpty(iccId)) {
4087 return false;
4088 }
4089
4090 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4091
4092 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4093 if (alphaTag == null) {
4094 editor.remove(alphaTagPrefKey);
4095 } else {
4096 editor.putString(alphaTagPrefKey, alphaTag);
4097 }
4098
4099 // Record both the line number and IMSI for this ICCID, since we need to
4100 // track all merged IMSIs based on line number
4101 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4102 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4103 if (number == null) {
4104 editor.remove(numberPrefKey);
4105 editor.remove(subscriberPrefKey);
4106 } else {
4107 editor.putString(numberPrefKey, number);
4108 editor.putString(subscriberPrefKey, subscriberId);
4109 }
4110
4111 editor.commit();
4112 return true;
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004115 }
Derek Tan7226c842014-07-02 17:42:23 -07004116 }
4117
4118 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004119 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004120 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004122 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004123 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004124 return null;
4125 }
Derek Tan97ebb422014-09-05 16:55:38 -07004126
Malcolm Chend965c8b2018-02-28 15:00:40 -08004127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 String iccId = getIccId(subId);
4130 if (iccId != null) {
4131 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4132 if (DBG_MERGE) {
4133 log("getLine1NumberForDisplay returning "
4134 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4135 }
4136 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004137 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004138 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4139 return null;
4140 } finally {
4141 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004142 }
Derek Tan7226c842014-07-02 17:42:23 -07004143 }
4144
4145 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004146 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004148 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004149 return null;
4150 }
Derek Tan97ebb422014-09-05 16:55:38 -07004151
Malcolm Chend965c8b2018-02-28 15:00:40 -08004152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 String iccId = getIccId(subId);
4155 if (iccId != null) {
4156 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4157 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4158 }
4159 return null;
4160 } finally {
4161 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004162 }
Derek Tan7226c842014-07-02 17:42:23 -07004163 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004164
4165 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004166 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004167 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4168 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004169 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004170 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4171 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004172 return null;
4173 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004174
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004175 final long identity = Binder.clearCallingIdentity();
4176 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004177 final Context context = mPhone.getContext();
4178 final TelephonyManager tele = TelephonyManager.from(context);
4179 final SubscriptionManager sub = SubscriptionManager.from(context);
4180
4181 // Figure out what subscribers are currently active
4182 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4183 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4184 // the process, where TelephonyManager was instantiated.
4185 // Otherwise AppOps check will fail.
4186
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004187 final int[] subIds = sub.getActiveSubscriptionIdList();
4188 for (int subId : subIds) {
4189 activeSubscriberIds.add(tele.getSubscriberId(subId));
4190 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004191
4192 // First pass, find a number override for an active subscriber
4193 String mergeNumber = null;
4194 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4195 for (String key : prefs.keySet()) {
4196 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4197 final String subscriberId = (String) prefs.get(key);
4198 if (activeSubscriberIds.contains(subscriberId)) {
4199 final String iccId = key.substring(
4200 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4201 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4202 mergeNumber = (String) prefs.get(numberKey);
4203 if (DBG_MERGE) {
4204 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4205 + " for active subscriber " + subscriberId);
4206 }
4207 if (!TextUtils.isEmpty(mergeNumber)) {
4208 break;
4209 }
4210 }
4211 }
4212 }
4213
4214 // Shortcut when no active merged subscribers
4215 if (TextUtils.isEmpty(mergeNumber)) {
4216 return null;
4217 }
4218
4219 // Second pass, find all subscribers under that line override
4220 final ArraySet<String> result = new ArraySet<>();
4221 for (String key : prefs.keySet()) {
4222 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4223 final String number = (String) prefs.get(key);
4224 if (mergeNumber.equals(number)) {
4225 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4226 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4227 final String subscriberId = (String) prefs.get(subscriberKey);
4228 if (!TextUtils.isEmpty(subscriberId)) {
4229 result.add(subscriberId);
4230 }
4231 }
4232 }
4233 }
4234
4235 final String[] resultArray = result.toArray(new String[result.size()]);
4236 Arrays.sort(resultArray);
4237 if (DBG_MERGE) {
4238 Slog.d(LOG_TAG,
4239 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4240 }
4241 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004242 } finally {
4243 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004244 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004245 }
4246
4247 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004248 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004249 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4250 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004251
4252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 final Phone phone = getPhone(subId);
4255 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004259 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004260
4261 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004262 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004263 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4264 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004265 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004266
4267 final long identity = Binder.clearCallingIdentity();
4268 try {
4269 final Phone phone = getPhone(subId);
4270 if (phone == null) {
4271 return false;
4272 }
4273 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4274 cdmaNonRoamingList);
4275 } finally {
4276 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004277 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004278 }
4279
4280 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004281 @Deprecated
4282 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4283 enforceModifyPermission();
4284
4285 int returnValue = 0;
4286 try {
vagdevie435a3e2018-08-15 16:01:53 -07004287 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004288 if(result.exception == null) {
4289 if (result.result != null) {
4290 byte[] responseData = (byte[])(result.result);
4291 if(responseData.length > oemResp.length) {
4292 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4293 responseData.length + "bytes. Buffer Size is " +
4294 oemResp.length + "bytes.");
4295 }
4296 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4297 returnValue = responseData.length;
4298 }
4299 } else {
4300 CommandException ex = (CommandException) result.exception;
4301 returnValue = ex.getCommandError().ordinal();
4302 if(returnValue > 0) returnValue *= -1;
4303 }
4304 } catch (RuntimeException e) {
4305 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4306 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4307 if(returnValue > 0) returnValue *= -1;
4308 }
4309
4310 return returnValue;
4311 }
4312
4313 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004314 public void setRadioCapability(RadioAccessFamily[] rafs) {
4315 try {
4316 ProxyController.getInstance().setRadioCapability(rafs);
4317 } catch (RuntimeException e) {
4318 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4319 }
4320 }
4321
4322 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004323 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004324 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004325 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004326 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004327 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004328 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004329 final long identity = Binder.clearCallingIdentity();
4330 try {
chen xufeeed752018-10-26 14:17:57 -07004331 TelephonyPermissions
4332 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4333 mApp, phone.getSubId(), "getRadioAccessFamily");
4334 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
chen xufeeed752018-10-26 14:17:57 -07004338 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004339 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004340
4341 @Override
4342 public void enableVideoCalling(boolean enable) {
4343 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004344
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4348 } finally {
4349 Binder.restoreCallingIdentity(identity);
4350 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004351 }
4352
4353 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004354 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4356 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4357 return false;
4358 }
Svet Ganovb320e182015-04-16 12:30:10 -07004359
Malcolm Chend965c8b2018-02-28 15:00:40 -08004360 final long identity = Binder.clearCallingIdentity();
4361 try {
4362 // Check the user preference and the system-level IMS setting. Even if the user has
4363 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4364 // In the long run, we may instead need to check if there exists a connection service
4365 // which can support video calling.
4366 ImsManager imsManager =
4367 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4368 return imsManager.isVtEnabledByPlatform()
4369 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4370 && imsManager.isVtEnabledByUser();
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004374 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004375
Andrew Leea1239f22015-03-02 17:44:07 -08004376 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004377 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4379 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4380 return false;
4381 }
4382
4383 final long identity = Binder.clearCallingIdentity();
4384 try {
4385 CarrierConfigManager configManager =
4386 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4387 return configManager.getConfigForSubId(mPhone.getSubId())
4388 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4389 } finally {
4390 Binder.restoreCallingIdentity(identity);
4391 }
Andrew Leea1239f22015-03-02 17:44:07 -08004392 }
4393
4394 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004395 public boolean isWorldPhone(int subId, String callingPackage) {
4396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4397 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4398 return false;
4399 }
4400
4401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 CarrierConfigManager configManager =
4404 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4405 return configManager.getConfigForSubId(mPhone.getSubId())
4406 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Andrew Leea1239f22015-03-02 17:44:07 -08004410 }
4411
Andrew Lee9431b832015-03-09 18:46:45 -07004412 @Override
4413 public boolean isTtyModeSupported() {
4414 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004415 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004416 }
4417
4418 @Override
4419 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
Andrew Lee9431b832015-03-09 18:46:45 -07004426 }
4427
Hall Liuf6668912018-10-31 17:05:23 -07004428 /**
4429 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4430 * support for the feature and device firmware support.
4431 *
4432 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4433 */
4434 @Override
4435 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004436 final long identity = Binder.clearCallingIdentity();
4437 try {
4438 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4439 mPhone.getSubId()).getBoolean(
4440 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4441 boolean isDeviceSupported =
4442 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4443 return isCarrierSupported && isDeviceSupported;
4444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
Hall Liu98187582018-01-22 19:15:32 -08004447 }
4448
Hall Liuf6668912018-10-31 17:05:23 -07004449 /**
4450 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4451 * both also support RTT.
4452 */
4453 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004454 final long identity = Binder.clearCallingIdentity();
4455 try {
Hall Liuf6668912018-10-31 17:05:23 -07004456 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004457 mPhone.getContext().getContentResolver(),
4458 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4459 } finally {
4460 Binder.restoreCallingIdentity(identity);
4461 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004462 }
4463
Sanket Padawe7310cc72015-01-14 09:53:20 -08004464 /**
4465 * Returns the unique device ID of phone, for example, the IMEI for
4466 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4467 *
4468 * <p>Requires Permission:
4469 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4470 */
4471 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004472 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004473 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004474 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004475 return null;
4476 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004477 int subId = phone.getSubId();
4478 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4479 mApp, subId, callingPackage, "getDeviceId")) {
4480 return null;
4481 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004482
4483 final long identity = Binder.clearCallingIdentity();
4484 try {
4485 return phone.getDeviceId();
4486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004489 }
4490
Ping Sunc67b7c22016-03-02 19:16:45 +08004491 /**
4492 * {@hide}
4493 * Returns the IMS Registration Status on a particular subid
4494 *
4495 * @param subId
4496 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004497 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004498 Phone phone = getPhone(subId);
4499 if (phone != null) {
4500 return phone.isImsRegistered();
4501 } else {
4502 return false;
4503 }
4504 }
4505
Santos Cordon7a1885b2015-02-03 11:15:19 -08004506 @Override
4507 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004508 final long identity = Binder.clearCallingIdentity();
4509 try {
4510 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004514 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004515
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004516 /**
4517 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004518 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004519 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004520 final long identity = Binder.clearCallingIdentity();
4521 try {
4522 Phone phone = getPhone(subId);
4523 if (phone != null) {
4524 return phone.isWifiCallingEnabled();
4525 } else {
4526 return false;
4527 }
4528 } finally {
4529 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004530 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004531 }
4532
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004533 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004534 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004535 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004536 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004537 final long identity = Binder.clearCallingIdentity();
4538 try {
4539 Phone phone = getPhone(subId);
4540 if (phone != null) {
4541 return phone.isVideoEnabled();
4542 } else {
4543 return false;
4544 }
4545 } finally {
4546 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004547 }
4548 }
4549
4550 /**
4551 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4552 * defined in {@link ImsRegistrationImplBase}.
4553 */
4554 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004555 final long identity = Binder.clearCallingIdentity();
4556 try {
4557 Phone phone = getPhone(subId);
4558 if (phone != null) {
4559 return phone.getImsRegistrationTech();
4560 } else {
4561 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4562 }
4563 } finally {
4564 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004565 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004566 }
4567
Stuart Scott8eef64f2015-04-08 15:13:54 -07004568 @Override
4569 public void factoryReset(int subId) {
4570 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004571 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4572 return;
4573 }
4574
Svet Ganovcc087f82015-05-12 20:35:54 -07004575 final long identity = Binder.clearCallingIdentity();
4576 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004577 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4578 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004579 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004580 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004581 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4582 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004583 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004584 }
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004587 }
4588 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004589
4590 @Override
4591 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004592 final long identity = Binder.clearCallingIdentity();
4593 try {
4594 // We query all subscriptions instead of just the active ones, because
4595 // this might be called early on in the provisioning flow when the
4596 // subscriptions potentially aren't active yet.
4597 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4598 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004599 return null;
4600 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004601
Malcolm Chend965c8b2018-02-28 15:00:40 -08004602 // This function may be called very early, say, from the setup wizard, at
4603 // which point we won't have a default subscription set. If that's the case
4604 // we just choose the first, which will be valid in "most cases".
4605 final int defaultSubId = getDefaultSubscription();
4606 SubscriptionInfo info = null;
4607 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4608 info = slist.get(0);
4609 } else {
4610 for (SubscriptionInfo item : slist) {
4611 if (item.getSubscriptionId() == defaultSubId) {
4612 info = item;
4613 break;
4614 }
4615 }
4616
4617 if (info == null) {
4618 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004619 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004620 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004621
Malcolm Chend965c8b2018-02-28 15:00:40 -08004622 // Try and fetch the locale from the carrier properties or from the SIM language
4623 // preferences (EF-PL and EF-LI)...
4624 final int mcc = info.getMcc();
4625 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4626 String simLanguage = null;
4627 if (defaultPhone != null) {
4628 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4629 if (localeFromDefaultSim != null) {
4630 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4631 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4632 return localeFromDefaultSim.toLanguageTag();
4633 } else {
4634 simLanguage = localeFromDefaultSim.getLanguage();
4635 }
4636 }
4637 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004638
Malcolm Chend965c8b2018-02-28 15:00:40 -08004639 // The SIM language preferences only store a language (e.g. fr = French), not an
4640 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4641 // the SIM and carrier preferences does not include a country we add the country
4642 // determined from the SIM MCC to provide an exact locale.
4643 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4644 simLanguage);
4645 if (mccLocale != null) {
4646 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4647 return mccLocale.toLanguageTag();
4648 }
4649
4650 if (DBG) log("No locale found - returning null");
4651 return null;
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004655 }
4656
4657 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004658 return mSubscriptionController.getAllSubInfoList(
4659 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004660 }
4661
Malcolm Chend965c8b2018-02-28 15:00:40 -08004662 /**
4663 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4664 */
4665 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4666 return mSubscriptionController.getActiveSubscriptionInfoList(
4667 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004668 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004669
Chenjie Yu1ba97252018-01-11 18:16:20 -08004670 private final ModemActivityInfo mLastModemActivityInfo =
4671 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4672
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004673 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004674 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4675 * representing the state of the modem.
4676 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004677 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4678 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004679 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004680 */
4681 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004682 public void requestModemActivityInfo(ResultReceiver result) {
4683 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004684 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
4688 ModemActivityInfo ret = null;
4689 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004690 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4691 CMD_GET_MODEM_ACTIVITY_INFO,
4692 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004693 if (isModemActivityInfoValid(info)) {
4694 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4695 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4696 mergedTxTimeMs[i] =
4697 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4698 }
4699 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4700 mLastModemActivityInfo.setSleepTimeMillis(
4701 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4702 mLastModemActivityInfo.setIdleTimeMillis(
4703 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4704 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4705 mLastModemActivityInfo.setRxTimeMillis(
4706 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4707 mLastModemActivityInfo.setEnergyUsed(
4708 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004709 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004710 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4711 mLastModemActivityInfo.getSleepTimeMillis(),
4712 mLastModemActivityInfo.getIdleTimeMillis(),
4713 mLastModemActivityInfo.getTxTimeMillis(),
4714 mLastModemActivityInfo.getRxTimeMillis(),
4715 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004716 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004717 Bundle bundle = new Bundle();
4718 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4719 result.send(0, bundle);
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004722 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004723 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004724
Siddharth Rayf5d29552018-06-17 15:02:38 -07004725 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4726 // less than total activity duration.
4727 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4728 if (info == null) {
4729 return false;
4730 }
4731 int activityDurationMs =
4732 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4733 int totalTxTimeMs = 0;
4734 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4735 totalTxTimeMs += info.getTxTimeMillis()[i];
4736 }
4737 return (info.isValid()
4738 && (info.getSleepTimeMillis() <= activityDurationMs)
4739 && (info.getIdleTimeMillis() <= activityDurationMs)
4740 && (info.getRxTimeMillis() <= activityDurationMs)
4741 && (totalTxTimeMs <= activityDurationMs));
4742 }
4743
Jack Yu85bd38a2015-11-09 11:34:32 -08004744 /**
4745 * {@hide}
4746 * Returns the service state information on specified subscription.
4747 */
4748 @Override
4749 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004750 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004751 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004752 return null;
4753 }
4754
Malcolm Chend965c8b2018-02-28 15:00:40 -08004755 final long identity = Binder.clearCallingIdentity();
4756 try {
4757 final Phone phone = getPhone(subId);
4758 if (phone == null) {
4759 return null;
4760 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004761
Malcolm Chend965c8b2018-02-28 15:00:40 -08004762 return phone.getServiceState();
4763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004766 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004767
4768 /**
4769 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4770 *
4771 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4772 * voicemail ringtone.
4773 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4774 * PhoneAccount.
4775 */
4776 @Override
4777 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004778 final long identity = Binder.clearCallingIdentity();
4779 try {
4780 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4781 if (phone == null) {
4782 phone = mPhone;
4783 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004784
Malcolm Chend965c8b2018-02-28 15:00:40 -08004785 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4786 } finally {
4787 Binder.restoreCallingIdentity(identity);
4788 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004789 }
4790
4791 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004792 * Sets the per-account voicemail ringtone.
4793 *
4794 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4795 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4796 *
4797 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4798 * voicemail ringtone.
4799 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4800 * PhoneAccount.
4801 */
4802 @Override
4803 public void setVoicemailRingtoneUri(String callingPackage,
4804 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4805 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4806 if (!TextUtils.equals(callingPackage,
4807 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4809 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4810 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004811 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004812
4813 final long identity = Binder.clearCallingIdentity();
4814 try {
4815 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4816 if (phone == null) {
4817 phone = mPhone;
4818 }
4819 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004822 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004823 }
4824
4825 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004826 * Returns whether vibration is set for voicemail notification in Phone settings.
4827 *
4828 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4829 * voicemail vibration setting.
4830 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4831 */
4832 @Override
4833 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004834 final long identity = Binder.clearCallingIdentity();
4835 try {
4836 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4837 if (phone == null) {
4838 phone = mPhone;
4839 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004840
Malcolm Chend965c8b2018-02-28 15:00:40 -08004841 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4842 } finally {
4843 Binder.restoreCallingIdentity(identity);
4844 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004845 }
4846
Youhan Wange64578a2016-05-02 15:32:42 -07004847 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004848 * Sets the per-account voicemail vibration.
4849 *
4850 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4851 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4852 *
4853 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4854 * voicemail vibration setting.
4855 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4856 * specific PhoneAccount.
4857 */
4858 @Override
4859 public void setVoicemailVibrationEnabled(String callingPackage,
4860 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4861 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4862 if (!TextUtils.equals(callingPackage,
4863 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4865 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4866 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004867 }
4868
Malcolm Chend965c8b2018-02-28 15:00:40 -08004869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4872 if (phone == null) {
4873 phone = mPhone;
4874 }
4875 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4876 } finally {
4877 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004878 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004879 }
4880
4881 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004882 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4883 *
4884 * @throws SecurityException if the caller does not have the required permission
4885 */
Brad Ebinger4c460712018-10-01 10:40:55 -07004886 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004887 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07004888 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004889 }
4890
4891 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004892 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4893 * permission.
4894 *
4895 * @throws SecurityException if the caller does not have the required permission
4896 */
4897 private void enforceSendSmsPermission() {
4898 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4899 }
4900
4901 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004902 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004903 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004904 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004905 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004906 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 ComponentName componentName =
4910 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4911 if (componentName == null) {
4912 throw new SecurityException(
4913 "Caller not current active visual voicemail package[null]");
4914 }
4915 String vvmPackage = componentName.getPackageName();
4916 if (!callingPackage.equals(vvmPackage)) {
4917 throw new SecurityException("Caller not current active visual voicemail package["
4918 + vvmPackage + "]");
4919 }
4920 } finally {
4921 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004922 }
4923 }
4924
4925 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004926 * Return the application ID for the app type.
4927 *
4928 * @param subId the subscription ID that this request applies to.
4929 * @param appType the uicc app type.
4930 * @return Application ID for specificied app type, or null if no uicc.
4931 */
4932 @Override
4933 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07004934 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07004935 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004936
4937 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004938 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004939 if (phone == null) {
4940 return null;
4941 }
4942 String aid = null;
4943 try {
4944 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4945 .getApplicationByType(appType).getAid();
4946 } catch (Exception e) {
4947 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4948 }
4949 return aid;
4950 } finally {
4951 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004952 }
Youhan Wange64578a2016-05-02 15:32:42 -07004953 }
4954
Youhan Wang4001d252016-05-11 10:29:41 -07004955 /**
4956 * Return the Electronic Serial Number.
4957 *
4958 * @param subId the subscription ID that this request applies to.
4959 * @return ESN or null if error.
4960 */
4961 @Override
4962 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07004963 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07004964 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004965
4966 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004967 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004968 if (phone == null) {
4969 return null;
4970 }
4971 String esn = null;
4972 try {
4973 esn = phone.getEsn();
4974 } catch (Exception e) {
4975 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4976 }
4977 return esn;
4978 } finally {
4979 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004980 }
Youhan Wang4001d252016-05-11 10:29:41 -07004981 }
4982
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004983 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004984 * Return the Preferred Roaming List Version.
4985 *
4986 * @param subId the subscription ID that this request applies to.
4987 * @return PRLVersion or null if error.
4988 */
4989 @Override
4990 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07004991 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07004992 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004993
4994 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004995 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004996 if (phone == null) {
4997 return null;
4998 }
4999 String cdmaPrlVersion = null;
5000 try {
5001 cdmaPrlVersion = phone.getCdmaPrlVersion();
5002 } catch (Exception e) {
5003 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5004 }
5005 return cdmaPrlVersion;
5006 } finally {
5007 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005008 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005009 }
5010
5011 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005012 * Get snapshot of Telephony histograms
5013 * @return List of Telephony histograms
5014 * @hide
5015 */
5016 @Override
5017 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5019 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005020
5021 final long identity = Binder.clearCallingIdentity();
5022 try {
5023 return RIL.getTelephonyRILTimingHistograms();
5024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005027 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005028
5029 /**
5030 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005031 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005032 * Require system privileges. In the future we may add this to carrier APIs.
5033 *
5034 * @return The number of carriers set successfully, should match length of carriers
5035 */
5036 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005037 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005038 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005039 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005040
Meng Wang9b7c4e92017-02-17 11:41:27 -08005041 if (carriers == null) {
5042 throw new NullPointerException("carriers cannot be null");
5043 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005044
Malcolm Chend965c8b2018-02-28 15:00:40 -08005045 final long identity = Binder.clearCallingIdentity();
5046 try {
5047 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005048 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5049 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005050 return retVal[0];
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
5053 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005054 }
5055
5056 /**
5057 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005058 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005059 * Require system privileges. In the future we may add this to carrier APIs.
5060 *
5061 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5062 * means all carriers are allowed.
5063 */
5064 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005065 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005066 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005067 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005068
5069 final long identity = Binder.clearCallingIdentity();
5070 try {
5071 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005072 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5073 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005074 } finally {
5075 Binder.restoreCallingIdentity(identity);
5076 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005077 }
5078
fionaxu59545b42016-05-25 15:53:37 -07005079 /**
5080 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5081 * @param subId the subscription ID that this action applies to.
5082 * @param enabled control enable or disable metered apns.
5083 * {@hide}
5084 */
5085 @Override
5086 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5087 enforceModifyPermission();
5088 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005089
5090 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005091 if (phone == null) {
5092 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5093 return;
5094 }
5095 try {
5096 phone.carrierActionSetMeteredApnsEnabled(enabled);
5097 } catch (Exception e) {
5098 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005099 } finally {
5100 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005101 }
5102 }
5103
5104 /**
5105 * Action set from carrier signalling broadcast receivers to enable/disable radio
5106 * @param subId the subscription ID that this action applies to.
5107 * @param enabled control enable or disable radio.
5108 * {@hide}
5109 */
5110 @Override
5111 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5112 enforceModifyPermission();
5113 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005114
5115 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005116 if (phone == null) {
5117 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5118 return;
5119 }
5120 try {
5121 phone.carrierActionSetRadioEnabled(enabled);
5122 } catch (Exception e) {
5123 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005124 } finally {
5125 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005126 }
5127 }
5128
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005129 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005130 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5131 * network status based on which carrier apps could apply actions accordingly,
5132 * enable/disable default url handler for example.
5133 *
5134 * @param subId the subscription ID that this action applies to.
5135 * @param report control start/stop reporting the default network status.
5136 * {@hide}
5137 */
5138 @Override
5139 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5140 enforceModifyPermission();
5141 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005142
5143 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005144 if (phone == null) {
5145 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5146 return;
5147 }
5148 try {
5149 phone.carrierActionReportDefaultNetworkStatus(report);
5150 } catch (Exception e) {
5151 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005152 } finally {
5153 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005154 }
5155 }
5156
5157 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005158 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5159 * bug report is being generated.
5160 */
5161 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005162 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005163 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5164 != PackageManager.PERMISSION_GRANTED) {
5165 writer.println("Permission Denial: can't dump Phone from pid="
5166 + Binder.getCallingPid()
5167 + ", uid=" + Binder.getCallingUid()
5168 + "without permission "
5169 + android.Manifest.permission.DUMP);
5170 return;
5171 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005172 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005173 }
Jack Yueb89b242016-06-22 13:27:47 -07005174
Brad Ebingerdac2f002018-04-03 15:17:52 -07005175 @Override
5176 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5177 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5178 throws RemoteException {
5179 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5180 }
5181
Jack Yueb89b242016-06-22 13:27:47 -07005182 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005183 * Get aggregated video call data usage since boot.
5184 *
5185 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5186 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005187 * {@hide}
5188 */
5189 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005190 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005191 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5192 null);
5193
Malcolm Chend965c8b2018-02-28 15:00:40 -08005194 final long identity = Binder.clearCallingIdentity();
5195 try {
5196 // NetworkStatsService keeps tracking the active network interface and identity. It
5197 // records the delta with the corresponding network identity.
5198 // We just return the total video call data usage snapshot since boot.
5199 Phone phone = getPhone(subId);
5200 if (phone != null) {
5201 return phone.getVtDataUsage(perUidStats);
5202 }
5203 return null;
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005206 }
Jack Yueb89b242016-06-22 13:27:47 -07005207 }
Jack Yu75ab2952016-07-08 14:29:33 -07005208
5209 /**
5210 * Policy control of data connection. Usually used when data limit is passed.
5211 * @param enabled True if enabling the data, otherwise disabling.
5212 * @param subId Subscription index
5213 * {@hide}
5214 */
5215 @Override
5216 public void setPolicyDataEnabled(boolean enabled, int subId) {
5217 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005218
5219 final long identity = Binder.clearCallingIdentity();
5220 try {
5221 Phone phone = getPhone(subId);
5222 if (phone != null) {
5223 phone.setPolicyDataEnabled(enabled);
5224 }
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005227 }
5228 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005229
5230 /**
5231 * Get Client request stats
5232 * @return List of Client Request Stats
5233 * @hide
5234 */
5235 @Override
5236 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005238 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005239 return null;
5240 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005241 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005242
Malcolm Chend965c8b2018-02-28 15:00:40 -08005243 final long identity = Binder.clearCallingIdentity();
5244 try {
5245 if (phone != null) {
5246 return phone.getClientRequestStats();
5247 }
5248
5249 return null;
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005253 }
5254
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005255 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005256 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005257 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005258 }
Jack Yueb4124c2017-02-16 15:32:43 -08005259
5260 /**
Grace Chen70990072017-03-24 17:21:30 -07005261 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005262 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005263 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005264 * @param state State of SIM (power down, power up, pass through)
5265 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5266 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5267 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005268 *
5269 **/
5270 @Override
Grace Chen70990072017-03-24 17:21:30 -07005271 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005272 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005273 Phone phone = PhoneFactory.getPhone(slotIndex);
5274
vagdevie435a3e2018-08-15 16:01:53 -07005275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5276
Malcolm Chend965c8b2018-02-28 15:00:40 -08005277 final long identity = Binder.clearCallingIdentity();
5278 try {
5279 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005280 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005281 }
5282 } finally {
5283 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005284 }
5285 }
Shuo Qiandd210312017-04-12 22:11:33 +00005286
Tyler Gunn65d45c22017-06-05 11:22:26 -07005287 private boolean isUssdApiAllowed(int subId) {
5288 CarrierConfigManager configManager =
5289 (CarrierConfigManager) mPhone.getContext().getSystemService(
5290 Context.CARRIER_CONFIG_SERVICE);
5291 if (configManager == null) {
5292 return false;
5293 }
5294 PersistableBundle pb = configManager.getConfigForSubId(subId);
5295 if (pb == null) {
5296 return false;
5297 }
5298 return pb.getBoolean(
5299 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5300 }
5301
Shuo Qiandd210312017-04-12 22:11:33 +00005302 /**
5303 * Check if phone is in emergency callback mode
5304 * @return true if phone is in emergency callback mode
5305 * @param subId sub id
5306 */
goneil9c5f4872017-12-05 14:07:56 -08005307 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005308 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005309 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005310 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005311
5312 final long identity = Binder.clearCallingIdentity();
5313 try {
5314 if (phone != null) {
5315 return phone.isInEcm();
5316 } else {
5317 return false;
5318 }
5319 } finally {
5320 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005321 }
5322 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005323
5324 /**
5325 * Get the current signal strength information for the given subscription.
5326 * Because this information is not updated when the device is in a low power state
5327 * it should not be relied-upon to be current.
5328 * @param subId Subscription index
5329 * @return the most recent cached signal strength info from the modem
5330 */
5331 @Override
5332 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005333 final long identity = Binder.clearCallingIdentity();
5334 try {
5335 Phone p = getPhone(subId);
5336 if (p == null) {
5337 return null;
5338 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005339
Malcolm Chend965c8b2018-02-28 15:00:40 -08005340 return p.getSignalStrength();
5341 } finally {
5342 Binder.restoreCallingIdentity(identity);
5343 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005344 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005345
Pengquan Meng9140aec2018-08-22 14:49:57 -07005346 /**
chen xu907e5a22018-10-11 13:21:04 -07005347 * Get the current modem radio state for the given slot.
5348 * @param slotIndex slot index.
5349 * @param callingPackage the name of the package making the call.
5350 * @return the current radio power state from the modem
5351 */
5352 @Override
5353 public int getRadioPowerState(int slotIndex, String callingPackage) {
5354 Phone phone = PhoneFactory.getPhone(slotIndex);
5355 if (phone != null) {
5356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5357 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5358 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5359 }
5360
5361 final long identity = Binder.clearCallingIdentity();
5362 try {
5363 return phone.getRadioPowerState();
5364 } finally {
5365 Binder.restoreCallingIdentity(identity);
5366 }
5367 }
5368 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5369 }
5370
5371 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005372 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5373 *
5374 * <p>Requires one of the following permissions:
5375 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5376 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5377 * privileges.
5378 *
5379 * @param subId subscription id
5380 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5381 * {@code false}.
5382 */
5383 @Override
5384 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005385 boolean isEnabled = false;
5386 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005387 try {
5388 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005389 null /* message */);
5390 Phone phone = getPhone(subId);
5391 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005392 } catch (Exception e) {
5393 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5394 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005395 } finally {
5396 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005397 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005398 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005399 }
5400
5401
5402 /**
5403 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5404 *
5405 * <p> Requires permission:
5406 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5407 * privileges.
5408 *
5409 * @param subId subscription id
5410 * @param isEnabled {@code true} means enable, {@code false} means disable.
5411 */
5412 @Override
5413 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5417 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005418
Pengquan Meng0c05b502018-09-06 09:59:22 -07005419 Phone phone = getPhone(subId);
5420 if (phone != null) {
5421 phone.setDataRoamingEnabled(isEnabled);
5422 }
5423 } finally {
5424 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005425 }
5426 }
5427
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005428 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005429 public boolean isManualNetworkSelectionAllowed(int subId) {
5430 boolean isAllowed = true;
5431 final long identity = Binder.clearCallingIdentity();
5432 try {
5433 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5434 mApp, subId, "isManualNetworkSelectionAllowed");
5435 Phone phone = getPhone(subId);
5436 if (phone != null) {
5437 isAllowed = phone.isCspPlmnEnabled();
5438 }
5439 } finally {
5440 Binder.restoreCallingIdentity(identity);
5441 }
5442 return isAllowed;
5443 }
5444
5445 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005446 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005447 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005448
Malcolm Chend965c8b2018-02-28 15:00:40 -08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
5451 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5452 if (slots == null) {
5453 Rlog.i(LOG_TAG, "slots is null.");
5454 return null;
5455 }
5456
5457 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5458 for (int i = 0; i < slots.length; i++) {
5459 UiccSlot slot = slots[i];
5460 if (slot == null) {
5461 continue;
5462 }
5463
5464 String cardId;
5465 UiccCard card = slot.getUiccCard();
5466 if (card != null) {
5467 cardId = card.getCardId();
5468 } else {
5469 cardId = slot.getIccId();
5470 }
5471
5472 int cardState = 0;
5473 switch (slot.getCardState()) {
5474 case CARDSTATE_ABSENT:
5475 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5476 break;
5477 case CARDSTATE_PRESENT:
5478 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5479 break;
5480 case CARDSTATE_ERROR:
5481 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5482 break;
5483 case CARDSTATE_RESTRICTED:
5484 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5485 break;
5486 default:
5487 break;
5488
5489 }
5490
5491 infos[i] = new UiccSlotInfo(
5492 slot.isActive(),
5493 slot.isEuicc(),
5494 cardId,
5495 cardState,
5496 slot.getPhoneId(),
5497 slot.isExtendedApduSupported());
5498 }
5499 return infos;
5500 } finally {
5501 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005502 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005503 }
5504
5505 @Override
5506 public boolean switchSlots(int[] physicalSlots) {
5507 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005508
5509 final long identity = Binder.clearCallingIdentity();
5510 try {
5511 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5512 } finally {
5513 Binder.restoreCallingIdentity(identity);
5514 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005515 }
Jack Yu4c988042018-02-27 15:30:01 -08005516
5517 @Override
5518 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5519 enforceModifyPermission();
5520 final Phone phone = getPhone(subId);
5521 if (phone == null) {
5522 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5523 return;
5524 }
5525
Malcolm Chend965c8b2018-02-28 15:00:40 -08005526 final long identity = Binder.clearCallingIdentity();
5527 try {
5528 phone.setRadioIndicationUpdateMode(filters, mode);
5529 } finally {
5530 Binder.restoreCallingIdentity(identity);
5531 }
Jack Yu4c988042018-02-27 15:30:01 -08005532 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005533
5534 /**
goneil47ffb6e2018-04-06 15:40:58 -07005535 * A test API to reload the UICC profile.
5536 *
5537 * <p>Requires that the calling app has permission
5538 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5539 * @hide
5540 */
5541 @Override
5542 public void refreshUiccProfile(int subId) {
5543 enforceModifyPermission();
5544
5545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 Phone phone = getPhone(subId);
5548 if (phone == null) {
5549 return;
5550 }
5551 UiccCard uiccCard = phone.getUiccCard();
5552 if (uiccCard == null) {
5553 return;
5554 }
5555 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5556 if (uiccProfile == null) {
5557 return;
5558 }
5559 uiccProfile.refresh();
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
5563 }
5564
5565 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005566 * Returns false if the mobile data is disabled by default, otherwise return true.
5567 */
5568 private boolean getDefaultDataEnabled() {
5569 return "true".equalsIgnoreCase(
5570 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5571 }
5572
5573 /**
5574 * Returns true if the data roaming is enabled by default, i.e the system property
5575 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5576 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5577 */
5578 private boolean getDefaultDataRoamingEnabled(int subId) {
5579 final CarrierConfigManager configMgr = (CarrierConfigManager)
5580 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5581 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5582 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5583 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5584 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5585 return isDataRoamingEnabled;
5586 }
5587
5588 /**
5589 * Returns the default network type for the given {@code subId}, if the default network type is
5590 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5591 */
5592 private int getDefaultNetworkType(int subId) {
5593 return Integer.parseInt(
5594 TelephonyManager.getTelephonyProperty(
5595 mSubscriptionController.getPhoneId(subId),
5596 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5597 String.valueOf(Phone.PREFERRED_NT_MODE)));
5598 }
fionaxua13278b2018-03-21 00:08:13 -07005599
5600 @Override
5601 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5602 gid1, String gid2, String plmn, String spn) {
5603 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005604
5605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 final Phone phone = getPhone(subId);
5608 if (phone == null) {
5609 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5610 return;
5611 }
5612 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5613 } finally {
5614 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005615 }
fionaxua13278b2018-03-21 00:08:13 -07005616 }
5617
5618 @Override
5619 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005620 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005621
5622 final long identity = Binder.clearCallingIdentity();
5623 try {
5624 final Phone phone = getPhone(subId);
5625 if (phone == null) {
5626 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5627 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5628 }
5629 return phone.getCarrierIdListVersion();
5630 } finally {
5631 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005632 }
fionaxua13278b2018-03-21 00:08:13 -07005633 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005634
5635 @Override
5636 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5637 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5638 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5639 return -1;
5640 }
5641
5642 final long identity = Binder.clearCallingIdentity();
5643 try {
5644 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
5648 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005649
5650 @Override
5651 public int getCdmaRoamingMode(int subId) {
5652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5653 mApp, subId, "getCdmaRoamingMode");
5654
5655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
5661 }
5662
5663 @Override
5664 public boolean setCdmaRoamingMode(int subId, int mode) {
5665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5666 mApp, subId, "setCdmaRoamingMode");
5667
5668 final long identity = Binder.clearCallingIdentity();
5669 try {
5670 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
5673 }
5674 }
5675
5676 @Override
5677 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5679 mApp, subId, "setCdmaSubscriptionMode");
5680
5681 final long identity = Binder.clearCallingIdentity();
5682 try {
5683 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
5687 }
chen xu7ee67862018-10-30 22:27:10 -07005688
sqian2fff4a32018-11-05 14:18:37 -08005689 private void ensureUserRunning(int userId) {
5690 if (!mUserManager.isUserRunning(userId)) {
5691 throw new IllegalStateException("User " + userId + " does not exist or not running");
5692 }
5693 }
5694
5695 /**
5696 * Returns a list of SMS apps on a given user.
5697 *
5698 * Only the shell user (UID 2000 or 0) can call it.
5699 * Target user must be running.
5700 */
5701 @Override
5702 public String[] getSmsApps(int userId) {
5703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5704 ensureUserRunning(userId);
5705
5706 final Collection<SmsApplicationData> apps =
5707 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5708
5709 String[] ret = new String[apps.size()];
5710 int i = 0;
5711 for (SmsApplicationData app : apps) {
5712 ret[i++] = app.mPackageName;
5713 }
5714 return ret;
5715 }
5716
5717 /**
5718 * Returns the default SMS app package name on a given user.
5719 *
5720 * Only the shell user (UID 2000 or 0) can call it.
5721 * Target user must be running.
5722 */
5723 @Override
5724 public String getDefaultSmsApp(int userId) {
5725 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5726 ensureUserRunning(userId);
5727
5728 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5729 /* updateIfNeeded= */ true, userId);
5730 return cn == null ? null : cn.getPackageName();
5731 }
5732
5733 /**
5734 * Set a package as the default SMS app on a given user.
5735 *
5736 * Only the shell user (UID 2000 or 0) can call it.
5737 * Target user must be running.
5738 */
5739 @Override
5740 public void setDefaultSmsApp(int userId, String packageName) {
5741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5742 ensureUserRunning(userId);
5743
5744 boolean found = false;
5745 for (String pkg : getSmsApps(userId)) {
5746 if (TextUtils.equals(packageName, pkg)) {
5747 found = true;
5748 break;
5749 }
5750 }
5751 if (!found) {
5752 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5753 }
5754
5755 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5756 }
5757
chen xu7ee67862018-10-30 22:27:10 -07005758 @Override
sqian04b86072018-11-07 14:02:21 -08005759 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5760 String callingPackage) {
5761 // TODO connect with internal content
5762 return null;
5763 }
5764
5765 @Override
5766 public boolean isCurrentEmergencyNumber(String number) {
5767 // TODO connect with internal content
5768 return false;
5769 }
5770
5771 @Override
chen xu7ee67862018-10-30 22:27:10 -07005772 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5773 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5774 Phone phone = getPhone(subId);
5775 if (phone == null) {
5776 return null;
5777 }
5778 final long identity = Binder.clearCallingIdentity();
5779 try {
5780 UiccProfile profile = UiccController.getInstance()
5781 .getUiccProfileForPhone(phone.getPhoneId());
5782 if (profile != null) {
5783 return profile.getCertsFromCarrierPrivilegeAccessRules();
5784 }
5785 } finally {
5786 Binder.restoreCallingIdentity(identity);
5787 }
5788 return null;
5789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005790}