blob: f896012b7c4de653e137b6be8860a04ae256b2fe [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070028import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080043import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070046import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070047import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070049import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070050import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080052import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070053import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080054import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080055import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070056import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070057import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070059import android.telephony.CellInfoGsm;
60import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070061import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070063import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080064import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070065import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080066import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070067import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070068import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070069import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080071import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070072import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080073import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070075import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070076import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000077import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070078import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070079import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070080import android.telephony.cdma.CdmaCellLocation;
81import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070082import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080083import android.telephony.ims.aidl.IImsConfig;
84import android.telephony.ims.aidl.IImsMmTelFeature;
85import android.telephony.ims.aidl.IImsRcsFeature;
86import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070087import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080088import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080092import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080093import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080094
Brad Ebinger4c460712018-10-01 10:40:55 -070095import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070096import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080097import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070098import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070099import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700100import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700101import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700102import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800105import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700106import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100107import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700108import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700109import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700111import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800112import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700113import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700114import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700115import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700116import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700117import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700118import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800119import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800120import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700121import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.uicc.IccIoResult;
123import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800124import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700125import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800126import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800128import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000129import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700130import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800131import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700132import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800133import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700134import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700135import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700137import java.io.FileDescriptor;
138import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800139import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800142import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100143import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800144import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145
146/**
147 * Implementation of the ITelephony interface.
148 */
Santos Cordon117fee72014-05-16 17:56:12 -0700149public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150 private static final String LOG_TAG = "PhoneInterfaceManager";
151 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
152 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800153 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154
155 // Message codes used with mMainThreadHandler
156 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700157 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
158 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159 private static final int CMD_OPEN_CHANNEL = 9;
160 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
161 private static final int CMD_CLOSE_CHANNEL = 11;
162 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800163 private static final int CMD_NV_READ_ITEM = 13;
164 private static final int EVENT_NV_READ_ITEM_DONE = 14;
165 private static final int CMD_NV_WRITE_ITEM = 15;
166 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
167 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
168 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700169 private static final int CMD_RESET_MODEM_CONFIG = 19;
170 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800171 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
172 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
173 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
174 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800175 private static final int CMD_SEND_ENVELOPE = 25;
176 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000177 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
178 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700179 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
180 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
181 private static final int CMD_EXCHANGE_SIM_IO = 31;
182 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800183 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
184 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700185 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
186 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700187 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
188 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700189 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
190 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
191 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
192 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700193 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
194 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
195 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
196 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700197 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
199 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000200 private static final int CMD_SWITCH_SLOTS = 50;
201 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700202 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
203 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
204 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
205 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
206 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
207 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
208 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
209 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700210 private static final int CMD_GET_ALL_CELL_INFO = 60;
211 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
212 private static final int CMD_GET_CELL_LOCATION = 62;
213 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700214 private static final int CMD_MODEM_REBOOT = 64;
215 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800217 // Parameters of select command.
218 private static final int SELECT_COMMAND = 0xA4;
219 private static final int SELECT_P1 = 0x04;
220 private static final int SELECT_P2 = 0;
221 private static final int SELECT_P3 = 0x10;
222
Pengquan Meng85728fb2018-03-12 16:31:21 -0700223 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
224 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
225 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
226
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227 /** The singleton instance. */
228 private static PhoneInterfaceManager sInstance;
229
Wink Saville3ab207e2014-11-20 13:07:20 -0800230 private PhoneGlobals mApp;
231 private Phone mPhone;
232 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700233 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800234 private AppOpsManager mAppOps;
235 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800236 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800237 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700238 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
Derek Tan97ebb422014-09-05 16:55:38 -0700240 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
241 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800242 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700243
Derek Tan740e1672017-06-27 14:56:27 -0700244 // The AID of ISD-R.
245 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
246
yinxub1bed742017-04-17 11:45:04 -0700247 private NetworkScanRequestTracker mNetworkScanRequestTracker;
248
David Kelly5e06a7f2018-03-12 14:10:59 +0000249 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
250 private static final int MANUFACTURER_CODE_LENGTH = 8;
251
Derek Tan89e89d42014-07-08 17:00:10 -0700252 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700253 * A request object to use for transmitting data to an ICC.
254 */
255 private static final class IccAPDUArgument {
256 public int channel, cla, command, p1, p2, p3;
257 public String data;
258
259 public IccAPDUArgument(int channel, int cla, int command,
260 int p1, int p2, int p3, String data) {
261 this.channel = channel;
262 this.cla = cla;
263 this.command = command;
264 this.p1 = p1;
265 this.p2 = p2;
266 this.p3 = p3;
267 this.data = data;
268 }
269 }
270
271 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700272 * A request object to use for transmitting data to an ICC.
273 */
274 private static final class ManualNetworkSelectionArgument {
275 public OperatorInfo operatorInfo;
276 public boolean persistSelection;
277
278 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
279 this.operatorInfo = operatorInfo;
280 this.persistSelection = persistSelection;
281 }
282 }
283
284 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
286 * request after sending. The main thread will notify the request when it is complete.
287 */
288 private static final class MainThreadRequest {
289 /** The argument to use for the request */
290 public Object argument;
291 /** The result of the request that is run on the main thread */
292 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800293 // The subscriber id that this request applies to. Defaults to
294 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
295 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296
Nathan Harold92bed182018-10-12 18:16:49 -0700297 // In cases where subId is unavailable, the caller needs to specify the phone.
298 public Phone phone;
299
vagdevie435a3e2018-08-15 16:01:53 -0700300 public WorkSource workSource;
301
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 public MainThreadRequest(Object argument) {
303 this.argument = argument;
304 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800305
Nathan Harold92bed182018-10-12 18:16:49 -0700306 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
307 this.argument = argument;
308 if (phone != null) {
309 this.phone = phone;
310 }
311 this.workSource = workSource;
312 }
313
vagdevie435a3e2018-08-15 16:01:53 -0700314 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800315 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800316 if (subId != null) {
317 this.subId = subId;
318 }
vagdevie435a3e2018-08-15 16:01:53 -0700319 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 }
322
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800323 private static final class IncomingThirdPartyCallArgs {
324 public final ComponentName component;
325 public final String callId;
326 public final String callerDisplayName;
327
328 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
329 String callerDisplayName) {
330 this.component = component;
331 this.callId = callId;
332 this.callerDisplayName = callerDisplayName;
333 }
334 }
335
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 /**
337 * A handler that processes messages on the main thread in the phone process. Since many
338 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
339 * inbound binder threads to the main thread in the phone process. The Binder thread
340 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
341 * on, which will be notified when the operation completes and will contain the result of the
342 * request.
343 *
344 * <p>If a MainThreadRequest object is provided in the msg.obj field,
345 * note that request.result must be set to something non-null for the calling thread to
346 * unblock.
347 */
348 private final class MainThreadHandler extends Handler {
349 @Override
350 public void handleMessage(Message msg) {
351 MainThreadRequest request;
352 Message onCompleted;
353 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800354 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700355 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
357 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700358 case CMD_HANDLE_USSD_REQUEST: {
359 request = (MainThreadRequest) msg.obj;
360 final Phone phone = getPhoneFromRequest(request);
361 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
362 String ussdRequest = ussdObject.first;
363 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700364
Pengquan Meng0c05b502018-09-06 09:59:22 -0700365 if (!isUssdApiAllowed(request.subId)) {
366 // Carrier does not support use of this API, return failure.
367 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
368 UssdResponse response = new UssdResponse(ussdRequest, null);
369 Bundle returnData = new Bundle();
370 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
371 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700372
Pengquan Meng0c05b502018-09-06 09:59:22 -0700373 request.result = true;
374 notifyRequester(request);
375 return;
376 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700377
Pengquan Meng0c05b502018-09-06 09:59:22 -0700378 try {
379 request.result = phone != null
380 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
381 } catch (CallStateException cse) {
382 request.result = false;
383 }
384 // Wake up the requesting thread
385 notifyRequester(request);
386 break;
pkanwar32d516d2016-10-14 19:37:38 -0700387 }
388
Yorke Lee716f67e2015-06-17 15:39:16 -0700389 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700391 final Phone phone = getPhoneFromRequest(request);
392 request.result = phone != null ?
393 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
394 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700396 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700401 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700402 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800403 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700404 if (uiccCard == null) {
405 loge("iccTransmitApduLogicalChannel: No UICC");
406 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700407 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700408 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700409 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
410 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700411 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 iccArgument.channel, iccArgument.cla, iccArgument.command,
413 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700415 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 break;
417
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 ar = (AsyncResult) msg.obj;
420 request = (MainThreadRequest) ar.userObj;
421 if (ar.exception == null && ar.result != null) {
422 request.result = ar.result;
423 } else {
424 request.result = new IccIoResult(0x6F, 0, (byte[])null);
425 if (ar.result == null) {
426 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800427 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800429 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 } else {
431 loge("iccTransmitApduLogicalChannel: Unknown exception");
432 }
433 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700434 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 break;
436
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
438 request = (MainThreadRequest) msg.obj;
439 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 if (uiccCard == null) {
442 loge("iccTransmitApduBasicChannel: No UICC");
443 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700444 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 } else {
446 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
447 request);
448 uiccCard.iccTransmitApduBasicChannel(
449 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
450 iccArgument.p3, iccArgument.data, onCompleted);
451 }
452 break;
453
454 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
455 ar = (AsyncResult) msg.obj;
456 request = (MainThreadRequest) ar.userObj;
457 if (ar.exception == null && ar.result != null) {
458 request.result = ar.result;
459 } else {
460 request.result = new IccIoResult(0x6F, 0, (byte[])null);
461 if (ar.result == null) {
462 loge("iccTransmitApduBasicChannel: Empty response");
463 } else if (ar.exception instanceof CommandException) {
464 loge("iccTransmitApduBasicChannel: CommandException: " +
465 ar.exception);
466 } else {
467 loge("iccTransmitApduBasicChannel: Unknown exception");
468 }
469 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700470 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 break;
472
473 case CMD_EXCHANGE_SIM_IO:
474 request = (MainThreadRequest) msg.obj;
475 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800476 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 if (uiccCard == null) {
478 loge("iccExchangeSimIO: No UICC");
479 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 } else {
482 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
483 request);
484 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
485 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
486 iccArgument.data, onCompleted);
487 }
488 break;
489
490 case EVENT_EXCHANGE_SIM_IO_DONE:
491 ar = (AsyncResult) msg.obj;
492 request = (MainThreadRequest) ar.userObj;
493 if (ar.exception == null && ar.result != null) {
494 request.result = ar.result;
495 } else {
496 request.result = new IccIoResult(0x6f, 0, (byte[])null);
497 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700498 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 break;
500
Derek Tan4d5e5c12014-02-04 11:54:58 -0800501 case CMD_SEND_ENVELOPE:
502 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800503 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 if (uiccCard == null) {
505 loge("sendEnvelopeWithStatus: No UICC");
506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700507 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700508 } else {
509 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
510 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
511 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800512 break;
513
514 case EVENT_SEND_ENVELOPE_DONE:
515 ar = (AsyncResult) msg.obj;
516 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700517 if (ar.exception == null && ar.result != null) {
518 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800519 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
521 if (ar.result == null) {
522 loge("sendEnvelopeWithStatus: Empty response");
523 } else if (ar.exception instanceof CommandException) {
524 loge("sendEnvelopeWithStatus: CommandException: " +
525 ar.exception);
526 } else {
527 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
528 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800529 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700530 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800531 break;
532
Shishir Agrawal566b7612013-10-28 14:41:00 -0700533 case CMD_OPEN_CHANNEL:
534 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800535 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800536 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 if (uiccCard == null) {
538 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800539 request.result = new IccOpenLogicalChannelResponse(-1,
540 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 } else {
543 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800544 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
545 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 break;
548
549 case EVENT_OPEN_CHANNEL_DONE:
550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 int[] result = (int[]) ar.result;
555 int channelId = result[0];
556 byte[] selectResponse = null;
557 if (result.length > 1) {
558 selectResponse = new byte[result.length - 1];
559 for (int i = 1; i < result.length; ++i) {
560 selectResponse[i - 1] = (byte) result[i];
561 }
562 }
563 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700564 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 if (ar.result == null) {
567 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 if (ar.exception != null) {
570 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
571 }
572
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700573 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700574 if (ar.exception instanceof CommandException) {
575 CommandException.Error error =
576 ((CommandException) (ar.exception)).getCommandError();
577 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700578 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700579 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700580 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 }
582 }
583 openChannelResp = new IccOpenLogicalChannelResponse(
584 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700586 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
590 case CMD_CLOSE_CHANNEL:
591 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800592 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 if (uiccCard == null) {
594 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900595 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 } else {
598 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
599 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
600 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 break;
602
603 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800604 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
605 break;
606
607 case CMD_NV_READ_ITEM:
608 request = (MainThreadRequest) msg.obj;
609 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700610 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800611 break;
612
613 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 ar = (AsyncResult) msg.obj;
615 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800616 if (ar.exception == null && ar.result != null) {
617 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800619 request.result = "";
620 if (ar.result == null) {
621 loge("nvReadItem: Empty response");
622 } else if (ar.exception instanceof CommandException) {
623 loge("nvReadItem: CommandException: " +
624 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800626 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
628 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 break;
631
Jake Hambye994d462014-02-03 13:10:13 -0800632 case CMD_NV_WRITE_ITEM:
633 request = (MainThreadRequest) msg.obj;
634 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
635 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700636 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
637 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800638 break;
639
640 case EVENT_NV_WRITE_ITEM_DONE:
641 handleNullReturnEvent(msg, "nvWriteItem");
642 break;
643
644 case CMD_NV_WRITE_CDMA_PRL:
645 request = (MainThreadRequest) msg.obj;
646 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
647 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
648 break;
649
650 case EVENT_NV_WRITE_CDMA_PRL_DONE:
651 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
652 break;
653
chen xu1cc0abe2018-10-26 17:39:23 -0700654 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800655 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700656 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
657 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800658 break;
659
chen xu1cc0abe2018-10-26 17:39:23 -0700660 case EVENT_RESET_MODEM_CONFIG_DONE:
661 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800662 break;
663
Jake Hamby7c27be32014-03-03 13:25:59 -0800664 case CMD_GET_PREFERRED_NETWORK_TYPE:
665 request = (MainThreadRequest) msg.obj;
666 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700667 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800668 break;
669
670 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
671 ar = (AsyncResult) msg.obj;
672 request = (MainThreadRequest) ar.userObj;
673 if (ar.exception == null && ar.result != null) {
674 request.result = ar.result; // Integer
675 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800676 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800677 if (ar.result == null) {
678 loge("getPreferredNetworkType: Empty response");
679 } else if (ar.exception instanceof CommandException) {
680 loge("getPreferredNetworkType: CommandException: " +
681 ar.exception);
682 } else {
683 loge("getPreferredNetworkType: Unknown exception");
684 }
685 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700686 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 break;
688
689 case CMD_SET_PREFERRED_NETWORK_TYPE:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
692 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700693 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800694 break;
695
696 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
697 handleNullReturnEvent(msg, "setPreferredNetworkType");
698 break;
699
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000700 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
701 request = (MainThreadRequest)msg.obj;
702 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700703 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000704 break;
705
706 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
707 ar = (AsyncResult)msg.obj;
708 request = (MainThreadRequest)ar.userObj;
709 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700710 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000711 break;
712
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800713 case CMD_SET_VOICEMAIL_NUMBER:
714 request = (MainThreadRequest) msg.obj;
715 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
716 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800717 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
718 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800719 break;
720
721 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
722 handleNullReturnEvent(msg, "setVoicemailNumber");
723 break;
724
Stuart Scott54788802015-03-30 13:18:01 -0700725 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
728 request);
729 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
730 break;
731
732 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
733 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
734 break;
735
Shishir Agrawal302c8692015-06-19 13:49:39 -0700736 case CMD_PERFORM_NETWORK_SCAN:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
739 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
740 break;
741
742 case EVENT_PERFORM_NETWORK_SCAN_DONE:
743 ar = (AsyncResult) msg.obj;
744 request = (MainThreadRequest) ar.userObj;
745 CellNetworkScanResult cellScanResult;
746 if (ar.exception == null && ar.result != null) {
747 cellScanResult = new CellNetworkScanResult(
748 CellNetworkScanResult.STATUS_SUCCESS,
749 (List<OperatorInfo>) ar.result);
750 } else {
751 if (ar.result == null) {
752 loge("getCellNetworkScanResults: Empty response");
753 }
754 if (ar.exception != null) {
755 loge("getCellNetworkScanResults: Exception: " + ar.exception);
756 }
757 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
758 if (ar.exception instanceof CommandException) {
759 CommandException.Error error =
760 ((CommandException) (ar.exception)).getCommandError();
761 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
762 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
763 } else if (error == CommandException.Error.GENERIC_FAILURE) {
764 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
765 }
766 }
767 cellScanResult = new CellNetworkScanResult(errorCode, null);
768 }
769 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700770 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700771 break;
772
773 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
774 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700775 ManualNetworkSelectionArgument selArg =
776 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700777 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
778 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700779 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
780 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700781 break;
782
783 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700784 ar = (AsyncResult) msg.obj;
785 request = (MainThreadRequest) ar.userObj;
786 if (ar.exception == null) {
787 request.result = true;
788 } else {
789 request.result = false;
790 loge("setNetworkSelectionModeManual " + ar.exception);
791 }
792 notifyRequester(request);
793 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 break;
795
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700796 case CMD_GET_MODEM_ACTIVITY_INFO:
797 request = (MainThreadRequest) msg.obj;
798 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700799 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700800 break;
801
802 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 if (ar.exception == null && ar.result != null) {
806 request.result = ar.result;
807 } else {
808 if (ar.result == null) {
809 loge("queryModemActivityInfo: Empty response");
810 } else if (ar.exception instanceof CommandException) {
811 loge("queryModemActivityInfo: CommandException: " +
812 ar.exception);
813 } else {
814 loge("queryModemActivityInfo: Unknown exception");
815 }
816 }
Amit Mahajand4766222016-01-28 15:28:28 -0800817 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
818 if (request.result == null) {
819 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
820 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700821 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700822 break;
823
Meng Wang1a7c35a2016-05-05 20:56:15 -0700824 case CMD_SET_ALLOWED_CARRIERS:
825 request = (MainThreadRequest) msg.obj;
826 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
827 mPhone.setAllowedCarriers(
828 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700829 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700830 break;
831
832 case EVENT_SET_ALLOWED_CARRIERS_DONE:
833 ar = (AsyncResult) msg.obj;
834 request = (MainThreadRequest) ar.userObj;
835 if (ar.exception == null && ar.result != null) {
836 request.result = ar.result;
837 } else {
838 if (ar.result == null) {
839 loge("setAllowedCarriers: Empty response");
840 } else if (ar.exception instanceof CommandException) {
841 loge("setAllowedCarriers: CommandException: " +
842 ar.exception);
843 } else {
844 loge("setAllowedCarriers: Unknown exception");
845 }
846 }
847 // Result cannot be null. Return -1 on error.
848 if (request.result == null) {
849 request.result = new int[]{-1};
850 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700851 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700852 break;
853
854 case CMD_GET_ALLOWED_CARRIERS:
855 request = (MainThreadRequest) msg.obj;
856 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700857 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700858 break;
859
860 case EVENT_GET_ALLOWED_CARRIERS_DONE:
861 ar = (AsyncResult) msg.obj;
862 request = (MainThreadRequest) ar.userObj;
863 if (ar.exception == null && ar.result != null) {
864 request.result = ar.result;
865 } else {
866 if (ar.result == null) {
867 loge("getAllowedCarriers: Empty response");
868 } else if (ar.exception instanceof CommandException) {
869 loge("getAllowedCarriers: CommandException: " +
870 ar.exception);
871 } else {
872 loge("getAllowedCarriers: Unknown exception");
873 }
874 }
875 // Result cannot be null. Return empty list of CarrierIdentifier.
876 if (request.result == null) {
877 request.result = new ArrayList<CarrierIdentifier>(0);
878 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700879 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 break;
881
Nathan Haroldb3014052017-01-25 15:57:32 -0800882 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result;
887 } else {
888 request.result = new IllegalArgumentException(
889 "Failed to retrieve Forbidden Plmns");
890 if (ar.result == null) {
891 loge("getForbiddenPlmns: Empty response");
892 } else {
893 loge("getForbiddenPlmns: Unknown exception");
894 }
895 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700896 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800897 break;
898
899 case CMD_GET_FORBIDDEN_PLMNS:
900 request = (MainThreadRequest) msg.obj;
901 uiccCard = getUiccCardFromRequest(request);
902 if (uiccCard == null) {
903 loge("getForbiddenPlmns() UiccCard is null");
904 request.result = new IllegalArgumentException(
905 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700906 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800907 break;
908 }
909 Integer appType = (Integer) request.argument;
910 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
911 if (uiccApp == null) {
912 loge("getForbiddenPlmns() no app with specified type -- "
913 + appType);
914 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700915 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800916 break;
917 } else {
918 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
919 + " specified type -- " + appType);
920 }
921 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
922 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
923 onCompleted);
924 break;
925
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000926 case CMD_SWITCH_SLOTS:
927 request = (MainThreadRequest) msg.obj;
928 int[] physicalSlots = (int[]) request.argument;
929 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
930 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
931 break;
932
933 case EVENT_SWITCH_SLOTS_DONE:
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700937 notifyRequester(request);
938 break;
939 case CMD_GET_NETWORK_SELECTION_MODE:
940 request = (MainThreadRequest) msg.obj;
941 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
942 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
943 break;
944
945 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
946 ar = (AsyncResult) msg.obj;
947 request = (MainThreadRequest) ar.userObj;
948 if (ar.exception != null) {
949 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
950 } else {
951 int mode = ((int[]) ar.result)[0];
952 if (mode == 0) {
953 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
954 } else {
955 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
956 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000957 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700958 notifyRequester(request);
959 break;
960 case CMD_GET_CDMA_ROAMING_MODE:
961 request = (MainThreadRequest) msg.obj;
962 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
963 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
964 break;
965 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
968 if (ar.exception != null) {
969 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
970 } else {
971 request.result = ((int[]) ar.result)[0];
972 }
973 notifyRequester(request);
974 break;
975 case CMD_SET_CDMA_ROAMING_MODE:
976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
978 int mode = (int) request.argument;
979 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
980 break;
981 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 request.result = ar.exception == null;
985 notifyRequester(request);
986 break;
987 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
990 int subscriptionMode = (int) request.argument;
991 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
992 break;
993 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 request.result = ar.exception == null;
997 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000998 break;
999
Nathan Harold3ff88932018-08-14 10:19:49 -07001000 case CMD_GET_ALL_CELL_INFO:
1001 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001002 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001003 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001004 break;
1005
1006 case EVENT_GET_ALL_CELL_INFO_DONE:
1007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001009 // If a timeout occurs, the response will be null
1010 request.result = (ar.exception == null && ar.result != null)
1011 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001012 synchronized (request) {
1013 request.notifyAll();
1014 }
1015 break;
1016
1017 case CMD_GET_CELL_LOCATION: {
1018 request = (MainThreadRequest) msg.obj;
1019 WorkSource ws = (WorkSource) request.argument;
1020 Phone phone = getPhoneFromRequest(request);
1021 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1022 break;
1023 }
1024
1025 case EVENT_GET_CELL_LOCATION_DONE: {
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception == null) {
1029 request.result = ar.result;
1030 } else {
1031 Phone phone = getPhoneFromRequest(request);
1032 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1033 ? new CdmaCellLocation() : new GsmCellLocation();
1034 }
1035
1036 synchronized (request) {
1037 request.notifyAll();
1038 }
1039 break;
1040 }
1041
chen xu1cc0abe2018-10-26 17:39:23 -07001042 case CMD_MODEM_REBOOT:
1043 request = (MainThreadRequest) msg.obj;
1044 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1045 mPhone.rebootModem(onCompleted);
1046 break;
1047
1048 case EVENT_CMD_MODEM_REBOOT_DONE:
1049 handleNullReturnEvent(msg, "rebootModem");
1050 break;
1051
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001052 default:
1053 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1054 break;
1055 }
1056 }
Jake Hambye994d462014-02-03 13:10:13 -08001057
Pengquan Meng0c05b502018-09-06 09:59:22 -07001058 private void notifyRequester(MainThreadRequest request) {
1059 synchronized (request) {
1060 request.notifyAll();
1061 }
1062 }
1063
Jake Hambye994d462014-02-03 13:10:13 -08001064 private void handleNullReturnEvent(Message msg, String command) {
1065 AsyncResult ar = (AsyncResult) msg.obj;
1066 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1067 if (ar.exception == null) {
1068 request.result = true;
1069 } else {
1070 request.result = false;
1071 if (ar.exception instanceof CommandException) {
1072 loge(command + ": CommandException: " + ar.exception);
1073 } else {
1074 loge(command + ": Unknown exception");
1075 }
1076 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001077 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001079 }
1080
1081 /**
1082 * Posts the specified command to be executed on the main thread,
1083 * waits for the request to complete, and returns the result.
1084 * @see #sendRequestAsync
1085 */
1086 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001087 return sendRequest(
1088 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001089 }
1090
1091 /**
1092 * Posts the specified command to be executed on the main thread,
1093 * waits for the request to complete, and returns the result.
1094 * @see #sendRequestAsync
1095 */
1096 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1097 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001098 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001099 }
1100
1101 /**
1102 * Posts the specified command to be executed on the main thread,
1103 * waits for the request to complete, and returns the result.
1104 * @see #sendRequestAsync
1105 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001106 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001107 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001108 }
1109
1110 /**
1111 * Posts the specified command to be executed on the main thread,
1112 * waits for the request to complete, and returns the result.
1113 * @see #sendRequestAsync
1114 */
Nathan Harold92bed182018-10-12 18:16:49 -07001115 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1116 return sendRequest(command, argument, subId, null, workSource);
1117 }
1118
1119 /**
1120 * Posts the specified command to be executed on the main thread,
1121 * waits for the request to complete, and returns the result.
1122 * @see #sendRequestAsync
1123 */
1124 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1125 return sendRequest(
1126 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1127 }
1128
1129 /**
1130 * Posts the specified command to be executed on the main thread,
1131 * waits for the request to complete, and returns the result.
1132 * @see #sendRequestAsync
1133 */
1134 private Object sendRequest(
1135 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1137 throw new RuntimeException("This method will deadlock if called from the main thread.");
1138 }
1139
Nathan Harold92bed182018-10-12 18:16:49 -07001140 MainThreadRequest request = null;
1141 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1142 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1143 } else if (phone != null) {
1144 request = new MainThreadRequest(argument, phone, workSource);
1145 } else {
1146 request = new MainThreadRequest(argument, subId, workSource);
1147 }
1148
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001149 Message msg = mMainThreadHandler.obtainMessage(command, request);
1150 msg.sendToTarget();
1151
1152 // Wait for the request to complete
1153 synchronized (request) {
1154 while (request.result == null) {
1155 try {
1156 request.wait();
1157 } catch (InterruptedException e) {
1158 // Do nothing, go back and wait until the request is complete
1159 }
1160 }
1161 }
1162 return request.result;
1163 }
1164
1165 /**
1166 * Asynchronous ("fire and forget") version of sendRequest():
1167 * Posts the specified command to be executed on the main thread, and
1168 * returns immediately.
1169 * @see #sendRequest
1170 */
1171 private void sendRequestAsync(int command) {
1172 mMainThreadHandler.sendEmptyMessage(command);
1173 }
1174
1175 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001176 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1177 * @see {@link #sendRequest(int,Object)}
1178 */
1179 private void sendRequestAsync(int command, Object argument) {
1180 MainThreadRequest request = new MainThreadRequest(argument);
1181 Message msg = mMainThreadHandler.obtainMessage(command, request);
1182 msg.sendToTarget();
1183 }
1184
1185 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001186 * Initialize the singleton PhoneInterfaceManager instance.
1187 * This is only done once, at startup, from PhoneApp.onCreate().
1188 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001189 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 synchronized (PhoneInterfaceManager.class) {
1191 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001192 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001193 } else {
1194 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1195 }
1196 return sInstance;
1197 }
1198 }
1199
1200 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001201 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 mApp = app;
1203 mPhone = phone;
1204 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001205 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1207 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001208 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001209 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001210 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001211 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001212 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 publish();
1215 }
1216
1217 private void publish() {
1218 if (DBG) log("publish: " + this);
1219
1220 ServiceManager.addService("phone", this);
1221 }
1222
Stuart Scott584921c2015-01-15 17:10:34 -08001223 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001224 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1225 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001226 }
1227
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001228 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1229 Phone phone = getPhoneFromRequest(request);
1230 return phone == null ? null :
1231 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1232 }
1233
Wink Saville36469e72014-06-11 15:17:00 -07001234 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001235 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001236 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001238
1239 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001240 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001241 }
1242
Wink Savilleb564aae2014-10-23 10:18:09 -07001243 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 if (DBG) log("dial: " + number);
1245 // No permission check needed here: This is just a wrapper around the
1246 // ACTION_DIAL intent, which is available to any app since it puts up
1247 // the UI before it does anything.
1248
Malcolm Chend965c8b2018-02-28 15:00:40 -08001249 final long identity = Binder.clearCallingIdentity();
1250 try {
1251 String url = createTelUrl(number);
1252 if (url == null) {
1253 return;
1254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255
Malcolm Chend965c8b2018-02-28 15:00:40 -08001256 // PENDING: should we just silently fail if phone is offhook or ringing?
1257 PhoneConstants.State state = mCM.getState(subId);
1258 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1259 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1260 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1261 mApp.startActivity(intent);
1262 }
1263 } finally {
1264 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 }
1266 }
1267
1268 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001269 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001270 }
1271
Wink Savilleb564aae2014-10-23 10:18:09 -07001272 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 if (DBG) log("call: " + number);
1274
1275 // This is just a wrapper around the ACTION_CALL intent, but we still
1276 // need to do a permission check since we're calling startActivity()
1277 // from the context of the phone app.
1278 enforceCallPermission();
1279
1280 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1281 != AppOpsManager.MODE_ALLOWED) {
1282 return;
1283 }
1284
Malcolm Chend965c8b2018-02-28 15:00:40 -08001285 final long identity = Binder.clearCallingIdentity();
1286 try {
1287 String url = createTelUrl(number);
1288 if (url == null) {
1289 return;
1290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001291
Malcolm Chend965c8b2018-02-28 15:00:40 -08001292 boolean isValid = false;
1293 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1294 if (slist != null) {
1295 for (SubscriptionInfo subInfoRecord : slist) {
1296 if (subInfoRecord.getSubscriptionId() == subId) {
1297 isValid = true;
1298 break;
1299 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001300 }
Wink Saville08874612014-08-31 19:19:58 -07001301 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001302 if (!isValid) {
1303 return;
1304 }
Wink Saville08874612014-08-31 19:19:58 -07001305
Malcolm Chend965c8b2018-02-28 15:00:40 -08001306 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1307 intent.putExtra(SUBSCRIPTION_KEY, subId);
1308 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1309 mApp.startActivity(intent);
1310 } finally {
1311 Binder.restoreCallingIdentity(identity);
1312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 }
1314
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001316 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001317 }
1318
Wink Savilleb564aae2014-10-23 10:18:09 -07001319 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001321 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1322 }
1323
1324 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001325 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
1327
Wink Savilleb564aae2014-10-23 10:18:09 -07001328 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001329 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001330 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1331 }
1332
1333 /** {@hide} */
1334 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001335 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001336 }
1337
Wink Savilleb564aae2014-10-23 10:18:09 -07001338 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001340
1341 final long identity = Binder.clearCallingIdentity();
1342 try {
1343 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1344 checkSimPin.start();
1345 return checkSimPin.unlockSim(null, pin);
1346 } finally {
1347 Binder.restoreCallingIdentity(identity);
1348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 }
1350
Wink Saville9de0f752013-10-22 19:04:03 -07001351 /** {@hide} */
1352 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001353 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001354 }
1355
Wink Savilleb564aae2014-10-23 10:18:09 -07001356 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001358
1359 final long identity = Binder.clearCallingIdentity();
1360 try {
1361 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1362 checkSimPuk.start();
1363 return checkSimPuk.unlockSim(puk, pin);
1364 } finally {
1365 Binder.restoreCallingIdentity(identity);
1366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367 }
1368
1369 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001370 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371 * a synchronous one.
1372 */
1373 private static class UnlockSim extends Thread {
1374
1375 private final IccCard mSimCard;
1376
1377 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001378 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1379 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380
1381 // For replies from SimCard interface
1382 private Handler mHandler;
1383
1384 // For async handler to identify request type
1385 private static final int SUPPLY_PIN_COMPLETE = 100;
1386
1387 public UnlockSim(IccCard simCard) {
1388 mSimCard = simCard;
1389 }
1390
1391 @Override
1392 public void run() {
1393 Looper.prepare();
1394 synchronized (UnlockSim.this) {
1395 mHandler = new Handler() {
1396 @Override
1397 public void handleMessage(Message msg) {
1398 AsyncResult ar = (AsyncResult) msg.obj;
1399 switch (msg.what) {
1400 case SUPPLY_PIN_COMPLETE:
1401 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1402 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001403 mRetryCount = msg.arg1;
1404 if (ar.exception != null) {
1405 if (ar.exception instanceof CommandException &&
1406 ((CommandException)(ar.exception)).getCommandError()
1407 == CommandException.Error.PASSWORD_INCORRECT) {
1408 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1409 } else {
1410 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1411 }
1412 } else {
1413 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 mDone = true;
1416 UnlockSim.this.notifyAll();
1417 }
1418 break;
1419 }
1420 }
1421 };
1422 UnlockSim.this.notifyAll();
1423 }
1424 Looper.loop();
1425 }
1426
1427 /*
1428 * Use PIN or PUK to unlock SIM card
1429 *
1430 * If PUK is null, unlock SIM card with PIN
1431 *
1432 * If PUK is not null, unlock SIM card with PUK and set PIN code
1433 */
Wink Saville9de0f752013-10-22 19:04:03 -07001434 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001435
1436 while (mHandler == null) {
1437 try {
1438 wait();
1439 } catch (InterruptedException e) {
1440 Thread.currentThread().interrupt();
1441 }
1442 }
1443 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1444
1445 if (puk == null) {
1446 mSimCard.supplyPin(pin, callback);
1447 } else {
1448 mSimCard.supplyPuk(puk, pin, callback);
1449 }
1450
1451 while (!mDone) {
1452 try {
1453 Log.d(LOG_TAG, "wait for done");
1454 wait();
1455 } catch (InterruptedException e) {
1456 // Restore the interrupted status
1457 Thread.currentThread().interrupt();
1458 }
1459 }
1460 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001461 int[] resultArray = new int[2];
1462 resultArray[0] = mResult;
1463 resultArray[1] = mRetryCount;
1464 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 }
1466 }
1467
1468 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001469 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001470
1471 }
1472
Wink Savilleb564aae2014-10-23 10:18:09 -07001473 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474 // No permission check needed here: this call is harmless, and it's
1475 // needed for the ServiceState.requestStateUpdate() call (which is
1476 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001477 final long identity = Binder.clearCallingIdentity();
1478 try {
1479 final Phone phone = getPhone(subId);
1480 if (phone != null) {
1481 phone.updateServiceLocation();
1482 }
1483 } finally {
1484 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 }
1487
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001488 @Override
1489 public boolean isRadioOn(String callingPackage) {
1490 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001491 }
1492
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001493 @Override
1494 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001496 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001497 return false;
1498 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001499
1500 final long identity = Binder.clearCallingIdentity();
1501 try {
1502 return isRadioOnForSubscriber(subId);
1503 } finally {
1504 Binder.restoreCallingIdentity(identity);
1505 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001506 }
1507
1508 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001509 final long identity = Binder.clearCallingIdentity();
1510 try {
1511 final Phone phone = getPhone(subId);
1512 if (phone != null) {
1513 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1514 } else {
1515 return false;
1516 }
1517 } finally {
1518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 }
1521
1522 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001523 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 }
Wink Saville36469e72014-06-11 15:17:00 -07001525
Wink Savilleb564aae2014-10-23 10:18:09 -07001526 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001528
1529 final long identity = Binder.clearCallingIdentity();
1530 try {
1531 final Phone phone = getPhone(subId);
1532 if (phone != null) {
1533 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1534 }
1535 } finally {
1536 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001537 }
Wink Saville36469e72014-06-11 15:17:00 -07001538 }
1539
1540 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001541 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001545 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001546
1547 final long identity = Binder.clearCallingIdentity();
1548 try {
1549 final Phone phone = getPhone(subId);
1550 if (phone == null) {
1551 return false;
1552 }
1553 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1554 toggleRadioOnOffForSubscriber(subId);
1555 }
1556 return true;
1557 } finally {
1558 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 }
Wink Saville36469e72014-06-11 15:17:00 -07001561
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001562 public boolean needMobileRadioShutdown() {
1563 /*
1564 * If any of the Radios are available, it will need to be
1565 * shutdown. So return true if any Radio is available.
1566 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001567 final long identity = Binder.clearCallingIdentity();
1568 try {
1569 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1570 Phone phone = PhoneFactory.getPhone(i);
1571 if (phone != null && phone.isRadioAvailable()) return true;
1572 }
1573 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1574 return false;
1575 } finally {
1576 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001577 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001578 }
1579
Malcolm Chend965c8b2018-02-28 15:00:40 -08001580 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001581 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001582 enforceModifyPermission();
1583
1584 final long identity = Binder.clearCallingIdentity();
1585 try {
1586 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1587 logv("Shutting down Phone " + i);
1588 shutdownRadioUsingPhoneId(i);
1589 }
1590 } finally {
1591 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001592 }
1593 }
1594
1595 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001596 Phone phone = PhoneFactory.getPhone(phoneId);
1597 if (phone != null && phone.isRadioAvailable()) {
1598 phone.shutdownRadio();
1599 }
1600 }
1601
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001603 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001604
1605 final long identity = Binder.clearCallingIdentity();
1606 try {
1607 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1608 if (defaultPhone != null) {
1609 defaultPhone.setRadioPower(turnOn);
1610 return true;
1611 } else {
1612 loge("There's no default phone.");
1613 return false;
1614 }
1615 } finally {
1616 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001617 }
Wink Saville36469e72014-06-11 15:17:00 -07001618 }
1619
Wink Savilleb564aae2014-10-23 10:18:09 -07001620 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001622
1623 final long identity = Binder.clearCallingIdentity();
1624 try {
1625 final Phone phone = getPhone(subId);
1626 if (phone != null) {
1627 phone.setRadioPower(turnOn);
1628 return true;
1629 } else {
1630 return false;
1631 }
1632 } finally {
1633 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 }
1636
Wink Saville36469e72014-06-11 15:17:00 -07001637 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 public boolean enableDataConnectivity() {
1640 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001641
1642 final long identity = Binder.clearCallingIdentity();
1643 try {
1644 int subId = mSubscriptionController.getDefaultDataSubId();
1645 final Phone phone = getPhone(subId);
1646 if (phone != null) {
1647 phone.setUserDataEnabled(true);
1648 return true;
1649 } else {
1650 return false;
1651 }
1652 } finally {
1653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 }
1656
Wink Saville36469e72014-06-11 15:17:00 -07001657 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001658 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 public boolean disableDataConnectivity() {
1660 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001661
1662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 int subId = mSubscriptionController.getDefaultDataSubId();
1665 final Phone phone = getPhone(subId);
1666 if (phone != null) {
1667 phone.setUserDataEnabled(false);
1668 return true;
1669 } else {
1670 return false;
1671 }
1672 } finally {
1673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 }
1676
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001678 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001679 final long identity = Binder.clearCallingIdentity();
1680 try {
1681 final Phone phone = getPhone(subId);
1682 if (phone != null) {
1683 return phone.isDataAllowed();
1684 } else {
1685 return false;
1686 }
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
1691
1692 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001693 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001694 }
1695
pkanwarae03a6b2016-11-06 20:37:09 -08001696 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001697 enforceCallPermission();
1698
1699 final long identity = Binder.clearCallingIdentity();
1700 try {
1701 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1702 return;
1703 }
1704 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1705 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
1708 }
pkanwar32d516d2016-10-14 19:37:38 -07001709 };
1710
Wink Savilleb564aae2014-10-23 10:18:09 -07001711 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1717 return false;
1718 }
1719 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 }
1724
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001726 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001727 }
1728
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001729 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001730 final long identity = Binder.clearCallingIdentity();
1731 try {
1732 Phone phone = PhoneFactory.getPhone(slotIndex);
1733 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1734 PhoneConstantConversions.convertCallState(phone.getState());
1735 } finally {
1736 Binder.restoreCallingIdentity(identity);
1737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
1739
Sanket Padawe356d7632015-06-22 14:03:32 -07001740 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001742 final long identity = Binder.clearCallingIdentity();
1743 try {
1744 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1745 if (phone != null) {
1746 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1747 } else {
1748 return PhoneConstantConversions.convertDataState(
1749 PhoneConstants.DataState.DISCONNECTED);
1750 }
1751 } finally {
1752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 }
1755
Sanket Padawe356d7632015-06-22 14:03:32 -07001756 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1761 if (phone != null) {
1762 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1763 } else {
1764 return TelephonyManager.DATA_ACTIVITY_NONE;
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
1771 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001772 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001773 mPhone.getContext().getSystemService(AppOpsManager.class)
1774 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001775 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001776 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001777 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001780 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001781 final long identity = Binder.clearCallingIdentity();
1782 try {
1783 if (DBG_LOC) log("getCellLocation: is active user");
1784 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001785 int subId = mSubscriptionController.getDefaultDataSubId();
1786 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1787 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001788 return data;
1789 } finally {
1790 Binder.restoreCallingIdentity(identity);
1791 }
Svetoslav64fad262015-04-14 14:35:21 -07001792 }
1793
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001795 public String getNetworkCountryIsoForPhone(int phoneId) {
1796 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1797 // registered cell info, so return a NULL country instead.
1798 final long identity = Binder.clearCallingIdentity();
1799 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001800 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1801 // Get default phone in this case.
1802 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1803 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001804 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001805 // Todo: fix this when we can get the actual cellular network info when the device
1806 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001807 if (TelephonyManager.NETWORK_TYPE_IWLAN
1808 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1809 return "";
1810 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001811 Phone phone = PhoneFactory.getPhone(phoneId);
1812 if (phone != null) {
1813 ServiceStateTracker sst = phone.getServiceStateTracker();
1814 if (sst != null) {
1815 LocaleTracker lt = sst.getLocaleTracker();
1816 if (lt != null) {
1817 return lt.getCurrentCountry();
1818 }
1819 }
1820 }
1821 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001822 } finally {
1823 Binder.restoreCallingIdentity(identity);
1824 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001825 }
1826
1827 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001829 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001830 }
1831
Sanket Padawe356d7632015-06-22 14:03:32 -07001832 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001833 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 mApp.enforceCallingOrSelfPermission(
1835 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001836
1837 final long identity = Binder.clearCallingIdentity();
1838 try {
1839 final Phone phone = getPhone(subId);
1840 if (phone != null) {
1841 phone.enableLocationUpdates();
1842 }
1843 } finally {
1844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 }
1847
1848 @Override
1849 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001850 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001851 }
1852
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001854 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855 mApp.enforceCallingOrSelfPermission(
1856 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001857
1858 final long identity = Binder.clearCallingIdentity();
1859 try {
1860 final Phone phone = getPhone(subId);
1861 if (phone != null) {
1862 phone.disableLocationUpdates();
1863 }
1864 } finally {
1865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 }
1868
Nathan Harold31d7ff32018-10-15 20:20:30 -07001869 /**
1870 * Returns the target SDK version number for a given package name.
1871 *
1872 * @return target SDK if the package is found or INT_MAX.
1873 */
1874 private int getTargetSdk(String packageName) {
1875 try {
1876 final ApplicationInfo ai =
1877 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1878 if (ai != null) return ai.targetSdkVersion;
1879 } catch (PackageManager.NameNotFoundException unexpected) {
1880 }
1881 return Integer.MAX_VALUE;
1882 }
1883
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 @Override
1885 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001886 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1887 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001888 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1889 throw new SecurityException(
1890 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1891 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001892
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1894 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1895 return null;
1896 }
Svetoslav64fad262015-04-14 14:35:21 -07001897
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001898 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899
Nathan Haroldf180aac2018-06-01 18:43:55 -07001900 List<CellInfo> info = getAllCellInfo(callingPackage);
1901 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902
Nathan Haroldf180aac2018-06-01 18:43:55 -07001903 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1904 for (CellInfo ci : info) {
1905 if (ci instanceof CellInfoGsm) {
1906 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1907 } else if (ci instanceof CellInfoWcdma) {
1908 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001911 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 }
1913
1914
1915 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001916 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001917 mPhone.getContext().getSystemService(AppOpsManager.class)
1918 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001919 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001920 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001921 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001924 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001926 final long identity = Binder.clearCallingIdentity();
1927 try {
1928 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1929 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001930 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001931 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001932 if (info != null) cellInfos.addAll(info);
1933 }
1934 return cellInfos;
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 }
1938 }
1939
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001940 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001942 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001943 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001944
1945 final long identity = Binder.clearCallingIdentity();
1946 try {
1947 mPhone.setCellInfoListRate(rateInMillis, workSource);
1948 } finally {
1949 Binder.restoreCallingIdentity(identity);
1950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 }
1952
Shishir Agrawala9f32182016-04-12 12:00:16 -07001953 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001954 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001955 Phone phone = PhoneFactory.getPhone(slotIndex);
1956 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001957 return null;
1958 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001959 int subId = phone.getSubId();
1960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1961 mApp, subId, callingPackage, "getImeiForSlot")) {
1962 return null;
1963 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001964
1965 final long identity = Binder.clearCallingIdentity();
1966 try {
1967 return phone.getImei();
1968 } finally {
1969 Binder.restoreCallingIdentity(identity);
1970 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001971 }
1972
1973 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001974 public String getTypeAllocationCodeForSlot(int slotIndex) {
1975 Phone phone = PhoneFactory.getPhone(slotIndex);
1976 String tac = null;
1977 if (phone != null) {
1978 String imei = phone.getImei();
1979 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1980 }
1981 return tac;
1982 }
1983
1984 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001985 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001986 Phone phone = PhoneFactory.getPhone(slotIndex);
1987 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001988 return null;
1989 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001990 int subId = phone.getSubId();
1991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1992 mApp, subId, callingPackage, "getMeidForSlot")) {
1993 return null;
1994 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001995
1996 final long identity = Binder.clearCallingIdentity();
1997 try {
1998 return phone.getMeid();
1999 } finally {
2000 Binder.restoreCallingIdentity(identity);
2001 }
Jack Yu2af8d712017-03-15 17:14:14 -07002002 }
2003
2004 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002005 public String getManufacturerCodeForSlot(int slotIndex) {
2006 Phone phone = PhoneFactory.getPhone(slotIndex);
2007 String manufacturerCode = null;
2008 if (phone != null) {
2009 String meid = phone.getMeid();
2010 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2011 }
2012 return manufacturerCode;
2013 }
2014
2015 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002016 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002017 Phone phone = PhoneFactory.getPhone(slotIndex);
2018 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002019 return null;
2020 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002021 int subId = phone.getSubId();
2022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2023 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2024 return null;
2025 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002026
2027 final long identity = Binder.clearCallingIdentity();
2028 try {
2029 return phone.getDeviceSvn();
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
2032 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002033 }
2034
fionaxu43304da2017-11-27 22:51:16 -08002035 @Override
2036 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 final Phone phone = getPhone(subId);
2040 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2041 } finally {
2042 Binder.restoreCallingIdentity(identity);
2043 }
fionaxu43304da2017-11-27 22:51:16 -08002044 }
2045
2046 @Override
2047 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002048 final long identity = Binder.clearCallingIdentity();
2049 try {
2050 final Phone phone = getPhone(subId);
2051 return phone == null ? null : phone.getCarrierName();
2052 } finally {
2053 Binder.restoreCallingIdentity(identity);
2054 }
fionaxu43304da2017-11-27 22:51:16 -08002055 }
2056
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 //
2058 // Internal helper methods.
2059 //
2060
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002061 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2063 *
2064 * @throws SecurityException if the caller does not have the required permission
2065 */
2066 private void enforceModifyPermission() {
2067 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2068 }
2069
2070 /**
2071 * Make sure the caller has the CALL_PHONE permission.
2072 *
2073 * @throws SecurityException if the caller does not have the required permission
2074 */
2075 private void enforceCallPermission() {
2076 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2077 }
2078
Stuart Scott8eef64f2015-04-08 15:13:54 -07002079 private void enforceConnectivityInternalPermission() {
2080 mApp.enforceCallingOrSelfPermission(
2081 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2082 "ConnectivityService");
2083 }
2084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 private String createTelUrl(String number) {
2086 if (TextUtils.isEmpty(number)) {
2087 return null;
2088 }
2089
Jake Hambye994d462014-02-03 13:10:13 -08002090 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 }
2092
Ihab Awadf9e92732013-12-05 18:02:52 -08002093 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2095 }
2096
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002097 private static void logv(String msg) {
2098 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2099 }
2100
Ihab Awadf9e92732013-12-05 18:02:52 -08002101 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2103 }
2104
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002105 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002107 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002108 }
2109
Sanket Padawe356d7632015-06-22 14:03:32 -07002110 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002111 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 final Phone phone = PhoneFactory.getPhone(slotIndex);
2115 if (phone == null) {
2116 return PhoneConstants.PHONE_TYPE_NONE;
2117 } else {
2118 return phone.getPhoneType();
2119 }
2120 } finally {
2121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 }
2124
2125 /**
2126 * Returns the CDMA ERI icon index to display
2127 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002128 @Override
2129 public int getCdmaEriIconIndex(String callingPackage) {
2130 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002131 }
2132
Sanket Padawe356d7632015-06-22 14:03:32 -07002133 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002134 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002136 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002137 return -1;
2138 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002139
2140 final long identity = Binder.clearCallingIdentity();
2141 try {
2142 final Phone phone = getPhone(subId);
2143 if (phone != null) {
2144 return phone.getCdmaEriIconIndex();
2145 } else {
2146 return -1;
2147 }
2148 } finally {
2149 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 }
2152
2153 /**
2154 * Returns the CDMA ERI icon mode,
2155 * 0 - ON
2156 * 1 - FLASHING
2157 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002158 @Override
2159 public int getCdmaEriIconMode(String callingPackage) {
2160 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002161 }
2162
Sanket Padawe356d7632015-06-22 14:03:32 -07002163 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002164 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002166 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002167 return -1;
2168 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002169
2170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 final Phone phone = getPhone(subId);
2173 if (phone != null) {
2174 return phone.getCdmaEriIconMode();
2175 } else {
2176 return -1;
2177 }
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182
2183 /**
2184 * Returns the CDMA ERI text,
2185 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002186 @Override
2187 public String getCdmaEriText(String callingPackage) {
2188 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002189 }
2190
Sanket Padawe356d7632015-06-22 14:03:32 -07002191 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002192 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002193 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002194 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002195 return null;
2196 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002197
2198 final long identity = Binder.clearCallingIdentity();
2199 try {
2200 final Phone phone = getPhone(subId);
2201 if (phone != null) {
2202 return phone.getCdmaEriText();
2203 } else {
2204 return null;
2205 }
2206 } finally {
2207 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 }
2210
2211 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002212 * Returns the CDMA MDN.
2213 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002215 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2217 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002218
2219 final long identity = Binder.clearCallingIdentity();
2220 try {
2221 final Phone phone = getPhone(subId);
2222 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2223 return phone.getLine1Number();
2224 } else {
2225 return null;
2226 }
2227 } finally {
2228 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002229 }
2230 }
2231
2232 /**
2233 * Returns the CDMA MIN.
2234 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002235 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002236 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2238 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002239
2240 final long identity = Binder.clearCallingIdentity();
2241 try {
2242 final Phone phone = getPhone(subId);
2243 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2244 return phone.getCdmaMin();
2245 } else {
2246 return null;
2247 }
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002250 }
2251 }
2252
2253 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 * Returns true if CDMA provisioning needs to run.
2255 */
2256 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 return mPhone.needsOtaServiceProvisioning();
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
2262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 }
2264
2265 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002266 * Sets the voice mail number of a given subId.
2267 */
2268 @Override
2269 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002270 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002271
2272 final long identity = Binder.clearCallingIdentity();
2273 try {
2274 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2275 new Pair<String, String>(alphaTag, number), new Integer(subId));
2276 return success;
2277 } finally {
2278 Binder.restoreCallingIdentity(identity);
2279 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002280 }
2281
Ta-wei Yen87c49842016-05-13 21:19:52 -07002282 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002283 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2284 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2285 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2286 if (!TextUtils.equals(callingPackage, systemDialer)) {
2287 throw new SecurityException("caller must be system dialer");
2288 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002289
2290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2293 if (phoneAccountHandle == null) {
2294 return null;
2295 }
2296 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2297 } finally {
2298 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002299 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002300 }
2301
2302 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002303 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002304 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002306 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002307 return null;
2308 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002309
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 return RemoteVvmTaskManager
2313 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2314 } finally {
2315 Binder.restoreCallingIdentity(identity);
2316 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002317 }
2318
2319 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002320 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2321 VisualVoicemailSmsFilterSettings settings) {
2322 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002323
2324 final long identity = Binder.clearCallingIdentity();
2325 try {
2326 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2327 mPhone.getContext(), callingPackage, subId, settings);
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
2330 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002331 }
2332
2333 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002334 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2335 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002336
2337 final long identity = Binder.clearCallingIdentity();
2338 try {
2339 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2340 mPhone.getContext(), callingPackage, subId);
2341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002344 }
2345
2346 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002347 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2348 String callingPackage, int subId) {
2349 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002350
2351 final long identity = Binder.clearCallingIdentity();
2352 try {
2353 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2354 mPhone.getContext(), callingPackage, subId);
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
2357 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002358 }
2359
2360 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002361 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002362 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002363
2364 final long identity = Binder.clearCallingIdentity();
2365 try {
2366 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2367 mPhone.getContext(), subId);
2368 } finally {
2369 Binder.restoreCallingIdentity(identity);
2370 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002371 }
2372
2373 @Override
2374 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2375 String number, int port, String text, PendingIntent sentIntent) {
2376 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002377 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002378 enforceSendSmsPermission();
2379 // Make the calls as the phone process.
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2383 if (port == 0) {
2384 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2385 sentIntent, null, false);
2386 } else {
2387 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2388 smsManager.sendDataMessageWithSelfPermissions(number, null,
2389 (short) port, data, sentIntent, null);
2390 }
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002394 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002395 /**
fionaxu0152e512016-11-14 13:36:14 -08002396 * Sets the voice activation state of a given subId.
2397 */
2398 @Override
2399 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2401 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002402
2403 final long identity = Binder.clearCallingIdentity();
2404 try {
2405 final Phone phone = getPhone(subId);
2406 if (phone != null) {
2407 phone.setVoiceActivationState(activationState);
2408 } else {
2409 loge("setVoiceActivationState fails with invalid subId: " + subId);
2410 }
2411 } finally {
2412 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002413 }
2414 }
2415
2416 /**
2417 * Sets the data activation state of a given subId.
2418 */
2419 @Override
2420 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2422 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002423
2424 final long identity = Binder.clearCallingIdentity();
2425 try {
2426 final Phone phone = getPhone(subId);
2427 if (phone != null) {
2428 phone.setDataActivationState(activationState);
2429 } else {
2430 loge("setVoiceActivationState fails with invalid subId: " + subId);
2431 }
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002434 }
2435 }
2436
2437 /**
2438 * Returns the voice activation state of a given subId.
2439 */
2440 @Override
2441 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002442 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002443
fionaxu0152e512016-11-14 13:36:14 -08002444 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002445 final long identity = Binder.clearCallingIdentity();
2446 try {
2447 if (phone != null) {
2448 return phone.getVoiceActivationState();
2449 } else {
2450 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2451 }
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002454 }
2455 }
2456
2457 /**
2458 * Returns the data activation state of a given subId.
2459 */
2460 @Override
2461 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002462 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002463
fionaxu0152e512016-11-14 13:36:14 -08002464 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 if (phone != null) {
2468 return phone.getDataActivationState();
2469 } else {
2470 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2471 }
2472 } finally {
2473 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002474 }
2475 }
2476
2477 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 * Returns the unread count of voicemails
2479 */
2480 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002481 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002482 }
2483
2484 /**
2485 * Returns the unread count of voicemails for a subId
2486 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002488 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = getPhone(subId);
2492 if (phone != null) {
2493 return phone.getVoiceMessageCount();
2494 } else {
2495 return 0;
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
2502 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002503 * returns true, if the device is in a state where both voice and data
2504 * are supported simultaneously. This can change based on location or network condition.
2505 */
2506 @Override
2507 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002508 final long identity = Binder.clearCallingIdentity();
2509 try {
2510 final Phone phone = getPhone(subId);
2511 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002515 }
2516
2517 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002518 * Send the dialer code if called from the current default dialer or the caller has
2519 * carrier privilege.
2520 * @param inputCode The dialer code to send
2521 */
2522 @Override
2523 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2524 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2525 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2526 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002527 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2528 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002529 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 mPhone.sendDialerSpecialCode(inputCode);
2534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
fionaxu235cc5e2017-03-06 22:25:57 -08002537 }
2538
2539 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002540 * Returns the data network type.
2541 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 *
2543 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2544 */
2545 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002546 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002547 final long identity = Binder.clearCallingIdentity();
2548 try {
2549 final Phone phone = getPhone(getDefaultSubscription());
2550 if (phone != null) {
2551 return phone.getServiceState().getDataNetworkType();
2552 } else {
2553 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2554 }
2555 } finally {
2556 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002557 }
Wink Saville36469e72014-06-11 15:17:00 -07002558 }
2559
Pengquan Meng0c05b502018-09-06 09:59:22 -07002560 @Override
2561 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002562 if (!isActiveSubscription(subId)) {
2563 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2564 }
2565
Pengquan Meng0c05b502018-09-06 09:59:22 -07002566 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2567 }
2568
Brad Ebinger4c460712018-10-01 10:40:55 -07002569 @Override
2570 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2571 String callingPackage) throws RemoteException {
2572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2573 "addImsRegistrationCallback")) {
2574 return;
2575 }
2576 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2577 final long token = Binder.clearCallingIdentity();
2578 try {
2579 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2580 .addRegistrationCallbackForSubscription(c, subId);
2581 } finally {
2582 Binder.restoreCallingIdentity(token);
2583 }
2584 }
2585
2586 @Override
2587 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2588 String callingPackage) {
2589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2590 "removeImsRegistrationCallback")) {
2591 return;
2592 }
2593 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2594 Binder.withCleanCallingIdentity(() ->
2595 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2596 .removeRegistrationCallbackForSubscription(c, subId));
2597 }
2598
2599 @Override
2600 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2601 String callingPackage) throws RemoteException {
2602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2603 "addMmTelCapabilityCallback")) {
2604 return;
2605 }
2606 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2607 final long token = Binder.clearCallingIdentity();
2608 try {
2609 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2610 .addCapabilitiesCallbackForSubscription(c, subId);
2611 } finally {
2612 Binder.restoreCallingIdentity(token);
2613 }
2614 }
2615
2616 @Override
2617 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2618 String callingPackage) {
2619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2620 "removeMmTelCapabilityCallback")) {
2621 return;
2622 }
2623 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2624 Binder.withCleanCallingIdentity(() ->
2625 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2626 .removeCapabilitiesCallbackForSubscription(c, subId));
2627 }
2628
2629 @Override
2630 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2632 "isCapable")) {
2633 return false;
2634 }
2635 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2636 final long token = Binder.clearCallingIdentity();
2637 try {
2638 return ImsManager.getInstance(mPhone.getContext(),
2639 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2640 } catch (ImsException e) {
2641 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2642 return false;
2643 } finally {
2644 Binder.restoreCallingIdentity(token);
2645 }
2646 }
2647
2648 @Override
2649 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2651 "isAvailable")) {
2652 return false;
2653 }
2654 final long token = Binder.clearCallingIdentity();
2655 try {
2656 Phone phone = getPhone(subId);
2657 if (phone == null) return false;
2658 return phone.isImsCapabilityAvailable(capability, regTech);
2659 } finally {
2660 Binder.restoreCallingIdentity(token);
2661 }
2662 }
2663
2664 @Override
2665 public boolean isAdvancedCallingSettingEnabled(int subId) {
2666 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2667 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2668 final long token = Binder.clearCallingIdentity();
2669 try {
2670 return ImsManager.getInstance(mPhone.getContext(),
2671 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2672 } finally {
2673 Binder.restoreCallingIdentity(token);
2674 }
2675 }
2676
2677 @Override
2678 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2680 "setAdvancedCallingSetting");
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2684 ImsManager.getInstance(mPhone.getContext(),
2685 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
2688 }
2689 }
2690
2691 @Override
2692 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2694 "isVtSettingEnabled")) {
2695 return false;
2696 }
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2700 return ImsManager.getInstance(mPhone.getContext(),
2701 getSlotIndexOrException(subId)).isVtEnabledByUser();
2702 } finally {
2703 Binder.restoreCallingIdentity(identity);
2704 }
2705 }
2706
2707 @Override
2708 public void setVtSetting(int subId, boolean isEnabled) {
2709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2710 "setVtSetting");
2711 final long identity = Binder.clearCallingIdentity();
2712 try {
2713 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2714 ImsManager.getInstance(mPhone.getContext(),
2715 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2716 } finally {
2717 Binder.restoreCallingIdentity(identity);
2718 }
2719 }
2720
2721 @Override
2722 public boolean isVoWiFiSettingEnabled(int subId) {
2723 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2727 return ImsManager.getInstance(mPhone.getContext(),
2728 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2729 } finally {
2730 Binder.restoreCallingIdentity(identity);
2731 }
2732 }
2733
2734 @Override
2735 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2737 "setVoWiFiSetting");
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2741 ImsManager.getInstance(mPhone.getContext(),
2742 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
2745 }
2746 }
2747
2748 @Override
2749 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2750 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2754 return ImsManager.getInstance(mPhone.getContext(),
2755 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
2758 }
2759 }
2760
2761 @Override
2762 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2764 "setVoWiFiRoamingSetting");
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2768 ImsManager.getInstance(mPhone.getContext(),
2769 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
2772 }
2773 }
2774
2775 @Override
2776 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2778 "setVoWiFiNonPersistent");
2779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2782 ImsManager.getInstance(mPhone.getContext(),
2783 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2784 } finally {
2785 Binder.restoreCallingIdentity(identity);
2786 }
2787 }
2788
2789 @Override
2790 public int getVoWiFiModeSetting(int subId) {
2791 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2795 return ImsManager.getInstance(mPhone.getContext(),
2796 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
2799 }
2800 }
2801
2802 @Override
2803 public void setVoWiFiModeSetting(int subId, int mode) {
2804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2805 "setVoWiFiModeSetting");
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2809 ImsManager.getInstance(mPhone.getContext(),
2810 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
2813 }
2814 }
2815
2816 @Override
2817 public int getVoWiFiRoamingModeSetting(int subId) {
2818 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2822 return ImsManager.getInstance(mPhone.getContext(),
2823 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2824 } finally {
2825 Binder.restoreCallingIdentity(identity);
2826 }
2827 }
2828
2829 @Override
2830 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2832 "setVoWiFiRoamingModeSetting");
2833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2836 ImsManager.getInstance(mPhone.getContext(),
2837 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
2840 }
2841 }
2842
2843 @Override
2844 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2846 "setRttCapabilityEnabled");
2847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2850 ImsManager.getInstance(mPhone.getContext(),
2851 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
2854 }
2855 }
2856
2857 @Override
2858 public boolean isTtyOverVolteEnabled(int subId) {
2859 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2863 return ImsManager.getInstance(mPhone.getContext(),
2864 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
2868 }
2869
2870 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2871 int slotId = SubscriptionManager.getSlotIndex(subId);
2872 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2873 throw new IllegalArgumentException("Invalid Subscription Id.");
2874 }
2875 return slotId;
2876 }
2877
Wink Saville36469e72014-06-11 15:17:00 -07002878 /**
2879 * Returns the network type for a subId
2880 */
2881 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002882 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002884 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002885 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2886 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002887
Malcolm Chend965c8b2018-02-28 15:00:40 -08002888 final long identity = Binder.clearCallingIdentity();
2889 try {
2890 final Phone phone = getPhone(subId);
2891 if (phone != null) {
2892 return phone.getServiceState().getDataNetworkType();
2893 } else {
2894 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2895 }
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002898 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002899 }
2900
2901 /**
2902 * Returns the data network type
2903 */
2904 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002905 public int getDataNetworkType(String callingPackage) {
2906 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002907 }
2908
2909 /**
2910 * Returns the data network type for a subId
2911 */
2912 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002913 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002915 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002916 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2917 }
2918
Malcolm Chend965c8b2018-02-28 15:00:40 -08002919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 final Phone phone = getPhone(subId);
2922 if (phone != null) {
2923 return phone.getServiceState().getDataNetworkType();
2924 } else {
2925 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2926 }
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931
2932 /**
Wink Saville36469e72014-06-11 15:17:00 -07002933 * Returns the Voice network type for a subId
2934 */
2935 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002936 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002938 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002939 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2940 }
2941
Malcolm Chend965c8b2018-02-28 15:00:40 -08002942 final long identity = Binder.clearCallingIdentity();
2943 try {
2944 final Phone phone = getPhone(subId);
2945 if (phone != null) {
2946 return phone.getServiceState().getVoiceNetworkType();
2947 } else {
2948 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2949 }
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
2955 /**
2956 * @return true if a ICC card is present
2957 */
2958 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002959 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002960 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2961 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002962 }
2963
2964 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002965 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002966 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002968 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 final Phone phone = PhoneFactory.getPhone(slotIndex);
2972 if (phone != null) {
2973 return phone.getIccCard().hasIccCard();
2974 } else {
2975 return false;
2976 }
2977 } finally {
2978 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002979 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002980 }
2981
2982 /**
2983 * Return if the current radio is LTE on CDMA. This
2984 * is a tri-state return value as for a period of time
2985 * the mode may be unknown.
2986 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002987 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002988 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002989 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002991 @Override
2992 public int getLteOnCdmaMode(String callingPackage) {
2993 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002994 }
2995
Sanket Padawe356d7632015-06-22 14:03:32 -07002996 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002997 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002999 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003000 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3001 }
3002
Malcolm Chend965c8b2018-02-28 15:00:40 -08003003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 final Phone phone = getPhone(subId);
3006 if (phone == null) {
3007 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3008 } else {
3009 return phone.getLteOnCdmaMode();
3010 }
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003013 }
Wink Saville36469e72014-06-11 15:17:00 -07003014 }
3015
3016 public void setPhone(Phone phone) {
3017 mPhone = phone;
3018 }
3019
3020 /**
3021 * {@hide}
3022 * Returns Default subId, 0 in the case of single standby.
3023 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003024 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003025 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003026 }
3027
Shishir Agrawala9f32182016-04-12 12:00:16 -07003028 private int getSlotForDefaultSubscription() {
3029 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3030 }
3031
Wink Savilleb564aae2014-10-23 10:18:09 -07003032 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003033 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003034 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003035
Pengquan Meng466e2482018-09-21 15:54:48 -07003036 private boolean isActiveSubscription(int subId) {
3037 return mSubscriptionController.isActiveSubId(subId);
3038 }
3039
Ihab Awadf2177b72013-11-25 13:33:23 -08003040 /**
3041 * @see android.telephony.TelephonyManager.WifiCallingChoices
3042 */
3043 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3047 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3048 getWhenToMakeWifiCallsDefaultPreference());
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003052 }
3053
3054 /**
3055 * @see android.telephony.TelephonyManager.WifiCallingChoices
3056 */
3057 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3061 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3062 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3063 } finally {
3064 Binder.restoreCallingIdentity(identity);
3065 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003066 }
3067
Sailesh Nepald1e68152013-12-12 19:08:02 -08003068 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003069 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003070 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003071 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003072
Shishir Agrawal566b7612013-10-28 14:41:00 -07003073 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003074 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3075 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3077 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003079
Malcolm Chend965c8b2018-02-28 15:00:40 -08003080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 if (TextUtils.equals(ISDR_AID, aid)) {
3083 // Only allows LPA to open logical channel to ISD-R.
3084 ComponentInfo bestComponent =
3085 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3086 if (bestComponent == null
3087 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3088 loge("The calling package is not allowed to access ISD-R.");
3089 throw new SecurityException(
3090 "The calling package is not allowed to access ISD-R.");
3091 }
Derek Tan740e1672017-06-27 14:56:27 -07003092 }
Derek Tan740e1672017-06-27 14:56:27 -07003093
Malcolm Chend965c8b2018-02-28 15:00:40 -08003094 if (DBG) {
3095 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3096 }
3097 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3098 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3099 if (DBG) log("iccOpenLogicalChannel: " + response);
3100 return response;
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003104 }
3105
3106 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003107 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3109 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003110
Malcolm Chend965c8b2018-02-28 15:00:40 -08003111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3114 if (channel < 0) {
3115 return false;
3116 }
3117 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3118 if (DBG) log("iccCloseLogicalChannel: " + success);
3119 return success;
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003122 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003123 }
3124
3125 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003126 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003127 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3129 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003130
Malcolm Chend965c8b2018-02-28 15:00:40 -08003131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 if (DBG) {
3134 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3135 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3136 + p3 + " data=" + data);
3137 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003138
Malcolm Chend965c8b2018-02-28 15:00:40 -08003139 if (channel < 0) {
3140 return "";
3141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003142
Malcolm Chend965c8b2018-02-28 15:00:40 -08003143 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3144 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3145 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003146
Malcolm Chend965c8b2018-02-28 15:00:40 -08003147 // Append the returned status code to the end of the response payload.
3148 String s = Integer.toHexString(
3149 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3150 if (response.payload != null) {
3151 s = IccUtils.bytesToHexString(response.payload) + s;
3152 }
3153 return s;
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003156 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003157 }
Jake Hambye994d462014-02-03 13:10:13 -08003158
Evan Charltonc66da362014-05-16 14:06:40 -07003159 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003160 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3161 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3163 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003164 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003165
Malcolm Chend965c8b2018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3169 && TextUtils.equals(ISDR_AID, data)) {
3170 // Only allows LPA to select ISD-R.
3171 ComponentInfo bestComponent =
3172 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3173 if (bestComponent == null
3174 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3175 loge("The calling package is not allowed to select ISD-R.");
3176 throw new SecurityException(
3177 "The calling package is not allowed to select ISD-R.");
3178 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003179 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003180
Malcolm Chend965c8b2018-02-28 15:00:40 -08003181 if (DBG) {
3182 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3183 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3184 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003185
Malcolm Chend965c8b2018-02-28 15:00:40 -08003186 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3187 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3188 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003189
Malcolm Chend965c8b2018-02-28 15:00:40 -08003190 // Append the returned status code to the end of the response payload.
3191 String s = Integer.toHexString(
3192 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3193 if (response.payload != null) {
3194 s = IccUtils.bytesToHexString(response.payload) + s;
3195 }
3196 return s;
3197 } finally {
3198 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003199 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003200 }
3201
3202 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003203 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003204 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3206 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003207
Malcolm Chend965c8b2018-02-28 15:00:40 -08003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 if (DBG) {
3211 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3212 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3213 }
3214
3215 IccIoResult response =
3216 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3217 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3218 subId);
3219
3220 if (DBG) {
3221 log("Exchange SIM_IO [R]" + response);
3222 }
3223
3224 byte[] result = null;
3225 int length = 2;
3226 if (response.payload != null) {
3227 length = 2 + response.payload.length;
3228 result = new byte[length];
3229 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3230 } else {
3231 result = new byte[length];
3232 }
3233
3234 result[length - 1] = (byte) response.sw2;
3235 result[length - 2] = (byte) response.sw1;
3236 return result;
3237 } finally {
3238 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003239 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003240 }
3241
Nathan Haroldb3014052017-01-25 15:57:32 -08003242 /**
3243 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3244 * on a particular subscription
3245 */
sqianb6e41952018-03-12 14:54:01 -07003246 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3248 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3249 return null;
3250 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003251
3252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 if (appType != TelephonyManager.APPTYPE_USIM
3255 && appType != TelephonyManager.APPTYPE_SIM) {
3256 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3257 return null;
3258 }
3259 Object response = sendRequest(
3260 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3261 if (response instanceof String[]) {
3262 return (String[]) response;
3263 }
3264 // Response is an Exception of some kind,
3265 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003266 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003267 } finally {
3268 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003269 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003270 }
3271
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003272 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003273 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3275 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003276
Malcolm Chend965c8b2018-02-28 15:00:40 -08003277 final long identity = Binder.clearCallingIdentity();
3278 try {
3279 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3280 if (response.payload == null) {
3281 return "";
3282 }
Evan Charltonc66da362014-05-16 14:06:40 -07003283
Malcolm Chend965c8b2018-02-28 15:00:40 -08003284 // Append the returned status code to the end of the response payload.
3285 String s = Integer.toHexString(
3286 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3287 s = IccUtils.bytesToHexString(response.payload) + s;
3288 return s;
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
3291 }
Evan Charltonc66da362014-05-16 14:06:40 -07003292 }
3293
Jake Hambye994d462014-02-03 13:10:13 -08003294 /**
3295 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3296 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3297 *
3298 * @param itemID the ID of the item to read
3299 * @return the NV item as a String, or null on error.
3300 */
3301 @Override
3302 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003303 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3305 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003306
3307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003310 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003311 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3312 return value;
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
Jake Hambye994d462014-02-03 13:10:13 -08003316 }
3317
3318 /**
3319 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3320 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3321 *
3322 * @param itemID the ID of the item to read
3323 * @param itemValue the value to write, as a String
3324 * @return true on success; false on any failure
3325 */
3326 @Override
3327 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003328 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3330 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003331
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3335 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003336 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003337 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3338 return success;
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
Jake Hambye994d462014-02-03 13:10:13 -08003342 }
3343
3344 /**
3345 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3346 * Used for device configuration by some CDMA operators.
3347 *
3348 * @param preferredRoamingList byte array containing the new PRL
3349 * @return true on success; false on any failure
3350 */
3351 @Override
3352 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3354 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003355
3356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3359 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3360 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3361 return success;
3362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
Jake Hambye994d462014-02-03 13:10:13 -08003365 }
3366
3367 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003368 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003369 * Used for device configuration by some CDMA operators.
3370 *
chen xu1cc0abe2018-10-26 17:39:23 -07003371 * @param slotIndex - device slot.
3372 *
Jake Hambye994d462014-02-03 13:10:13 -08003373 * @return true on success; false on any failure
3374 */
3375 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003376 public boolean resetModemConfig(int slotIndex) {
3377 Phone phone = PhoneFactory.getPhone(slotIndex);
3378 if (phone != null) {
3379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3380 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003381
chen xu1cc0abe2018-10-26 17:39:23 -07003382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3385 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3386 return success;
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
3389 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003390 }
chen xu1cc0abe2018-10-26 17:39:23 -07003391 return false;
3392 }
3393
3394 /**
3395 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3396 *
3397 * @param slotIndex - device slot.
3398 *
3399 * @return true on success; false on any failure
3400 */
3401 @Override
3402 public boolean rebootModem(int slotIndex) {
3403 Phone phone = PhoneFactory.getPhone(slotIndex);
3404 if (phone != null) {
3405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3406 mApp, phone.getSubId(), "rebootModem");
3407
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3411 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3412 return success;
3413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
3416 }
3417 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003418 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003419
Svet Ganovb320e182015-04-16 12:30:10 -07003420 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003422 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003423 return new String[0];
3424 }
3425
Malcolm Chend965c8b2018-02-28 15:00:40 -08003426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 return mPhone.getPcscfAddress(apnType);
3429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
Wink Saville36469e72014-06-11 15:17:00 -07003432 }
3433
Brad Ebinger51f743a2017-01-23 13:50:20 -08003434 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003435 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3436 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003437 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003438 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003439 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 PhoneFactory.getImsResolver().enableIms(slotId);
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003447 }
3448
3449 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003450 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3451 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003452 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003453 public void disableIms(int slotId) {
3454 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003455
3456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 PhoneFactory.getImsResolver().disableIms(slotId);
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
3461 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003462 }
3463
3464 /**
3465 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3466 * feature or {@link null} if the service is not available. If the feature is available, the
3467 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3468 */
3469 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003470 IImsServiceFeatureCallback callback) {
3471 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003472
3473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3476 } finally {
3477 Binder.restoreCallingIdentity(identity);
3478 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003479 }
3480
3481 /**
3482 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3483 * feature during emergency calling or {@link null} if the service is not available. If the
3484 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3485 * listener for feature updates.
3486 */
3487 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3488 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003489
3490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003496 }
3497
Brad Ebinger5f64b052017-12-14 14:26:15 -08003498 /**
3499 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3500 * specified.
3501 */
3502 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3503 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003504
3505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
3510 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003511 }
3512
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003513 /**
3514 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3515 * specified.
3516 */
3517 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3518 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003519
3520 final long identity = Binder.clearCallingIdentity();
3521 try {
3522 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003526 }
3527
Brad Ebinger884c07b2018-02-15 16:17:40 -08003528 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003529 * Sets the ImsService Package Name that Telephony will bind to.
3530 *
3531 * @param slotId the slot ID that the ImsService should bind for.
3532 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3533 * ImsService is the device default ImsService.
3534 * @param packageName The package name of the application that contains the ImsService to bind
3535 * to.
3536 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3537 * @hide
3538 */
3539 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003540 int[] subIds = SubscriptionManager.getSubId(slotId);
3541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3542 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3543 "setImsService");
3544
Malcolm Chend965c8b2018-02-28 15:00:40 -08003545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3548 isCarrierImsService, packageName);
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
3551 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003552 }
3553
3554 /**
3555 * Return the ImsService configuration.
3556 *
3557 * @param slotId The slot that the ImsService is associated with.
3558 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3559 * the device default.
3560 * @return the package name of the ImsService configuration.
3561 */
3562 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003563 int[] subIds = SubscriptionManager.getSubId(slotId);
3564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3565 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3566 "getImsService");
3567
Malcolm Chend965c8b2018-02-28 15:00:40 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3571 isCarrierImsService);
3572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003575 }
3576
Wink Saville36469e72014-06-11 15:17:00 -07003577 public void setImsRegistrationState(boolean registered) {
3578 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003579
3580 final long identity = Binder.clearCallingIdentity();
3581 try {
3582 mPhone.setImsRegistrationState(registered);
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
3585 }
Wink Saville36469e72014-06-11 15:17:00 -07003586 }
3587
3588 /**
Stuart Scott54788802015-03-30 13:18:01 -07003589 * Set the network selection mode to automatic.
3590 *
3591 */
3592 @Override
3593 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3595 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003596
Pengquan Meng466e2482018-09-21 15:54:48 -07003597 if (!isActiveSubscription(subId)) {
3598 return;
3599 }
3600
Malcolm Chend965c8b2018-02-28 15:00:40 -08003601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3604 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
Stuart Scott54788802015-03-30 13:18:01 -07003608 }
3609
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003610 /**
3611 * Ask the radio to connect to the input network and change selection mode to manual.
3612 *
3613 * @param subId the id of the subscription.
3614 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3615 * the operator to attach to.
3616 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3617 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3618 * normal network selection next time.
3619 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003620 */
3621 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003622 public boolean setNetworkSelectionModeManual(
3623 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3625 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003626
3627 if (!isActiveSubscription(subId)) {
3628 return false;
3629 }
3630
Malcolm Chend965c8b2018-02-28 15:00:40 -08003631 final long identity = Binder.clearCallingIdentity();
3632 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003633 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003634 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003635 if (DBG) {
3636 log("setNetworkSelectionModeManual: subId: " + subId
3637 + " operator: " + operatorInfo);
3638 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003639 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003643 }
3644
3645 /**
3646 * Scans for available networks.
3647 */
3648 @Override
3649 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3651 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003652
Pengquan Meng0c05b502018-09-06 09:59:22 -07003653 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003654 try {
3655 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003656 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003657 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003661 }
3662
3663 /**
yinxub1bed742017-04-17 11:45:04 -07003664 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003665 *
yinxub1bed742017-04-17 11:45:04 -07003666 * @param subId id of the subscription
3667 * @param request contains the radio access networks with bands/channels to scan
3668 * @param messenger callback messenger for scan results or errors
3669 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003670 * @return the id of the requested scan which can be used to stop the scan.
3671 */
3672 @Override
3673 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3674 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3676 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003677
3678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 return mNetworkScanRequestTracker.startNetworkScan(
3681 request, messenger, binder, getPhone(subId));
3682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
yinxu504e1392017-04-12 16:03:22 -07003685 }
3686
3687 /**
3688 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003689 *
3690 * @param subId id of the subscription
3691 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003692 */
3693 @Override
3694 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3696 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003697
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
yinxu504e1392017-04-12 16:03:22 -07003704 }
3705
3706 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003707 * Get the calculated preferred network type.
3708 * Used for debugging incorrect network type.
3709 *
3710 * @return the preferred network type, defined in RILConstants.java.
3711 */
3712 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003713 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003715 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003716 return RILConstants.PREFERRED_NETWORK_MODE;
3717 }
3718
Malcolm Chend965c8b2018-02-28 15:00:40 -08003719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 // FIXME: need to get SubId from somewhere.
3722 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
Junda Liu84d15a22014-07-02 11:21:04 -07003726 }
3727
3728 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003729 * Get the preferred network type.
3730 * Used for device configuration by some CDMA operators.
3731 *
3732 * @return the preferred network type, defined in RILConstants.java.
3733 */
3734 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003735 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3737 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003738
3739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 if (DBG) log("getPreferredNetworkType");
3742 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3743 int networkType = (result != null ? result[0] : -1);
3744 if (DBG) log("getPreferredNetworkType: " + networkType);
3745 return networkType;
3746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003749 }
3750
3751 /**
3752 * Set the preferred network type.
3753 * Used for device configuration by some CDMA operators.
3754 *
3755 * @param networkType the preferred network type, defined in RILConstants.java.
3756 * @return true on success; false on any failure.
3757 */
3758 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003759 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3761 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003762
3763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3766 Boolean success = (Boolean) sendRequest(
3767 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3768 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3769 if (success) {
3770 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3771 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3772 }
3773 return success;
3774 } finally {
3775 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003776 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003777 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003778
3779 /**
Junda Liu475951f2014-11-07 16:45:03 -08003780 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3781 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3782 * tethering.
3783 *
3784 * @return 0: Not required. 1: required. 2: Not set.
3785 * @hide
3786 */
3787 @Override
3788 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003789 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003790
3791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3794 Settings.Global.TETHER_DUN_REQUIRED, 2);
3795 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3796 // config_tether_apndata.
3797 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3798 dunRequired = 1;
3799 }
3800 return dunRequired;
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003803 }
Junda Liu475951f2014-11-07 16:45:03 -08003804 }
3805
3806 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003807 * Set mobile data enabled
3808 * Used by the user through settings etc to turn on/off mobile data
3809 *
3810 * @param enable {@code true} turn turn data on, else {@code false}
3811 */
3812 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003813 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3815 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003816
3817 final long identity = Binder.clearCallingIdentity();
3818 try {
3819 int phoneId = mSubscriptionController.getPhoneId(subId);
3820 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3821 Phone phone = PhoneFactory.getPhone(phoneId);
3822 if (phone != null) {
3823 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3824 phone.setUserDataEnabled(enable);
3825 } else {
3826 loge("setUserDataEnabled: no phone for subId=" + subId);
3827 }
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003830 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003831 }
3832
3833 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003834 * Get the user enabled state of Mobile Data.
3835 *
3836 * TODO: remove and use isUserDataEnabled.
3837 * This can't be removed now because some vendor codes
3838 * calls through ITelephony directly while they should
3839 * use TelephonyManager.
3840 *
3841 * @return true on enabled
3842 */
3843 @Override
3844 public boolean getDataEnabled(int subId) {
3845 return isUserDataEnabled(subId);
3846 }
3847
3848 /**
3849 * Get whether mobile data is enabled per user setting.
3850 *
3851 * There are other factors deciding whether mobile data is actually enabled, but they are
3852 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003853 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003854 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003855 *
3856 * @return {@code true} if data is enabled else {@code false}
3857 */
3858 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003859 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003860 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, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003866 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003867
3868 final long identity = Binder.clearCallingIdentity();
3869 try {
3870 int phoneId = mSubscriptionController.getPhoneId(subId);
3871 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3872 Phone phone = PhoneFactory.getPhone(phoneId);
3873 if (phone != null) {
3874 boolean retVal = phone.isUserDataEnabled();
3875 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3876 return retVal;
3877 } else {
3878 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3879 return false;
3880 }
3881 } finally {
3882 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003883 }
3884 }
3885
3886 /**
3887 * Get whether mobile data is enabled.
3888 *
3889 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3890 * whether mobile data is actually enabled.
3891 *
3892 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3893 *
3894 * @return {@code true} if data is enabled else {@code false}
3895 */
3896 @Override
3897 public boolean isDataEnabled(int subId) {
3898 try {
3899 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3900 null);
3901 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3903 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003904 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003905
3906 final long identity = Binder.clearCallingIdentity();
3907 try {
3908 int phoneId = mSubscriptionController.getPhoneId(subId);
3909 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3910 Phone phone = PhoneFactory.getPhone(phoneId);
3911 if (phone != null) {
3912 boolean retVal = phone.isDataEnabled();
3913 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3914 return retVal;
3915 } else {
3916 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3917 return false;
3918 }
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003921 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003922 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003923
3924 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003925 public int getCarrierPrivilegeStatus(int subId) {
3926 final Phone phone = getPhone(subId);
3927 if (phone == null) {
3928 loge("getCarrierPrivilegeStatus: Invalid subId");
3929 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3930 }
3931 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003932 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003933 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003934 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3935 }
3936 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003937 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003938 }
Junda Liu29340342014-07-10 15:23:27 -07003939
3940 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003941 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3942 final Phone phone = getPhone(subId);
3943 if (phone == null) {
3944 loge("getCarrierPrivilegeStatus: Invalid subId");
3945 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3946 }
3947 UiccProfile profile =
3948 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3949 if (profile == null) {
3950 loge("getCarrierPrivilegeStatus: No UICC");
3951 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3952 }
3953 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3954 }
3955
3956 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003957 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003958 if (TextUtils.isEmpty(pkgName))
3959 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003960 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003961 if (card == null) {
3962 loge("checkCarrierPrivilegesForPackage: No UICC");
3963 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3964 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003965 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3966 }
3967
3968 @Override
3969 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003970 if (TextUtils.isEmpty(pkgName))
3971 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003972 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3973 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3974 UiccCard card = UiccController.getInstance().getUiccCard(i);
3975 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003976 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003977 continue;
3978 }
3979
3980 result = card.getCarrierPrivilegeStatus(
3981 mPhone.getContext().getPackageManager(), pkgName);
3982 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3983 break;
3984 }
3985 }
3986
3987 return result;
Junda Liu29340342014-07-10 15:23:27 -07003988 }
Derek Tan89e89d42014-07-08 17:00:10 -07003989
3990 @Override
Junda Liue64de782015-04-16 17:19:16 -07003991 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3992 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3993 loge("phoneId " + phoneId + " is not valid.");
3994 return null;
3995 }
3996 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003997 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003998 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003999 return null ;
4000 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004001 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004002 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004003 }
4004
Amith Yamasani6e118872016-02-19 12:53:51 -08004005 @Override
4006 public List<String> getPackagesWithCarrierPrivileges() {
4007 PackageManager pm = mPhone.getContext().getPackageManager();
4008 List<String> privilegedPackages = new ArrayList<>();
4009 List<PackageInfo> packages = null;
4010 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4011 UiccCard card = UiccController.getInstance().getUiccCard(i);
4012 if (card == null) {
4013 // No UICC in that slot.
4014 continue;
4015 }
4016 if (card.hasCarrierPrivilegeRules()) {
4017 if (packages == null) {
4018 // Only check packages in user 0 for now
4019 packages = pm.getInstalledPackagesAsUser(
4020 PackageManager.MATCH_DISABLED_COMPONENTS
4021 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4022 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4023 }
4024 for (int p = packages.size() - 1; p >= 0; p--) {
4025 PackageInfo pkgInfo = packages.get(p);
4026 if (pkgInfo != null && pkgInfo.packageName != null
4027 && card.getCarrierPrivilegeStatus(pkgInfo)
4028 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4029 privilegedPackages.add(pkgInfo.packageName);
4030 }
4031 }
4032 }
4033 }
4034 return privilegedPackages;
4035 }
4036
Wink Savilleb564aae2014-10-23 10:18:09 -07004037 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004038 final Phone phone = getPhone(subId);
4039 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004040 if (card == null) {
4041 loge("getIccId: No UICC");
4042 return null;
4043 }
4044 String iccId = card.getIccId();
4045 if (TextUtils.isEmpty(iccId)) {
4046 loge("getIccId: ICC ID is null or empty.");
4047 return null;
4048 }
4049 return iccId;
4050 }
4051
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004052 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004053 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4054 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004055 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4056 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004057
Malcolm Chend965c8b2018-02-28 15:00:40 -08004058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 final String iccId = getIccId(subId);
4061 final Phone phone = getPhone(subId);
4062 if (phone == null) {
4063 return false;
4064 }
4065 final String subscriberId = phone.getSubscriberId();
4066
4067 if (DBG_MERGE) {
4068 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4069 + subscriberId + " to " + number);
4070 }
4071
4072 if (TextUtils.isEmpty(iccId)) {
4073 return false;
4074 }
4075
4076 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4077
4078 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4079 if (alphaTag == null) {
4080 editor.remove(alphaTagPrefKey);
4081 } else {
4082 editor.putString(alphaTagPrefKey, alphaTag);
4083 }
4084
4085 // Record both the line number and IMSI for this ICCID, since we need to
4086 // track all merged IMSIs based on line number
4087 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4088 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4089 if (number == null) {
4090 editor.remove(numberPrefKey);
4091 editor.remove(subscriberPrefKey);
4092 } else {
4093 editor.putString(numberPrefKey, number);
4094 editor.putString(subscriberPrefKey, subscriberId);
4095 }
4096
4097 editor.commit();
4098 return true;
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004101 }
Derek Tan7226c842014-07-02 17:42:23 -07004102 }
4103
4104 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004105 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004106 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004108 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004109 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004110 return null;
4111 }
Derek Tan97ebb422014-09-05 16:55:38 -07004112
Malcolm Chend965c8b2018-02-28 15:00:40 -08004113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 String iccId = getIccId(subId);
4116 if (iccId != null) {
4117 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4118 if (DBG_MERGE) {
4119 log("getLine1NumberForDisplay returning "
4120 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4121 }
4122 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004123 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004124 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4125 return null;
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004128 }
Derek Tan7226c842014-07-02 17:42:23 -07004129 }
4130
4131 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004132 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004134 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004135 return null;
4136 }
Derek Tan97ebb422014-09-05 16:55:38 -07004137
Malcolm Chend965c8b2018-02-28 15:00:40 -08004138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 String iccId = getIccId(subId);
4141 if (iccId != null) {
4142 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4143 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4144 }
4145 return null;
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004148 }
Derek Tan7226c842014-07-02 17:42:23 -07004149 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004150
4151 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004152 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004153 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4154 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004155 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004156 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4157 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004158 return null;
4159 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004160
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004161 final long identity = Binder.clearCallingIdentity();
4162 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004163 final Context context = mPhone.getContext();
4164 final TelephonyManager tele = TelephonyManager.from(context);
4165 final SubscriptionManager sub = SubscriptionManager.from(context);
4166
4167 // Figure out what subscribers are currently active
4168 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4169 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4170 // the process, where TelephonyManager was instantiated.
4171 // Otherwise AppOps check will fail.
4172
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004173 final int[] subIds = sub.getActiveSubscriptionIdList();
4174 for (int subId : subIds) {
4175 activeSubscriberIds.add(tele.getSubscriberId(subId));
4176 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004177
4178 // First pass, find a number override for an active subscriber
4179 String mergeNumber = null;
4180 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4181 for (String key : prefs.keySet()) {
4182 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4183 final String subscriberId = (String) prefs.get(key);
4184 if (activeSubscriberIds.contains(subscriberId)) {
4185 final String iccId = key.substring(
4186 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4187 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4188 mergeNumber = (String) prefs.get(numberKey);
4189 if (DBG_MERGE) {
4190 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4191 + " for active subscriber " + subscriberId);
4192 }
4193 if (!TextUtils.isEmpty(mergeNumber)) {
4194 break;
4195 }
4196 }
4197 }
4198 }
4199
4200 // Shortcut when no active merged subscribers
4201 if (TextUtils.isEmpty(mergeNumber)) {
4202 return null;
4203 }
4204
4205 // Second pass, find all subscribers under that line override
4206 final ArraySet<String> result = new ArraySet<>();
4207 for (String key : prefs.keySet()) {
4208 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4209 final String number = (String) prefs.get(key);
4210 if (mergeNumber.equals(number)) {
4211 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4212 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4213 final String subscriberId = (String) prefs.get(subscriberKey);
4214 if (!TextUtils.isEmpty(subscriberId)) {
4215 result.add(subscriberId);
4216 }
4217 }
4218 }
4219 }
4220
4221 final String[] resultArray = result.toArray(new String[result.size()]);
4222 Arrays.sort(resultArray);
4223 if (DBG_MERGE) {
4224 Slog.d(LOG_TAG,
4225 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4226 }
4227 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004228 } finally {
4229 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004230 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004231 }
4232
4233 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004234 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004235 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4236 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004237
4238 final long identity = Binder.clearCallingIdentity();
4239 try {
4240 final Phone phone = getPhone(subId);
4241 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004245 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004246
4247 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004248 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004249 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4250 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004251 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004252
4253 final long identity = Binder.clearCallingIdentity();
4254 try {
4255 final Phone phone = getPhone(subId);
4256 if (phone == null) {
4257 return false;
4258 }
4259 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4260 cdmaNonRoamingList);
4261 } finally {
4262 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004263 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004264 }
4265
4266 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004267 @Deprecated
4268 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4269 enforceModifyPermission();
4270
4271 int returnValue = 0;
4272 try {
vagdevie435a3e2018-08-15 16:01:53 -07004273 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004274 if(result.exception == null) {
4275 if (result.result != null) {
4276 byte[] responseData = (byte[])(result.result);
4277 if(responseData.length > oemResp.length) {
4278 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4279 responseData.length + "bytes. Buffer Size is " +
4280 oemResp.length + "bytes.");
4281 }
4282 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4283 returnValue = responseData.length;
4284 }
4285 } else {
4286 CommandException ex = (CommandException) result.exception;
4287 returnValue = ex.getCommandError().ordinal();
4288 if(returnValue > 0) returnValue *= -1;
4289 }
4290 } catch (RuntimeException e) {
4291 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4292 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4293 if(returnValue > 0) returnValue *= -1;
4294 }
4295
4296 return returnValue;
4297 }
4298
4299 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004300 public void setRadioCapability(RadioAccessFamily[] rafs) {
4301 try {
4302 ProxyController.getInstance().setRadioCapability(rafs);
4303 } catch (RuntimeException e) {
4304 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4305 }
4306 }
4307
4308 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004309 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004310 Phone phone = PhoneFactory.getPhone(phoneId);
4311 if (phone == null) {
4312 return RadioAccessFamily.RAF_UNKNOWN;
4313 }
4314 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004316 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004317 return RadioAccessFamily.RAF_UNKNOWN;
4318 }
4319
Malcolm Chend965c8b2018-02-28 15:00:40 -08004320 final long identity = Binder.clearCallingIdentity();
4321 try {
4322 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004326 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004327
4328 @Override
4329 public void enableVideoCalling(boolean enable) {
4330 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004331
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004338 }
4339
4340 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004341 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4343 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4344 return false;
4345 }
Svet Ganovb320e182015-04-16 12:30:10 -07004346
Malcolm Chend965c8b2018-02-28 15:00:40 -08004347 final long identity = Binder.clearCallingIdentity();
4348 try {
4349 // Check the user preference and the system-level IMS setting. Even if the user has
4350 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4351 // In the long run, we may instead need to check if there exists a connection service
4352 // which can support video calling.
4353 ImsManager imsManager =
4354 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4355 return imsManager.isVtEnabledByPlatform()
4356 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4357 && imsManager.isVtEnabledByUser();
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004361 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004362
Andrew Leea1239f22015-03-02 17:44:07 -08004363 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004364 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4366 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4367 return false;
4368 }
4369
4370 final long identity = Binder.clearCallingIdentity();
4371 try {
4372 CarrierConfigManager configManager =
4373 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4374 return configManager.getConfigForSubId(mPhone.getSubId())
4375 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
Andrew Leea1239f22015-03-02 17:44:07 -08004379 }
4380
4381 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004382 public boolean isWorldPhone(int subId, String callingPackage) {
4383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4384 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4385 return false;
4386 }
4387
4388 final long identity = Binder.clearCallingIdentity();
4389 try {
4390 CarrierConfigManager configManager =
4391 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4392 return configManager.getConfigForSubId(mPhone.getSubId())
4393 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
4396 }
Andrew Leea1239f22015-03-02 17:44:07 -08004397 }
4398
Andrew Lee9431b832015-03-09 18:46:45 -07004399 @Override
4400 public boolean isTtyModeSupported() {
4401 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004402 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004403 }
4404
4405 @Override
4406 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004407 final long identity = Binder.clearCallingIdentity();
4408 try {
4409 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
Andrew Lee9431b832015-03-09 18:46:45 -07004413 }
4414
Hall Liu98187582018-01-22 19:15:32 -08004415 public boolean isRttSupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004416 final long identity = Binder.clearCallingIdentity();
4417 try {
4418 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4419 mPhone.getSubId()).getBoolean(
4420 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4421 boolean isDeviceSupported =
4422 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4423 return isCarrierSupported && isDeviceSupported;
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
Hall Liu98187582018-01-22 19:15:32 -08004427 }
4428
Hall Liu3ad5f012018-04-06 16:23:39 -07004429 public boolean isRttEnabled() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004430 final long identity = Binder.clearCallingIdentity();
4431 try {
4432 return isRttSupported() && Settings.Secure.getInt(
4433 mPhone.getContext().getContentResolver(),
4434 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004438 }
4439
Sanket Padawe7310cc72015-01-14 09:53:20 -08004440 /**
4441 * Returns the unique device ID of phone, for example, the IMEI for
4442 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4443 *
4444 * <p>Requires Permission:
4445 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4446 */
4447 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004448 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004449 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004450 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004451 return null;
4452 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004453 int subId = phone.getSubId();
4454 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4455 mApp, subId, callingPackage, "getDeviceId")) {
4456 return null;
4457 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004458
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
4461 return phone.getDeviceId();
4462 } finally {
4463 Binder.restoreCallingIdentity(identity);
4464 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004465 }
4466
Ping Sunc67b7c22016-03-02 19:16:45 +08004467 /**
4468 * {@hide}
4469 * Returns the IMS Registration Status on a particular subid
4470 *
4471 * @param subId
4472 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004473 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004474 Phone phone = getPhone(subId);
4475 if (phone != null) {
4476 return phone.isImsRegistered();
4477 } else {
4478 return false;
4479 }
4480 }
4481
Santos Cordon7a1885b2015-02-03 11:15:19 -08004482 @Override
4483 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004484 final long identity = Binder.clearCallingIdentity();
4485 try {
4486 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004490 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004491
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004492 /**
4493 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004494 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004495 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 Phone phone = getPhone(subId);
4499 if (phone != null) {
4500 return phone.isWifiCallingEnabled();
4501 } else {
4502 return false;
4503 }
4504 } finally {
4505 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004506 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004507 }
4508
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004509 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004510 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004511 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004512 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004513 final long identity = Binder.clearCallingIdentity();
4514 try {
4515 Phone phone = getPhone(subId);
4516 if (phone != null) {
4517 return phone.isVideoEnabled();
4518 } else {
4519 return false;
4520 }
4521 } finally {
4522 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004523 }
4524 }
4525
4526 /**
4527 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4528 * defined in {@link ImsRegistrationImplBase}.
4529 */
4530 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004531 final long identity = Binder.clearCallingIdentity();
4532 try {
4533 Phone phone = getPhone(subId);
4534 if (phone != null) {
4535 return phone.getImsRegistrationTech();
4536 } else {
4537 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4538 }
4539 } finally {
4540 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004541 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004542 }
4543
Stuart Scott8eef64f2015-04-08 15:13:54 -07004544 @Override
4545 public void factoryReset(int subId) {
4546 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004547 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4548 return;
4549 }
4550
Svet Ganovcc087f82015-05-12 20:35:54 -07004551 final long identity = Binder.clearCallingIdentity();
4552 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004553 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4554 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004555 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004556 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004557 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4558 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004559 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004560 }
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004563 }
4564 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004565
4566 @Override
4567 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004568 final long identity = Binder.clearCallingIdentity();
4569 try {
4570 // We query all subscriptions instead of just the active ones, because
4571 // this might be called early on in the provisioning flow when the
4572 // subscriptions potentially aren't active yet.
4573 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4574 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004575 return null;
4576 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004577
Malcolm Chend965c8b2018-02-28 15:00:40 -08004578 // This function may be called very early, say, from the setup wizard, at
4579 // which point we won't have a default subscription set. If that's the case
4580 // we just choose the first, which will be valid in "most cases".
4581 final int defaultSubId = getDefaultSubscription();
4582 SubscriptionInfo info = null;
4583 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4584 info = slist.get(0);
4585 } else {
4586 for (SubscriptionInfo item : slist) {
4587 if (item.getSubscriptionId() == defaultSubId) {
4588 info = item;
4589 break;
4590 }
4591 }
4592
4593 if (info == null) {
4594 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004595 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004596 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004597
Malcolm Chend965c8b2018-02-28 15:00:40 -08004598 // Try and fetch the locale from the carrier properties or from the SIM language
4599 // preferences (EF-PL and EF-LI)...
4600 final int mcc = info.getMcc();
4601 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4602 String simLanguage = null;
4603 if (defaultPhone != null) {
4604 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4605 if (localeFromDefaultSim != null) {
4606 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4607 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4608 return localeFromDefaultSim.toLanguageTag();
4609 } else {
4610 simLanguage = localeFromDefaultSim.getLanguage();
4611 }
4612 }
4613 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004614
Malcolm Chend965c8b2018-02-28 15:00:40 -08004615 // The SIM language preferences only store a language (e.g. fr = French), not an
4616 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4617 // the SIM and carrier preferences does not include a country we add the country
4618 // determined from the SIM MCC to provide an exact locale.
4619 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4620 simLanguage);
4621 if (mccLocale != null) {
4622 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4623 return mccLocale.toLanguageTag();
4624 }
4625
4626 if (DBG) log("No locale found - returning null");
4627 return null;
4628 } finally {
4629 Binder.restoreCallingIdentity(identity);
4630 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004631 }
4632
4633 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004634 return mSubscriptionController.getAllSubInfoList(
4635 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004636 }
4637
Malcolm Chend965c8b2018-02-28 15:00:40 -08004638 /**
4639 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4640 */
4641 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4642 return mSubscriptionController.getActiveSubscriptionInfoList(
4643 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004644 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004645
Chenjie Yu1ba97252018-01-11 18:16:20 -08004646 private final ModemActivityInfo mLastModemActivityInfo =
4647 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4648
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004649 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004650 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4651 * representing the state of the modem.
4652 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004653 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4654 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004655 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004656 */
4657 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004658 public void requestModemActivityInfo(ResultReceiver result) {
4659 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004660 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004661
4662 final long identity = Binder.clearCallingIdentity();
4663 try {
4664 ModemActivityInfo ret = null;
4665 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004666 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4667 CMD_GET_MODEM_ACTIVITY_INFO,
4668 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004669 if (isModemActivityInfoValid(info)) {
4670 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4671 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4672 mergedTxTimeMs[i] =
4673 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4674 }
4675 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4676 mLastModemActivityInfo.setSleepTimeMillis(
4677 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4678 mLastModemActivityInfo.setIdleTimeMillis(
4679 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4680 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4681 mLastModemActivityInfo.setRxTimeMillis(
4682 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4683 mLastModemActivityInfo.setEnergyUsed(
4684 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004685 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004686 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4687 mLastModemActivityInfo.getSleepTimeMillis(),
4688 mLastModemActivityInfo.getIdleTimeMillis(),
4689 mLastModemActivityInfo.getTxTimeMillis(),
4690 mLastModemActivityInfo.getRxTimeMillis(),
4691 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004692 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004693 Bundle bundle = new Bundle();
4694 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4695 result.send(0, bundle);
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004698 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004699 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004700
Siddharth Rayf5d29552018-06-17 15:02:38 -07004701 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4702 // less than total activity duration.
4703 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4704 if (info == null) {
4705 return false;
4706 }
4707 int activityDurationMs =
4708 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4709 int totalTxTimeMs = 0;
4710 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4711 totalTxTimeMs += info.getTxTimeMillis()[i];
4712 }
4713 return (info.isValid()
4714 && (info.getSleepTimeMillis() <= activityDurationMs)
4715 && (info.getIdleTimeMillis() <= activityDurationMs)
4716 && (info.getRxTimeMillis() <= activityDurationMs)
4717 && (totalTxTimeMs <= activityDurationMs));
4718 }
4719
Jack Yu85bd38a2015-11-09 11:34:32 -08004720 /**
4721 * {@hide}
4722 * Returns the service state information on specified subscription.
4723 */
4724 @Override
4725 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004727 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004728 return null;
4729 }
4730
Malcolm Chend965c8b2018-02-28 15:00:40 -08004731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 final Phone phone = getPhone(subId);
4734 if (phone == null) {
4735 return null;
4736 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004737
Malcolm Chend965c8b2018-02-28 15:00:40 -08004738 return phone.getServiceState();
4739 } finally {
4740 Binder.restoreCallingIdentity(identity);
4741 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004742 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004743
4744 /**
4745 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4746 *
4747 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4748 * voicemail ringtone.
4749 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4750 * PhoneAccount.
4751 */
4752 @Override
4753 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004754 final long identity = Binder.clearCallingIdentity();
4755 try {
4756 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4757 if (phone == null) {
4758 phone = mPhone;
4759 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004760
Malcolm Chend965c8b2018-02-28 15:00:40 -08004761 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
4764 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004765 }
4766
4767 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004768 * Sets the per-account voicemail ringtone.
4769 *
4770 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4771 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4772 *
4773 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4774 * voicemail ringtone.
4775 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4776 * PhoneAccount.
4777 */
4778 @Override
4779 public void setVoicemailRingtoneUri(String callingPackage,
4780 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4781 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4782 if (!TextUtils.equals(callingPackage,
4783 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4785 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4786 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004787 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004788
4789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4792 if (phone == null) {
4793 phone = mPhone;
4794 }
4795 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4796 } finally {
4797 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004798 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004799 }
4800
4801 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004802 * Returns whether vibration is set for voicemail notification in Phone settings.
4803 *
4804 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4805 * voicemail vibration setting.
4806 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4807 */
4808 @Override
4809 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004810 final long identity = Binder.clearCallingIdentity();
4811 try {
4812 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4813 if (phone == null) {
4814 phone = mPhone;
4815 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004816
Malcolm Chend965c8b2018-02-28 15:00:40 -08004817 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4818 } finally {
4819 Binder.restoreCallingIdentity(identity);
4820 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004821 }
4822
Youhan Wange64578a2016-05-02 15:32:42 -07004823 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004824 * Sets the per-account voicemail vibration.
4825 *
4826 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4827 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4828 *
4829 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4830 * voicemail vibration setting.
4831 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4832 * specific PhoneAccount.
4833 */
4834 @Override
4835 public void setVoicemailVibrationEnabled(String callingPackage,
4836 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4837 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4838 if (!TextUtils.equals(callingPackage,
4839 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4841 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4842 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004843 }
4844
Malcolm Chend965c8b2018-02-28 15:00:40 -08004845 final long identity = Binder.clearCallingIdentity();
4846 try {
4847 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4848 if (phone == null) {
4849 phone = mPhone;
4850 }
4851 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4852 } finally {
4853 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004854 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004855 }
4856
4857 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004858 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4859 *
4860 * @throws SecurityException if the caller does not have the required permission
4861 */
Brad Ebinger4c460712018-10-01 10:40:55 -07004862 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004863 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07004864 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004865 }
4866
4867 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004868 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4869 * permission.
4870 *
4871 * @throws SecurityException if the caller does not have the required permission
4872 */
4873 private void enforceSendSmsPermission() {
4874 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4875 }
4876
4877 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004878 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004879 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004880 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004881 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004882 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004883 final long identity = Binder.clearCallingIdentity();
4884 try {
4885 ComponentName componentName =
4886 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4887 if (componentName == null) {
4888 throw new SecurityException(
4889 "Caller not current active visual voicemail package[null]");
4890 }
4891 String vvmPackage = componentName.getPackageName();
4892 if (!callingPackage.equals(vvmPackage)) {
4893 throw new SecurityException("Caller not current active visual voicemail package["
4894 + vvmPackage + "]");
4895 }
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004898 }
4899 }
4900
4901 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004902 * Return the application ID for the app type.
4903 *
4904 * @param subId the subscription ID that this request applies to.
4905 * @param appType the uicc app type.
4906 * @return Application ID for specificied app type, or null if no uicc.
4907 */
4908 @Override
4909 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07004910 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07004911 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004912
4913 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004914 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004915 if (phone == null) {
4916 return null;
4917 }
4918 String aid = null;
4919 try {
4920 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4921 .getApplicationByType(appType).getAid();
4922 } catch (Exception e) {
4923 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4924 }
4925 return aid;
4926 } finally {
4927 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004928 }
Youhan Wange64578a2016-05-02 15:32:42 -07004929 }
4930
Youhan Wang4001d252016-05-11 10:29:41 -07004931 /**
4932 * Return the Electronic Serial Number.
4933 *
4934 * @param subId the subscription ID that this request applies to.
4935 * @return ESN or null if error.
4936 */
4937 @Override
4938 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07004939 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07004940 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004941
4942 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004943 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004944 if (phone == null) {
4945 return null;
4946 }
4947 String esn = null;
4948 try {
4949 esn = phone.getEsn();
4950 } catch (Exception e) {
4951 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4952 }
4953 return esn;
4954 } finally {
4955 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004956 }
Youhan Wang4001d252016-05-11 10:29:41 -07004957 }
4958
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004959 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004960 * Return the Preferred Roaming List Version.
4961 *
4962 * @param subId the subscription ID that this request applies to.
4963 * @return PRLVersion or null if error.
4964 */
4965 @Override
4966 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07004967 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07004968 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004969
4970 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004971 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004972 if (phone == null) {
4973 return null;
4974 }
4975 String cdmaPrlVersion = null;
4976 try {
4977 cdmaPrlVersion = phone.getCdmaPrlVersion();
4978 } catch (Exception e) {
4979 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4980 }
4981 return cdmaPrlVersion;
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004984 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004985 }
4986
4987 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004988 * Get snapshot of Telephony histograms
4989 * @return List of Telephony histograms
4990 * @hide
4991 */
4992 @Override
4993 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4995 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004996
4997 final long identity = Binder.clearCallingIdentity();
4998 try {
4999 return RIL.getTelephonyRILTimingHistograms();
5000 } finally {
5001 Binder.restoreCallingIdentity(identity);
5002 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005003 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005004
5005 /**
5006 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005007 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005008 * Require system privileges. In the future we may add this to carrier APIs.
5009 *
5010 * @return The number of carriers set successfully, should match length of carriers
5011 */
5012 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005013 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005014 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005015 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005016
Meng Wang9b7c4e92017-02-17 11:41:27 -08005017 if (carriers == null) {
5018 throw new NullPointerException("carriers cannot be null");
5019 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005020
Malcolm Chend965c8b2018-02-28 15:00:40 -08005021 final long identity = Binder.clearCallingIdentity();
5022 try {
5023 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005024 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5025 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005026 return retVal[0];
5027 } finally {
5028 Binder.restoreCallingIdentity(identity);
5029 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005030 }
5031
5032 /**
5033 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005034 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005035 * Require system privileges. In the future we may add this to carrier APIs.
5036 *
5037 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5038 * means all carriers are allowed.
5039 */
5040 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005041 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005042 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005043 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005044
5045 final long identity = Binder.clearCallingIdentity();
5046 try {
5047 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005048 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5049 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005050 } finally {
5051 Binder.restoreCallingIdentity(identity);
5052 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005053 }
5054
fionaxu59545b42016-05-25 15:53:37 -07005055 /**
5056 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5057 * @param subId the subscription ID that this action applies to.
5058 * @param enabled control enable or disable metered apns.
5059 * {@hide}
5060 */
5061 @Override
5062 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5063 enforceModifyPermission();
5064 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005065
5066 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005067 if (phone == null) {
5068 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5069 return;
5070 }
5071 try {
5072 phone.carrierActionSetMeteredApnsEnabled(enabled);
5073 } catch (Exception e) {
5074 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005075 } finally {
5076 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005077 }
5078 }
5079
5080 /**
5081 * Action set from carrier signalling broadcast receivers to enable/disable radio
5082 * @param subId the subscription ID that this action applies to.
5083 * @param enabled control enable or disable radio.
5084 * {@hide}
5085 */
5086 @Override
5087 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5088 enforceModifyPermission();
5089 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005090
5091 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005092 if (phone == null) {
5093 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5094 return;
5095 }
5096 try {
5097 phone.carrierActionSetRadioEnabled(enabled);
5098 } catch (Exception e) {
5099 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005102 }
5103 }
5104
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005105 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005106 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5107 * network status based on which carrier apps could apply actions accordingly,
5108 * enable/disable default url handler for example.
5109 *
5110 * @param subId the subscription ID that this action applies to.
5111 * @param report control start/stop reporting the default network status.
5112 * {@hide}
5113 */
5114 @Override
5115 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5116 enforceModifyPermission();
5117 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005118
5119 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005120 if (phone == null) {
5121 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5122 return;
5123 }
5124 try {
5125 phone.carrierActionReportDefaultNetworkStatus(report);
5126 } catch (Exception e) {
5127 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005128 } finally {
5129 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005130 }
5131 }
5132
5133 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005134 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5135 * bug report is being generated.
5136 */
5137 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005138 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005139 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5140 != PackageManager.PERMISSION_GRANTED) {
5141 writer.println("Permission Denial: can't dump Phone from pid="
5142 + Binder.getCallingPid()
5143 + ", uid=" + Binder.getCallingUid()
5144 + "without permission "
5145 + android.Manifest.permission.DUMP);
5146 return;
5147 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005148 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005149 }
Jack Yueb89b242016-06-22 13:27:47 -07005150
Brad Ebingerdac2f002018-04-03 15:17:52 -07005151 @Override
5152 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5153 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5154 throws RemoteException {
5155 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5156 }
5157
Jack Yueb89b242016-06-22 13:27:47 -07005158 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005159 * Get aggregated video call data usage since boot.
5160 *
5161 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5162 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005163 * {@hide}
5164 */
5165 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005166 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005167 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5168 null);
5169
Malcolm Chend965c8b2018-02-28 15:00:40 -08005170 final long identity = Binder.clearCallingIdentity();
5171 try {
5172 // NetworkStatsService keeps tracking the active network interface and identity. It
5173 // records the delta with the corresponding network identity.
5174 // We just return the total video call data usage snapshot since boot.
5175 Phone phone = getPhone(subId);
5176 if (phone != null) {
5177 return phone.getVtDataUsage(perUidStats);
5178 }
5179 return null;
5180 } finally {
5181 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005182 }
Jack Yueb89b242016-06-22 13:27:47 -07005183 }
Jack Yu75ab2952016-07-08 14:29:33 -07005184
5185 /**
5186 * Policy control of data connection. Usually used when data limit is passed.
5187 * @param enabled True if enabling the data, otherwise disabling.
5188 * @param subId Subscription index
5189 * {@hide}
5190 */
5191 @Override
5192 public void setPolicyDataEnabled(boolean enabled, int subId) {
5193 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005194
5195 final long identity = Binder.clearCallingIdentity();
5196 try {
5197 Phone phone = getPhone(subId);
5198 if (phone != null) {
5199 phone.setPolicyDataEnabled(enabled);
5200 }
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005203 }
5204 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005205
5206 /**
5207 * Get Client request stats
5208 * @return List of Client Request Stats
5209 * @hide
5210 */
5211 @Override
5212 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005213 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005214 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005215 return null;
5216 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005217 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005218
Malcolm Chend965c8b2018-02-28 15:00:40 -08005219 final long identity = Binder.clearCallingIdentity();
5220 try {
5221 if (phone != null) {
5222 return phone.getClientRequestStats();
5223 }
5224
5225 return null;
5226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005229 }
5230
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005231 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005232 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005233 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005234 }
Jack Yueb4124c2017-02-16 15:32:43 -08005235
5236 /**
Grace Chen70990072017-03-24 17:21:30 -07005237 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005238 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005239 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005240 * @param state State of SIM (power down, power up, pass through)
5241 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5242 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5243 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005244 *
5245 **/
5246 @Override
Grace Chen70990072017-03-24 17:21:30 -07005247 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005248 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005249 Phone phone = PhoneFactory.getPhone(slotIndex);
5250
vagdevie435a3e2018-08-15 16:01:53 -07005251 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5252
Malcolm Chend965c8b2018-02-28 15:00:40 -08005253 final long identity = Binder.clearCallingIdentity();
5254 try {
5255 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005256 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005257 }
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005260 }
5261 }
Shuo Qiandd210312017-04-12 22:11:33 +00005262
Tyler Gunn65d45c22017-06-05 11:22:26 -07005263 private boolean isUssdApiAllowed(int subId) {
5264 CarrierConfigManager configManager =
5265 (CarrierConfigManager) mPhone.getContext().getSystemService(
5266 Context.CARRIER_CONFIG_SERVICE);
5267 if (configManager == null) {
5268 return false;
5269 }
5270 PersistableBundle pb = configManager.getConfigForSubId(subId);
5271 if (pb == null) {
5272 return false;
5273 }
5274 return pb.getBoolean(
5275 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5276 }
5277
Shuo Qiandd210312017-04-12 22:11:33 +00005278 /**
5279 * Check if phone is in emergency callback mode
5280 * @return true if phone is in emergency callback mode
5281 * @param subId sub id
5282 */
goneil9c5f4872017-12-05 14:07:56 -08005283 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005284 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005285 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005286 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005287
5288 final long identity = Binder.clearCallingIdentity();
5289 try {
5290 if (phone != null) {
5291 return phone.isInEcm();
5292 } else {
5293 return false;
5294 }
5295 } finally {
5296 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005297 }
5298 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005299
5300 /**
5301 * Get the current signal strength information for the given subscription.
5302 * Because this information is not updated when the device is in a low power state
5303 * it should not be relied-upon to be current.
5304 * @param subId Subscription index
5305 * @return the most recent cached signal strength info from the modem
5306 */
5307 @Override
5308 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005309 final long identity = Binder.clearCallingIdentity();
5310 try {
5311 Phone p = getPhone(subId);
5312 if (p == null) {
5313 return null;
5314 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005315
Malcolm Chend965c8b2018-02-28 15:00:40 -08005316 return p.getSignalStrength();
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005320 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005321
Pengquan Meng9140aec2018-08-22 14:49:57 -07005322 /**
chen xu907e5a22018-10-11 13:21:04 -07005323 * Get the current modem radio state for the given slot.
5324 * @param slotIndex slot index.
5325 * @param callingPackage the name of the package making the call.
5326 * @return the current radio power state from the modem
5327 */
5328 @Override
5329 public int getRadioPowerState(int slotIndex, String callingPackage) {
5330 Phone phone = PhoneFactory.getPhone(slotIndex);
5331 if (phone != null) {
5332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5333 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5334 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5335 }
5336
5337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 return phone.getRadioPowerState();
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
5342 }
5343 }
5344 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5345 }
5346
5347 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005348 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5349 *
5350 * <p>Requires one of the following permissions:
5351 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5352 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5353 * privileges.
5354 *
5355 * @param subId subscription id
5356 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5357 * {@code false}.
5358 */
5359 @Override
5360 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005361 boolean isEnabled = false;
5362 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005363 try {
5364 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005365 null /* message */);
5366 Phone phone = getPhone(subId);
5367 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005368 } catch (Exception e) {
5369 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5370 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005371 } finally {
5372 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005373 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005374 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005375 }
5376
5377
5378 /**
5379 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5380 *
5381 * <p> Requires permission:
5382 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5383 * privileges.
5384 *
5385 * @param subId subscription id
5386 * @param isEnabled {@code true} means enable, {@code false} means disable.
5387 */
5388 @Override
5389 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5393 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005394
Pengquan Meng0c05b502018-09-06 09:59:22 -07005395 Phone phone = getPhone(subId);
5396 if (phone != null) {
5397 phone.setDataRoamingEnabled(isEnabled);
5398 }
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005401 }
5402 }
5403
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005404 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005405 public boolean isManualNetworkSelectionAllowed(int subId) {
5406 boolean isAllowed = true;
5407 final long identity = Binder.clearCallingIdentity();
5408 try {
5409 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5410 mApp, subId, "isManualNetworkSelectionAllowed");
5411 Phone phone = getPhone(subId);
5412 if (phone != null) {
5413 isAllowed = phone.isCspPlmnEnabled();
5414 }
5415 } finally {
5416 Binder.restoreCallingIdentity(identity);
5417 }
5418 return isAllowed;
5419 }
5420
5421 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005422 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005423 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005424
Malcolm Chend965c8b2018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5428 if (slots == null) {
5429 Rlog.i(LOG_TAG, "slots is null.");
5430 return null;
5431 }
5432
5433 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5434 for (int i = 0; i < slots.length; i++) {
5435 UiccSlot slot = slots[i];
5436 if (slot == null) {
5437 continue;
5438 }
5439
5440 String cardId;
5441 UiccCard card = slot.getUiccCard();
5442 if (card != null) {
5443 cardId = card.getCardId();
5444 } else {
5445 cardId = slot.getIccId();
5446 }
5447
5448 int cardState = 0;
5449 switch (slot.getCardState()) {
5450 case CARDSTATE_ABSENT:
5451 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5452 break;
5453 case CARDSTATE_PRESENT:
5454 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5455 break;
5456 case CARDSTATE_ERROR:
5457 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5458 break;
5459 case CARDSTATE_RESTRICTED:
5460 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5461 break;
5462 default:
5463 break;
5464
5465 }
5466
5467 infos[i] = new UiccSlotInfo(
5468 slot.isActive(),
5469 slot.isEuicc(),
5470 cardId,
5471 cardState,
5472 slot.getPhoneId(),
5473 slot.isExtendedApduSupported());
5474 }
5475 return infos;
5476 } finally {
5477 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005478 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005479 }
5480
5481 @Override
5482 public boolean switchSlots(int[] physicalSlots) {
5483 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005484
5485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005491 }
Jack Yu4c988042018-02-27 15:30:01 -08005492
5493 @Override
5494 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5495 enforceModifyPermission();
5496 final Phone phone = getPhone(subId);
5497 if (phone == null) {
5498 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5499 return;
5500 }
5501
Malcolm Chend965c8b2018-02-28 15:00:40 -08005502 final long identity = Binder.clearCallingIdentity();
5503 try {
5504 phone.setRadioIndicationUpdateMode(filters, mode);
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
Jack Yu4c988042018-02-27 15:30:01 -08005508 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005509
5510 /**
goneil47ffb6e2018-04-06 15:40:58 -07005511 * A test API to reload the UICC profile.
5512 *
5513 * <p>Requires that the calling app has permission
5514 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5515 * @hide
5516 */
5517 @Override
5518 public void refreshUiccProfile(int subId) {
5519 enforceModifyPermission();
5520
5521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 Phone phone = getPhone(subId);
5524 if (phone == null) {
5525 return;
5526 }
5527 UiccCard uiccCard = phone.getUiccCard();
5528 if (uiccCard == null) {
5529 return;
5530 }
5531 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5532 if (uiccProfile == null) {
5533 return;
5534 }
5535 uiccProfile.refresh();
5536 } finally {
5537 Binder.restoreCallingIdentity(identity);
5538 }
5539 }
5540
5541 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005542 * Returns false if the mobile data is disabled by default, otherwise return true.
5543 */
5544 private boolean getDefaultDataEnabled() {
5545 return "true".equalsIgnoreCase(
5546 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5547 }
5548
5549 /**
5550 * Returns true if the data roaming is enabled by default, i.e the system property
5551 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5552 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5553 */
5554 private boolean getDefaultDataRoamingEnabled(int subId) {
5555 final CarrierConfigManager configMgr = (CarrierConfigManager)
5556 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5557 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5558 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5559 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5560 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5561 return isDataRoamingEnabled;
5562 }
5563
5564 /**
5565 * Returns the default network type for the given {@code subId}, if the default network type is
5566 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5567 */
5568 private int getDefaultNetworkType(int subId) {
5569 return Integer.parseInt(
5570 TelephonyManager.getTelephonyProperty(
5571 mSubscriptionController.getPhoneId(subId),
5572 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5573 String.valueOf(Phone.PREFERRED_NT_MODE)));
5574 }
fionaxua13278b2018-03-21 00:08:13 -07005575
5576 @Override
5577 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5578 gid1, String gid2, String plmn, String spn) {
5579 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 final Phone phone = getPhone(subId);
5584 if (phone == null) {
5585 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5586 return;
5587 }
5588 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5589 } finally {
5590 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005591 }
fionaxua13278b2018-03-21 00:08:13 -07005592 }
5593
5594 @Override
5595 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005596 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005597
5598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 final Phone phone = getPhone(subId);
5601 if (phone == null) {
5602 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5603 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5604 }
5605 return phone.getCarrierIdListVersion();
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005608 }
fionaxua13278b2018-03-21 00:08:13 -07005609 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005610
5611 @Override
5612 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5614 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5615 return -1;
5616 }
5617
5618 final long identity = Binder.clearCallingIdentity();
5619 try {
5620 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
5624 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005625
5626 @Override
5627 public int getCdmaRoamingMode(int subId) {
5628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5629 mApp, subId, "getCdmaRoamingMode");
5630
5631 final long identity = Binder.clearCallingIdentity();
5632 try {
5633 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
5637 }
5638
5639 @Override
5640 public boolean setCdmaRoamingMode(int subId, int mode) {
5641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5642 mApp, subId, "setCdmaRoamingMode");
5643
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5647 } finally {
5648 Binder.restoreCallingIdentity(identity);
5649 }
5650 }
5651
5652 @Override
5653 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5655 mApp, subId, "setCdmaSubscriptionMode");
5656
5657 final long identity = Binder.clearCallingIdentity();
5658 try {
5659 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
5663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005664}