blob: f9f60d419d157cb78147f37dd9f6db2fce9a5640 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070028import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080043import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070046import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070047import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070049import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070050import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080052import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070053import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080054import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080055import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070056import android.telecom.TelecomManager;
sqianc5eccab2018-10-19 18:46:41 -070057import android.telephony.emergency.EmergencyNumber;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070060import android.telephony.CellInfoGsm;
61import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070062import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070063import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070064import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080065import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070066import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080067import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070068import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070069import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080072import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070073import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080074import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070076import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000078import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070081import android.telephony.cdma.CdmaCellLocation;
82import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070083import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080084import android.telephony.ims.aidl.IImsConfig;
85import android.telephony.ims.aidl.IImsMmTelFeature;
86import android.telephony.ims.aidl.IImsRcsFeature;
87import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070088import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080089import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080095
Brad Ebinger35c841c2018-10-01 10:40:55 -070096import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070097import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080098import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070099import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700100import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700101import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700102import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700103import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800106import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700107import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100108import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700109import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700112import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800113import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700114import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700115import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700116import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700117import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700118import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700119import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700120import com.android.internal.telephony.SmsApplication;
121import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800122import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800123import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700124import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.uicc.IccIoResult;
126import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800127import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700128import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800129import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800131import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000132import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700133import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700135import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800136import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700137import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700138import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800139
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700140import java.io.FileDescriptor;
141import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800144import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700145import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800146import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100147import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800148import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149
150/**
151 * Implementation of the ITelephony interface.
152 */
Santos Cordon117fee72014-05-16 17:56:12 -0700153public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154 private static final String LOG_TAG = "PhoneInterfaceManager";
155 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
156 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800157 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158
159 // Message codes used with mMainThreadHandler
160 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700161 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
162 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163 private static final int CMD_OPEN_CHANNEL = 9;
164 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
165 private static final int CMD_CLOSE_CHANNEL = 11;
166 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800167 private static final int CMD_NV_READ_ITEM = 13;
168 private static final int EVENT_NV_READ_ITEM_DONE = 14;
169 private static final int CMD_NV_WRITE_ITEM = 15;
170 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
171 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
172 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
173 private static final int CMD_NV_RESET_CONFIG = 19;
174 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800175 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
176 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
177 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
178 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800179 private static final int CMD_SEND_ENVELOPE = 25;
180 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000181 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
182 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700183 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
184 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
185 private static final int CMD_EXCHANGE_SIM_IO = 31;
186 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800187 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
188 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700189 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
190 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700191 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
192 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700193 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
194 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
195 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
196 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700197 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
198 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
199 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
200 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700201 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
203 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000204 private static final int CMD_SWITCH_SLOTS = 50;
205 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700206 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
207 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
208 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
209 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
210 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
211 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
212 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
213 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700214 private static final int CMD_GET_ALL_CELL_INFO = 60;
215 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
216 private static final int CMD_GET_CELL_LOCATION = 62;
217 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800219 // Parameters of select command.
220 private static final int SELECT_COMMAND = 0xA4;
221 private static final int SELECT_P1 = 0x04;
222 private static final int SELECT_P2 = 0;
223 private static final int SELECT_P3 = 0x10;
224
Pengquan Meng85728fb2018-03-12 16:31:21 -0700225 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
226 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
227 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
228
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229 /** The singleton instance. */
230 private static PhoneInterfaceManager sInstance;
231
Wink Saville3ab207e2014-11-20 13:07:20 -0800232 private PhoneGlobals mApp;
233 private Phone mPhone;
234 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700235 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800236 private AppOpsManager mAppOps;
237 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800238 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800239 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700240 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241
Derek Tan97ebb422014-09-05 16:55:38 -0700242 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
243 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800244 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700245
Derek Tan740e1672017-06-27 14:56:27 -0700246 // The AID of ISD-R.
247 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
248
yinxub1bed742017-04-17 11:45:04 -0700249 private NetworkScanRequestTracker mNetworkScanRequestTracker;
250
David Kelly5e06a7f2018-03-12 14:10:59 +0000251 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
252 private static final int MANUFACTURER_CODE_LENGTH = 8;
253
Derek Tan89e89d42014-07-08 17:00:10 -0700254 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700255 * A request object to use for transmitting data to an ICC.
256 */
257 private static final class IccAPDUArgument {
258 public int channel, cla, command, p1, p2, p3;
259 public String data;
260
261 public IccAPDUArgument(int channel, int cla, int command,
262 int p1, int p2, int p3, String data) {
263 this.channel = channel;
264 this.cla = cla;
265 this.command = command;
266 this.p1 = p1;
267 this.p2 = p2;
268 this.p3 = p3;
269 this.data = data;
270 }
271 }
272
273 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700274 * A request object to use for transmitting data to an ICC.
275 */
276 private static final class ManualNetworkSelectionArgument {
277 public OperatorInfo operatorInfo;
278 public boolean persistSelection;
279
280 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
281 this.operatorInfo = operatorInfo;
282 this.persistSelection = persistSelection;
283 }
284 }
285
286 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
288 * request after sending. The main thread will notify the request when it is complete.
289 */
290 private static final class MainThreadRequest {
291 /** The argument to use for the request */
292 public Object argument;
293 /** The result of the request that is run on the main thread */
294 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800295 // The subscriber id that this request applies to. Defaults to
296 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
297 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298
Nathan Harold92bed182018-10-12 18:16:49 -0700299 // In cases where subId is unavailable, the caller needs to specify the phone.
300 public Phone phone;
301
vagdeviaf9a5b92018-08-15 16:01:53 -0700302 public WorkSource workSource;
303
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304 public MainThreadRequest(Object argument) {
305 this.argument = argument;
306 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800307
Nathan Harold92bed182018-10-12 18:16:49 -0700308 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
309 this.argument = argument;
310 if (phone != null) {
311 this.phone = phone;
312 }
313 this.workSource = workSource;
314 }
315
vagdeviaf9a5b92018-08-15 16:01:53 -0700316 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800317 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800318 if (subId != null) {
319 this.subId = subId;
320 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700321 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323 }
324
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800325 private static final class IncomingThirdPartyCallArgs {
326 public final ComponentName component;
327 public final String callId;
328 public final String callerDisplayName;
329
330 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
331 String callerDisplayName) {
332 this.component = component;
333 this.callId = callId;
334 this.callerDisplayName = callerDisplayName;
335 }
336 }
337
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 /**
339 * A handler that processes messages on the main thread in the phone process. Since many
340 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
341 * inbound binder threads to the main thread in the phone process. The Binder thread
342 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
343 * on, which will be notified when the operation completes and will contain the result of the
344 * request.
345 *
346 * <p>If a MainThreadRequest object is provided in the msg.obj field,
347 * note that request.result must be set to something non-null for the calling thread to
348 * unblock.
349 */
350 private final class MainThreadHandler extends Handler {
351 @Override
352 public void handleMessage(Message msg) {
353 MainThreadRequest request;
354 Message onCompleted;
355 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800356 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700357 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
359 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700360 case CMD_HANDLE_USSD_REQUEST: {
361 request = (MainThreadRequest) msg.obj;
362 final Phone phone = getPhoneFromRequest(request);
363 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
364 String ussdRequest = ussdObject.first;
365 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700366
Pengquan Menga1bb6272018-09-06 09:59:22 -0700367 if (!isUssdApiAllowed(request.subId)) {
368 // Carrier does not support use of this API, return failure.
369 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
370 UssdResponse response = new UssdResponse(ussdRequest, null);
371 Bundle returnData = new Bundle();
372 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
373 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700374
Pengquan Menga1bb6272018-09-06 09:59:22 -0700375 request.result = true;
376 notifyRequester(request);
377 return;
378 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700379
Pengquan Menga1bb6272018-09-06 09:59:22 -0700380 try {
381 request.result = phone != null
382 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
383 } catch (CallStateException cse) {
384 request.result = false;
385 }
386 // Wake up the requesting thread
387 notifyRequester(request);
388 break;
pkanwar32d516d2016-10-14 19:37:38 -0700389 }
390
Yorke Lee716f67e2015-06-17 15:39:16 -0700391 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700393 final Phone phone = getPhoneFromRequest(request);
394 request.result = phone != null ?
395 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
396 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700398 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700402 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700403 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800405 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700406 if (uiccCard == null) {
407 loge("iccTransmitApduLogicalChannel: No UICC");
408 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700409 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700410 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
412 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700413 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 iccArgument.channel, iccArgument.cla, iccArgument.command,
415 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 break;
419
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 ar = (AsyncResult) msg.obj;
422 request = (MainThreadRequest) ar.userObj;
423 if (ar.exception == null && ar.result != null) {
424 request.result = ar.result;
425 } else {
426 request.result = new IccIoResult(0x6F, 0, (byte[])null);
427 if (ar.result == null) {
428 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800429 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800431 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 } else {
433 loge("iccTransmitApduLogicalChannel: Unknown exception");
434 }
435 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 break;
438
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700439 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
440 request = (MainThreadRequest) msg.obj;
441 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800442 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 if (uiccCard == null) {
444 loge("iccTransmitApduBasicChannel: No UICC");
445 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700446 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 } else {
448 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
449 request);
450 uiccCard.iccTransmitApduBasicChannel(
451 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
452 iccArgument.p3, iccArgument.data, onCompleted);
453 }
454 break;
455
456 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
457 ar = (AsyncResult) msg.obj;
458 request = (MainThreadRequest) ar.userObj;
459 if (ar.exception == null && ar.result != null) {
460 request.result = ar.result;
461 } else {
462 request.result = new IccIoResult(0x6F, 0, (byte[])null);
463 if (ar.result == null) {
464 loge("iccTransmitApduBasicChannel: Empty response");
465 } else if (ar.exception instanceof CommandException) {
466 loge("iccTransmitApduBasicChannel: CommandException: " +
467 ar.exception);
468 } else {
469 loge("iccTransmitApduBasicChannel: Unknown exception");
470 }
471 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700472 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 break;
474
475 case CMD_EXCHANGE_SIM_IO:
476 request = (MainThreadRequest) msg.obj;
477 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800478 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 if (uiccCard == null) {
480 loge("iccExchangeSimIO: No UICC");
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 } else {
484 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
485 request);
486 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
487 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
488 iccArgument.data, onCompleted);
489 }
490 break;
491
492 case EVENT_EXCHANGE_SIM_IO_DONE:
493 ar = (AsyncResult) msg.obj;
494 request = (MainThreadRequest) ar.userObj;
495 if (ar.exception == null && ar.result != null) {
496 request.result = ar.result;
497 } else {
498 request.result = new IccIoResult(0x6f, 0, (byte[])null);
499 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700500 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 break;
502
Derek Tan4d5e5c12014-02-04 11:54:58 -0800503 case CMD_SEND_ENVELOPE:
504 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800505 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700506 if (uiccCard == null) {
507 loge("sendEnvelopeWithStatus: No UICC");
508 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700510 } else {
511 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
512 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
513 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800514 break;
515
516 case EVENT_SEND_ENVELOPE_DONE:
517 ar = (AsyncResult) msg.obj;
518 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700519 if (ar.exception == null && ar.result != null) {
520 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800521 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
523 if (ar.result == null) {
524 loge("sendEnvelopeWithStatus: Empty response");
525 } else if (ar.exception instanceof CommandException) {
526 loge("sendEnvelopeWithStatus: CommandException: " +
527 ar.exception);
528 } else {
529 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
530 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800531 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 break;
534
Shishir Agrawal566b7612013-10-28 14:41:00 -0700535 case CMD_OPEN_CHANNEL:
536 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800538 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 if (uiccCard == null) {
540 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800541 request.result = new IccOpenLogicalChannelResponse(-1,
542 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700544 } else {
545 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800546 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
547 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700548 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 break;
550
551 case EVENT_OPEN_CHANNEL_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 int[] result = (int[]) ar.result;
557 int channelId = result[0];
558 byte[] selectResponse = null;
559 if (result.length > 1) {
560 selectResponse = new byte[result.length - 1];
561 for (int i = 1; i < result.length; ++i) {
562 selectResponse[i - 1] = (byte) result[i];
563 }
564 }
565 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700566 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 if (ar.result == null) {
569 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 if (ar.exception != null) {
572 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
573 }
574
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700575 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700576 if (ar.exception instanceof CommandException) {
577 CommandException.Error error =
578 ((CommandException) (ar.exception)).getCommandError();
579 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700580 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700581 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 }
584 }
585 openChannelResp = new IccOpenLogicalChannelResponse(
586 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700588 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
592 case CMD_CLOSE_CHANNEL:
593 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800594 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 if (uiccCard == null) {
596 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900597 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 } else {
600 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
601 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
602 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 break;
604
605 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800606 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
607 break;
608
609 case CMD_NV_READ_ITEM:
610 request = (MainThreadRequest) msg.obj;
611 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700612 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800613 break;
614
615 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 ar = (AsyncResult) msg.obj;
617 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800618 if (ar.exception == null && ar.result != null) {
619 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800621 request.result = "";
622 if (ar.result == null) {
623 loge("nvReadItem: Empty response");
624 } else if (ar.exception instanceof CommandException) {
625 loge("nvReadItem: CommandException: " +
626 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800628 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 }
630 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 break;
633
Jake Hambye994d462014-02-03 13:10:13 -0800634 case CMD_NV_WRITE_ITEM:
635 request = (MainThreadRequest) msg.obj;
636 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
637 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700638 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
639 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800640 break;
641
642 case EVENT_NV_WRITE_ITEM_DONE:
643 handleNullReturnEvent(msg, "nvWriteItem");
644 break;
645
646 case CMD_NV_WRITE_CDMA_PRL:
647 request = (MainThreadRequest) msg.obj;
648 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
649 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
650 break;
651
652 case EVENT_NV_WRITE_CDMA_PRL_DONE:
653 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
654 break;
655
656 case CMD_NV_RESET_CONFIG:
657 request = (MainThreadRequest) msg.obj;
658 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
659 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
660 break;
661
662 case EVENT_NV_RESET_CONFIG_DONE:
663 handleNullReturnEvent(msg, "nvResetConfig");
664 break;
665
Jake Hamby7c27be32014-03-03 13:25:59 -0800666 case CMD_GET_PREFERRED_NETWORK_TYPE:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700669 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800670 break;
671
672 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
673 ar = (AsyncResult) msg.obj;
674 request = (MainThreadRequest) ar.userObj;
675 if (ar.exception == null && ar.result != null) {
676 request.result = ar.result; // Integer
677 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800678 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800679 if (ar.result == null) {
680 loge("getPreferredNetworkType: Empty response");
681 } else if (ar.exception instanceof CommandException) {
682 loge("getPreferredNetworkType: CommandException: " +
683 ar.exception);
684 } else {
685 loge("getPreferredNetworkType: Unknown exception");
686 }
687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800689 break;
690
691 case CMD_SET_PREFERRED_NETWORK_TYPE:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
694 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700695 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800696 break;
697
698 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
699 handleNullReturnEvent(msg, "setPreferredNetworkType");
700 break;
701
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000702 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
703 request = (MainThreadRequest)msg.obj;
704 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700705 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000706 break;
707
708 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
709 ar = (AsyncResult)msg.obj;
710 request = (MainThreadRequest)ar.userObj;
711 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700712 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000713 break;
714
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800715 case CMD_SET_VOICEMAIL_NUMBER:
716 request = (MainThreadRequest) msg.obj;
717 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
718 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800719 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
720 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800721 break;
722
723 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
724 handleNullReturnEvent(msg, "setVoicemailNumber");
725 break;
726
Stuart Scott54788802015-03-30 13:18:01 -0700727 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
730 request);
731 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
732 break;
733
734 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
735 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
736 break;
737
Shishir Agrawal302c8692015-06-19 13:49:39 -0700738 case CMD_PERFORM_NETWORK_SCAN:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
741 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
742 break;
743
744 case EVENT_PERFORM_NETWORK_SCAN_DONE:
745 ar = (AsyncResult) msg.obj;
746 request = (MainThreadRequest) ar.userObj;
747 CellNetworkScanResult cellScanResult;
748 if (ar.exception == null && ar.result != null) {
749 cellScanResult = new CellNetworkScanResult(
750 CellNetworkScanResult.STATUS_SUCCESS,
751 (List<OperatorInfo>) ar.result);
752 } else {
753 if (ar.result == null) {
754 loge("getCellNetworkScanResults: Empty response");
755 }
756 if (ar.exception != null) {
757 loge("getCellNetworkScanResults: Exception: " + ar.exception);
758 }
759 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
760 if (ar.exception instanceof CommandException) {
761 CommandException.Error error =
762 ((CommandException) (ar.exception)).getCommandError();
763 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
764 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
765 } else if (error == CommandException.Error.GENERIC_FAILURE) {
766 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
767 }
768 }
769 cellScanResult = new CellNetworkScanResult(errorCode, null);
770 }
771 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700772 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700773 break;
774
775 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
776 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700777 ManualNetworkSelectionArgument selArg =
778 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700779 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
780 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700781 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
782 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700783 break;
784
785 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700786 ar = (AsyncResult) msg.obj;
787 request = (MainThreadRequest) ar.userObj;
788 if (ar.exception == null) {
789 request.result = true;
790 } else {
791 request.result = false;
792 loge("setNetworkSelectionModeManual " + ar.exception);
793 }
794 notifyRequester(request);
795 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 break;
797
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700798 case CMD_GET_MODEM_ACTIVITY_INFO:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700801 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700802 break;
803
804 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 if (ar.exception == null && ar.result != null) {
808 request.result = ar.result;
809 } else {
810 if (ar.result == null) {
811 loge("queryModemActivityInfo: Empty response");
812 } else if (ar.exception instanceof CommandException) {
813 loge("queryModemActivityInfo: CommandException: " +
814 ar.exception);
815 } else {
816 loge("queryModemActivityInfo: Unknown exception");
817 }
818 }
Amit Mahajand4766222016-01-28 15:28:28 -0800819 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
820 if (request.result == null) {
821 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
822 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700823 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700824 break;
825
Meng Wang1a7c35a2016-05-05 20:56:15 -0700826 case CMD_SET_ALLOWED_CARRIERS:
827 request = (MainThreadRequest) msg.obj;
828 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
829 mPhone.setAllowedCarriers(
830 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700831 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700832 break;
833
834 case EVENT_SET_ALLOWED_CARRIERS_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result;
839 } else {
840 if (ar.result == null) {
841 loge("setAllowedCarriers: Empty response");
842 } else if (ar.exception instanceof CommandException) {
843 loge("setAllowedCarriers: CommandException: " +
844 ar.exception);
845 } else {
846 loge("setAllowedCarriers: Unknown exception");
847 }
848 }
849 // Result cannot be null. Return -1 on error.
850 if (request.result == null) {
851 request.result = new int[]{-1};
852 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700853 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700854 break;
855
856 case CMD_GET_ALLOWED_CARRIERS:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700859 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700860 break;
861
862 case EVENT_GET_ALLOWED_CARRIERS_DONE:
863 ar = (AsyncResult) msg.obj;
864 request = (MainThreadRequest) ar.userObj;
865 if (ar.exception == null && ar.result != null) {
866 request.result = ar.result;
867 } else {
868 if (ar.result == null) {
869 loge("getAllowedCarriers: Empty response");
870 } else if (ar.exception instanceof CommandException) {
871 loge("getAllowedCarriers: CommandException: " +
872 ar.exception);
873 } else {
874 loge("getAllowedCarriers: Unknown exception");
875 }
876 }
877 // Result cannot be null. Return empty list of CarrierIdentifier.
878 if (request.result == null) {
879 request.result = new ArrayList<CarrierIdentifier>(0);
880 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700881 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700882 break;
883
Nathan Haroldb3014052017-01-25 15:57:32 -0800884 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null && ar.result != null) {
888 request.result = ar.result;
889 } else {
890 request.result = new IllegalArgumentException(
891 "Failed to retrieve Forbidden Plmns");
892 if (ar.result == null) {
893 loge("getForbiddenPlmns: Empty response");
894 } else {
895 loge("getForbiddenPlmns: Unknown exception");
896 }
897 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700898 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800899 break;
900
901 case CMD_GET_FORBIDDEN_PLMNS:
902 request = (MainThreadRequest) msg.obj;
903 uiccCard = getUiccCardFromRequest(request);
904 if (uiccCard == null) {
905 loge("getForbiddenPlmns() UiccCard is null");
906 request.result = new IllegalArgumentException(
907 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700908 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800909 break;
910 }
911 Integer appType = (Integer) request.argument;
912 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
913 if (uiccApp == null) {
914 loge("getForbiddenPlmns() no app with specified type -- "
915 + appType);
916 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700917 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800918 break;
919 } else {
920 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
921 + " specified type -- " + appType);
922 }
923 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
924 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
925 onCompleted);
926 break;
927
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000928 case CMD_SWITCH_SLOTS:
929 request = (MainThreadRequest) msg.obj;
930 int[] physicalSlots = (int[]) request.argument;
931 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
932 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
933 break;
934
935 case EVENT_SWITCH_SLOTS_DONE:
936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
938 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
940 break;
941 case CMD_GET_NETWORK_SELECTION_MODE:
942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
944 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
945 break;
946
947 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
948 ar = (AsyncResult) msg.obj;
949 request = (MainThreadRequest) ar.userObj;
950 if (ar.exception != null) {
951 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
952 } else {
953 int mode = ((int[]) ar.result)[0];
954 if (mode == 0) {
955 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
956 } else {
957 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
958 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000959 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700960 notifyRequester(request);
961 break;
962 case CMD_GET_CDMA_ROAMING_MODE:
963 request = (MainThreadRequest) msg.obj;
964 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
965 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
966 break;
967 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
970 if (ar.exception != null) {
971 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
972 } else {
973 request.result = ((int[]) ar.result)[0];
974 }
975 notifyRequester(request);
976 break;
977 case CMD_SET_CDMA_ROAMING_MODE:
978 request = (MainThreadRequest) msg.obj;
979 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
980 int mode = (int) request.argument;
981 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
982 break;
983 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 request.result = ar.exception == null;
987 notifyRequester(request);
988 break;
989 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
992 int subscriptionMode = (int) request.argument;
993 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
994 break;
995 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 request.result = ar.exception == null;
999 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001000 break;
1001
Nathan Harold3ff88932018-08-14 10:19:49 -07001002 case CMD_GET_ALL_CELL_INFO:
1003 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001004 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001005 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001006 break;
1007
1008 case EVENT_GET_ALL_CELL_INFO_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001011 // If a timeout occurs, the response will be null
1012 request.result = (ar.exception == null && ar.result != null)
1013 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001014 synchronized (request) {
1015 request.notifyAll();
1016 }
1017 break;
1018
1019 case CMD_GET_CELL_LOCATION: {
1020 request = (MainThreadRequest) msg.obj;
1021 WorkSource ws = (WorkSource) request.argument;
1022 Phone phone = getPhoneFromRequest(request);
1023 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1024 break;
1025 }
1026
1027 case EVENT_GET_CELL_LOCATION_DONE: {
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception == null) {
1031 request.result = ar.result;
1032 } else {
1033 Phone phone = getPhoneFromRequest(request);
1034 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1035 ? new CdmaCellLocation() : new GsmCellLocation();
1036 }
1037
1038 synchronized (request) {
1039 request.notifyAll();
1040 }
1041 break;
1042 }
1043
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001044 default:
1045 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1046 break;
1047 }
1048 }
Jake Hambye994d462014-02-03 13:10:13 -08001049
Pengquan Menga1bb6272018-09-06 09:59:22 -07001050 private void notifyRequester(MainThreadRequest request) {
1051 synchronized (request) {
1052 request.notifyAll();
1053 }
1054 }
1055
Jake Hambye994d462014-02-03 13:10:13 -08001056 private void handleNullReturnEvent(Message msg, String command) {
1057 AsyncResult ar = (AsyncResult) msg.obj;
1058 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1059 if (ar.exception == null) {
1060 request.result = true;
1061 } else {
1062 request.result = false;
1063 if (ar.exception instanceof CommandException) {
1064 loge(command + ": CommandException: " + ar.exception);
1065 } else {
1066 loge(command + ": Unknown exception");
1067 }
1068 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001069 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001070 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001071 }
1072
1073 /**
1074 * Posts the specified command to be executed on the main thread,
1075 * waits for the request to complete, and returns the result.
1076 * @see #sendRequestAsync
1077 */
1078 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001079 return sendRequest(
1080 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001081 }
1082
1083 /**
1084 * Posts the specified command to be executed on the main thread,
1085 * waits for the request to complete, and returns the result.
1086 * @see #sendRequestAsync
1087 */
1088 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1089 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001090 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001091 }
1092
1093 /**
1094 * Posts the specified command to be executed on the main thread,
1095 * waits for the request to complete, and returns the result.
1096 * @see #sendRequestAsync
1097 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001098 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001099 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001100 }
1101
1102 /**
1103 * Posts the specified command to be executed on the main thread,
1104 * waits for the request to complete, and returns the result.
1105 * @see #sendRequestAsync
1106 */
Nathan Harold92bed182018-10-12 18:16:49 -07001107 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1108 return sendRequest(command, argument, subId, null, workSource);
1109 }
1110
1111 /**
1112 * Posts the specified command to be executed on the main thread,
1113 * waits for the request to complete, and returns the result.
1114 * @see #sendRequestAsync
1115 */
1116 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1117 return sendRequest(
1118 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1119 }
1120
1121 /**
1122 * Posts the specified command to be executed on the main thread,
1123 * waits for the request to complete, and returns the result.
1124 * @see #sendRequestAsync
1125 */
1126 private Object sendRequest(
1127 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001128 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1129 throw new RuntimeException("This method will deadlock if called from the main thread.");
1130 }
1131
Nathan Harold92bed182018-10-12 18:16:49 -07001132 MainThreadRequest request = null;
1133 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1134 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1135 } else if (phone != null) {
1136 request = new MainThreadRequest(argument, phone, workSource);
1137 } else {
1138 request = new MainThreadRequest(argument, subId, workSource);
1139 }
1140
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 Message msg = mMainThreadHandler.obtainMessage(command, request);
1142 msg.sendToTarget();
1143
1144 // Wait for the request to complete
1145 synchronized (request) {
1146 while (request.result == null) {
1147 try {
1148 request.wait();
1149 } catch (InterruptedException e) {
1150 // Do nothing, go back and wait until the request is complete
1151 }
1152 }
1153 }
1154 return request.result;
1155 }
1156
1157 /**
1158 * Asynchronous ("fire and forget") version of sendRequest():
1159 * Posts the specified command to be executed on the main thread, and
1160 * returns immediately.
1161 * @see #sendRequest
1162 */
1163 private void sendRequestAsync(int command) {
1164 mMainThreadHandler.sendEmptyMessage(command);
1165 }
1166
1167 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001168 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1169 * @see {@link #sendRequest(int,Object)}
1170 */
1171 private void sendRequestAsync(int command, Object argument) {
1172 MainThreadRequest request = new MainThreadRequest(argument);
1173 Message msg = mMainThreadHandler.obtainMessage(command, request);
1174 msg.sendToTarget();
1175 }
1176
1177 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001178 * Initialize the singleton PhoneInterfaceManager instance.
1179 * This is only done once, at startup, from PhoneApp.onCreate().
1180 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001181 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001182 synchronized (PhoneInterfaceManager.class) {
1183 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001184 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001185 } else {
1186 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1187 }
1188 return sInstance;
1189 }
1190 }
1191
1192 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001193 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 mApp = app;
1195 mPhone = phone;
1196 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001197 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001198 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1199 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001200 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001201 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001202 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001203 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001204 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001205
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 publish();
1207 }
1208
1209 private void publish() {
1210 if (DBG) log("publish: " + this);
1211
1212 ServiceManager.addService("phone", this);
1213 }
1214
Stuart Scott584921c2015-01-15 17:10:34 -08001215 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001216 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1217 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001218 }
1219
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001220 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1221 Phone phone = getPhoneFromRequest(request);
1222 return phone == null ? null :
1223 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1224 }
1225
Wink Saville36469e72014-06-11 15:17:00 -07001226 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001227 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001228 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230
1231 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001232 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001233 }
1234
Wink Savilleb564aae2014-10-23 10:18:09 -07001235 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 if (DBG) log("dial: " + number);
1237 // No permission check needed here: This is just a wrapper around the
1238 // ACTION_DIAL intent, which is available to any app since it puts up
1239 // the UI before it does anything.
1240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001241 final long identity = Binder.clearCallingIdentity();
1242 try {
1243 String url = createTelUrl(number);
1244 if (url == null) {
1245 return;
1246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001248 // PENDING: should we just silently fail if phone is offhook or ringing?
1249 PhoneConstants.State state = mCM.getState(subId);
1250 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1251 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1252 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1253 mApp.startActivity(intent);
1254 }
1255 } finally {
1256 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 }
1258 }
1259
1260 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001261 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001262 }
1263
Wink Savilleb564aae2014-10-23 10:18:09 -07001264 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 if (DBG) log("call: " + number);
1266
1267 // This is just a wrapper around the ACTION_CALL intent, but we still
1268 // need to do a permission check since we're calling startActivity()
1269 // from the context of the phone app.
1270 enforceCallPermission();
1271
1272 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1273 != AppOpsManager.MODE_ALLOWED) {
1274 return;
1275 }
1276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001277 final long identity = Binder.clearCallingIdentity();
1278 try {
1279 String url = createTelUrl(number);
1280 if (url == null) {
1281 return;
1282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001284 boolean isValid = false;
1285 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1286 if (slist != null) {
1287 for (SubscriptionInfo subInfoRecord : slist) {
1288 if (subInfoRecord.getSubscriptionId() == subId) {
1289 isValid = true;
1290 break;
1291 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001292 }
Wink Saville08874612014-08-31 19:19:58 -07001293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001294 if (!isValid) {
1295 return;
1296 }
Wink Saville08874612014-08-31 19:19:58 -07001297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001298 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1299 intent.putExtra(SUBSCRIPTION_KEY, subId);
1300 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1301 mApp.startActivity(intent);
1302 } finally {
1303 Binder.restoreCallingIdentity(identity);
1304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 }
1306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001308 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001309 }
1310
Wink Savilleb564aae2014-10-23 10:18:09 -07001311 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001312 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001313 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1314 }
1315
1316 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001317 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001318 }
1319
Wink Savilleb564aae2014-10-23 10:18:09 -07001320 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001321 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001322 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1323 }
1324
1325 /** {@hide} */
1326 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001327 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001328 }
1329
Wink Savilleb564aae2014-10-23 10:18:09 -07001330 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001332
1333 final long identity = Binder.clearCallingIdentity();
1334 try {
1335 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1336 checkSimPin.start();
1337 return checkSimPin.unlockSim(null, pin);
1338 } finally {
1339 Binder.restoreCallingIdentity(identity);
1340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341 }
1342
Wink Saville9de0f752013-10-22 19:04:03 -07001343 /** {@hide} */
1344 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001345 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001346 }
1347
Wink Savilleb564aae2014-10-23 10:18:09 -07001348 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001350
1351 final long identity = Binder.clearCallingIdentity();
1352 try {
1353 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1354 checkSimPuk.start();
1355 return checkSimPuk.unlockSim(puk, pin);
1356 } finally {
1357 Binder.restoreCallingIdentity(identity);
1358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 }
1360
1361 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001362 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 * a synchronous one.
1364 */
1365 private static class UnlockSim extends Thread {
1366
1367 private final IccCard mSimCard;
1368
1369 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001370 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1371 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372
1373 // For replies from SimCard interface
1374 private Handler mHandler;
1375
1376 // For async handler to identify request type
1377 private static final int SUPPLY_PIN_COMPLETE = 100;
1378
1379 public UnlockSim(IccCard simCard) {
1380 mSimCard = simCard;
1381 }
1382
1383 @Override
1384 public void run() {
1385 Looper.prepare();
1386 synchronized (UnlockSim.this) {
1387 mHandler = new Handler() {
1388 @Override
1389 public void handleMessage(Message msg) {
1390 AsyncResult ar = (AsyncResult) msg.obj;
1391 switch (msg.what) {
1392 case SUPPLY_PIN_COMPLETE:
1393 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1394 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001395 mRetryCount = msg.arg1;
1396 if (ar.exception != null) {
1397 if (ar.exception instanceof CommandException &&
1398 ((CommandException)(ar.exception)).getCommandError()
1399 == CommandException.Error.PASSWORD_INCORRECT) {
1400 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1401 } else {
1402 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1403 }
1404 } else {
1405 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 mDone = true;
1408 UnlockSim.this.notifyAll();
1409 }
1410 break;
1411 }
1412 }
1413 };
1414 UnlockSim.this.notifyAll();
1415 }
1416 Looper.loop();
1417 }
1418
1419 /*
1420 * Use PIN or PUK to unlock SIM card
1421 *
1422 * If PUK is null, unlock SIM card with PIN
1423 *
1424 * If PUK is not null, unlock SIM card with PUK and set PIN code
1425 */
Wink Saville9de0f752013-10-22 19:04:03 -07001426 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427
1428 while (mHandler == null) {
1429 try {
1430 wait();
1431 } catch (InterruptedException e) {
1432 Thread.currentThread().interrupt();
1433 }
1434 }
1435 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1436
1437 if (puk == null) {
1438 mSimCard.supplyPin(pin, callback);
1439 } else {
1440 mSimCard.supplyPuk(puk, pin, callback);
1441 }
1442
1443 while (!mDone) {
1444 try {
1445 Log.d(LOG_TAG, "wait for done");
1446 wait();
1447 } catch (InterruptedException e) {
1448 // Restore the interrupted status
1449 Thread.currentThread().interrupt();
1450 }
1451 }
1452 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001453 int[] resultArray = new int[2];
1454 resultArray[0] = mResult;
1455 resultArray[1] = mRetryCount;
1456 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 }
1458 }
1459
1460 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001461 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001462
1463 }
1464
Wink Savilleb564aae2014-10-23 10:18:09 -07001465 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 // No permission check needed here: this call is harmless, and it's
1467 // needed for the ServiceState.requestStateUpdate() call (which is
1468 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001469 final long identity = Binder.clearCallingIdentity();
1470 try {
1471 final Phone phone = getPhone(subId);
1472 if (phone != null) {
1473 phone.updateServiceLocation();
1474 }
1475 } finally {
1476 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 }
1479
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001480 @Override
1481 public boolean isRadioOn(String callingPackage) {
1482 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001483 }
1484
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001485 @Override
1486 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001488 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001489 return false;
1490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001491
1492 final long identity = Binder.clearCallingIdentity();
1493 try {
1494 return isRadioOnForSubscriber(subId);
1495 } finally {
1496 Binder.restoreCallingIdentity(identity);
1497 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001498 }
1499
1500 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001501 final long identity = Binder.clearCallingIdentity();
1502 try {
1503 final Phone phone = getPhone(subId);
1504 if (phone != null) {
1505 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1506 } else {
1507 return false;
1508 }
1509 } finally {
1510 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 }
1513
1514 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001515 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001516 }
Wink Saville36469e72014-06-11 15:17:00 -07001517
Wink Savilleb564aae2014-10-23 10:18:09 -07001518 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001519 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520
1521 final long identity = Binder.clearCallingIdentity();
1522 try {
1523 final Phone phone = getPhone(subId);
1524 if (phone != null) {
1525 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1526 }
1527 } finally {
1528 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001529 }
Wink Saville36469e72014-06-11 15:17:00 -07001530 }
1531
1532 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001533 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001534 }
1535
Wink Savilleb564aae2014-10-23 10:18:09 -07001536 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001537 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001538
1539 final long identity = Binder.clearCallingIdentity();
1540 try {
1541 final Phone phone = getPhone(subId);
1542 if (phone == null) {
1543 return false;
1544 }
1545 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1546 toggleRadioOnOffForSubscriber(subId);
1547 }
1548 return true;
1549 } finally {
1550 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 }
Wink Saville36469e72014-06-11 15:17:00 -07001553
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001554 public boolean needMobileRadioShutdown() {
1555 /*
1556 * If any of the Radios are available, it will need to be
1557 * shutdown. So return true if any Radio is available.
1558 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1562 Phone phone = PhoneFactory.getPhone(i);
1563 if (phone != null && phone.isRadioAvailable()) return true;
1564 }
1565 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1566 return false;
1567 } finally {
1568 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001569 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001570 }
1571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001572 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001573 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001574 enforceModifyPermission();
1575
1576 final long identity = Binder.clearCallingIdentity();
1577 try {
1578 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1579 logv("Shutting down Phone " + i);
1580 shutdownRadioUsingPhoneId(i);
1581 }
1582 } finally {
1583 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001584 }
1585 }
1586
1587 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001588 Phone phone = PhoneFactory.getPhone(phoneId);
1589 if (phone != null && phone.isRadioAvailable()) {
1590 phone.shutdownRadio();
1591 }
1592 }
1593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001595 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001596
1597 final long identity = Binder.clearCallingIdentity();
1598 try {
1599 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1600 if (defaultPhone != null) {
1601 defaultPhone.setRadioPower(turnOn);
1602 return true;
1603 } else {
1604 loge("There's no default phone.");
1605 return false;
1606 }
1607 } finally {
1608 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001609 }
Wink Saville36469e72014-06-11 15:17:00 -07001610 }
1611
Wink Savilleb564aae2014-10-23 10:18:09 -07001612 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001614
1615 final long identity = Binder.clearCallingIdentity();
1616 try {
1617 final Phone phone = getPhone(subId);
1618 if (phone != null) {
1619 phone.setRadioPower(turnOn);
1620 return true;
1621 } else {
1622 return false;
1623 }
1624 } finally {
1625 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001626 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 }
1628
Wink Saville36469e72014-06-11 15:17:00 -07001629 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 public boolean enableDataConnectivity() {
1632 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001633
1634 final long identity = Binder.clearCallingIdentity();
1635 try {
1636 int subId = mSubscriptionController.getDefaultDataSubId();
1637 final Phone phone = getPhone(subId);
1638 if (phone != null) {
1639 phone.setUserDataEnabled(true);
1640 return true;
1641 } else {
1642 return false;
1643 }
1644 } finally {
1645 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 }
1648
Wink Saville36469e72014-06-11 15:17:00 -07001649 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001650 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 public boolean disableDataConnectivity() {
1652 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001653
1654 final long identity = Binder.clearCallingIdentity();
1655 try {
1656 int subId = mSubscriptionController.getDefaultDataSubId();
1657 final Phone phone = getPhone(subId);
1658 if (phone != null) {
1659 phone.setUserDataEnabled(false);
1660 return true;
1661 } else {
1662 return false;
1663 }
1664 } finally {
1665 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 }
1668
Sanket Padawe356d7632015-06-22 14:03:32 -07001669 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001670 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001671 final long identity = Binder.clearCallingIdentity();
1672 try {
1673 final Phone phone = getPhone(subId);
1674 if (phone != null) {
1675 return phone.isDataAllowed();
1676 } else {
1677 return false;
1678 }
1679 } finally {
1680 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001681 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 }
1683
1684 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001685 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001686 }
1687
pkanwarae03a6b2016-11-06 20:37:09 -08001688 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001689 enforceCallPermission();
1690
1691 final long identity = Binder.clearCallingIdentity();
1692 try {
1693 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1694 return;
1695 }
1696 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1697 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1698 } finally {
1699 Binder.restoreCallingIdentity(identity);
1700 }
pkanwar32d516d2016-10-14 19:37:38 -07001701 };
1702
Wink Savilleb564aae2014-10-23 10:18:09 -07001703 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001705
1706 final long identity = Binder.clearCallingIdentity();
1707 try {
1708 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1709 return false;
1710 }
1711 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1712 } finally {
1713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 }
1716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001718 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001719 }
1720
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001721 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001722 final long identity = Binder.clearCallingIdentity();
1723 try {
1724 Phone phone = PhoneFactory.getPhone(slotIndex);
1725 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1726 PhoneConstantConversions.convertCallState(phone.getState());
1727 } finally {
1728 Binder.restoreCallingIdentity(identity);
1729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 }
1731
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1737 if (phone != null) {
1738 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1739 } else {
1740 return PhoneConstantConversions.convertDataState(
1741 PhoneConstants.DataState.DISCONNECTED);
1742 }
1743 } finally {
1744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
1747
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1753 if (phone != null) {
1754 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1755 } else {
1756 return TelephonyManager.DATA_ACTIVITY_NONE;
1757 }
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 }
1762
1763 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001764 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001765 mPhone.getContext().getSystemService(AppOpsManager.class)
1766 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001767 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001768 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001769 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001772 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001773 final long identity = Binder.clearCallingIdentity();
1774 try {
1775 if (DBG_LOC) log("getCellLocation: is active user");
1776 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001777 int subId = mSubscriptionController.getDefaultDataSubId();
1778 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1779 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001780 return data;
1781 } finally {
1782 Binder.restoreCallingIdentity(identity);
1783 }
Svetoslav64fad262015-04-14 14:35:21 -07001784 }
1785
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001787 public String getNetworkCountryIsoForPhone(int phoneId) {
1788 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1789 // registered cell info, so return a NULL country instead.
1790 final long identity = Binder.clearCallingIdentity();
1791 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001792 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1793 // Get default phone in this case.
1794 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1795 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001796 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001797 // Todo: fix this when we can get the actual cellular network info when the device
1798 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001799 if (TelephonyManager.NETWORK_TYPE_IWLAN
1800 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1801 return "";
1802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001803 Phone phone = PhoneFactory.getPhone(phoneId);
1804 if (phone != null) {
1805 ServiceStateTracker sst = phone.getServiceStateTracker();
1806 if (sst != null) {
1807 LocaleTracker lt = sst.getLocaleTracker();
1808 if (lt != null) {
1809 return lt.getCurrentCountry();
1810 }
1811 }
1812 }
1813 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001814 } finally {
1815 Binder.restoreCallingIdentity(identity);
1816 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001817 }
1818
1819 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001821 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001822 }
1823
Sanket Padawe356d7632015-06-22 14:03:32 -07001824 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001825 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 mApp.enforceCallingOrSelfPermission(
1827 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001828
1829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 final Phone phone = getPhone(subId);
1832 if (phone != null) {
1833 phone.enableLocationUpdates();
1834 }
1835 } finally {
1836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 }
1839
1840 @Override
1841 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001842 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001843 }
1844
Sanket Padawe356d7632015-06-22 14:03:32 -07001845 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001846 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 mApp.enforceCallingOrSelfPermission(
1848 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001849
1850 final long identity = Binder.clearCallingIdentity();
1851 try {
1852 final Phone phone = getPhone(subId);
1853 if (phone != null) {
1854 phone.disableLocationUpdates();
1855 }
1856 } finally {
1857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 }
1860
Nathan Harold31d7ff32018-10-15 20:20:30 -07001861 /**
1862 * Returns the target SDK version number for a given package name.
1863 *
1864 * @return target SDK if the package is found or INT_MAX.
1865 */
1866 private int getTargetSdk(String packageName) {
1867 try {
1868 final ApplicationInfo ai =
1869 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1870 if (ai != null) return ai.targetSdkVersion;
1871 } catch (PackageManager.NameNotFoundException unexpected) {
1872 }
1873 return Integer.MAX_VALUE;
1874 }
1875
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 @Override
1877 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001878 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1879 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001880 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1881 throw new SecurityException(
1882 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1883 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001884
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1886 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1887 return null;
1888 }
Svetoslav64fad262015-04-14 14:35:21 -07001889
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001890 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891
Nathan Haroldf180aac2018-06-01 18:43:55 -07001892 List<CellInfo> info = getAllCellInfo(callingPackage);
1893 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894
Nathan Haroldf180aac2018-06-01 18:43:55 -07001895 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1896 for (CellInfo ci : info) {
1897 if (ci instanceof CellInfoGsm) {
1898 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1899 } else if (ci instanceof CellInfoWcdma) {
1900 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001903 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 }
1905
1906
1907 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001908 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001909 mPhone.getContext().getSystemService(AppOpsManager.class)
1910 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001911 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001912 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001913 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 }
1915
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001916 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001917 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001918 final long identity = Binder.clearCallingIdentity();
1919 try {
1920 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1921 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001922 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001923 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001924 if (info != null) cellInfos.addAll(info);
1925 }
1926 return cellInfos;
1927 } finally {
1928 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 }
1930 }
1931
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001932 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001934 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001935 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001936
1937 final long identity = Binder.clearCallingIdentity();
1938 try {
1939 mPhone.setCellInfoListRate(rateInMillis, workSource);
1940 } finally {
1941 Binder.restoreCallingIdentity(identity);
1942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
Shishir Agrawala9f32182016-04-12 12:00:16 -07001945 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001946 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001947 Phone phone = PhoneFactory.getPhone(slotIndex);
1948 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001949 return null;
1950 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001951 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001952 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1953 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001954 return null;
1955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956
1957 final long identity = Binder.clearCallingIdentity();
1958 try {
1959 return phone.getImei();
1960 } finally {
1961 Binder.restoreCallingIdentity(identity);
1962 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001963 }
1964
1965 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001966 public String getTypeAllocationCodeForSlot(int slotIndex) {
1967 Phone phone = PhoneFactory.getPhone(slotIndex);
1968 String tac = null;
1969 if (phone != null) {
1970 String imei = phone.getImei();
1971 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1972 }
1973 return tac;
1974 }
1975
1976 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001977 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001978 Phone phone = PhoneFactory.getPhone(slotIndex);
1979 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001980 return null;
1981 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001982 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001983 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1984 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001985 return null;
1986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987
1988 final long identity = Binder.clearCallingIdentity();
1989 try {
1990 return phone.getMeid();
1991 } finally {
1992 Binder.restoreCallingIdentity(identity);
1993 }
Jack Yu2af8d712017-03-15 17:14:14 -07001994 }
1995
1996 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001997 public String getManufacturerCodeForSlot(int slotIndex) {
1998 Phone phone = PhoneFactory.getPhone(slotIndex);
1999 String manufacturerCode = null;
2000 if (phone != null) {
2001 String meid = phone.getMeid();
2002 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2003 }
2004 return manufacturerCode;
2005 }
2006
2007 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002008 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002009 Phone phone = PhoneFactory.getPhone(slotIndex);
2010 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002011 return null;
2012 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002013 int subId = phone.getSubId();
2014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2015 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2016 return null;
2017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002018
2019 final long identity = Binder.clearCallingIdentity();
2020 try {
2021 return phone.getDeviceSvn();
2022 } finally {
2023 Binder.restoreCallingIdentity(identity);
2024 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002025 }
2026
fionaxu43304da2017-11-27 22:51:16 -08002027 @Override
2028 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002029 final long identity = Binder.clearCallingIdentity();
2030 try {
2031 final Phone phone = getPhone(subId);
2032 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2033 } finally {
2034 Binder.restoreCallingIdentity(identity);
2035 }
fionaxu43304da2017-11-27 22:51:16 -08002036 }
2037
2038 @Override
2039 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 final long identity = Binder.clearCallingIdentity();
2041 try {
2042 final Phone phone = getPhone(subId);
2043 return phone == null ? null : phone.getCarrierName();
2044 } finally {
2045 Binder.restoreCallingIdentity(identity);
2046 }
fionaxu43304da2017-11-27 22:51:16 -08002047 }
2048
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 //
2050 // Internal helper methods.
2051 //
2052
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002053 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2055 *
2056 * @throws SecurityException if the caller does not have the required permission
2057 */
2058 private void enforceModifyPermission() {
2059 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2060 }
2061
2062 /**
2063 * Make sure the caller has the CALL_PHONE permission.
2064 *
2065 * @throws SecurityException if the caller does not have the required permission
2066 */
2067 private void enforceCallPermission() {
2068 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2069 }
2070
Stuart Scott8eef64f2015-04-08 15:13:54 -07002071 private void enforceConnectivityInternalPermission() {
2072 mApp.enforceCallingOrSelfPermission(
2073 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2074 "ConnectivityService");
2075 }
2076
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 private String createTelUrl(String number) {
2078 if (TextUtils.isEmpty(number)) {
2079 return null;
2080 }
2081
Jake Hambye994d462014-02-03 13:10:13 -08002082 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 }
2084
Ihab Awadf9e92732013-12-05 18:02:52 -08002085 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2087 }
2088
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002089 private static void logv(String msg) {
2090 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2091 }
2092
Ihab Awadf9e92732013-12-05 18:02:52 -08002093 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2095 }
2096
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002097 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002099 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002100 }
2101
Sanket Padawe356d7632015-06-22 14:03:32 -07002102 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002103 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 final Phone phone = PhoneFactory.getPhone(slotIndex);
2107 if (phone == null) {
2108 return PhoneConstants.PHONE_TYPE_NONE;
2109 } else {
2110 return phone.getPhoneType();
2111 }
2112 } finally {
2113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 }
2116
2117 /**
2118 * Returns the CDMA ERI icon index to display
2119 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002120 @Override
2121 public int getCdmaEriIconIndex(String callingPackage) {
2122 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002123 }
2124
Sanket Padawe356d7632015-06-22 14:03:32 -07002125 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002126 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002128 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002129 return -1;
2130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002131
2132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 final Phone phone = getPhone(subId);
2135 if (phone != null) {
2136 return phone.getCdmaEriIconIndex();
2137 } else {
2138 return -1;
2139 }
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 }
2144
2145 /**
2146 * Returns the CDMA ERI icon mode,
2147 * 0 - ON
2148 * 1 - FLASHING
2149 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002150 @Override
2151 public int getCdmaEriIconMode(String callingPackage) {
2152 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002153 }
2154
Sanket Padawe356d7632015-06-22 14:03:32 -07002155 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002156 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002158 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002159 return -1;
2160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002161
2162 final long identity = Binder.clearCallingIdentity();
2163 try {
2164 final Phone phone = getPhone(subId);
2165 if (phone != null) {
2166 return phone.getCdmaEriIconMode();
2167 } else {
2168 return -1;
2169 }
2170 } finally {
2171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 }
2174
2175 /**
2176 * Returns the CDMA ERI text,
2177 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002178 @Override
2179 public String getCdmaEriText(String callingPackage) {
2180 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002181 }
2182
Sanket Padawe356d7632015-06-22 14:03:32 -07002183 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002184 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002185 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002186 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002187 return null;
2188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189
2190 final long identity = Binder.clearCallingIdentity();
2191 try {
2192 final Phone phone = getPhone(subId);
2193 if (phone != null) {
2194 return phone.getCdmaEriText();
2195 } else {
2196 return null;
2197 }
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 }
2202
2203 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002204 * Returns the CDMA MDN.
2205 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002206 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002207 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2209 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210
2211 final long identity = Binder.clearCallingIdentity();
2212 try {
2213 final Phone phone = getPhone(subId);
2214 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2215 return phone.getLine1Number();
2216 } else {
2217 return null;
2218 }
2219 } finally {
2220 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002221 }
2222 }
2223
2224 /**
2225 * Returns the CDMA MIN.
2226 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002227 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002228 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2230 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231
2232 final long identity = Binder.clearCallingIdentity();
2233 try {
2234 final Phone phone = getPhone(subId);
2235 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2236 return phone.getCdmaMin();
2237 } else {
2238 return null;
2239 }
2240 } finally {
2241 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002242 }
2243 }
2244
2245 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 * Returns true if CDMA provisioning needs to run.
2247 */
2248 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249 final long identity = Binder.clearCallingIdentity();
2250 try {
2251 return mPhone.needsOtaServiceProvisioning();
2252 } finally {
2253 Binder.restoreCallingIdentity(identity);
2254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 }
2256
2257 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002258 * Sets the voice mail number of a given subId.
2259 */
2260 @Override
2261 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002262 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263
2264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2267 new Pair<String, String>(alphaTag, number), new Integer(subId));
2268 return success;
2269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002272 }
2273
Ta-wei Yen87c49842016-05-13 21:19:52 -07002274 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002275 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2277 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2278 if (!TextUtils.equals(callingPackage, systemDialer)) {
2279 throw new SecurityException("caller must be system dialer");
2280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002281
2282 final long identity = Binder.clearCallingIdentity();
2283 try {
2284 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2285 if (phoneAccountHandle == null) {
2286 return null;
2287 }
2288 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2289 } finally {
2290 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002291 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002292 }
2293
2294 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002295 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002296 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002297 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002298 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002299 return null;
2300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002302 final long identity = Binder.clearCallingIdentity();
2303 try {
2304 return RemoteVvmTaskManager
2305 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
2308 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002309 }
2310
2311 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002312 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2313 VisualVoicemailSmsFilterSettings settings) {
2314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002315
2316 final long identity = Binder.clearCallingIdentity();
2317 try {
2318 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2319 mPhone.getContext(), callingPackage, subId, settings);
2320 } finally {
2321 Binder.restoreCallingIdentity(identity);
2322 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002323 }
2324
2325 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002326 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2327 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328
2329 final long identity = Binder.clearCallingIdentity();
2330 try {
2331 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2332 mPhone.getContext(), callingPackage, subId);
2333 } finally {
2334 Binder.restoreCallingIdentity(identity);
2335 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002336 }
2337
2338 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002339 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2340 String callingPackage, int subId) {
2341 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2346 mPhone.getContext(), callingPackage, subId);
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
2349 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002350 }
2351
2352 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002353 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002354 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355
2356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2359 mPhone.getContext(), subId);
2360 } finally {
2361 Binder.restoreCallingIdentity(identity);
2362 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002363 }
2364
2365 @Override
2366 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2367 String number, int port, String text, PendingIntent sentIntent) {
2368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002369 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002370 enforceSendSmsPermission();
2371 // Make the calls as the phone process.
2372 final long identity = Binder.clearCallingIdentity();
2373 try {
2374 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2375 if (port == 0) {
2376 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2377 sentIntent, null, false);
2378 } else {
2379 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2380 smsManager.sendDataMessageWithSelfPermissions(number, null,
2381 (short) port, data, sentIntent, null);
2382 }
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
2385 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002386 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002387 /**
fionaxu0152e512016-11-14 13:36:14 -08002388 * Sets the voice activation state of a given subId.
2389 */
2390 @Override
2391 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2393 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002394
2395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 final Phone phone = getPhone(subId);
2398 if (phone != null) {
2399 phone.setVoiceActivationState(activationState);
2400 } else {
2401 loge("setVoiceActivationState fails with invalid subId: " + subId);
2402 }
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002405 }
2406 }
2407
2408 /**
2409 * Sets the data activation state of a given subId.
2410 */
2411 @Override
2412 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2414 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415
2416 final long identity = Binder.clearCallingIdentity();
2417 try {
2418 final Phone phone = getPhone(subId);
2419 if (phone != null) {
2420 phone.setDataActivationState(activationState);
2421 } else {
2422 loge("setVoiceActivationState fails with invalid subId: " + subId);
2423 }
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002426 }
2427 }
2428
2429 /**
2430 * Returns the voice activation state of a given subId.
2431 */
2432 @Override
2433 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002434 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435
fionaxu0152e512016-11-14 13:36:14 -08002436 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437 final long identity = Binder.clearCallingIdentity();
2438 try {
2439 if (phone != null) {
2440 return phone.getVoiceActivationState();
2441 } else {
2442 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2443 }
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002446 }
2447 }
2448
2449 /**
2450 * Returns the data activation state of a given subId.
2451 */
2452 @Override
2453 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002454 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002455
fionaxu0152e512016-11-14 13:36:14 -08002456 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 final long identity = Binder.clearCallingIdentity();
2458 try {
2459 if (phone != null) {
2460 return phone.getDataActivationState();
2461 } else {
2462 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2463 }
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002466 }
2467 }
2468
2469 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 * Returns the unread count of voicemails
2471 */
2472 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002473 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002474 }
2475
2476 /**
2477 * Returns the unread count of voicemails for a subId
2478 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002479 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002480 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 final Phone phone = getPhone(subId);
2484 if (phone != null) {
2485 return phone.getVoiceMessageCount();
2486 } else {
2487 return 0;
2488 }
2489 } finally {
2490 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 }
2493
2494 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002495 * returns true, if the device is in a state where both voice and data
2496 * are supported simultaneously. This can change based on location or network condition.
2497 */
2498 @Override
2499 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 final Phone phone = getPhone(subId);
2503 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2504 } finally {
2505 Binder.restoreCallingIdentity(identity);
2506 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002507 }
2508
2509 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002510 * Send the dialer code if called from the current default dialer or the caller has
2511 * carrier privilege.
2512 * @param inputCode The dialer code to send
2513 */
2514 @Override
2515 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2517 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2518 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002519 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2520 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522
2523 final long identity = Binder.clearCallingIdentity();
2524 try {
2525 mPhone.sendDialerSpecialCode(inputCode);
2526 } finally {
2527 Binder.restoreCallingIdentity(identity);
2528 }
fionaxu235cc5e2017-03-06 22:25:57 -08002529 }
2530
2531 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002532 * Returns the data network type.
2533 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 *
2535 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2536 */
2537 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002538 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539 final long identity = Binder.clearCallingIdentity();
2540 try {
2541 final Phone phone = getPhone(getDefaultSubscription());
2542 if (phone != null) {
2543 return phone.getServiceState().getDataNetworkType();
2544 } else {
2545 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2546 }
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002549 }
Wink Saville36469e72014-06-11 15:17:00 -07002550 }
2551
Pengquan Menga1bb6272018-09-06 09:59:22 -07002552 @Override
2553 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002554 if (!isActiveSubscription(subId)) {
2555 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2556 }
2557
Pengquan Menga1bb6272018-09-06 09:59:22 -07002558 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2559 }
2560
Brad Ebinger35c841c2018-10-01 10:40:55 -07002561 @Override
2562 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2563 String callingPackage) throws RemoteException {
2564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2565 "addImsRegistrationCallback")) {
2566 return;
2567 }
2568 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2569 final long token = Binder.clearCallingIdentity();
2570 try {
2571 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2572 .addRegistrationCallbackForSubscription(c, subId);
2573 } finally {
2574 Binder.restoreCallingIdentity(token);
2575 }
2576 }
2577
2578 @Override
2579 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2580 String callingPackage) {
2581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2582 "removeImsRegistrationCallback")) {
2583 return;
2584 }
2585 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2586 Binder.withCleanCallingIdentity(() ->
2587 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2588 .removeRegistrationCallbackForSubscription(c, subId));
2589 }
2590
2591 @Override
2592 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2593 String callingPackage) throws RemoteException {
2594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2595 "addMmTelCapabilityCallback")) {
2596 return;
2597 }
2598 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2599 final long token = Binder.clearCallingIdentity();
2600 try {
2601 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2602 .addCapabilitiesCallbackForSubscription(c, subId);
2603 } finally {
2604 Binder.restoreCallingIdentity(token);
2605 }
2606 }
2607
2608 @Override
2609 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2610 String callingPackage) {
2611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2612 "removeMmTelCapabilityCallback")) {
2613 return;
2614 }
2615 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2616 Binder.withCleanCallingIdentity(() ->
2617 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2618 .removeCapabilitiesCallbackForSubscription(c, subId));
2619 }
2620
2621 @Override
2622 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2624 "isCapable")) {
2625 return false;
2626 }
2627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2628 final long token = Binder.clearCallingIdentity();
2629 try {
2630 return ImsManager.getInstance(mPhone.getContext(),
2631 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2632 } catch (ImsException e) {
2633 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2634 return false;
2635 } finally {
2636 Binder.restoreCallingIdentity(token);
2637 }
2638 }
2639
2640 @Override
2641 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2643 "isAvailable")) {
2644 return false;
2645 }
2646 final long token = Binder.clearCallingIdentity();
2647 try {
2648 Phone phone = getPhone(subId);
2649 if (phone == null) return false;
2650 return phone.isImsCapabilityAvailable(capability, regTech);
2651 } finally {
2652 Binder.restoreCallingIdentity(token);
2653 }
2654 }
2655
2656 @Override
2657 public boolean isAdvancedCallingSettingEnabled(int subId) {
2658 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2659 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2660 final long token = Binder.clearCallingIdentity();
2661 try {
2662 return ImsManager.getInstance(mPhone.getContext(),
2663 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2664 } finally {
2665 Binder.restoreCallingIdentity(token);
2666 }
2667 }
2668
2669 @Override
2670 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2672 "setAdvancedCallingSetting");
2673 final long identity = Binder.clearCallingIdentity();
2674 try {
2675 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2676 ImsManager.getInstance(mPhone.getContext(),
2677 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
2680 }
2681 }
2682
2683 @Override
2684 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2686 "isVtSettingEnabled")) {
2687 return false;
2688 }
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2692 return ImsManager.getInstance(mPhone.getContext(),
2693 getSlotIndexOrException(subId)).isVtEnabledByUser();
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
2696 }
2697 }
2698
2699 @Override
2700 public void setVtSetting(int subId, boolean isEnabled) {
2701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2702 "setVtSetting");
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2706 ImsManager.getInstance(mPhone.getContext(),
2707 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2708 } finally {
2709 Binder.restoreCallingIdentity(identity);
2710 }
2711 }
2712
2713 @Override
2714 public boolean isVoWiFiSettingEnabled(int subId) {
2715 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2719 return ImsManager.getInstance(mPhone.getContext(),
2720 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
2723 }
2724 }
2725
2726 @Override
2727 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2729 "setVoWiFiSetting");
2730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2733 ImsManager.getInstance(mPhone.getContext(),
2734 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
2737 }
2738 }
2739
2740 @Override
2741 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2742 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2743 final long identity = Binder.clearCallingIdentity();
2744 try {
2745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2746 return ImsManager.getInstance(mPhone.getContext(),
2747 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2748 } finally {
2749 Binder.restoreCallingIdentity(identity);
2750 }
2751 }
2752
2753 @Override
2754 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2756 "setVoWiFiRoamingSetting");
2757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2760 ImsManager.getInstance(mPhone.getContext(),
2761 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
2764 }
2765 }
2766
2767 @Override
2768 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2770 "setVoWiFiNonPersistent");
2771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2774 ImsManager.getInstance(mPhone.getContext(),
2775 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
2778 }
2779 }
2780
2781 @Override
2782 public int getVoWiFiModeSetting(int subId) {
2783 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2787 return ImsManager.getInstance(mPhone.getContext(),
2788 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
2791 }
2792 }
2793
2794 @Override
2795 public void setVoWiFiModeSetting(int subId, int mode) {
2796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2797 "setVoWiFiModeSetting");
2798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2801 ImsManager.getInstance(mPhone.getContext(),
2802 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2803 } finally {
2804 Binder.restoreCallingIdentity(identity);
2805 }
2806 }
2807
2808 @Override
2809 public int getVoWiFiRoamingModeSetting(int subId) {
2810 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
2813 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2814 return ImsManager.getInstance(mPhone.getContext(),
2815 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
2818 }
2819 }
2820
2821 @Override
2822 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2824 "setVoWiFiRoamingModeSetting");
2825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2828 ImsManager.getInstance(mPhone.getContext(),
2829 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
2832 }
2833 }
2834
2835 @Override
2836 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2838 "setRttCapabilityEnabled");
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2842 ImsManager.getInstance(mPhone.getContext(),
2843 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
2846 }
2847 }
2848
2849 @Override
2850 public boolean isTtyOverVolteEnabled(int subId) {
2851 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2855 return ImsManager.getInstance(mPhone.getContext(),
2856 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
2859 }
2860 }
2861
2862 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2863 int slotId = SubscriptionManager.getSlotIndex(subId);
2864 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2865 throw new IllegalArgumentException("Invalid Subscription Id.");
2866 }
2867 return slotId;
2868 }
2869
Wink Saville36469e72014-06-11 15:17:00 -07002870 /**
2871 * Returns the network type for a subId
2872 */
2873 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002874 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002876 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002877 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2878 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 final Phone phone = getPhone(subId);
2883 if (phone != null) {
2884 return phone.getServiceState().getDataNetworkType();
2885 } else {
2886 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2887 }
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
2893 /**
2894 * Returns the data network type
2895 */
2896 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002897 public int getDataNetworkType(String callingPackage) {
2898 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002899 }
2900
2901 /**
2902 * Returns the data network type for a subId
2903 */
2904 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002905 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002907 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002908 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2909 }
2910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 final Phone phone = getPhone(subId);
2914 if (phone != null) {
2915 return phone.getServiceState().getDataNetworkType();
2916 } else {
2917 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2918 }
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 }
2923
2924 /**
Wink Saville36469e72014-06-11 15:17:00 -07002925 * Returns the Voice network type for a subId
2926 */
2927 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002928 public int getVoiceNetworkTypeForSubscriber(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 Greenwalta5dcfcb2015-07-10 09:06:29 -07002931 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2932 }
2933
Malcolm Chenaa4a8532018-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().getVoiceNetworkType();
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 /**
2948 * @return true if a ICC card is present
2949 */
2950 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002951 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002952 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2953 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002954 }
2955
2956 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002957 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002958 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002959 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002960 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 final Phone phone = PhoneFactory.getPhone(slotIndex);
2964 if (phone != null) {
2965 return phone.getIccCard().hasIccCard();
2966 } else {
2967 return false;
2968 }
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002971 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002972 }
2973
2974 /**
2975 * Return if the current radio is LTE on CDMA. This
2976 * is a tri-state return value as for a period of time
2977 * the mode may be unknown.
2978 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002979 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002980 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002981 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002982 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002983 @Override
2984 public int getLteOnCdmaMode(String callingPackage) {
2985 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002986 }
2987
Sanket Padawe356d7632015-06-22 14:03:32 -07002988 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002989 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002991 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002992 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2993 }
2994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 final Phone phone = getPhone(subId);
2998 if (phone == null) {
2999 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3000 } else {
3001 return phone.getLteOnCdmaMode();
3002 }
3003 } finally {
3004 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003005 }
Wink Saville36469e72014-06-11 15:17:00 -07003006 }
3007
3008 public void setPhone(Phone phone) {
3009 mPhone = phone;
3010 }
3011
3012 /**
3013 * {@hide}
3014 * Returns Default subId, 0 in the case of single standby.
3015 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003016 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003017 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003018 }
3019
Shishir Agrawala9f32182016-04-12 12:00:16 -07003020 private int getSlotForDefaultSubscription() {
3021 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3022 }
3023
Wink Savilleb564aae2014-10-23 10:18:09 -07003024 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003025 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003027
Pengquan Menge92a50d2018-09-21 15:54:48 -07003028 private boolean isActiveSubscription(int subId) {
3029 return mSubscriptionController.isActiveSubId(subId);
3030 }
3031
Ihab Awadf2177b72013-11-25 13:33:23 -08003032 /**
3033 * @see android.telephony.TelephonyManager.WifiCallingChoices
3034 */
3035 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3039 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3040 getWhenToMakeWifiCallsDefaultPreference());
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003044 }
3045
3046 /**
3047 * @see android.telephony.TelephonyManager.WifiCallingChoices
3048 */
3049 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3053 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3054 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3055 } finally {
3056 Binder.restoreCallingIdentity(identity);
3057 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003058 }
3059
Sailesh Nepald1e68152013-12-12 19:08:02 -08003060 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003061 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003062 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003063 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003064
Shishir Agrawal566b7612013-10-28 14:41:00 -07003065 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003066 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3067 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3069 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 if (TextUtils.equals(ISDR_AID, aid)) {
3075 // Only allows LPA to open logical channel to ISD-R.
3076 ComponentInfo bestComponent =
3077 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3078 if (bestComponent == null
3079 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3080 loge("The calling package is not allowed to access ISD-R.");
3081 throw new SecurityException(
3082 "The calling package is not allowed to access ISD-R.");
3083 }
Derek Tan740e1672017-06-27 14:56:27 -07003084 }
Derek Tan740e1672017-06-27 14:56:27 -07003085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003086 if (DBG) {
3087 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3088 }
3089 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3090 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3091 if (DBG) log("iccOpenLogicalChannel: " + response);
3092 return response;
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003096 }
3097
3098 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003099 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3101 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3106 if (channel < 0) {
3107 return false;
3108 }
3109 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3110 if (DBG) log("iccCloseLogicalChannel: " + success);
3111 return success;
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003114 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003115 }
3116
3117 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003118 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003119 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3121 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 if (DBG) {
3126 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3127 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3128 + p3 + " data=" + data);
3129 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131 if (channel < 0) {
3132 return "";
3133 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3136 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3137 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139 // Append the returned status code to the end of the response payload.
3140 String s = Integer.toHexString(
3141 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3142 if (response.payload != null) {
3143 s = IccUtils.bytesToHexString(response.payload) + s;
3144 }
3145 return s;
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003148 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003149 }
Jake Hambye994d462014-02-03 13:10:13 -08003150
Evan Charltonc66da362014-05-16 14:06:40 -07003151 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003152 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3153 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3155 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3161 && TextUtils.equals(ISDR_AID, data)) {
3162 // Only allows LPA to select ISD-R.
3163 ComponentInfo bestComponent =
3164 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3165 if (bestComponent == null
3166 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3167 loge("The calling package is not allowed to select ISD-R.");
3168 throw new SecurityException(
3169 "The calling package is not allowed to select ISD-R.");
3170 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003171 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173 if (DBG) {
3174 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3175 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3176 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003178 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3179 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3180 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182 // Append the returned status code to the end of the response payload.
3183 String s = Integer.toHexString(
3184 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3185 if (response.payload != null) {
3186 s = IccUtils.bytesToHexString(response.payload) + s;
3187 }
3188 return s;
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003191 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003192 }
3193
3194 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003195 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003196 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3198 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 if (DBG) {
3203 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3204 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3205 }
3206
3207 IccIoResult response =
3208 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3209 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3210 subId);
3211
3212 if (DBG) {
3213 log("Exchange SIM_IO [R]" + response);
3214 }
3215
3216 byte[] result = null;
3217 int length = 2;
3218 if (response.payload != null) {
3219 length = 2 + response.payload.length;
3220 result = new byte[length];
3221 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3222 } else {
3223 result = new byte[length];
3224 }
3225
3226 result[length - 1] = (byte) response.sw2;
3227 result[length - 2] = (byte) response.sw1;
3228 return result;
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003231 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003232 }
3233
Nathan Haroldb3014052017-01-25 15:57:32 -08003234 /**
3235 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3236 * on a particular subscription
3237 */
sqianb6e41952018-03-12 14:54:01 -07003238 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3240 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3241 return null;
3242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243
3244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 if (appType != TelephonyManager.APPTYPE_USIM
3247 && appType != TelephonyManager.APPTYPE_SIM) {
3248 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3249 return null;
3250 }
3251 Object response = sendRequest(
3252 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3253 if (response instanceof String[]) {
3254 return (String[]) response;
3255 }
3256 // Response is an Exception of some kind,
3257 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003258 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003259 } finally {
3260 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003261 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003262 }
3263
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003264 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003265 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3267 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3272 if (response.payload == null) {
3273 return "";
3274 }
Evan Charltonc66da362014-05-16 14:06:40 -07003275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276 // Append the returned status code to the end of the response payload.
3277 String s = Integer.toHexString(
3278 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3279 s = IccUtils.bytesToHexString(response.payload) + s;
3280 return s;
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
Evan Charltonc66da362014-05-16 14:06:40 -07003284 }
3285
Jake Hambye994d462014-02-03 13:10:13 -08003286 /**
3287 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3288 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3289 *
3290 * @param itemID the ID of the item to read
3291 * @return the NV item as a String, or null on error.
3292 */
3293 @Override
3294 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003295 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3297 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003298
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003302 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3304 return value;
3305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
Jake Hambye994d462014-02-03 13:10:13 -08003308 }
3309
3310 /**
3311 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3312 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3313 *
3314 * @param itemID the ID of the item to read
3315 * @param itemValue the value to write, as a String
3316 * @return true on success; false on any failure
3317 */
3318 @Override
3319 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003320 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3322 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003323
3324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3327 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003328 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3330 return success;
3331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
Jake Hambye994d462014-02-03 13:10:13 -08003334 }
3335
3336 /**
3337 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3338 * Used for device configuration by some CDMA operators.
3339 *
3340 * @param preferredRoamingList byte array containing the new PRL
3341 * @return true on success; false on any failure
3342 */
3343 @Override
3344 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3346 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3351 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3352 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3353 return success;
3354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
Jake Hambye994d462014-02-03 13:10:13 -08003357 }
3358
3359 /**
3360 * Perform the specified type of NV config reset.
3361 * Used for device configuration by some CDMA operators.
3362 *
3363 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3364 * @return true on success; false on any failure
3365 */
3366 @Override
3367 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3369 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003370
3371 final long identity = Binder.clearCallingIdentity();
3372 try {
3373 if (DBG) log("nvResetConfig: type " + resetType);
3374 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3375 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3376 return success;
3377 } finally {
3378 Binder.restoreCallingIdentity(identity);
3379 }
Jake Hambye994d462014-02-03 13:10:13 -08003380 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003381
Svet Ganovb320e182015-04-16 12:30:10 -07003382 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003384 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003385 return new String[0];
3386 }
3387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003388 final long identity = Binder.clearCallingIdentity();
3389 try {
3390 return mPhone.getPcscfAddress(apnType);
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
Wink Saville36469e72014-06-11 15:17:00 -07003394 }
3395
Brad Ebinger51f743a2017-01-23 13:50:20 -08003396 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003397 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3398 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003399 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003400 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003401 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402
3403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 PhoneFactory.getImsResolver().enableIms(slotId);
3406 } finally {
3407 Binder.restoreCallingIdentity(identity);
3408 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003409 }
3410
3411 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003412 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3413 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003414 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003415 public void disableIms(int slotId) {
3416 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003417
3418 final long identity = Binder.clearCallingIdentity();
3419 try {
3420 PhoneFactory.getImsResolver().disableIms(slotId);
3421 } finally {
3422 Binder.restoreCallingIdentity(identity);
3423 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003424 }
3425
3426 /**
3427 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3428 * feature or {@link null} if the service is not available. If the feature is available, the
3429 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3430 */
3431 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003432 IImsServiceFeatureCallback callback) {
3433 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3438 } finally {
3439 Binder.restoreCallingIdentity(identity);
3440 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003441 }
3442
3443 /**
3444 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3445 * feature during emergency calling or {@link null} if the service is not available. If the
3446 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3447 * listener for feature updates.
3448 */
3449 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3450 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003451
3452 final long identity = Binder.clearCallingIdentity();
3453 try {
3454 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3455 } finally {
3456 Binder.restoreCallingIdentity(identity);
3457 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003458 }
3459
Brad Ebinger5f64b052017-12-14 14:26:15 -08003460 /**
3461 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3462 * specified.
3463 */
3464 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3465 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466
3467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3470 } finally {
3471 Binder.restoreCallingIdentity(identity);
3472 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003473 }
3474
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003475 /**
3476 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3477 * specified.
3478 */
3479 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3480 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003481
3482 final long identity = Binder.clearCallingIdentity();
3483 try {
3484 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3485 } finally {
3486 Binder.restoreCallingIdentity(identity);
3487 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003488 }
3489
Brad Ebinger884c07b2018-02-15 16:17:40 -08003490 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003491 * Sets the ImsService Package Name that Telephony will bind to.
3492 *
3493 * @param slotId the slot ID that the ImsService should bind for.
3494 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3495 * ImsService is the device default ImsService.
3496 * @param packageName The package name of the application that contains the ImsService to bind
3497 * to.
3498 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3499 * @hide
3500 */
3501 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003502 int[] subIds = SubscriptionManager.getSubId(slotId);
3503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3504 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3505 "setImsService");
3506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3510 isCarrierImsService, packageName);
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003514 }
3515
3516 /**
3517 * Return the ImsService configuration.
3518 *
3519 * @param slotId The slot that the ImsService is associated with.
3520 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3521 * the device default.
3522 * @return the package name of the ImsService configuration.
3523 */
3524 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003525 int[] subIds = SubscriptionManager.getSubId(slotId);
3526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3527 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3528 "getImsService");
3529
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3533 isCarrierImsService);
3534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003537 }
3538
Wink Saville36469e72014-06-11 15:17:00 -07003539 public void setImsRegistrationState(boolean registered) {
3540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003541
3542 final long identity = Binder.clearCallingIdentity();
3543 try {
3544 mPhone.setImsRegistrationState(registered);
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
Wink Saville36469e72014-06-11 15:17:00 -07003548 }
3549
3550 /**
Stuart Scott54788802015-03-30 13:18:01 -07003551 * Set the network selection mode to automatic.
3552 *
3553 */
3554 @Override
3555 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3557 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003558
Pengquan Menge92a50d2018-09-21 15:54:48 -07003559 if (!isActiveSubscription(subId)) {
3560 return;
3561 }
3562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3566 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3567 } finally {
3568 Binder.restoreCallingIdentity(identity);
3569 }
Stuart Scott54788802015-03-30 13:18:01 -07003570 }
3571
Pengquan Mengea84e042018-09-20 14:57:26 -07003572 /**
3573 * Ask the radio to connect to the input network and change selection mode to manual.
3574 *
3575 * @param subId the id of the subscription.
3576 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3577 * the operator to attach to.
3578 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3579 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3580 * normal network selection next time.
3581 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003582 */
3583 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003584 public boolean setNetworkSelectionModeManual(
3585 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3587 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003588
3589 if (!isActiveSubscription(subId)) {
3590 return false;
3591 }
3592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593 final long identity = Binder.clearCallingIdentity();
3594 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003595 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003597 if (DBG) {
3598 log("setNetworkSelectionModeManual: subId: " + subId
3599 + " operator: " + operatorInfo);
3600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003601 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3602 } finally {
3603 Binder.restoreCallingIdentity(identity);
3604 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003605 }
3606
3607 /**
3608 * Scans for available networks.
3609 */
3610 @Override
3611 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3613 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614
Pengquan Menga1bb6272018-09-06 09:59:22 -07003615 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003616 try {
3617 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003618 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620 } finally {
3621 Binder.restoreCallingIdentity(identity);
3622 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003623 }
3624
3625 /**
yinxub1bed742017-04-17 11:45:04 -07003626 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003627 *
yinxub1bed742017-04-17 11:45:04 -07003628 * @param subId id of the subscription
3629 * @param request contains the radio access networks with bands/channels to scan
3630 * @param messenger callback messenger for scan results or errors
3631 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003632 * @return the id of the requested scan which can be used to stop the scan.
3633 */
3634 @Override
3635 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3636 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3638 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639
3640 final long identity = Binder.clearCallingIdentity();
3641 try {
3642 return mNetworkScanRequestTracker.startNetworkScan(
3643 request, messenger, binder, getPhone(subId));
3644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
yinxu504e1392017-04-12 16:03:22 -07003647 }
3648
3649 /**
3650 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003651 *
3652 * @param subId id of the subscription
3653 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003654 */
3655 @Override
3656 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3658 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659
3660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
yinxu504e1392017-04-12 16:03:22 -07003666 }
3667
3668 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003669 * Get the calculated preferred network type.
3670 * Used for debugging incorrect network type.
3671 *
3672 * @return the preferred network type, defined in RILConstants.java.
3673 */
3674 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003675 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003676 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003677 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003678 return RILConstants.PREFERRED_NETWORK_MODE;
3679 }
3680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 // FIXME: need to get SubId from somewhere.
3684 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
Junda Liu84d15a22014-07-02 11:21:04 -07003688 }
3689
3690 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003691 * Get the preferred network type.
3692 * Used for device configuration by some CDMA operators.
3693 *
3694 * @return the preferred network type, defined in RILConstants.java.
3695 */
3696 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003697 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3699 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003700
3701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 if (DBG) log("getPreferredNetworkType");
3704 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3705 int networkType = (result != null ? result[0] : -1);
3706 if (DBG) log("getPreferredNetworkType: " + networkType);
3707 return networkType;
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003711 }
3712
3713 /**
3714 * Set the preferred network type.
3715 * Used for device configuration by some CDMA operators.
3716 *
3717 * @param networkType the preferred network type, defined in RILConstants.java.
3718 * @return true on success; false on any failure.
3719 */
3720 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003721 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3723 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724
3725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3728 Boolean success = (Boolean) sendRequest(
3729 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3730 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3731 if (success) {
3732 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3733 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3734 }
3735 return success;
3736 } finally {
3737 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003738 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003739 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003740
3741 /**
Junda Liu475951f2014-11-07 16:45:03 -08003742 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3743 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3744 * tethering.
3745 *
3746 * @return 0: Not required. 1: required. 2: Not set.
3747 * @hide
3748 */
3749 @Override
3750 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752
3753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3756 Settings.Global.TETHER_DUN_REQUIRED, 2);
3757 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3758 // config_tether_apndata.
3759 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3760 dunRequired = 1;
3761 }
3762 return dunRequired;
3763 } finally {
3764 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003765 }
Junda Liu475951f2014-11-07 16:45:03 -08003766 }
3767
3768 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003769 * Set mobile data enabled
3770 * Used by the user through settings etc to turn on/off mobile data
3771 *
3772 * @param enable {@code true} turn turn data on, else {@code false}
3773 */
3774 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003775 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3777 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003778
3779 final long identity = Binder.clearCallingIdentity();
3780 try {
3781 int phoneId = mSubscriptionController.getPhoneId(subId);
3782 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3783 Phone phone = PhoneFactory.getPhone(phoneId);
3784 if (phone != null) {
3785 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3786 phone.setUserDataEnabled(enable);
3787 } else {
3788 loge("setUserDataEnabled: no phone for subId=" + subId);
3789 }
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003792 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003793 }
3794
3795 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003796 * Get the user enabled state of Mobile Data.
3797 *
3798 * TODO: remove and use isUserDataEnabled.
3799 * This can't be removed now because some vendor codes
3800 * calls through ITelephony directly while they should
3801 * use TelephonyManager.
3802 *
3803 * @return true on enabled
3804 */
3805 @Override
3806 public boolean getDataEnabled(int subId) {
3807 return isUserDataEnabled(subId);
3808 }
3809
3810 /**
3811 * Get whether mobile data is enabled per user setting.
3812 *
3813 * There are other factors deciding whether mobile data is actually enabled, but they are
3814 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003815 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003816 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003817 *
3818 * @return {@code true} if data is enabled else {@code false}
3819 */
3820 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003821 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003822 try {
3823 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3824 null);
3825 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3827 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829
3830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 int phoneId = mSubscriptionController.getPhoneId(subId);
3833 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3834 Phone phone = PhoneFactory.getPhone(phoneId);
3835 if (phone != null) {
3836 boolean retVal = phone.isUserDataEnabled();
3837 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3838 return retVal;
3839 } else {
3840 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3841 return false;
3842 }
3843 } finally {
3844 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003845 }
3846 }
3847
3848 /**
3849 * Get whether mobile data is enabled.
3850 *
3851 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3852 * whether mobile data is actually enabled.
3853 *
3854 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3855 *
3856 * @return {@code true} if data is enabled else {@code false}
3857 */
3858 @Override
3859 public boolean isDataEnabled(int subId) {
3860 try {
3861 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3862 null);
3863 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3865 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867
3868 final long identity = Binder.clearCallingIdentity();
3869 try {
3870 int phoneId = mSubscriptionController.getPhoneId(subId);
3871 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3872 Phone phone = PhoneFactory.getPhone(phoneId);
3873 if (phone != null) {
3874 boolean retVal = phone.isDataEnabled();
3875 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3876 return retVal;
3877 } else {
3878 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3879 return false;
3880 }
3881 } finally {
3882 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003883 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003884 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003885
3886 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003887 public int getCarrierPrivilegeStatus(int subId) {
3888 final Phone phone = getPhone(subId);
3889 if (phone == null) {
3890 loge("getCarrierPrivilegeStatus: Invalid subId");
3891 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3892 }
3893 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003894 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003895 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003896 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3897 }
3898 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003899 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003900 }
Junda Liu29340342014-07-10 15:23:27 -07003901
3902 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003903 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3904 final Phone phone = getPhone(subId);
3905 if (phone == null) {
3906 loge("getCarrierPrivilegeStatus: Invalid subId");
3907 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3908 }
3909 UiccProfile profile =
3910 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3911 if (profile == null) {
3912 loge("getCarrierPrivilegeStatus: No UICC");
3913 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3914 }
3915 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3916 }
3917
3918 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003919 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003920 if (TextUtils.isEmpty(pkgName))
3921 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003922 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003923 if (card == null) {
3924 loge("checkCarrierPrivilegesForPackage: No UICC");
3925 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3926 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003927 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3928 }
3929
3930 @Override
3931 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003932 if (TextUtils.isEmpty(pkgName))
3933 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003934 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3935 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3936 UiccCard card = UiccController.getInstance().getUiccCard(i);
3937 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003938 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003939 continue;
3940 }
3941
3942 result = card.getCarrierPrivilegeStatus(
3943 mPhone.getContext().getPackageManager(), pkgName);
3944 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3945 break;
3946 }
3947 }
3948
3949 return result;
Junda Liu29340342014-07-10 15:23:27 -07003950 }
Derek Tan89e89d42014-07-08 17:00:10 -07003951
3952 @Override
Junda Liue64de782015-04-16 17:19:16 -07003953 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3954 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3955 loge("phoneId " + phoneId + " is not valid.");
3956 return null;
3957 }
3958 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003959 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003960 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003961 return null ;
3962 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003963 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003964 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003965 }
3966
Amith Yamasani6e118872016-02-19 12:53:51 -08003967 @Override
3968 public List<String> getPackagesWithCarrierPrivileges() {
3969 PackageManager pm = mPhone.getContext().getPackageManager();
3970 List<String> privilegedPackages = new ArrayList<>();
3971 List<PackageInfo> packages = null;
3972 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3973 UiccCard card = UiccController.getInstance().getUiccCard(i);
3974 if (card == null) {
3975 // No UICC in that slot.
3976 continue;
3977 }
3978 if (card.hasCarrierPrivilegeRules()) {
3979 if (packages == null) {
3980 // Only check packages in user 0 for now
3981 packages = pm.getInstalledPackagesAsUser(
3982 PackageManager.MATCH_DISABLED_COMPONENTS
3983 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3984 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3985 }
3986 for (int p = packages.size() - 1; p >= 0; p--) {
3987 PackageInfo pkgInfo = packages.get(p);
3988 if (pkgInfo != null && pkgInfo.packageName != null
3989 && card.getCarrierPrivilegeStatus(pkgInfo)
3990 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3991 privilegedPackages.add(pkgInfo.packageName);
3992 }
3993 }
3994 }
3995 }
3996 return privilegedPackages;
3997 }
3998
Wink Savilleb564aae2014-10-23 10:18:09 -07003999 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004000 final Phone phone = getPhone(subId);
4001 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004002 if (card == null) {
4003 loge("getIccId: No UICC");
4004 return null;
4005 }
4006 String iccId = card.getIccId();
4007 if (TextUtils.isEmpty(iccId)) {
4008 loge("getIccId: ICC ID is null or empty.");
4009 return null;
4010 }
4011 return iccId;
4012 }
4013
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004014 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004015 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4016 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004017 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4018 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 final String iccId = getIccId(subId);
4023 final Phone phone = getPhone(subId);
4024 if (phone == null) {
4025 return false;
4026 }
4027 final String subscriberId = phone.getSubscriberId();
4028
4029 if (DBG_MERGE) {
4030 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4031 + subscriberId + " to " + number);
4032 }
4033
4034 if (TextUtils.isEmpty(iccId)) {
4035 return false;
4036 }
4037
4038 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4039
4040 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4041 if (alphaTag == null) {
4042 editor.remove(alphaTagPrefKey);
4043 } else {
4044 editor.putString(alphaTagPrefKey, alphaTag);
4045 }
4046
4047 // Record both the line number and IMSI for this ICCID, since we need to
4048 // track all merged IMSIs based on line number
4049 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4050 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4051 if (number == null) {
4052 editor.remove(numberPrefKey);
4053 editor.remove(subscriberPrefKey);
4054 } else {
4055 editor.putString(numberPrefKey, number);
4056 editor.putString(subscriberPrefKey, subscriberId);
4057 }
4058
4059 editor.commit();
4060 return true;
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004063 }
Derek Tan7226c842014-07-02 17:42:23 -07004064 }
4065
4066 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004067 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004068 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004070 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004071 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004072 return null;
4073 }
Derek Tan97ebb422014-09-05 16:55:38 -07004074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 String iccId = getIccId(subId);
4078 if (iccId != null) {
4079 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4080 if (DBG_MERGE) {
4081 log("getLine1NumberForDisplay returning "
4082 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4083 }
4084 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4087 return null;
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004090 }
Derek Tan7226c842014-07-02 17:42:23 -07004091 }
4092
4093 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004094 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004095 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004096 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004097 return null;
4098 }
Derek Tan97ebb422014-09-05 16:55:38 -07004099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 String iccId = getIccId(subId);
4103 if (iccId != null) {
4104 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4105 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4106 }
4107 return null;
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004110 }
Derek Tan7226c842014-07-02 17:42:23 -07004111 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004112
4113 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004114 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004115 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4116 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004118 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4119 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004120 return null;
4121 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004122
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004123 final long identity = Binder.clearCallingIdentity();
4124 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125 final Context context = mPhone.getContext();
4126 final TelephonyManager tele = TelephonyManager.from(context);
4127 final SubscriptionManager sub = SubscriptionManager.from(context);
4128
4129 // Figure out what subscribers are currently active
4130 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4131 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4132 // the process, where TelephonyManager was instantiated.
4133 // Otherwise AppOps check will fail.
4134
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004135 final int[] subIds = sub.getActiveSubscriptionIdList();
4136 for (int subId : subIds) {
4137 activeSubscriberIds.add(tele.getSubscriberId(subId));
4138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139
4140 // First pass, find a number override for an active subscriber
4141 String mergeNumber = null;
4142 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4143 for (String key : prefs.keySet()) {
4144 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4145 final String subscriberId = (String) prefs.get(key);
4146 if (activeSubscriberIds.contains(subscriberId)) {
4147 final String iccId = key.substring(
4148 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4149 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4150 mergeNumber = (String) prefs.get(numberKey);
4151 if (DBG_MERGE) {
4152 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4153 + " for active subscriber " + subscriberId);
4154 }
4155 if (!TextUtils.isEmpty(mergeNumber)) {
4156 break;
4157 }
4158 }
4159 }
4160 }
4161
4162 // Shortcut when no active merged subscribers
4163 if (TextUtils.isEmpty(mergeNumber)) {
4164 return null;
4165 }
4166
4167 // Second pass, find all subscribers under that line override
4168 final ArraySet<String> result = new ArraySet<>();
4169 for (String key : prefs.keySet()) {
4170 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4171 final String number = (String) prefs.get(key);
4172 if (mergeNumber.equals(number)) {
4173 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4174 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4175 final String subscriberId = (String) prefs.get(subscriberKey);
4176 if (!TextUtils.isEmpty(subscriberId)) {
4177 result.add(subscriberId);
4178 }
4179 }
4180 }
4181 }
4182
4183 final String[] resultArray = result.toArray(new String[result.size()]);
4184 Arrays.sort(resultArray);
4185 if (DBG_MERGE) {
4186 Slog.d(LOG_TAG,
4187 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4188 }
4189 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004190 } finally {
4191 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004192 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004193 }
4194
4195 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004196 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004197 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4198 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004199
4200 final long identity = Binder.clearCallingIdentity();
4201 try {
4202 final Phone phone = getPhone(subId);
4203 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004207 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004208
4209 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004210 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004211 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4212 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004213 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214
4215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 final Phone phone = getPhone(subId);
4218 if (phone == null) {
4219 return false;
4220 }
4221 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4222 cdmaNonRoamingList);
4223 } finally {
4224 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004225 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004226 }
4227
4228 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004229 @Deprecated
4230 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4231 enforceModifyPermission();
4232
4233 int returnValue = 0;
4234 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004235 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004236 if(result.exception == null) {
4237 if (result.result != null) {
4238 byte[] responseData = (byte[])(result.result);
4239 if(responseData.length > oemResp.length) {
4240 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4241 responseData.length + "bytes. Buffer Size is " +
4242 oemResp.length + "bytes.");
4243 }
4244 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4245 returnValue = responseData.length;
4246 }
4247 } else {
4248 CommandException ex = (CommandException) result.exception;
4249 returnValue = ex.getCommandError().ordinal();
4250 if(returnValue > 0) returnValue *= -1;
4251 }
4252 } catch (RuntimeException e) {
4253 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4254 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4255 if(returnValue > 0) returnValue *= -1;
4256 }
4257
4258 return returnValue;
4259 }
4260
4261 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004262 public void setRadioCapability(RadioAccessFamily[] rafs) {
4263 try {
4264 ProxyController.getInstance().setRadioCapability(rafs);
4265 } catch (RuntimeException e) {
4266 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4267 }
4268 }
4269
4270 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004271 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004272 Phone phone = PhoneFactory.getPhone(phoneId);
4273 if (phone == null) {
4274 return RadioAccessFamily.RAF_UNKNOWN;
4275 }
4276 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004278 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004279 return RadioAccessFamily.RAF_UNKNOWN;
4280 }
4281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282 final long identity = Binder.clearCallingIdentity();
4283 try {
4284 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
4287 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004288 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004289
4290 @Override
4291 public void enableVideoCalling(boolean enable) {
4292 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293
4294 final long identity = Binder.clearCallingIdentity();
4295 try {
4296 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4297 } finally {
4298 Binder.restoreCallingIdentity(identity);
4299 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004300 }
4301
4302 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004303 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004304 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4305 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4306 return false;
4307 }
Svet Ganovb320e182015-04-16 12:30:10 -07004308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 final long identity = Binder.clearCallingIdentity();
4310 try {
4311 // Check the user preference and the system-level IMS setting. Even if the user has
4312 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4313 // In the long run, we may instead need to check if there exists a connection service
4314 // which can support video calling.
4315 ImsManager imsManager =
4316 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4317 return imsManager.isVtEnabledByPlatform()
4318 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4319 && imsManager.isVtEnabledByUser();
4320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004323 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004324
Andrew Leea1239f22015-03-02 17:44:07 -08004325 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4328 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4329 return false;
4330 }
4331
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 CarrierConfigManager configManager =
4335 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4336 return configManager.getConfigForSubId(mPhone.getSubId())
4337 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
Andrew Leea1239f22015-03-02 17:44:07 -08004341 }
4342
4343 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004344 public boolean isWorldPhone(int subId, String callingPackage) {
4345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4346 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4347 return false;
4348 }
4349
4350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 CarrierConfigManager configManager =
4353 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4354 return configManager.getConfigForSubId(mPhone.getSubId())
4355 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
Andrew Leea1239f22015-03-02 17:44:07 -08004359 }
4360
Andrew Lee9431b832015-03-09 18:46:45 -07004361 @Override
4362 public boolean isTtyModeSupported() {
4363 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004364 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004365 }
4366
4367 @Override
4368 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369 final long identity = Binder.clearCallingIdentity();
4370 try {
4371 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4372 } finally {
4373 Binder.restoreCallingIdentity(identity);
4374 }
Andrew Lee9431b832015-03-09 18:46:45 -07004375 }
4376
Hall Liu98187582018-01-22 19:15:32 -08004377 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 final long identity = Binder.clearCallingIdentity();
4379 try {
4380 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4381 mPhone.getSubId()).getBoolean(
4382 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4383 boolean isDeviceSupported =
4384 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4385 return isCarrierSupported && isDeviceSupported;
4386 } finally {
4387 Binder.restoreCallingIdentity(identity);
4388 }
Hall Liu98187582018-01-22 19:15:32 -08004389 }
4390
Hall Liu3ad5f012018-04-06 16:23:39 -07004391 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392 final long identity = Binder.clearCallingIdentity();
4393 try {
4394 return isRttSupported() && Settings.Secure.getInt(
4395 mPhone.getContext().getContentResolver(),
4396 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004400 }
4401
Sanket Padawe7310cc72015-01-14 09:53:20 -08004402 /**
4403 * Returns the unique device ID of phone, for example, the IMEI for
4404 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4405 *
4406 * <p>Requires Permission:
4407 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4408 */
4409 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004410 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004411 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004412 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004413 return null;
4414 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004415 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004416 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4417 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004418 return null;
4419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420
4421 final long identity = Binder.clearCallingIdentity();
4422 try {
4423 return phone.getDeviceId();
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004427 }
4428
Ping Sunc67b7c22016-03-02 19:16:45 +08004429 /**
4430 * {@hide}
4431 * Returns the IMS Registration Status on a particular subid
4432 *
4433 * @param subId
4434 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004435 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004436 Phone phone = getPhone(subId);
4437 if (phone != null) {
4438 return phone.isImsRegistered();
4439 } else {
4440 return false;
4441 }
4442 }
4443
Santos Cordon7a1885b2015-02-03 11:15:19 -08004444 @Override
4445 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 final long identity = Binder.clearCallingIdentity();
4447 try {
4448 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004452 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004453
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004454 /**
4455 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004456 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004457 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 final long identity = Binder.clearCallingIdentity();
4459 try {
4460 Phone phone = getPhone(subId);
4461 if (phone != null) {
4462 return phone.isWifiCallingEnabled();
4463 } else {
4464 return false;
4465 }
4466 } finally {
4467 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004468 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004469 }
4470
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004471 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004472 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004473 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004474 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 Phone phone = getPhone(subId);
4478 if (phone != null) {
4479 return phone.isVideoEnabled();
4480 } else {
4481 return false;
4482 }
4483 } finally {
4484 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004485 }
4486 }
4487
4488 /**
4489 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4490 * defined in {@link ImsRegistrationImplBase}.
4491 */
4492 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004493 final long identity = Binder.clearCallingIdentity();
4494 try {
4495 Phone phone = getPhone(subId);
4496 if (phone != null) {
4497 return phone.getImsRegistrationTech();
4498 } else {
4499 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4500 }
4501 } finally {
4502 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004503 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004504 }
4505
Stuart Scott8eef64f2015-04-08 15:13:54 -07004506 @Override
4507 public void factoryReset(int subId) {
4508 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004509 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4510 return;
4511 }
4512
Svet Ganovcc087f82015-05-12 20:35:54 -07004513 final long identity = Binder.clearCallingIdentity();
4514 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004515 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4516 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004517 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004518 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004519 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4520 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004521 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004522 }
4523 } finally {
4524 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004525 }
4526 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004527
4528 @Override
4529 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530 final long identity = Binder.clearCallingIdentity();
4531 try {
4532 // We query all subscriptions instead of just the active ones, because
4533 // this might be called early on in the provisioning flow when the
4534 // subscriptions potentially aren't active yet.
4535 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4536 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004537 return null;
4538 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 // This function may be called very early, say, from the setup wizard, at
4541 // which point we won't have a default subscription set. If that's the case
4542 // we just choose the first, which will be valid in "most cases".
4543 final int defaultSubId = getDefaultSubscription();
4544 SubscriptionInfo info = null;
4545 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4546 info = slist.get(0);
4547 } else {
4548 for (SubscriptionInfo item : slist) {
4549 if (item.getSubscriptionId() == defaultSubId) {
4550 info = item;
4551 break;
4552 }
4553 }
4554
4555 if (info == null) {
4556 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004557 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004558 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004559
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 // Try and fetch the locale from the carrier properties or from the SIM language
4561 // preferences (EF-PL and EF-LI)...
4562 final int mcc = info.getMcc();
4563 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4564 String simLanguage = null;
4565 if (defaultPhone != null) {
4566 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4567 if (localeFromDefaultSim != null) {
4568 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4569 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4570 return localeFromDefaultSim.toLanguageTag();
4571 } else {
4572 simLanguage = localeFromDefaultSim.getLanguage();
4573 }
4574 }
4575 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577 // The SIM language preferences only store a language (e.g. fr = French), not an
4578 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4579 // the SIM and carrier preferences does not include a country we add the country
4580 // determined from the SIM MCC to provide an exact locale.
4581 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4582 simLanguage);
4583 if (mccLocale != null) {
4584 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4585 return mccLocale.toLanguageTag();
4586 }
4587
4588 if (DBG) log("No locale found - returning null");
4589 return null;
4590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004593 }
4594
4595 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 return mSubscriptionController.getAllSubInfoList(
4597 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004598 }
4599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004600 /**
4601 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4602 */
4603 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4604 return mSubscriptionController.getActiveSubscriptionInfoList(
4605 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004606 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004607
Chenjie Yu1ba97252018-01-11 18:16:20 -08004608 private final ModemActivityInfo mLastModemActivityInfo =
4609 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4610
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004611 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004612 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4613 * representing the state of the modem.
4614 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004615 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4616 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004617 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004618 */
4619 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004620 public void requestModemActivityInfo(ResultReceiver result) {
4621 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004622 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623
4624 final long identity = Binder.clearCallingIdentity();
4625 try {
4626 ModemActivityInfo ret = null;
4627 synchronized (mLastModemActivityInfo) {
4628 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4629 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004630 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004631 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4633 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4634 mergedTxTimeMs[i] =
4635 info.getTxTimeMillis()[i]
4636 + mLastModemActivityInfo.getTxTimeMillis()[i];
4637 }
4638 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4639 mLastModemActivityInfo.setSleepTimeMillis(
4640 info.getSleepTimeMillis()
4641 + mLastModemActivityInfo.getSleepTimeMillis());
4642 mLastModemActivityInfo.setIdleTimeMillis(
4643 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4644 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4645 mLastModemActivityInfo.setRxTimeMillis(
4646 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4647 mLastModemActivityInfo.setEnergyUsed(
4648 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4651 mLastModemActivityInfo.getSleepTimeMillis(),
4652 mLastModemActivityInfo.getIdleTimeMillis(),
4653 mLastModemActivityInfo.getTxTimeMillis(),
4654 mLastModemActivityInfo.getRxTimeMillis(),
4655 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 Bundle bundle = new Bundle();
4658 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4659 result.send(0, bundle);
4660 } finally {
4661 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004662 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004663 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004664
Siddharth Rayb8114062018-06-17 15:02:38 -07004665 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4666 // less than total activity duration.
4667 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4668 if (info == null) {
4669 return false;
4670 }
4671 int activityDurationMs =
4672 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4673 int totalTxTimeMs = 0;
4674 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4675 totalTxTimeMs += info.getTxTimeMillis()[i];
4676 }
4677 return (info.isValid()
4678 && (info.getSleepTimeMillis() <= activityDurationMs)
4679 && (info.getIdleTimeMillis() <= activityDurationMs)
4680 && (info.getRxTimeMillis() <= activityDurationMs)
4681 && (totalTxTimeMs <= activityDurationMs));
4682 }
4683
Jack Yu85bd38a2015-11-09 11:34:32 -08004684 /**
4685 * {@hide}
4686 * Returns the service state information on specified subscription.
4687 */
4688 @Override
4689 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004691 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004692 return null;
4693 }
4694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 final long identity = Binder.clearCallingIdentity();
4696 try {
4697 final Phone phone = getPhone(subId);
4698 if (phone == null) {
4699 return null;
4700 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702 return phone.getServiceState();
4703 } finally {
4704 Binder.restoreCallingIdentity(identity);
4705 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004706 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004707
4708 /**
4709 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4710 *
4711 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4712 * voicemail ringtone.
4713 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4714 * PhoneAccount.
4715 */
4716 @Override
4717 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 final long identity = Binder.clearCallingIdentity();
4719 try {
4720 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4721 if (phone == null) {
4722 phone = mPhone;
4723 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4726 } finally {
4727 Binder.restoreCallingIdentity(identity);
4728 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004729 }
4730
4731 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004732 * Sets the per-account voicemail ringtone.
4733 *
4734 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4735 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4736 *
4737 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4738 * voicemail ringtone.
4739 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4740 * PhoneAccount.
4741 */
4742 @Override
4743 public void setVoicemailRingtoneUri(String callingPackage,
4744 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4745 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4746 if (!TextUtils.equals(callingPackage,
4747 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4749 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4750 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004751 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752
4753 final long identity = Binder.clearCallingIdentity();
4754 try {
4755 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4756 if (phone == null) {
4757 phone = mPhone;
4758 }
4759 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4760 } finally {
4761 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004762 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004763 }
4764
4765 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004766 * Returns whether vibration is set for voicemail notification in Phone settings.
4767 *
4768 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4769 * voicemail vibration setting.
4770 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4771 */
4772 @Override
4773 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4777 if (phone == null) {
4778 phone = mPhone;
4779 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
4784 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004785 }
4786
Youhan Wange64578a2016-05-02 15:32:42 -07004787 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004788 * Sets the per-account voicemail vibration.
4789 *
4790 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4791 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4792 *
4793 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4794 * voicemail vibration setting.
4795 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4796 * specific PhoneAccount.
4797 */
4798 @Override
4799 public void setVoicemailVibrationEnabled(String callingPackage,
4800 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4801 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4802 if (!TextUtils.equals(callingPackage,
4803 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4805 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4806 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004807 }
4808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 final long identity = Binder.clearCallingIdentity();
4810 try {
4811 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4812 if (phone == null) {
4813 phone = mPhone;
4814 }
4815 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4816 } finally {
4817 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004818 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004819 }
4820
4821 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004822 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4823 *
4824 * @throws SecurityException if the caller does not have the required permission
4825 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004826 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004827 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004828 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004829 }
4830
4831 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004832 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4833 * permission.
4834 *
4835 * @throws SecurityException if the caller does not have the required permission
4836 */
4837 private void enforceSendSmsPermission() {
4838 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4839 }
4840
4841 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004842 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004843 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004844 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004845 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004846 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 ComponentName componentName =
4850 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4851 if (componentName == null) {
4852 throw new SecurityException(
4853 "Caller not current active visual voicemail package[null]");
4854 }
4855 String vvmPackage = componentName.getPackageName();
4856 if (!callingPackage.equals(vvmPackage)) {
4857 throw new SecurityException("Caller not current active visual voicemail package["
4858 + vvmPackage + "]");
4859 }
4860 } finally {
4861 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004862 }
4863 }
4864
4865 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004866 * Return the application ID for the app type.
4867 *
4868 * @param subId the subscription ID that this request applies to.
4869 * @param appType the uicc app type.
4870 * @return Application ID for specificied app type, or null if no uicc.
4871 */
4872 @Override
4873 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004874 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07004875 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876
4877 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004878 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 if (phone == null) {
4880 return null;
4881 }
4882 String aid = null;
4883 try {
4884 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4885 .getApplicationByType(appType).getAid();
4886 } catch (Exception e) {
4887 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4888 }
4889 return aid;
4890 } finally {
4891 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004892 }
Youhan Wange64578a2016-05-02 15:32:42 -07004893 }
4894
Youhan Wang4001d252016-05-11 10:29:41 -07004895 /**
4896 * Return the Electronic Serial Number.
4897 *
4898 * @param subId the subscription ID that this request applies to.
4899 * @return ESN or null if error.
4900 */
4901 @Override
4902 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004903 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07004904 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905
4906 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004907 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 if (phone == null) {
4909 return null;
4910 }
4911 String esn = null;
4912 try {
4913 esn = phone.getEsn();
4914 } catch (Exception e) {
4915 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4916 }
4917 return esn;
4918 } finally {
4919 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004920 }
Youhan Wang4001d252016-05-11 10:29:41 -07004921 }
4922
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004923 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004924 * Return the Preferred Roaming List Version.
4925 *
4926 * @param subId the subscription ID that this request applies to.
4927 * @return PRLVersion or null if error.
4928 */
4929 @Override
4930 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004931 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07004932 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933
4934 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004935 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 if (phone == null) {
4937 return null;
4938 }
4939 String cdmaPrlVersion = null;
4940 try {
4941 cdmaPrlVersion = phone.getCdmaPrlVersion();
4942 } catch (Exception e) {
4943 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4944 }
4945 return cdmaPrlVersion;
4946 } finally {
4947 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004948 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004949 }
4950
4951 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004952 * Get snapshot of Telephony histograms
4953 * @return List of Telephony histograms
4954 * @hide
4955 */
4956 @Override
4957 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4959 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960
4961 final long identity = Binder.clearCallingIdentity();
4962 try {
4963 return RIL.getTelephonyRILTimingHistograms();
4964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004967 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004968
4969 /**
4970 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004971 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004972 * Require system privileges. In the future we may add this to carrier APIs.
4973 *
4974 * @return The number of carriers set successfully, should match length of carriers
4975 */
4976 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004977 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004978 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004980
Meng Wang9b7c4e92017-02-17 11:41:27 -08004981 if (carriers == null) {
4982 throw new NullPointerException("carriers cannot be null");
4983 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 final long identity = Binder.clearCallingIdentity();
4986 try {
4987 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004988 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4989 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 return retVal[0];
4991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004994 }
4995
4996 /**
4997 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004998 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004999 * Require system privileges. In the future we may add this to carrier APIs.
5000 *
5001 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5002 * means all carriers are allowed.
5003 */
5004 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005005 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005006 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005007 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008
5009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005012 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5013 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 } finally {
5015 Binder.restoreCallingIdentity(identity);
5016 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005017 }
5018
fionaxu59545b42016-05-25 15:53:37 -07005019 /**
5020 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5021 * @param subId the subscription ID that this action applies to.
5022 * @param enabled control enable or disable metered apns.
5023 * {@hide}
5024 */
5025 @Override
5026 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5027 enforceModifyPermission();
5028 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029
5030 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005031 if (phone == null) {
5032 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5033 return;
5034 }
5035 try {
5036 phone.carrierActionSetMeteredApnsEnabled(enabled);
5037 } catch (Exception e) {
5038 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 } finally {
5040 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005041 }
5042 }
5043
5044 /**
5045 * Action set from carrier signalling broadcast receivers to enable/disable radio
5046 * @param subId the subscription ID that this action applies to.
5047 * @param enabled control enable or disable radio.
5048 * {@hide}
5049 */
5050 @Override
5051 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5052 enforceModifyPermission();
5053 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054
5055 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005056 if (phone == null) {
5057 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5058 return;
5059 }
5060 try {
5061 phone.carrierActionSetRadioEnabled(enabled);
5062 } catch (Exception e) {
5063 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064 } finally {
5065 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005066 }
5067 }
5068
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005069 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005070 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5071 * network status based on which carrier apps could apply actions accordingly,
5072 * enable/disable default url handler for example.
5073 *
5074 * @param subId the subscription ID that this action applies to.
5075 * @param report control start/stop reporting the default network status.
5076 * {@hide}
5077 */
5078 @Override
5079 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5080 enforceModifyPermission();
5081 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082
5083 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005084 if (phone == null) {
5085 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5086 return;
5087 }
5088 try {
5089 phone.carrierActionReportDefaultNetworkStatus(report);
5090 } catch (Exception e) {
5091 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 } finally {
5093 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005094 }
5095 }
5096
5097 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005098 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5099 * bug report is being generated.
5100 */
5101 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005102 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005103 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5104 != PackageManager.PERMISSION_GRANTED) {
5105 writer.println("Permission Denial: can't dump Phone from pid="
5106 + Binder.getCallingPid()
5107 + ", uid=" + Binder.getCallingUid()
5108 + "without permission "
5109 + android.Manifest.permission.DUMP);
5110 return;
5111 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005112 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005113 }
Jack Yueb89b242016-06-22 13:27:47 -07005114
Brad Ebingerdac2f002018-04-03 15:17:52 -07005115 @Override
5116 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5117 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5118 throws RemoteException {
5119 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5120 }
5121
Jack Yueb89b242016-06-22 13:27:47 -07005122 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005123 * Get aggregated video call data usage since boot.
5124 *
5125 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5126 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005127 * {@hide}
5128 */
5129 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005130 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005131 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5132 null);
5133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 final long identity = Binder.clearCallingIdentity();
5135 try {
5136 // NetworkStatsService keeps tracking the active network interface and identity. It
5137 // records the delta with the corresponding network identity.
5138 // We just return the total video call data usage snapshot since boot.
5139 Phone phone = getPhone(subId);
5140 if (phone != null) {
5141 return phone.getVtDataUsage(perUidStats);
5142 }
5143 return null;
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005146 }
Jack Yueb89b242016-06-22 13:27:47 -07005147 }
Jack Yu75ab2952016-07-08 14:29:33 -07005148
5149 /**
5150 * Policy control of data connection. Usually used when data limit is passed.
5151 * @param enabled True if enabling the data, otherwise disabling.
5152 * @param subId Subscription index
5153 * {@hide}
5154 */
5155 @Override
5156 public void setPolicyDataEnabled(boolean enabled, int subId) {
5157 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158
5159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 Phone phone = getPhone(subId);
5162 if (phone != null) {
5163 phone.setPolicyDataEnabled(enabled);
5164 }
5165 } finally {
5166 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005167 }
5168 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005169
5170 /**
5171 * Get Client request stats
5172 * @return List of Client Request Stats
5173 * @hide
5174 */
5175 @Override
5176 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005177 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005178 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005179 return null;
5180 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005181 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183 final long identity = Binder.clearCallingIdentity();
5184 try {
5185 if (phone != null) {
5186 return phone.getClientRequestStats();
5187 }
5188
5189 return null;
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005193 }
5194
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005195 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005196 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005197 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005198 }
Jack Yueb4124c2017-02-16 15:32:43 -08005199
5200 /**
Grace Chen70990072017-03-24 17:21:30 -07005201 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005202 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005203 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005204 * @param state State of SIM (power down, power up, pass through)
5205 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5206 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5207 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005208 *
5209 **/
5210 @Override
Grace Chen70990072017-03-24 17:21:30 -07005211 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005212 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005213 Phone phone = PhoneFactory.getPhone(slotIndex);
5214
vagdeviaf9a5b92018-08-15 16:01:53 -07005215 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 final long identity = Binder.clearCallingIdentity();
5218 try {
5219 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005220 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 }
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005224 }
5225 }
Shuo Qiandd210312017-04-12 22:11:33 +00005226
Tyler Gunn65d45c22017-06-05 11:22:26 -07005227 private boolean isUssdApiAllowed(int subId) {
5228 CarrierConfigManager configManager =
5229 (CarrierConfigManager) mPhone.getContext().getSystemService(
5230 Context.CARRIER_CONFIG_SERVICE);
5231 if (configManager == null) {
5232 return false;
5233 }
5234 PersistableBundle pb = configManager.getConfigForSubId(subId);
5235 if (pb == null) {
5236 return false;
5237 }
5238 return pb.getBoolean(
5239 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5240 }
5241
Shuo Qiandd210312017-04-12 22:11:33 +00005242 /**
5243 * Check if phone is in emergency callback mode
5244 * @return true if phone is in emergency callback mode
5245 * @param subId sub id
5246 */
goneil9c5f4872017-12-05 14:07:56 -08005247 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005248 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005249 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005250 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251
5252 final long identity = Binder.clearCallingIdentity();
5253 try {
5254 if (phone != null) {
5255 return phone.isInEcm();
5256 } else {
5257 return false;
5258 }
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005261 }
5262 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005263
5264 /**
5265 * Get the current signal strength information for the given subscription.
5266 * Because this information is not updated when the device is in a low power state
5267 * it should not be relied-upon to be current.
5268 * @param subId Subscription index
5269 * @return the most recent cached signal strength info from the modem
5270 */
5271 @Override
5272 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 final long identity = Binder.clearCallingIdentity();
5274 try {
5275 Phone p = getPhone(subId);
5276 if (p == null) {
5277 return null;
5278 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 return p.getSignalStrength();
5281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005284 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005285
Pengquan Meng77b7f132018-08-22 14:49:57 -07005286 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005287 * Get the current modem radio state for the given slot.
5288 * @param slotIndex slot index.
5289 * @param callingPackage the name of the package making the call.
5290 * @return the current radio power state from the modem
5291 */
5292 @Override
5293 public int getRadioPowerState(int slotIndex, String callingPackage) {
5294 Phone phone = PhoneFactory.getPhone(slotIndex);
5295 if (phone != null) {
5296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5297 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5298 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5299 }
5300
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 return phone.getRadioPowerState();
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
5306 }
5307 }
5308 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5309 }
5310
5311 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005312 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5313 *
5314 * <p>Requires one of the following permissions:
5315 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5316 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5317 * privileges.
5318 *
5319 * @param subId subscription id
5320 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5321 * {@code false}.
5322 */
5323 @Override
5324 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005325 boolean isEnabled = false;
5326 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005327 try {
5328 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005329 null /* message */);
5330 Phone phone = getPhone(subId);
5331 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005332 } catch (Exception e) {
5333 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5334 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005335 } finally {
5336 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005337 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005338 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005339 }
5340
5341
5342 /**
5343 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5344 *
5345 * <p> Requires permission:
5346 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5347 * privileges.
5348 *
5349 * @param subId subscription id
5350 * @param isEnabled {@code true} means enable, {@code false} means disable.
5351 */
5352 @Override
5353 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005354 final long identity = Binder.clearCallingIdentity();
5355 try {
5356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5357 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005358
Pengquan Menga1bb6272018-09-06 09:59:22 -07005359 Phone phone = getPhone(subId);
5360 if (phone != null) {
5361 phone.setDataRoamingEnabled(isEnabled);
5362 }
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005365 }
5366 }
5367
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005368 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005369 public boolean isManualNetworkSelectionAllowed(int subId) {
5370 boolean isAllowed = true;
5371 final long identity = Binder.clearCallingIdentity();
5372 try {
5373 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5374 mApp, subId, "isManualNetworkSelectionAllowed");
5375 Phone phone = getPhone(subId);
5376 if (phone != null) {
5377 isAllowed = phone.isCspPlmnEnabled();
5378 }
5379 } finally {
5380 Binder.restoreCallingIdentity(identity);
5381 }
5382 return isAllowed;
5383 }
5384
5385 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005386 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005387 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 final long identity = Binder.clearCallingIdentity();
5390 try {
5391 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5392 if (slots == null) {
5393 Rlog.i(LOG_TAG, "slots is null.");
5394 return null;
5395 }
5396
5397 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5398 for (int i = 0; i < slots.length; i++) {
5399 UiccSlot slot = slots[i];
5400 if (slot == null) {
5401 continue;
5402 }
5403
5404 String cardId;
5405 UiccCard card = slot.getUiccCard();
5406 if (card != null) {
5407 cardId = card.getCardId();
5408 } else {
5409 cardId = slot.getIccId();
5410 }
5411
5412 int cardState = 0;
5413 switch (slot.getCardState()) {
5414 case CARDSTATE_ABSENT:
5415 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5416 break;
5417 case CARDSTATE_PRESENT:
5418 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5419 break;
5420 case CARDSTATE_ERROR:
5421 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5422 break;
5423 case CARDSTATE_RESTRICTED:
5424 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5425 break;
5426 default:
5427 break;
5428
5429 }
5430
5431 infos[i] = new UiccSlotInfo(
5432 slot.isActive(),
5433 slot.isEuicc(),
5434 cardId,
5435 cardState,
5436 slot.getPhoneId(),
5437 slot.isExtendedApduSupported());
5438 }
5439 return infos;
5440 } finally {
5441 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005442 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005443 }
5444
5445 @Override
5446 public boolean switchSlots(int[] physicalSlots) {
5447 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448
5449 final long identity = Binder.clearCallingIdentity();
5450 try {
5451 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5452 } finally {
5453 Binder.restoreCallingIdentity(identity);
5454 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005455 }
Jack Yu4c988042018-02-27 15:30:01 -08005456
5457 @Override
5458 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5459 enforceModifyPermission();
5460 final Phone phone = getPhone(subId);
5461 if (phone == null) {
5462 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5463 return;
5464 }
5465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 phone.setRadioIndicationUpdateMode(filters, mode);
5469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
Jack Yu4c988042018-02-27 15:30:01 -08005472 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005473
5474 /**
goneil47ffb6e2018-04-06 15:40:58 -07005475 * A test API to reload the UICC profile.
5476 *
5477 * <p>Requires that the calling app has permission
5478 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5479 * @hide
5480 */
5481 @Override
5482 public void refreshUiccProfile(int subId) {
5483 enforceModifyPermission();
5484
5485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 Phone phone = getPhone(subId);
5488 if (phone == null) {
5489 return;
5490 }
5491 UiccCard uiccCard = phone.getUiccCard();
5492 if (uiccCard == null) {
5493 return;
5494 }
5495 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5496 if (uiccProfile == null) {
5497 return;
5498 }
5499 uiccProfile.refresh();
5500 } finally {
5501 Binder.restoreCallingIdentity(identity);
5502 }
5503 }
5504
5505 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005506 * Returns false if the mobile data is disabled by default, otherwise return true.
5507 */
5508 private boolean getDefaultDataEnabled() {
5509 return "true".equalsIgnoreCase(
5510 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5511 }
5512
5513 /**
5514 * Returns true if the data roaming is enabled by default, i.e the system property
5515 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5516 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5517 */
5518 private boolean getDefaultDataRoamingEnabled(int subId) {
5519 final CarrierConfigManager configMgr = (CarrierConfigManager)
5520 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5521 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5522 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5523 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5524 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5525 return isDataRoamingEnabled;
5526 }
5527
5528 /**
5529 * Returns the default network type for the given {@code subId}, if the default network type is
5530 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5531 */
5532 private int getDefaultNetworkType(int subId) {
5533 return Integer.parseInt(
5534 TelephonyManager.getTelephonyProperty(
5535 mSubscriptionController.getPhoneId(subId),
5536 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5537 String.valueOf(Phone.PREFERRED_NT_MODE)));
5538 }
fionaxua13278b2018-03-21 00:08:13 -07005539
5540 @Override
5541 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5542 gid1, String gid2, String plmn, String spn) {
5543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544
5545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 final Phone phone = getPhone(subId);
5548 if (phone == null) {
5549 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5550 return;
5551 }
5552 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5553 } finally {
5554 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005555 }
fionaxua13278b2018-03-21 00:08:13 -07005556 }
5557
5558 @Override
5559 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005560 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 final Phone phone = getPhone(subId);
5565 if (phone == null) {
5566 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5567 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5568 }
5569 return phone.getCarrierIdListVersion();
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005572 }
fionaxua13278b2018-03-21 00:08:13 -07005573 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005574
5575 @Override
5576 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5578 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5579 return -1;
5580 }
5581
5582 final long identity = Binder.clearCallingIdentity();
5583 try {
5584 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
5588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005589
5590 @Override
5591 public int getCdmaRoamingMode(int subId) {
5592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5593 mApp, subId, "getCdmaRoamingMode");
5594
5595 final long identity = Binder.clearCallingIdentity();
5596 try {
5597 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
5601 }
5602
5603 @Override
5604 public boolean setCdmaRoamingMode(int subId, int mode) {
5605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5606 mApp, subId, "setCdmaRoamingMode");
5607
5608 final long identity = Binder.clearCallingIdentity();
5609 try {
5610 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
5614 }
5615
5616 @Override
5617 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5619 mApp, subId, "setCdmaSubscriptionMode");
5620
5621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
5627 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005628
5629 private void ensureUserRunning(int userId) {
5630 if (!mUserManager.isUserRunning(userId)) {
5631 throw new IllegalStateException("User " + userId + " does not exist or not running");
5632 }
5633 }
5634
5635 /**
5636 * Returns a list of SMS apps on a given user.
5637 *
5638 * Only the shell user (UID 2000 or 0) can call it.
5639 * Target user must be running.
5640 */
5641 @Override
5642 public String[] getSmsApps(int userId) {
5643 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5644 ensureUserRunning(userId);
5645
5646 final Collection<SmsApplicationData> apps =
5647 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5648
5649 String[] ret = new String[apps.size()];
5650 int i = 0;
5651 for (SmsApplicationData app : apps) {
5652 ret[i++] = app.mPackageName;
5653 }
5654 return ret;
5655 }
5656
5657 /**
5658 * Returns the default SMS app package name on a given user.
5659 *
5660 * Only the shell user (UID 2000 or 0) can call it.
5661 * Target user must be running.
5662 */
5663 @Override
5664 public String getDefaultSmsApp(int userId) {
5665 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5666 ensureUserRunning(userId);
5667
5668 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5669 /* updateIfNeeded= */ true, userId);
5670 return cn == null ? null : cn.getPackageName();
5671 }
5672
5673 /**
5674 * Set a package as the default SMS app on a given user.
5675 *
5676 * Only the shell user (UID 2000 or 0) can call it.
5677 * Target user must be running.
5678 */
5679 @Override
5680 public void setDefaultSmsApp(int userId, String packageName) {
5681 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5682 ensureUserRunning(userId);
5683
5684 boolean found = false;
5685 for (String pkg : getSmsApps(userId)) {
5686 if (TextUtils.equals(packageName, pkg)) {
5687 found = true;
5688 break;
5689 }
5690 }
5691 if (!found) {
5692 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5693 }
5694
5695 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5696 }
sqianc5eccab2018-10-19 18:46:41 -07005697
5698 @Override
5699 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5700 String callingPackage) {
5701 // TODO connect with internal content
5702 return null;
5703 }
5704
5705 @Override
5706 public boolean isCurrentEmergencyNumber(String number) {
5707 // TODO connect with internal content
5708 return false;
5709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005710}