blob: 0a6eb2460ef83cc0c1d93d553d9e4bd7a347664b [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 Ebinger35c841c2018-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 Ebinger35c841c2018-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 Ebinger35c841c2018-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 Chen2c63d402018-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;
Makoto Onukida3bf792018-09-18 16:06:29 -0700119import com.android.internal.telephony.SmsApplication;
120import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800121import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800122import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700123import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.uicc.IccIoResult;
125import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800126import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700127import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800128import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800130import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000131import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700132import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800133import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700134import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800135import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700136import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700137import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800138
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700139import java.io.FileDescriptor;
140import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800141import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800143import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700144import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800145import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100146import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800147import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148
149/**
150 * Implementation of the ITelephony interface.
151 */
Santos Cordon117fee72014-05-16 17:56:12 -0700152public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153 private static final String LOG_TAG = "PhoneInterfaceManager";
154 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
155 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800156 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157
158 // Message codes used with mMainThreadHandler
159 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700160 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
161 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162 private static final int CMD_OPEN_CHANNEL = 9;
163 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
164 private static final int CMD_CLOSE_CHANNEL = 11;
165 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800166 private static final int CMD_NV_READ_ITEM = 13;
167 private static final int EVENT_NV_READ_ITEM_DONE = 14;
168 private static final int CMD_NV_WRITE_ITEM = 15;
169 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
170 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
171 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700172 private static final int CMD_RESET_MODEM_CONFIG = 19;
173 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800174 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
175 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
176 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
177 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800178 private static final int CMD_SEND_ENVELOPE = 25;
179 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000180 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
181 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700182 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
183 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
184 private static final int CMD_EXCHANGE_SIM_IO = 31;
185 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800186 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
187 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700188 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
189 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700190 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
191 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700192 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
193 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
194 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
195 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700196 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
197 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
198 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
199 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700200 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
202 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000203 private static final int CMD_SWITCH_SLOTS = 50;
204 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700205 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
206 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
207 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
208 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
209 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
210 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
211 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
212 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700213 private static final int CMD_GET_ALL_CELL_INFO = 60;
214 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
215 private static final int CMD_GET_CELL_LOCATION = 62;
216 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700217 private static final int CMD_MODEM_REBOOT = 64;
218 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800220 // Parameters of select command.
221 private static final int SELECT_COMMAND = 0xA4;
222 private static final int SELECT_P1 = 0x04;
223 private static final int SELECT_P2 = 0;
224 private static final int SELECT_P3 = 0x10;
225
Pengquan Meng85728fb2018-03-12 16:31:21 -0700226 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
227 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
228 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
229
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230 /** The singleton instance. */
231 private static PhoneInterfaceManager sInstance;
232
Wink Saville3ab207e2014-11-20 13:07:20 -0800233 private PhoneGlobals mApp;
234 private Phone mPhone;
235 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700236 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800237 private AppOpsManager mAppOps;
238 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800239 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800240 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700241 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242
Derek Tan97ebb422014-09-05 16:55:38 -0700243 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
244 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800245 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700246
Derek Tan740e1672017-06-27 14:56:27 -0700247 // The AID of ISD-R.
248 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
249
yinxub1bed742017-04-17 11:45:04 -0700250 private NetworkScanRequestTracker mNetworkScanRequestTracker;
251
David Kelly5e06a7f2018-03-12 14:10:59 +0000252 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
253 private static final int MANUFACTURER_CODE_LENGTH = 8;
254
Derek Tan89e89d42014-07-08 17:00:10 -0700255 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700256 * A request object to use for transmitting data to an ICC.
257 */
258 private static final class IccAPDUArgument {
259 public int channel, cla, command, p1, p2, p3;
260 public String data;
261
262 public IccAPDUArgument(int channel, int cla, int command,
263 int p1, int p2, int p3, String data) {
264 this.channel = channel;
265 this.cla = cla;
266 this.command = command;
267 this.p1 = p1;
268 this.p2 = p2;
269 this.p3 = p3;
270 this.data = data;
271 }
272 }
273
274 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700275 * A request object to use for transmitting data to an ICC.
276 */
277 private static final class ManualNetworkSelectionArgument {
278 public OperatorInfo operatorInfo;
279 public boolean persistSelection;
280
281 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
282 this.operatorInfo = operatorInfo;
283 this.persistSelection = persistSelection;
284 }
285 }
286
287 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
289 * request after sending. The main thread will notify the request when it is complete.
290 */
291 private static final class MainThreadRequest {
292 /** The argument to use for the request */
293 public Object argument;
294 /** The result of the request that is run on the main thread */
295 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800296 // The subscriber id that this request applies to. Defaults to
297 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
298 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299
Nathan Harold92bed182018-10-12 18:16:49 -0700300 // In cases where subId is unavailable, the caller needs to specify the phone.
301 public Phone phone;
302
vagdeviaf9a5b92018-08-15 16:01:53 -0700303 public WorkSource workSource;
304
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305 public MainThreadRequest(Object argument) {
306 this.argument = argument;
307 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800308
Nathan Harold92bed182018-10-12 18:16:49 -0700309 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
310 this.argument = argument;
311 if (phone != null) {
312 this.phone = phone;
313 }
314 this.workSource = workSource;
315 }
316
vagdeviaf9a5b92018-08-15 16:01:53 -0700317 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800318 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800319 if (subId != null) {
320 this.subId = subId;
321 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700322 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 }
325
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800326 private static final class IncomingThirdPartyCallArgs {
327 public final ComponentName component;
328 public final String callId;
329 public final String callerDisplayName;
330
331 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
332 String callerDisplayName) {
333 this.component = component;
334 this.callId = callId;
335 this.callerDisplayName = callerDisplayName;
336 }
337 }
338
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 /**
340 * A handler that processes messages on the main thread in the phone process. Since many
341 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
342 * inbound binder threads to the main thread in the phone process. The Binder thread
343 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
344 * on, which will be notified when the operation completes and will contain the result of the
345 * request.
346 *
347 * <p>If a MainThreadRequest object is provided in the msg.obj field,
348 * note that request.result must be set to something non-null for the calling thread to
349 * unblock.
350 */
351 private final class MainThreadHandler extends Handler {
352 @Override
353 public void handleMessage(Message msg) {
354 MainThreadRequest request;
355 Message onCompleted;
356 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800357 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700358 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
360 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700361 case CMD_HANDLE_USSD_REQUEST: {
362 request = (MainThreadRequest) msg.obj;
363 final Phone phone = getPhoneFromRequest(request);
364 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
365 String ussdRequest = ussdObject.first;
366 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700367
Pengquan Menga1bb6272018-09-06 09:59:22 -0700368 if (!isUssdApiAllowed(request.subId)) {
369 // Carrier does not support use of this API, return failure.
370 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
371 UssdResponse response = new UssdResponse(ussdRequest, null);
372 Bundle returnData = new Bundle();
373 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
374 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700375
Pengquan Menga1bb6272018-09-06 09:59:22 -0700376 request.result = true;
377 notifyRequester(request);
378 return;
379 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700380
Pengquan Menga1bb6272018-09-06 09:59:22 -0700381 try {
382 request.result = phone != null
383 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
384 } catch (CallStateException cse) {
385 request.result = false;
386 }
387 // Wake up the requesting thread
388 notifyRequester(request);
389 break;
pkanwar32d516d2016-10-14 19:37:38 -0700390 }
391
Yorke Lee716f67e2015-06-17 15:39:16 -0700392 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700394 final Phone phone = getPhoneFromRequest(request);
395 request.result = phone != null ?
396 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
397 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700399 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700403 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700404 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700405 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800406 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700407 if (uiccCard == null) {
408 loge("iccTransmitApduLogicalChannel: No UICC");
409 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700410 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700411 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
413 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700414 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 iccArgument.channel, iccArgument.cla, iccArgument.command,
416 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 break;
420
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700422 ar = (AsyncResult) msg.obj;
423 request = (MainThreadRequest) ar.userObj;
424 if (ar.exception == null && ar.result != null) {
425 request.result = ar.result;
426 } else {
427 request.result = new IccIoResult(0x6F, 0, (byte[])null);
428 if (ar.result == null) {
429 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800430 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800432 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 } else {
434 loge("iccTransmitApduLogicalChannel: Unknown exception");
435 }
436 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700437 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 break;
439
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
441 request = (MainThreadRequest) msg.obj;
442 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800443 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 if (uiccCard == null) {
445 loge("iccTransmitApduBasicChannel: No UICC");
446 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700447 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 } else {
449 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
450 request);
451 uiccCard.iccTransmitApduBasicChannel(
452 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
453 iccArgument.p3, iccArgument.data, onCompleted);
454 }
455 break;
456
457 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
458 ar = (AsyncResult) msg.obj;
459 request = (MainThreadRequest) ar.userObj;
460 if (ar.exception == null && ar.result != null) {
461 request.result = ar.result;
462 } else {
463 request.result = new IccIoResult(0x6F, 0, (byte[])null);
464 if (ar.result == null) {
465 loge("iccTransmitApduBasicChannel: Empty response");
466 } else if (ar.exception instanceof CommandException) {
467 loge("iccTransmitApduBasicChannel: CommandException: " +
468 ar.exception);
469 } else {
470 loge("iccTransmitApduBasicChannel: Unknown exception");
471 }
472 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700473 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 break;
475
476 case CMD_EXCHANGE_SIM_IO:
477 request = (MainThreadRequest) msg.obj;
478 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800479 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 if (uiccCard == null) {
481 loge("iccExchangeSimIO: No UICC");
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 } else {
485 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
486 request);
487 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
488 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
489 iccArgument.data, onCompleted);
490 }
491 break;
492
493 case EVENT_EXCHANGE_SIM_IO_DONE:
494 ar = (AsyncResult) msg.obj;
495 request = (MainThreadRequest) ar.userObj;
496 if (ar.exception == null && ar.result != null) {
497 request.result = ar.result;
498 } else {
499 request.result = new IccIoResult(0x6f, 0, (byte[])null);
500 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700501 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 break;
503
Derek Tan4d5e5c12014-02-04 11:54:58 -0800504 case CMD_SEND_ENVELOPE:
505 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700507 if (uiccCard == null) {
508 loge("sendEnvelopeWithStatus: No UICC");
509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700510 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700511 } else {
512 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
513 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
514 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800515 break;
516
517 case EVENT_SEND_ENVELOPE_DONE:
518 ar = (AsyncResult) msg.obj;
519 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700520 if (ar.exception == null && ar.result != null) {
521 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800522 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700523 request.result = new IccIoResult(0x6F, 0, (byte[])null);
524 if (ar.result == null) {
525 loge("sendEnvelopeWithStatus: Empty response");
526 } else if (ar.exception instanceof CommandException) {
527 loge("sendEnvelopeWithStatus: CommandException: " +
528 ar.exception);
529 } else {
530 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
531 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800532 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800534 break;
535
Shishir Agrawal566b7612013-10-28 14:41:00 -0700536 case CMD_OPEN_CHANNEL:
537 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800539 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 if (uiccCard == null) {
541 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800542 request.result = new IccOpenLogicalChannelResponse(-1,
543 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 } else {
546 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800547 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
548 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700549 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 break;
551
552 case EVENT_OPEN_CHANNEL_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 int[] result = (int[]) ar.result;
558 int channelId = result[0];
559 byte[] selectResponse = null;
560 if (result.length > 1) {
561 selectResponse = new byte[result.length - 1];
562 for (int i = 1; i < result.length; ++i) {
563 selectResponse[i - 1] = (byte) result[i];
564 }
565 }
566 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700567 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 if (ar.result == null) {
570 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 if (ar.exception != null) {
573 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
574 }
575
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700576 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700577 if (ar.exception instanceof CommandException) {
578 CommandException.Error error =
579 ((CommandException) (ar.exception)).getCommandError();
580 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700581 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700582 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700583 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 }
585 }
586 openChannelResp = new IccOpenLogicalChannelResponse(
587 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700589 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 break;
592
593 case CMD_CLOSE_CHANNEL:
594 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800595 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 if (uiccCard == null) {
597 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900598 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
602 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
603 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 break;
605
606 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800607 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
608 break;
609
610 case CMD_NV_READ_ITEM:
611 request = (MainThreadRequest) msg.obj;
612 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700613 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800614 break;
615
616 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 ar = (AsyncResult) msg.obj;
618 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800619 if (ar.exception == null && ar.result != null) {
620 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800622 request.result = "";
623 if (ar.result == null) {
624 loge("nvReadItem: Empty response");
625 } else if (ar.exception instanceof CommandException) {
626 loge("nvReadItem: CommandException: " +
627 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800629 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
631 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
Jake Hambye994d462014-02-03 13:10:13 -0800635 case CMD_NV_WRITE_ITEM:
636 request = (MainThreadRequest) msg.obj;
637 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
638 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700639 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
640 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800641 break;
642
643 case EVENT_NV_WRITE_ITEM_DONE:
644 handleNullReturnEvent(msg, "nvWriteItem");
645 break;
646
647 case CMD_NV_WRITE_CDMA_PRL:
648 request = (MainThreadRequest) msg.obj;
649 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
650 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
651 break;
652
653 case EVENT_NV_WRITE_CDMA_PRL_DONE:
654 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
655 break;
656
chen xu6dac5ab2018-10-26 17:39:23 -0700657 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800658 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700659 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
660 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800661 break;
662
chen xu6dac5ab2018-10-26 17:39:23 -0700663 case EVENT_RESET_MODEM_CONFIG_DONE:
664 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800665 break;
666
Jake Hamby7c27be32014-03-03 13:25:59 -0800667 case CMD_GET_PREFERRED_NETWORK_TYPE:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700670 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800671 break;
672
673 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
674 ar = (AsyncResult) msg.obj;
675 request = (MainThreadRequest) ar.userObj;
676 if (ar.exception == null && ar.result != null) {
677 request.result = ar.result; // Integer
678 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800679 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800680 if (ar.result == null) {
681 loge("getPreferredNetworkType: Empty response");
682 } else if (ar.exception instanceof CommandException) {
683 loge("getPreferredNetworkType: CommandException: " +
684 ar.exception);
685 } else {
686 loge("getPreferredNetworkType: Unknown exception");
687 }
688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800690 break;
691
692 case CMD_SET_PREFERRED_NETWORK_TYPE:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
695 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700696 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 break;
698
699 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
700 handleNullReturnEvent(msg, "setPreferredNetworkType");
701 break;
702
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000703 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
704 request = (MainThreadRequest)msg.obj;
705 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700706 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000707 break;
708
709 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
710 ar = (AsyncResult)msg.obj;
711 request = (MainThreadRequest)ar.userObj;
712 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000714 break;
715
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800716 case CMD_SET_VOICEMAIL_NUMBER:
717 request = (MainThreadRequest) msg.obj;
718 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
719 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800720 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
721 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800722 break;
723
724 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
725 handleNullReturnEvent(msg, "setVoicemailNumber");
726 break;
727
Stuart Scott54788802015-03-30 13:18:01 -0700728 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
729 request = (MainThreadRequest) msg.obj;
730 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
731 request);
732 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
733 break;
734
735 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
736 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
737 break;
738
Shishir Agrawal302c8692015-06-19 13:49:39 -0700739 case CMD_PERFORM_NETWORK_SCAN:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
742 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
743 break;
744
745 case EVENT_PERFORM_NETWORK_SCAN_DONE:
746 ar = (AsyncResult) msg.obj;
747 request = (MainThreadRequest) ar.userObj;
748 CellNetworkScanResult cellScanResult;
749 if (ar.exception == null && ar.result != null) {
750 cellScanResult = new CellNetworkScanResult(
751 CellNetworkScanResult.STATUS_SUCCESS,
752 (List<OperatorInfo>) ar.result);
753 } else {
754 if (ar.result == null) {
755 loge("getCellNetworkScanResults: Empty response");
756 }
757 if (ar.exception != null) {
758 loge("getCellNetworkScanResults: Exception: " + ar.exception);
759 }
760 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
761 if (ar.exception instanceof CommandException) {
762 CommandException.Error error =
763 ((CommandException) (ar.exception)).getCommandError();
764 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
765 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
766 } else if (error == CommandException.Error.GENERIC_FAILURE) {
767 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
768 }
769 }
770 cellScanResult = new CellNetworkScanResult(errorCode, null);
771 }
772 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700774 break;
775
776 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
777 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700778 ManualNetworkSelectionArgument selArg =
779 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700780 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
781 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700782 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
783 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700784 break;
785
786 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
789 if (ar.exception == null) {
790 request.result = true;
791 } else {
792 request.result = false;
793 loge("setNetworkSelectionModeManual " + ar.exception);
794 }
795 notifyRequester(request);
796 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 break;
798
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700799 case CMD_GET_MODEM_ACTIVITY_INFO:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700802 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700803 break;
804
805 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 if (ar.exception == null && ar.result != null) {
809 request.result = ar.result;
810 } else {
811 if (ar.result == null) {
812 loge("queryModemActivityInfo: Empty response");
813 } else if (ar.exception instanceof CommandException) {
814 loge("queryModemActivityInfo: CommandException: " +
815 ar.exception);
816 } else {
817 loge("queryModemActivityInfo: Unknown exception");
818 }
819 }
Amit Mahajand4766222016-01-28 15:28:28 -0800820 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
821 if (request.result == null) {
822 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
823 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700824 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700825 break;
826
Meng Wang1a7c35a2016-05-05 20:56:15 -0700827 case CMD_SET_ALLOWED_CARRIERS:
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
830 mPhone.setAllowedCarriers(
831 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700832 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700833 break;
834
835 case EVENT_SET_ALLOWED_CARRIERS_DONE:
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null && ar.result != null) {
839 request.result = ar.result;
840 } else {
841 if (ar.result == null) {
842 loge("setAllowedCarriers: Empty response");
843 } else if (ar.exception instanceof CommandException) {
844 loge("setAllowedCarriers: CommandException: " +
845 ar.exception);
846 } else {
847 loge("setAllowedCarriers: Unknown exception");
848 }
849 }
850 // Result cannot be null. Return -1 on error.
851 if (request.result == null) {
852 request.result = new int[]{-1};
853 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700854 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700855 break;
856
857 case CMD_GET_ALLOWED_CARRIERS:
858 request = (MainThreadRequest) msg.obj;
859 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700860 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700861 break;
862
863 case EVENT_GET_ALLOWED_CARRIERS_DONE:
864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result;
868 } else {
869 if (ar.result == null) {
870 loge("getAllowedCarriers: Empty response");
871 } else if (ar.exception instanceof CommandException) {
872 loge("getAllowedCarriers: CommandException: " +
873 ar.exception);
874 } else {
875 loge("getAllowedCarriers: Unknown exception");
876 }
877 }
878 // Result cannot be null. Return empty list of CarrierIdentifier.
879 if (request.result == null) {
880 request.result = new ArrayList<CarrierIdentifier>(0);
881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700883 break;
884
Nathan Haroldb3014052017-01-25 15:57:32 -0800885 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
886 ar = (AsyncResult) msg.obj;
887 request = (MainThreadRequest) ar.userObj;
888 if (ar.exception == null && ar.result != null) {
889 request.result = ar.result;
890 } else {
891 request.result = new IllegalArgumentException(
892 "Failed to retrieve Forbidden Plmns");
893 if (ar.result == null) {
894 loge("getForbiddenPlmns: Empty response");
895 } else {
896 loge("getForbiddenPlmns: Unknown exception");
897 }
898 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700899 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800900 break;
901
902 case CMD_GET_FORBIDDEN_PLMNS:
903 request = (MainThreadRequest) msg.obj;
904 uiccCard = getUiccCardFromRequest(request);
905 if (uiccCard == null) {
906 loge("getForbiddenPlmns() UiccCard is null");
907 request.result = new IllegalArgumentException(
908 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700909 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800910 break;
911 }
912 Integer appType = (Integer) request.argument;
913 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
914 if (uiccApp == null) {
915 loge("getForbiddenPlmns() no app with specified type -- "
916 + appType);
917 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700918 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800919 break;
920 } else {
921 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
922 + " specified type -- " + appType);
923 }
924 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
925 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
926 onCompleted);
927 break;
928
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000929 case CMD_SWITCH_SLOTS:
930 request = (MainThreadRequest) msg.obj;
931 int[] physicalSlots = (int[]) request.argument;
932 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
933 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
934 break;
935
936 case EVENT_SWITCH_SLOTS_DONE:
937 ar = (AsyncResult) msg.obj;
938 request = (MainThreadRequest) ar.userObj;
939 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700940 notifyRequester(request);
941 break;
942 case CMD_GET_NETWORK_SELECTION_MODE:
943 request = (MainThreadRequest) msg.obj;
944 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
945 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
946 break;
947
948 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 if (ar.exception != null) {
952 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
953 } else {
954 int mode = ((int[]) ar.result)[0];
955 if (mode == 0) {
956 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
957 } else {
958 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
959 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000960 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700961 notifyRequester(request);
962 break;
963 case CMD_GET_CDMA_ROAMING_MODE:
964 request = (MainThreadRequest) msg.obj;
965 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
966 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
967 break;
968 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
969 ar = (AsyncResult) msg.obj;
970 request = (MainThreadRequest) ar.userObj;
971 if (ar.exception != null) {
972 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
973 } else {
974 request.result = ((int[]) ar.result)[0];
975 }
976 notifyRequester(request);
977 break;
978 case CMD_SET_CDMA_ROAMING_MODE:
979 request = (MainThreadRequest) msg.obj;
980 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
981 int mode = (int) request.argument;
982 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
983 break;
984 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 request.result = ar.exception == null;
988 notifyRequester(request);
989 break;
990 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
991 request = (MainThreadRequest) msg.obj;
992 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
993 int subscriptionMode = (int) request.argument;
994 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
995 break;
996 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = ar.exception == null;
1000 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001001 break;
1002
Nathan Harold3ff88932018-08-14 10:19:49 -07001003 case CMD_GET_ALL_CELL_INFO:
1004 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001005 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001006 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001007 break;
1008
1009 case EVENT_GET_ALL_CELL_INFO_DONE:
1010 ar = (AsyncResult) msg.obj;
1011 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001012 // If a timeout occurs, the response will be null
1013 request.result = (ar.exception == null && ar.result != null)
1014 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001015 synchronized (request) {
1016 request.notifyAll();
1017 }
1018 break;
1019
1020 case CMD_GET_CELL_LOCATION: {
1021 request = (MainThreadRequest) msg.obj;
1022 WorkSource ws = (WorkSource) request.argument;
1023 Phone phone = getPhoneFromRequest(request);
1024 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1025 break;
1026 }
1027
1028 case EVENT_GET_CELL_LOCATION_DONE: {
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 if (ar.exception == null) {
1032 request.result = ar.result;
1033 } else {
1034 Phone phone = getPhoneFromRequest(request);
1035 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1036 ? new CdmaCellLocation() : new GsmCellLocation();
1037 }
1038
1039 synchronized (request) {
1040 request.notifyAll();
1041 }
1042 break;
1043 }
1044
chen xu6dac5ab2018-10-26 17:39:23 -07001045 case CMD_MODEM_REBOOT:
1046 request = (MainThreadRequest) msg.obj;
1047 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1048 mPhone.rebootModem(onCompleted);
1049 break;
1050
1051 case EVENT_CMD_MODEM_REBOOT_DONE:
1052 handleNullReturnEvent(msg, "rebootModem");
1053 break;
1054
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001055 default:
1056 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1057 break;
1058 }
1059 }
Jake Hambye994d462014-02-03 13:10:13 -08001060
Pengquan Menga1bb6272018-09-06 09:59:22 -07001061 private void notifyRequester(MainThreadRequest request) {
1062 synchronized (request) {
1063 request.notifyAll();
1064 }
1065 }
1066
Jake Hambye994d462014-02-03 13:10:13 -08001067 private void handleNullReturnEvent(Message msg, String command) {
1068 AsyncResult ar = (AsyncResult) msg.obj;
1069 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1070 if (ar.exception == null) {
1071 request.result = true;
1072 } else {
1073 request.result = false;
1074 if (ar.exception instanceof CommandException) {
1075 loge(command + ": CommandException: " + ar.exception);
1076 } else {
1077 loge(command + ": Unknown exception");
1078 }
1079 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001080 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001082 }
1083
1084 /**
1085 * Posts the specified command to be executed on the main thread,
1086 * waits for the request to complete, and returns the result.
1087 * @see #sendRequestAsync
1088 */
1089 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001090 return sendRequest(
1091 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001092 }
1093
1094 /**
1095 * Posts the specified command to be executed on the main thread,
1096 * waits for the request to complete, and returns the result.
1097 * @see #sendRequestAsync
1098 */
1099 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1100 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001101 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001102 }
1103
1104 /**
1105 * Posts the specified command to be executed on the main thread,
1106 * waits for the request to complete, and returns the result.
1107 * @see #sendRequestAsync
1108 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001109 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001110 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001111 }
1112
1113 /**
1114 * Posts the specified command to be executed on the main thread,
1115 * waits for the request to complete, and returns the result.
1116 * @see #sendRequestAsync
1117 */
Nathan Harold92bed182018-10-12 18:16:49 -07001118 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1119 return sendRequest(command, argument, subId, null, workSource);
1120 }
1121
1122 /**
1123 * Posts the specified command to be executed on the main thread,
1124 * waits for the request to complete, and returns the result.
1125 * @see #sendRequestAsync
1126 */
1127 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1128 return sendRequest(
1129 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1130 }
1131
1132 /**
1133 * Posts the specified command to be executed on the main thread,
1134 * waits for the request to complete, and returns the result.
1135 * @see #sendRequestAsync
1136 */
1137 private Object sendRequest(
1138 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1140 throw new RuntimeException("This method will deadlock if called from the main thread.");
1141 }
1142
Nathan Harold92bed182018-10-12 18:16:49 -07001143 MainThreadRequest request = null;
1144 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1145 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1146 } else if (phone != null) {
1147 request = new MainThreadRequest(argument, phone, workSource);
1148 } else {
1149 request = new MainThreadRequest(argument, subId, workSource);
1150 }
1151
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001152 Message msg = mMainThreadHandler.obtainMessage(command, request);
1153 msg.sendToTarget();
1154
1155 // Wait for the request to complete
1156 synchronized (request) {
1157 while (request.result == null) {
1158 try {
1159 request.wait();
1160 } catch (InterruptedException e) {
1161 // Do nothing, go back and wait until the request is complete
1162 }
1163 }
1164 }
1165 return request.result;
1166 }
1167
1168 /**
1169 * Asynchronous ("fire and forget") version of sendRequest():
1170 * Posts the specified command to be executed on the main thread, and
1171 * returns immediately.
1172 * @see #sendRequest
1173 */
1174 private void sendRequestAsync(int command) {
1175 mMainThreadHandler.sendEmptyMessage(command);
1176 }
1177
1178 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001179 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1180 * @see {@link #sendRequest(int,Object)}
1181 */
1182 private void sendRequestAsync(int command, Object argument) {
1183 MainThreadRequest request = new MainThreadRequest(argument);
1184 Message msg = mMainThreadHandler.obtainMessage(command, request);
1185 msg.sendToTarget();
1186 }
1187
1188 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189 * Initialize the singleton PhoneInterfaceManager instance.
1190 * This is only done once, at startup, from PhoneApp.onCreate().
1191 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001192 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001193 synchronized (PhoneInterfaceManager.class) {
1194 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001195 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 } else {
1197 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1198 }
1199 return sInstance;
1200 }
1201 }
1202
1203 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001204 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 mApp = app;
1206 mPhone = phone;
1207 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001208 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001209 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1210 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001211 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001212 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001213 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001214 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001215 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001216
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 publish();
1218 }
1219
1220 private void publish() {
1221 if (DBG) log("publish: " + this);
1222
1223 ServiceManager.addService("phone", this);
1224 }
1225
Stuart Scott584921c2015-01-15 17:10:34 -08001226 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001227 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1228 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001229 }
1230
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001231 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1232 Phone phone = getPhoneFromRequest(request);
1233 return phone == null ? null :
1234 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1235 }
1236
Wink Saville36469e72014-06-11 15:17:00 -07001237 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001238 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001239 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241
1242 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001243 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001244 }
1245
Wink Savilleb564aae2014-10-23 10:18:09 -07001246 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 if (DBG) log("dial: " + number);
1248 // No permission check needed here: This is just a wrapper around the
1249 // ACTION_DIAL intent, which is available to any app since it puts up
1250 // the UI before it does anything.
1251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001252 final long identity = Binder.clearCallingIdentity();
1253 try {
1254 String url = createTelUrl(number);
1255 if (url == null) {
1256 return;
1257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001259 // PENDING: should we just silently fail if phone is offhook or ringing?
1260 PhoneConstants.State state = mCM.getState(subId);
1261 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1262 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1263 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1264 mApp.startActivity(intent);
1265 }
1266 } finally {
1267 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 }
1269 }
1270
1271 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001272 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001273 }
1274
Wink Savilleb564aae2014-10-23 10:18:09 -07001275 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 if (DBG) log("call: " + number);
1277
1278 // This is just a wrapper around the ACTION_CALL intent, but we still
1279 // need to do a permission check since we're calling startActivity()
1280 // from the context of the phone app.
1281 enforceCallPermission();
1282
1283 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1284 != AppOpsManager.MODE_ALLOWED) {
1285 return;
1286 }
1287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001288 final long identity = Binder.clearCallingIdentity();
1289 try {
1290 String url = createTelUrl(number);
1291 if (url == null) {
1292 return;
1293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001295 boolean isValid = false;
1296 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1297 if (slist != null) {
1298 for (SubscriptionInfo subInfoRecord : slist) {
1299 if (subInfoRecord.getSubscriptionId() == subId) {
1300 isValid = true;
1301 break;
1302 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001303 }
Wink Saville08874612014-08-31 19:19:58 -07001304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001305 if (!isValid) {
1306 return;
1307 }
Wink Saville08874612014-08-31 19:19:58 -07001308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001309 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1310 intent.putExtra(SUBSCRIPTION_KEY, subId);
1311 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1312 mApp.startActivity(intent);
1313 } finally {
1314 Binder.restoreCallingIdentity(identity);
1315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 }
1317
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001319 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001320 }
1321
Wink Savilleb564aae2014-10-23 10:18:09 -07001322 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001323 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001324 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1325 }
1326
1327 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001328 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001329 }
1330
Wink Savilleb564aae2014-10-23 10:18:09 -07001331 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001332 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001333 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1334 }
1335
1336 /** {@hide} */
1337 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001338 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001339 }
1340
Wink Savilleb564aae2014-10-23 10:18:09 -07001341 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001343
1344 final long identity = Binder.clearCallingIdentity();
1345 try {
1346 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1347 checkSimPin.start();
1348 return checkSimPin.unlockSim(null, pin);
1349 } finally {
1350 Binder.restoreCallingIdentity(identity);
1351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001352 }
1353
Wink Saville9de0f752013-10-22 19:04:03 -07001354 /** {@hide} */
1355 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001357 }
1358
Wink Savilleb564aae2014-10-23 10:18:09 -07001359 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001361
1362 final long identity = Binder.clearCallingIdentity();
1363 try {
1364 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1365 checkSimPuk.start();
1366 return checkSimPuk.unlockSim(puk, pin);
1367 } finally {
1368 Binder.restoreCallingIdentity(identity);
1369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001370 }
1371
1372 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001373 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 * a synchronous one.
1375 */
1376 private static class UnlockSim extends Thread {
1377
1378 private final IccCard mSimCard;
1379
1380 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001381 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1382 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383
1384 // For replies from SimCard interface
1385 private Handler mHandler;
1386
1387 // For async handler to identify request type
1388 private static final int SUPPLY_PIN_COMPLETE = 100;
1389
1390 public UnlockSim(IccCard simCard) {
1391 mSimCard = simCard;
1392 }
1393
1394 @Override
1395 public void run() {
1396 Looper.prepare();
1397 synchronized (UnlockSim.this) {
1398 mHandler = new Handler() {
1399 @Override
1400 public void handleMessage(Message msg) {
1401 AsyncResult ar = (AsyncResult) msg.obj;
1402 switch (msg.what) {
1403 case SUPPLY_PIN_COMPLETE:
1404 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1405 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001406 mRetryCount = msg.arg1;
1407 if (ar.exception != null) {
1408 if (ar.exception instanceof CommandException &&
1409 ((CommandException)(ar.exception)).getCommandError()
1410 == CommandException.Error.PASSWORD_INCORRECT) {
1411 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1412 } else {
1413 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1414 }
1415 } else {
1416 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 mDone = true;
1419 UnlockSim.this.notifyAll();
1420 }
1421 break;
1422 }
1423 }
1424 };
1425 UnlockSim.this.notifyAll();
1426 }
1427 Looper.loop();
1428 }
1429
1430 /*
1431 * Use PIN or PUK to unlock SIM card
1432 *
1433 * If PUK is null, unlock SIM card with PIN
1434 *
1435 * If PUK is not null, unlock SIM card with PUK and set PIN code
1436 */
Wink Saville9de0f752013-10-22 19:04:03 -07001437 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438
1439 while (mHandler == null) {
1440 try {
1441 wait();
1442 } catch (InterruptedException e) {
1443 Thread.currentThread().interrupt();
1444 }
1445 }
1446 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1447
1448 if (puk == null) {
1449 mSimCard.supplyPin(pin, callback);
1450 } else {
1451 mSimCard.supplyPuk(puk, pin, callback);
1452 }
1453
1454 while (!mDone) {
1455 try {
1456 Log.d(LOG_TAG, "wait for done");
1457 wait();
1458 } catch (InterruptedException e) {
1459 // Restore the interrupted status
1460 Thread.currentThread().interrupt();
1461 }
1462 }
1463 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001464 int[] resultArray = new int[2];
1465 resultArray[0] = mResult;
1466 resultArray[1] = mRetryCount;
1467 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 }
1469 }
1470
1471 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001472 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001473
1474 }
1475
Wink Savilleb564aae2014-10-23 10:18:09 -07001476 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477 // No permission check needed here: this call is harmless, and it's
1478 // needed for the ServiceState.requestStateUpdate() call (which is
1479 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001480 final long identity = Binder.clearCallingIdentity();
1481 try {
1482 final Phone phone = getPhone(subId);
1483 if (phone != null) {
1484 phone.updateServiceLocation();
1485 }
1486 } finally {
1487 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 }
1490
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001491 @Override
1492 public boolean isRadioOn(String callingPackage) {
1493 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001494 }
1495
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001496 @Override
1497 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001499 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001500 return false;
1501 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001502
1503 final long identity = Binder.clearCallingIdentity();
1504 try {
1505 return isRadioOnForSubscriber(subId);
1506 } finally {
1507 Binder.restoreCallingIdentity(identity);
1508 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001509 }
1510
1511 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001512 final long identity = Binder.clearCallingIdentity();
1513 try {
1514 final Phone phone = getPhone(subId);
1515 if (phone != null) {
1516 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1517 } else {
1518 return false;
1519 }
1520 } finally {
1521 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523 }
1524
1525 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001526 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 }
Wink Saville36469e72014-06-11 15:17:00 -07001528
Wink Savilleb564aae2014-10-23 10:18:09 -07001529 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001531
1532 final long identity = Binder.clearCallingIdentity();
1533 try {
1534 final Phone phone = getPhone(subId);
1535 if (phone != null) {
1536 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1537 }
1538 } finally {
1539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001540 }
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
1543 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001544 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001545 }
1546
Wink Savilleb564aae2014-10-23 10:18:09 -07001547 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001548 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001549
1550 final long identity = Binder.clearCallingIdentity();
1551 try {
1552 final Phone phone = getPhone(subId);
1553 if (phone == null) {
1554 return false;
1555 }
1556 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1557 toggleRadioOnOffForSubscriber(subId);
1558 }
1559 return true;
1560 } finally {
1561 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
Wink Saville36469e72014-06-11 15:17:00 -07001564
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001565 public boolean needMobileRadioShutdown() {
1566 /*
1567 * If any of the Radios are available, it will need to be
1568 * shutdown. So return true if any Radio is available.
1569 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001570 final long identity = Binder.clearCallingIdentity();
1571 try {
1572 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1573 Phone phone = PhoneFactory.getPhone(i);
1574 if (phone != null && phone.isRadioAvailable()) return true;
1575 }
1576 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1577 return false;
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001580 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001581 }
1582
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001583 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001584 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001585 enforceModifyPermission();
1586
1587 final long identity = Binder.clearCallingIdentity();
1588 try {
1589 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1590 logv("Shutting down Phone " + i);
1591 shutdownRadioUsingPhoneId(i);
1592 }
1593 } finally {
1594 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001595 }
1596 }
1597
1598 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001599 Phone phone = PhoneFactory.getPhone(phoneId);
1600 if (phone != null && phone.isRadioAvailable()) {
1601 phone.shutdownRadio();
1602 }
1603 }
1604
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001607
1608 final long identity = Binder.clearCallingIdentity();
1609 try {
1610 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1611 if (defaultPhone != null) {
1612 defaultPhone.setRadioPower(turnOn);
1613 return true;
1614 } else {
1615 loge("There's no default phone.");
1616 return false;
1617 }
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001620 }
Wink Saville36469e72014-06-11 15:17:00 -07001621 }
1622
Wink Savilleb564aae2014-10-23 10:18:09 -07001623 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001625
1626 final long identity = Binder.clearCallingIdentity();
1627 try {
1628 final Phone phone = getPhone(subId);
1629 if (phone != null) {
1630 phone.setRadioPower(turnOn);
1631 return true;
1632 } else {
1633 return false;
1634 }
1635 } finally {
1636 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 }
1639
Wink Saville36469e72014-06-11 15:17:00 -07001640 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001641 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 public boolean enableDataConnectivity() {
1643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001644
1645 final long identity = Binder.clearCallingIdentity();
1646 try {
1647 int subId = mSubscriptionController.getDefaultDataSubId();
1648 final Phone phone = getPhone(subId);
1649 if (phone != null) {
1650 phone.setUserDataEnabled(true);
1651 return true;
1652 } else {
1653 return false;
1654 }
1655 } finally {
1656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
Wink Saville36469e72014-06-11 15:17:00 -07001660 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001661 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 public boolean disableDataConnectivity() {
1663 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001664
1665 final long identity = Binder.clearCallingIdentity();
1666 try {
1667 int subId = mSubscriptionController.getDefaultDataSubId();
1668 final Phone phone = getPhone(subId);
1669 if (phone != null) {
1670 phone.setUserDataEnabled(false);
1671 return true;
1672 } else {
1673 return false;
1674 }
1675 } finally {
1676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 }
1679
Sanket Padawe356d7632015-06-22 14:03:32 -07001680 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001681 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001682 final long identity = Binder.clearCallingIdentity();
1683 try {
1684 final Phone phone = getPhone(subId);
1685 if (phone != null) {
1686 return phone.isDataAllowed();
1687 } else {
1688 return false;
1689 }
1690 } finally {
1691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 }
1694
1695 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001696 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001697 }
1698
pkanwarae03a6b2016-11-06 20:37:09 -08001699 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001700 enforceCallPermission();
1701
1702 final long identity = Binder.clearCallingIdentity();
1703 try {
1704 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1705 return;
1706 }
1707 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1708 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1709 } finally {
1710 Binder.restoreCallingIdentity(identity);
1711 }
pkanwar32d516d2016-10-14 19:37:38 -07001712 };
1713
Wink Savilleb564aae2014-10-23 10:18:09 -07001714 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1720 return false;
1721 }
1722 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001729 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001730 }
1731
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001732 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 Phone phone = PhoneFactory.getPhone(slotIndex);
1736 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1737 PhoneConstantConversions.convertCallState(phone.getState());
1738 } finally {
1739 Binder.restoreCallingIdentity(identity);
1740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
1742
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1748 if (phone != null) {
1749 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1750 } else {
1751 return PhoneConstantConversions.convertDataState(
1752 PhoneConstants.DataState.DISCONNECTED);
1753 }
1754 } finally {
1755 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 }
1758
Sanket Padawe356d7632015-06-22 14:03:32 -07001759 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1764 if (phone != null) {
1765 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1766 } else {
1767 return TelephonyManager.DATA_ACTIVITY_NONE;
1768 }
1769 } finally {
1770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
1774 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001775 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001776 mPhone.getContext().getSystemService(AppOpsManager.class)
1777 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001778 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001779 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001780 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 }
1782
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001783 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 if (DBG_LOC) log("getCellLocation: is active user");
1787 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001788 int subId = mSubscriptionController.getDefaultDataSubId();
1789 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1790 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001791 return data;
1792 } finally {
1793 Binder.restoreCallingIdentity(identity);
1794 }
Svetoslav64fad262015-04-14 14:35:21 -07001795 }
1796
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001798 public String getNetworkCountryIsoForPhone(int phoneId) {
1799 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1800 // registered cell info, so return a NULL country instead.
1801 final long identity = Binder.clearCallingIdentity();
1802 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001803 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1804 // Get default phone in this case.
1805 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1806 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001807 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001808 // Todo: fix this when we can get the actual cellular network info when the device
1809 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001810 if (TelephonyManager.NETWORK_TYPE_IWLAN
1811 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1812 return "";
1813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001814 Phone phone = PhoneFactory.getPhone(phoneId);
1815 if (phone != null) {
1816 ServiceStateTracker sst = phone.getServiceStateTracker();
1817 if (sst != null) {
1818 LocaleTracker lt = sst.getLocaleTracker();
1819 if (lt != null) {
1820 return lt.getCurrentCountry();
1821 }
1822 }
1823 }
1824 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001825 } finally {
1826 Binder.restoreCallingIdentity(identity);
1827 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001828 }
1829
1830 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001832 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001833 }
1834
Sanket Padawe356d7632015-06-22 14:03:32 -07001835 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001836 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 mApp.enforceCallingOrSelfPermission(
1838 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001839
1840 final long identity = Binder.clearCallingIdentity();
1841 try {
1842 final Phone phone = getPhone(subId);
1843 if (phone != null) {
1844 phone.enableLocationUpdates();
1845 }
1846 } finally {
1847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 }
1850
1851 @Override
1852 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001853 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001854 }
1855
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001857 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 mApp.enforceCallingOrSelfPermission(
1859 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001860
1861 final long identity = Binder.clearCallingIdentity();
1862 try {
1863 final Phone phone = getPhone(subId);
1864 if (phone != null) {
1865 phone.disableLocationUpdates();
1866 }
1867 } finally {
1868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 }
1871
Nathan Harold31d7ff32018-10-15 20:20:30 -07001872 /**
1873 * Returns the target SDK version number for a given package name.
1874 *
1875 * @return target SDK if the package is found or INT_MAX.
1876 */
1877 private int getTargetSdk(String packageName) {
1878 try {
1879 final ApplicationInfo ai =
1880 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1881 if (ai != null) return ai.targetSdkVersion;
1882 } catch (PackageManager.NameNotFoundException unexpected) {
1883 }
1884 return Integer.MAX_VALUE;
1885 }
1886
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 @Override
1888 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001889 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1890 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001891 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1892 throw new SecurityException(
1893 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1894 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001895
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1897 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1898 return null;
1899 }
Svetoslav64fad262015-04-14 14:35:21 -07001900
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001901 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902
Nathan Haroldf180aac2018-06-01 18:43:55 -07001903 List<CellInfo> info = getAllCellInfo(callingPackage);
1904 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905
Nathan Haroldf180aac2018-06-01 18:43:55 -07001906 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1907 for (CellInfo ci : info) {
1908 if (ci instanceof CellInfoGsm) {
1909 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1910 } else if (ci instanceof CellInfoWcdma) {
1911 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001914 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917
1918 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001919 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001920 mPhone.getContext().getSystemService(AppOpsManager.class)
1921 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001922 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001923 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001924 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001927 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001928 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1932 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001933 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001934 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001935 if (info != null) cellInfos.addAll(info);
1936 }
1937 return cellInfos;
1938 } finally {
1939 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941 }
1942
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001943 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001945 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001946 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001947
1948 final long identity = Binder.clearCallingIdentity();
1949 try {
1950 mPhone.setCellInfoListRate(rateInMillis, workSource);
1951 } finally {
1952 Binder.restoreCallingIdentity(identity);
1953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
1955
Shishir Agrawala9f32182016-04-12 12:00:16 -07001956 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001957 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001958 Phone phone = PhoneFactory.getPhone(slotIndex);
1959 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001960 return null;
1961 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001962 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001963 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1964 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001965 return null;
1966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967
1968 final long identity = Binder.clearCallingIdentity();
1969 try {
1970 return phone.getImei();
1971 } finally {
1972 Binder.restoreCallingIdentity(identity);
1973 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001974 }
1975
1976 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001977 public String getTypeAllocationCodeForSlot(int slotIndex) {
1978 Phone phone = PhoneFactory.getPhone(slotIndex);
1979 String tac = null;
1980 if (phone != null) {
1981 String imei = phone.getImei();
1982 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1983 }
1984 return tac;
1985 }
1986
1987 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001988 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001989 Phone phone = PhoneFactory.getPhone(slotIndex);
1990 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001991 return null;
1992 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001993 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001994 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1995 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001996 return null;
1997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998
1999 final long identity = Binder.clearCallingIdentity();
2000 try {
2001 return phone.getMeid();
2002 } finally {
2003 Binder.restoreCallingIdentity(identity);
2004 }
Jack Yu2af8d712017-03-15 17:14:14 -07002005 }
2006
2007 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002008 public String getManufacturerCodeForSlot(int slotIndex) {
2009 Phone phone = PhoneFactory.getPhone(slotIndex);
2010 String manufacturerCode = null;
2011 if (phone != null) {
2012 String meid = phone.getMeid();
2013 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2014 }
2015 return manufacturerCode;
2016 }
2017
2018 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002019 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002020 Phone phone = PhoneFactory.getPhone(slotIndex);
2021 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002022 return null;
2023 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002024 int subId = phone.getSubId();
2025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2026 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2027 return null;
2028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002029
2030 final long identity = Binder.clearCallingIdentity();
2031 try {
2032 return phone.getDeviceSvn();
2033 } finally {
2034 Binder.restoreCallingIdentity(identity);
2035 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002036 }
2037
fionaxu43304da2017-11-27 22:51:16 -08002038 @Override
2039 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 final long identity = Binder.clearCallingIdentity();
2041 try {
2042 final Phone phone = getPhone(subId);
2043 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2044 } finally {
2045 Binder.restoreCallingIdentity(identity);
2046 }
fionaxu43304da2017-11-27 22:51:16 -08002047 }
2048
2049 @Override
2050 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002051 final long identity = Binder.clearCallingIdentity();
2052 try {
2053 final Phone phone = getPhone(subId);
2054 return phone == null ? null : phone.getCarrierName();
2055 } finally {
2056 Binder.restoreCallingIdentity(identity);
2057 }
fionaxu43304da2017-11-27 22:51:16 -08002058 }
2059
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 //
2061 // Internal helper methods.
2062 //
2063
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002064 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2066 *
2067 * @throws SecurityException if the caller does not have the required permission
2068 */
2069 private void enforceModifyPermission() {
2070 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2071 }
2072
2073 /**
2074 * Make sure the caller has the CALL_PHONE permission.
2075 *
2076 * @throws SecurityException if the caller does not have the required permission
2077 */
2078 private void enforceCallPermission() {
2079 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2080 }
2081
Stuart Scott8eef64f2015-04-08 15:13:54 -07002082 private void enforceConnectivityInternalPermission() {
2083 mApp.enforceCallingOrSelfPermission(
2084 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2085 "ConnectivityService");
2086 }
2087
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 private String createTelUrl(String number) {
2089 if (TextUtils.isEmpty(number)) {
2090 return null;
2091 }
2092
Jake Hambye994d462014-02-03 13:10:13 -08002093 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 }
2095
Ihab Awadf9e92732013-12-05 18:02:52 -08002096 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2098 }
2099
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002100 private static void logv(String msg) {
2101 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2102 }
2103
Ihab Awadf9e92732013-12-05 18:02:52 -08002104 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2106 }
2107
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002108 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002110 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002111 }
2112
Sanket Padawe356d7632015-06-22 14:03:32 -07002113 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002114 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002115 final long identity = Binder.clearCallingIdentity();
2116 try {
2117 final Phone phone = PhoneFactory.getPhone(slotIndex);
2118 if (phone == null) {
2119 return PhoneConstants.PHONE_TYPE_NONE;
2120 } else {
2121 return phone.getPhoneType();
2122 }
2123 } finally {
2124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 }
2127
2128 /**
2129 * Returns the CDMA ERI icon index to display
2130 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002131 @Override
2132 public int getCdmaEriIconIndex(String callingPackage) {
2133 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002134 }
2135
Sanket Padawe356d7632015-06-22 14:03:32 -07002136 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002137 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002138 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002139 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002140 return -1;
2141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002142
2143 final long identity = Binder.clearCallingIdentity();
2144 try {
2145 final Phone phone = getPhone(subId);
2146 if (phone != null) {
2147 return phone.getCdmaEriIconIndex();
2148 } else {
2149 return -1;
2150 }
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 }
2155
2156 /**
2157 * Returns the CDMA ERI icon mode,
2158 * 0 - ON
2159 * 1 - FLASHING
2160 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002161 @Override
2162 public int getCdmaEriIconMode(String callingPackage) {
2163 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002164 }
2165
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002167 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002169 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002170 return -1;
2171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 final Phone phone = getPhone(subId);
2176 if (phone != null) {
2177 return phone.getCdmaEriIconMode();
2178 } else {
2179 return -1;
2180 }
2181 } finally {
2182 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 }
2185
2186 /**
2187 * Returns the CDMA ERI text,
2188 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002189 @Override
2190 public String getCdmaEriText(String callingPackage) {
2191 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
Sanket Padawe356d7632015-06-22 14:03:32 -07002194 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002195 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002197 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002198 return null;
2199 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200
2201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 final Phone phone = getPhone(subId);
2204 if (phone != null) {
2205 return phone.getCdmaEriText();
2206 } else {
2207 return null;
2208 }
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 }
2213
2214 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002215 * Returns the CDMA MDN.
2216 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002217 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002218 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2220 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002221
2222 final long identity = Binder.clearCallingIdentity();
2223 try {
2224 final Phone phone = getPhone(subId);
2225 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2226 return phone.getLine1Number();
2227 } else {
2228 return null;
2229 }
2230 } finally {
2231 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002232 }
2233 }
2234
2235 /**
2236 * Returns the CDMA MIN.
2237 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002238 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002239 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2241 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242
2243 final long identity = Binder.clearCallingIdentity();
2244 try {
2245 final Phone phone = getPhone(subId);
2246 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2247 return phone.getCdmaMin();
2248 } else {
2249 return null;
2250 }
2251 } finally {
2252 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002253 }
2254 }
2255
2256 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 * Returns true if CDMA provisioning needs to run.
2258 */
2259 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 final long identity = Binder.clearCallingIdentity();
2261 try {
2262 return mPhone.needsOtaServiceProvisioning();
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
2265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
2268 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002269 * Sets the voice mail number of a given subId.
2270 */
2271 @Override
2272 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002273 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002274
2275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2278 new Pair<String, String>(alphaTag, number), new Integer(subId));
2279 return success;
2280 } finally {
2281 Binder.restoreCallingIdentity(identity);
2282 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002283 }
2284
Ta-wei Yen87c49842016-05-13 21:19:52 -07002285 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002286 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2287 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2288 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2289 if (!TextUtils.equals(callingPackage, systemDialer)) {
2290 throw new SecurityException("caller must be system dialer");
2291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
2295 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2296 if (phoneAccountHandle == null) {
2297 return null;
2298 }
2299 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2300 } finally {
2301 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002302 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002303 }
2304
2305 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002306 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002307 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002309 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002310 return null;
2311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 return RemoteVvmTaskManager
2316 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2317 } finally {
2318 Binder.restoreCallingIdentity(identity);
2319 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002320 }
2321
2322 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002323 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2324 VisualVoicemailSmsFilterSettings settings) {
2325 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2330 mPhone.getContext(), callingPackage, subId, settings);
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
2333 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002334 }
2335
2336 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002337 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2338 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339
2340 final long identity = Binder.clearCallingIdentity();
2341 try {
2342 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2343 mPhone.getContext(), callingPackage, subId);
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
2346 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002347 }
2348
2349 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002350 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2351 String callingPackage, int subId) {
2352 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002353
2354 final long identity = Binder.clearCallingIdentity();
2355 try {
2356 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2357 mPhone.getContext(), callingPackage, subId);
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
2360 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002361 }
2362
2363 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002364 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002365 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002366
2367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2370 mPhone.getContext(), subId);
2371 } finally {
2372 Binder.restoreCallingIdentity(identity);
2373 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002374 }
2375
2376 @Override
2377 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2378 String number, int port, String text, PendingIntent sentIntent) {
2379 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002380 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002381 enforceSendSmsPermission();
2382 // Make the calls as the phone process.
2383 final long identity = Binder.clearCallingIdentity();
2384 try {
2385 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2386 if (port == 0) {
2387 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2388 sentIntent, null, false);
2389 } else {
2390 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2391 smsManager.sendDataMessageWithSelfPermissions(number, null,
2392 (short) port, data, sentIntent, null);
2393 }
2394 } finally {
2395 Binder.restoreCallingIdentity(identity);
2396 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002397 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002398 /**
fionaxu0152e512016-11-14 13:36:14 -08002399 * Sets the voice activation state of a given subId.
2400 */
2401 @Override
2402 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2404 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002405
2406 final long identity = Binder.clearCallingIdentity();
2407 try {
2408 final Phone phone = getPhone(subId);
2409 if (phone != null) {
2410 phone.setVoiceActivationState(activationState);
2411 } else {
2412 loge("setVoiceActivationState fails with invalid subId: " + subId);
2413 }
2414 } finally {
2415 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002416 }
2417 }
2418
2419 /**
2420 * Sets the data activation state of a given subId.
2421 */
2422 @Override
2423 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2425 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426
2427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 final Phone phone = getPhone(subId);
2430 if (phone != null) {
2431 phone.setDataActivationState(activationState);
2432 } else {
2433 loge("setVoiceActivationState fails with invalid subId: " + subId);
2434 }
2435 } finally {
2436 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002437 }
2438 }
2439
2440 /**
2441 * Returns the voice activation state of a given subId.
2442 */
2443 @Override
2444 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002445 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446
fionaxu0152e512016-11-14 13:36:14 -08002447 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 if (phone != null) {
2451 return phone.getVoiceActivationState();
2452 } else {
2453 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2454 }
2455 } finally {
2456 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002457 }
2458 }
2459
2460 /**
2461 * Returns the data activation state of a given subId.
2462 */
2463 @Override
2464 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002465 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466
fionaxu0152e512016-11-14 13:36:14 -08002467 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468 final long identity = Binder.clearCallingIdentity();
2469 try {
2470 if (phone != null) {
2471 return phone.getDataActivationState();
2472 } else {
2473 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2474 }
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002477 }
2478 }
2479
2480 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 * Returns the unread count of voicemails
2482 */
2483 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002484 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002485 }
2486
2487 /**
2488 * Returns the unread count of voicemails for a subId
2489 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002490 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 final Phone phone = getPhone(subId);
2495 if (phone != null) {
2496 return phone.getVoiceMessageCount();
2497 } else {
2498 return 0;
2499 }
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 }
2504
2505 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002506 * returns true, if the device is in a state where both voice and data
2507 * are supported simultaneously. This can change based on location or network condition.
2508 */
2509 @Override
2510 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 final Phone phone = getPhone(subId);
2514 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002518 }
2519
2520 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002521 * Send the dialer code if called from the current default dialer or the caller has
2522 * carrier privilege.
2523 * @param inputCode The dialer code to send
2524 */
2525 @Override
2526 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2527 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2528 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2529 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002530 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2531 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533
2534 final long identity = Binder.clearCallingIdentity();
2535 try {
2536 mPhone.sendDialerSpecialCode(inputCode);
2537 } finally {
2538 Binder.restoreCallingIdentity(identity);
2539 }
fionaxu235cc5e2017-03-06 22:25:57 -08002540 }
2541
2542 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002543 * Returns the data network type.
2544 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 *
2546 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2547 */
2548 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002549 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002550 final long identity = Binder.clearCallingIdentity();
2551 try {
2552 final Phone phone = getPhone(getDefaultSubscription());
2553 if (phone != null) {
2554 return phone.getServiceState().getDataNetworkType();
2555 } else {
2556 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2557 }
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002560 }
Wink Saville36469e72014-06-11 15:17:00 -07002561 }
2562
Pengquan Menga1bb6272018-09-06 09:59:22 -07002563 @Override
2564 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002565 if (!isActiveSubscription(subId)) {
2566 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2567 }
2568
Pengquan Menga1bb6272018-09-06 09:59:22 -07002569 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2570 }
2571
Brad Ebinger35c841c2018-10-01 10:40:55 -07002572 @Override
2573 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2574 String callingPackage) throws RemoteException {
2575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2576 "addImsRegistrationCallback")) {
2577 return;
2578 }
2579 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2580 final long token = Binder.clearCallingIdentity();
2581 try {
2582 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2583 .addRegistrationCallbackForSubscription(c, subId);
2584 } finally {
2585 Binder.restoreCallingIdentity(token);
2586 }
2587 }
2588
2589 @Override
2590 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2591 String callingPackage) {
2592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2593 "removeImsRegistrationCallback")) {
2594 return;
2595 }
2596 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2597 Binder.withCleanCallingIdentity(() ->
2598 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2599 .removeRegistrationCallbackForSubscription(c, subId));
2600 }
2601
2602 @Override
2603 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2604 String callingPackage) throws RemoteException {
2605 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2606 "addMmTelCapabilityCallback")) {
2607 return;
2608 }
2609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2610 final long token = Binder.clearCallingIdentity();
2611 try {
2612 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2613 .addCapabilitiesCallbackForSubscription(c, subId);
2614 } finally {
2615 Binder.restoreCallingIdentity(token);
2616 }
2617 }
2618
2619 @Override
2620 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2621 String callingPackage) {
2622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2623 "removeMmTelCapabilityCallback")) {
2624 return;
2625 }
2626 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2627 Binder.withCleanCallingIdentity(() ->
2628 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2629 .removeCapabilitiesCallbackForSubscription(c, subId));
2630 }
2631
2632 @Override
2633 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2635 "isCapable")) {
2636 return false;
2637 }
2638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2639 final long token = Binder.clearCallingIdentity();
2640 try {
2641 return ImsManager.getInstance(mPhone.getContext(),
2642 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2643 } catch (ImsException e) {
2644 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2645 return false;
2646 } finally {
2647 Binder.restoreCallingIdentity(token);
2648 }
2649 }
2650
2651 @Override
2652 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2654 "isAvailable")) {
2655 return false;
2656 }
2657 final long token = Binder.clearCallingIdentity();
2658 try {
2659 Phone phone = getPhone(subId);
2660 if (phone == null) return false;
2661 return phone.isImsCapabilityAvailable(capability, regTech);
2662 } finally {
2663 Binder.restoreCallingIdentity(token);
2664 }
2665 }
2666
2667 @Override
2668 public boolean isAdvancedCallingSettingEnabled(int subId) {
2669 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2670 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2671 final long token = Binder.clearCallingIdentity();
2672 try {
2673 return ImsManager.getInstance(mPhone.getContext(),
2674 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2675 } finally {
2676 Binder.restoreCallingIdentity(token);
2677 }
2678 }
2679
2680 @Override
2681 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2683 "setAdvancedCallingSetting");
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2687 ImsManager.getInstance(mPhone.getContext(),
2688 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
2691 }
2692 }
2693
2694 @Override
2695 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2697 "isVtSettingEnabled")) {
2698 return false;
2699 }
2700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2703 return ImsManager.getInstance(mPhone.getContext(),
2704 getSlotIndexOrException(subId)).isVtEnabledByUser();
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
2707 }
2708 }
2709
2710 @Override
2711 public void setVtSetting(int subId, boolean isEnabled) {
2712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2713 "setVtSetting");
2714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2717 ImsManager.getInstance(mPhone.getContext(),
2718 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2719 } finally {
2720 Binder.restoreCallingIdentity(identity);
2721 }
2722 }
2723
2724 @Override
2725 public boolean isVoWiFiSettingEnabled(int subId) {
2726 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2730 return ImsManager.getInstance(mPhone.getContext(),
2731 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
2734 }
2735 }
2736
2737 @Override
2738 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2740 "setVoWiFiSetting");
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2744 ImsManager.getInstance(mPhone.getContext(),
2745 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2746 } finally {
2747 Binder.restoreCallingIdentity(identity);
2748 }
2749 }
2750
2751 @Override
2752 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2753 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2757 return ImsManager.getInstance(mPhone.getContext(),
2758 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2759 } finally {
2760 Binder.restoreCallingIdentity(identity);
2761 }
2762 }
2763
2764 @Override
2765 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2767 "setVoWiFiRoamingSetting");
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2771 ImsManager.getInstance(mPhone.getContext(),
2772 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
2776 }
2777
2778 @Override
2779 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2781 "setVoWiFiNonPersistent");
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2785 ImsManager.getInstance(mPhone.getContext(),
2786 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
2789 }
2790 }
2791
2792 @Override
2793 public int getVoWiFiModeSetting(int subId) {
2794 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2798 return ImsManager.getInstance(mPhone.getContext(),
2799 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2800 } finally {
2801 Binder.restoreCallingIdentity(identity);
2802 }
2803 }
2804
2805 @Override
2806 public void setVoWiFiModeSetting(int subId, int mode) {
2807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2808 "setVoWiFiModeSetting");
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2812 ImsManager.getInstance(mPhone.getContext(),
2813 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
2817 }
2818
2819 @Override
2820 public int getVoWiFiRoamingModeSetting(int subId) {
2821 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2825 return ImsManager.getInstance(mPhone.getContext(),
2826 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
2829 }
2830 }
2831
2832 @Override
2833 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2835 "setVoWiFiRoamingModeSetting");
2836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2839 ImsManager.getInstance(mPhone.getContext(),
2840 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
2843 }
2844 }
2845
2846 @Override
2847 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2849 "setRttCapabilityEnabled");
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2853 ImsManager.getInstance(mPhone.getContext(),
2854 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
2857 }
2858 }
2859
2860 @Override
2861 public boolean isTtyOverVolteEnabled(int subId) {
2862 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2866 return ImsManager.getInstance(mPhone.getContext(),
2867 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2868 } finally {
2869 Binder.restoreCallingIdentity(identity);
2870 }
2871 }
2872
2873 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2874 int slotId = SubscriptionManager.getSlotIndex(subId);
2875 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2876 throw new IllegalArgumentException("Invalid Subscription Id.");
2877 }
2878 return slotId;
2879 }
2880
Wink Saville36469e72014-06-11 15:17:00 -07002881 /**
2882 * Returns the network type for a subId
2883 */
2884 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002885 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002887 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002888 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2889 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone phone = getPhone(subId);
2894 if (phone != null) {
2895 return phone.getServiceState().getDataNetworkType();
2896 } else {
2897 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2898 }
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
2904 /**
2905 * Returns the data network type
2906 */
2907 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002908 public int getDataNetworkType(String callingPackage) {
2909 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002910 }
2911
2912 /**
2913 * Returns the data network type for a subId
2914 */
2915 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002916 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002918 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002919 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2920 }
2921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 final Phone phone = getPhone(subId);
2925 if (phone != null) {
2926 return phone.getServiceState().getDataNetworkType();
2927 } else {
2928 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
2935 /**
Wink Saville36469e72014-06-11 15:17:00 -07002936 * Returns the Voice network type for a subId
2937 */
2938 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002939 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002941 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002942 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2943 }
2944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 final long identity = Binder.clearCallingIdentity();
2946 try {
2947 final Phone phone = getPhone(subId);
2948 if (phone != null) {
2949 return phone.getServiceState().getVoiceNetworkType();
2950 } else {
2951 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2952 }
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 }
2957
2958 /**
2959 * @return true if a ICC card is present
2960 */
2961 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002962 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002963 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2964 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002965 }
2966
2967 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002968 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002969 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002970 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002971 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 final Phone phone = PhoneFactory.getPhone(slotIndex);
2975 if (phone != null) {
2976 return phone.getIccCard().hasIccCard();
2977 } else {
2978 return false;
2979 }
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983 }
2984
2985 /**
2986 * Return if the current radio is LTE on CDMA. This
2987 * is a tri-state return value as for a period of time
2988 * the mode may be unknown.
2989 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002990 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002992 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002994 @Override
2995 public int getLteOnCdmaMode(String callingPackage) {
2996 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002997 }
2998
Sanket Padawe356d7632015-06-22 14:03:32 -07002999 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003000 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003002 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003003 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3004 }
3005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 final Phone phone = getPhone(subId);
3009 if (phone == null) {
3010 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3011 } else {
3012 return phone.getLteOnCdmaMode();
3013 }
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003016 }
Wink Saville36469e72014-06-11 15:17:00 -07003017 }
3018
3019 public void setPhone(Phone phone) {
3020 mPhone = phone;
3021 }
3022
3023 /**
3024 * {@hide}
3025 * Returns Default subId, 0 in the case of single standby.
3026 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003027 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003028 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003029 }
3030
Shishir Agrawala9f32182016-04-12 12:00:16 -07003031 private int getSlotForDefaultSubscription() {
3032 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3033 }
3034
Wink Savilleb564aae2014-10-23 10:18:09 -07003035 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003036 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003038
Pengquan Menge92a50d2018-09-21 15:54:48 -07003039 private boolean isActiveSubscription(int subId) {
3040 return mSubscriptionController.isActiveSubId(subId);
3041 }
3042
Ihab Awadf2177b72013-11-25 13:33:23 -08003043 /**
3044 * @see android.telephony.TelephonyManager.WifiCallingChoices
3045 */
3046 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3050 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3051 getWhenToMakeWifiCallsDefaultPreference());
3052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003055 }
3056
3057 /**
3058 * @see android.telephony.TelephonyManager.WifiCallingChoices
3059 */
3060 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3064 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3065 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003069 }
3070
Sailesh Nepald1e68152013-12-12 19:08:02 -08003071 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003072 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003073 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003074 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003075
Shishir Agrawal566b7612013-10-28 14:41:00 -07003076 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003077 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3078 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3080 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 if (TextUtils.equals(ISDR_AID, aid)) {
3086 // Only allows LPA to open logical channel to ISD-R.
3087 ComponentInfo bestComponent =
3088 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3089 if (bestComponent == null
3090 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3091 loge("The calling package is not allowed to access ISD-R.");
3092 throw new SecurityException(
3093 "The calling package is not allowed to access ISD-R.");
3094 }
Derek Tan740e1672017-06-27 14:56:27 -07003095 }
Derek Tan740e1672017-06-27 14:56:27 -07003096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097 if (DBG) {
3098 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3099 }
3100 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3101 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3102 if (DBG) log("iccOpenLogicalChannel: " + response);
3103 return response;
3104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003107 }
3108
3109 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003110 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3112 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3117 if (channel < 0) {
3118 return false;
3119 }
3120 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3121 if (DBG) log("iccCloseLogicalChannel: " + success);
3122 return success;
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003125 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003126 }
3127
3128 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003129 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003130 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3132 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 final long identity = Binder.clearCallingIdentity();
3135 try {
3136 if (DBG) {
3137 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3138 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3139 + p3 + " data=" + data);
3140 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142 if (channel < 0) {
3143 return "";
3144 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3147 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3148 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 // Append the returned status code to the end of the response payload.
3151 String s = Integer.toHexString(
3152 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3153 if (response.payload != null) {
3154 s = IccUtils.bytesToHexString(response.payload) + s;
3155 }
3156 return s;
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003159 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003160 }
Jake Hambye994d462014-02-03 13:10:13 -08003161
Evan Charltonc66da362014-05-16 14:06:40 -07003162 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003163 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3164 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3166 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3172 && TextUtils.equals(ISDR_AID, data)) {
3173 // Only allows LPA to select ISD-R.
3174 ComponentInfo bestComponent =
3175 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3176 if (bestComponent == null
3177 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3178 loge("The calling package is not allowed to select ISD-R.");
3179 throw new SecurityException(
3180 "The calling package is not allowed to select ISD-R.");
3181 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003182 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184 if (DBG) {
3185 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3186 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3187 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3190 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3191 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 // Append the returned status code to the end of the response payload.
3194 String s = Integer.toHexString(
3195 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3196 if (response.payload != null) {
3197 s = IccUtils.bytesToHexString(response.payload) + s;
3198 }
3199 return s;
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003202 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003203 }
3204
3205 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003206 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003207 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3209 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 if (DBG) {
3214 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3215 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3216 }
3217
3218 IccIoResult response =
3219 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3220 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3221 subId);
3222
3223 if (DBG) {
3224 log("Exchange SIM_IO [R]" + response);
3225 }
3226
3227 byte[] result = null;
3228 int length = 2;
3229 if (response.payload != null) {
3230 length = 2 + response.payload.length;
3231 result = new byte[length];
3232 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3233 } else {
3234 result = new byte[length];
3235 }
3236
3237 result[length - 1] = (byte) response.sw2;
3238 result[length - 2] = (byte) response.sw1;
3239 return result;
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003242 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003243 }
3244
Nathan Haroldb3014052017-01-25 15:57:32 -08003245 /**
3246 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3247 * on a particular subscription
3248 */
sqianb6e41952018-03-12 14:54:01 -07003249 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3251 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3252 return null;
3253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254
3255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 if (appType != TelephonyManager.APPTYPE_USIM
3258 && appType != TelephonyManager.APPTYPE_SIM) {
3259 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3260 return null;
3261 }
3262 Object response = sendRequest(
3263 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3264 if (response instanceof String[]) {
3265 return (String[]) response;
3266 }
3267 // Response is an Exception of some kind,
3268 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003269 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270 } finally {
3271 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003272 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003273 }
3274
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003275 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003276 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3278 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3283 if (response.payload == null) {
3284 return "";
3285 }
Evan Charltonc66da362014-05-16 14:06:40 -07003286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287 // Append the returned status code to the end of the response payload.
3288 String s = Integer.toHexString(
3289 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3290 s = IccUtils.bytesToHexString(response.payload) + s;
3291 return s;
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
Evan Charltonc66da362014-05-16 14:06:40 -07003295 }
3296
Jake Hambye994d462014-02-03 13:10:13 -08003297 /**
3298 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3299 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3300 *
3301 * @param itemID the ID of the item to read
3302 * @return the NV item as a String, or null on error.
3303 */
3304 @Override
3305 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003306 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3308 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309
3310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003313 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3315 return value;
3316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
Jake Hambye994d462014-02-03 13:10:13 -08003319 }
3320
3321 /**
3322 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3323 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3324 *
3325 * @param itemID the ID of the item to read
3326 * @param itemValue the value to write, as a String
3327 * @return true on success; false on any failure
3328 */
3329 @Override
3330 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003331 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3333 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334
3335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3338 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003339 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3341 return success;
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
Jake Hambye994d462014-02-03 13:10:13 -08003345 }
3346
3347 /**
3348 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3349 * Used for device configuration by some CDMA operators.
3350 *
3351 * @param preferredRoamingList byte array containing the new PRL
3352 * @return true on success; false on any failure
3353 */
3354 @Override
3355 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3357 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358
3359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3362 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3363 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3364 return success;
3365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
Jake Hambye994d462014-02-03 13:10:13 -08003368 }
3369
3370 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003371 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003372 * Used for device configuration by some CDMA operators.
3373 *
chen xu6dac5ab2018-10-26 17:39:23 -07003374 * @param slotIndex - device slot.
3375 *
Jake Hambye994d462014-02-03 13:10:13 -08003376 * @return true on success; false on any failure
3377 */
3378 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003379 public boolean resetModemConfig(int slotIndex) {
3380 Phone phone = PhoneFactory.getPhone(slotIndex);
3381 if (phone != null) {
3382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3383 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003384
chen xu6dac5ab2018-10-26 17:39:23 -07003385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3388 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3389 return success;
3390 } finally {
3391 Binder.restoreCallingIdentity(identity);
3392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 }
chen xu6dac5ab2018-10-26 17:39:23 -07003394 return false;
3395 }
3396
3397 /**
3398 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3399 *
3400 * @param slotIndex - device slot.
3401 *
3402 * @return true on success; false on any failure
3403 */
3404 @Override
3405 public boolean rebootModem(int slotIndex) {
3406 Phone phone = PhoneFactory.getPhone(slotIndex);
3407 if (phone != null) {
3408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3409 mApp, phone.getSubId(), "rebootModem");
3410
3411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3414 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3415 return success;
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
3419 }
3420 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003421 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003422
Svet Ganovb320e182015-04-16 12:30:10 -07003423 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003424 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003425 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003426 return new String[0];
3427 }
3428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 return mPhone.getPcscfAddress(apnType);
3432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
Wink Saville36469e72014-06-11 15:17:00 -07003435 }
3436
Brad Ebinger51f743a2017-01-23 13:50:20 -08003437 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003438 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3439 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003440 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003441 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003442 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 PhoneFactory.getImsResolver().enableIms(slotId);
3447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003450 }
3451
3452 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003453 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3454 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003455 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003456 public void disableIms(int slotId) {
3457 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003458
3459 final long identity = Binder.clearCallingIdentity();
3460 try {
3461 PhoneFactory.getImsResolver().disableIms(slotId);
3462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003465 }
3466
3467 /**
3468 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3469 * feature or {@link null} if the service is not available. If the feature is available, the
3470 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3471 */
3472 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003473 IImsServiceFeatureCallback callback) {
3474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003475
3476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003482 }
3483
3484 /**
3485 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3486 * feature during emergency calling or {@link null} if the service is not available. If the
3487 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3488 * listener for feature updates.
3489 */
3490 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3496 } finally {
3497 Binder.restoreCallingIdentity(identity);
3498 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003499 }
3500
Brad Ebinger5f64b052017-12-14 14:26:15 -08003501 /**
3502 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3503 * specified.
3504 */
3505 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003514 }
3515
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003516 /**
3517 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3518 * specified.
3519 */
3520 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3521 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522
3523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3526 } finally {
3527 Binder.restoreCallingIdentity(identity);
3528 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003529 }
3530
Brad Ebinger884c07b2018-02-15 16:17:40 -08003531 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003532 * Sets the ImsService Package Name that Telephony will bind to.
3533 *
3534 * @param slotId the slot ID that the ImsService should bind for.
3535 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3536 * ImsService is the device default ImsService.
3537 * @param packageName The package name of the application that contains the ImsService to bind
3538 * to.
3539 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3540 * @hide
3541 */
3542 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003543 int[] subIds = SubscriptionManager.getSubId(slotId);
3544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3545 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3546 "setImsService");
3547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3551 isCarrierImsService, packageName);
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003555 }
3556
3557 /**
3558 * Return the ImsService configuration.
3559 *
3560 * @param slotId The slot that the ImsService is associated with.
3561 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3562 * the device default.
3563 * @return the package name of the ImsService configuration.
3564 */
3565 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003566 int[] subIds = SubscriptionManager.getSubId(slotId);
3567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3568 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3569 "getImsService");
3570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3574 isCarrierImsService);
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003578 }
3579
Wink Saville36469e72014-06-11 15:17:00 -07003580 public void setImsRegistrationState(boolean registered) {
3581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003582
3583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 mPhone.setImsRegistrationState(registered);
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
Wink Saville36469e72014-06-11 15:17:00 -07003589 }
3590
3591 /**
Stuart Scott54788802015-03-30 13:18:01 -07003592 * Set the network selection mode to automatic.
3593 *
3594 */
3595 @Override
3596 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3598 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599
Pengquan Menge92a50d2018-09-21 15:54:48 -07003600 if (!isActiveSubscription(subId)) {
3601 return;
3602 }
3603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3607 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3608 } finally {
3609 Binder.restoreCallingIdentity(identity);
3610 }
Stuart Scott54788802015-03-30 13:18:01 -07003611 }
3612
Pengquan Mengea84e042018-09-20 14:57:26 -07003613 /**
3614 * Ask the radio to connect to the input network and change selection mode to manual.
3615 *
3616 * @param subId the id of the subscription.
3617 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3618 * the operator to attach to.
3619 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3620 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3621 * normal network selection next time.
3622 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003623 */
3624 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003625 public boolean setNetworkSelectionModeManual(
3626 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3628 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003629
3630 if (!isActiveSubscription(subId)) {
3631 return false;
3632 }
3633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003634 final long identity = Binder.clearCallingIdentity();
3635 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003636 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003638 if (DBG) {
3639 log("setNetworkSelectionModeManual: subId: " + subId
3640 + " operator: " + operatorInfo);
3641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003646 }
3647
3648 /**
3649 * Scans for available networks.
3650 */
3651 @Override
3652 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3654 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655
Pengquan Menga1bb6272018-09-06 09:59:22 -07003656 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 try {
3658 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003659 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003664 }
3665
3666 /**
yinxub1bed742017-04-17 11:45:04 -07003667 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003668 *
yinxub1bed742017-04-17 11:45:04 -07003669 * @param subId id of the subscription
3670 * @param request contains the radio access networks with bands/channels to scan
3671 * @param messenger callback messenger for scan results or errors
3672 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003673 * @return the id of the requested scan which can be used to stop the scan.
3674 */
3675 @Override
3676 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3677 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3679 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 return mNetworkScanRequestTracker.startNetworkScan(
3684 request, messenger, binder, getPhone(subId));
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
yinxu504e1392017-04-12 16:03:22 -07003688 }
3689
3690 /**
3691 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003692 *
3693 * @param subId id of the subscription
3694 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003695 */
3696 @Override
3697 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3699 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003700
3701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
yinxu504e1392017-04-12 16:03:22 -07003707 }
3708
3709 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003710 * Get the calculated preferred network type.
3711 * Used for debugging incorrect network type.
3712 *
3713 * @return the preferred network type, defined in RILConstants.java.
3714 */
3715 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003716 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003718 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003719 return RILConstants.PREFERRED_NETWORK_MODE;
3720 }
3721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 // FIXME: need to get SubId from somewhere.
3725 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Junda Liu84d15a22014-07-02 11:21:04 -07003729 }
3730
3731 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003732 * Get the preferred network type.
3733 * Used for device configuration by some CDMA operators.
3734 *
3735 * @return the preferred network type, defined in RILConstants.java.
3736 */
3737 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003738 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3740 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741
3742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 if (DBG) log("getPreferredNetworkType");
3745 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3746 int networkType = (result != null ? result[0] : -1);
3747 if (DBG) log("getPreferredNetworkType: " + networkType);
3748 return networkType;
3749 } finally {
3750 Binder.restoreCallingIdentity(identity);
3751 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003752 }
3753
3754 /**
3755 * Set the preferred network type.
3756 * Used for device configuration by some CDMA operators.
3757 *
3758 * @param networkType the preferred network type, defined in RILConstants.java.
3759 * @return true on success; false on any failure.
3760 */
3761 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003762 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3764 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765
3766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3769 Boolean success = (Boolean) sendRequest(
3770 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3771 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3772 if (success) {
3773 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3774 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3775 }
3776 return success;
3777 } finally {
3778 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003779 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003780 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003781
3782 /**
Junda Liu475951f2014-11-07 16:45:03 -08003783 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3784 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3785 * tethering.
3786 *
3787 * @return 0: Not required. 1: required. 2: Not set.
3788 * @hide
3789 */
3790 @Override
3791 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003792 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793
3794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3797 Settings.Global.TETHER_DUN_REQUIRED, 2);
3798 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3799 // config_tether_apndata.
3800 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3801 dunRequired = 1;
3802 }
3803 return dunRequired;
3804 } finally {
3805 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003806 }
Junda Liu475951f2014-11-07 16:45:03 -08003807 }
3808
3809 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003810 * Set mobile data enabled
3811 * Used by the user through settings etc to turn on/off mobile data
3812 *
3813 * @param enable {@code true} turn turn data on, else {@code false}
3814 */
3815 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003816 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3818 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819
3820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 int phoneId = mSubscriptionController.getPhoneId(subId);
3823 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3824 Phone phone = PhoneFactory.getPhone(phoneId);
3825 if (phone != null) {
3826 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3827 phone.setUserDataEnabled(enable);
3828 } else {
3829 loge("setUserDataEnabled: no phone for subId=" + subId);
3830 }
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003833 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003834 }
3835
3836 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003837 * Get the user enabled state of Mobile Data.
3838 *
3839 * TODO: remove and use isUserDataEnabled.
3840 * This can't be removed now because some vendor codes
3841 * calls through ITelephony directly while they should
3842 * use TelephonyManager.
3843 *
3844 * @return true on enabled
3845 */
3846 @Override
3847 public boolean getDataEnabled(int subId) {
3848 return isUserDataEnabled(subId);
3849 }
3850
3851 /**
3852 * Get whether mobile data is enabled per user setting.
3853 *
3854 * There are other factors deciding whether mobile data is actually enabled, but they are
3855 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003856 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003857 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003858 *
3859 * @return {@code true} if data is enabled else {@code false}
3860 */
3861 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003862 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003863 try {
3864 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3865 null);
3866 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3868 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870
3871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 int phoneId = mSubscriptionController.getPhoneId(subId);
3874 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3875 Phone phone = PhoneFactory.getPhone(phoneId);
3876 if (phone != null) {
3877 boolean retVal = phone.isUserDataEnabled();
3878 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3879 return retVal;
3880 } else {
3881 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3882 return false;
3883 }
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003886 }
3887 }
3888
3889 /**
3890 * Get whether mobile data is enabled.
3891 *
3892 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3893 * whether mobile data is actually enabled.
3894 *
3895 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3896 *
3897 * @return {@code true} if data is enabled else {@code false}
3898 */
3899 @Override
3900 public boolean isDataEnabled(int subId) {
3901 try {
3902 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3903 null);
3904 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3906 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908
3909 final long identity = Binder.clearCallingIdentity();
3910 try {
3911 int phoneId = mSubscriptionController.getPhoneId(subId);
3912 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3913 Phone phone = PhoneFactory.getPhone(phoneId);
3914 if (phone != null) {
3915 boolean retVal = phone.isDataEnabled();
3916 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3917 return retVal;
3918 } else {
3919 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3920 return false;
3921 }
3922 } finally {
3923 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003924 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003925 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003926
3927 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003928 public int getCarrierPrivilegeStatus(int subId) {
3929 final Phone phone = getPhone(subId);
3930 if (phone == null) {
3931 loge("getCarrierPrivilegeStatus: Invalid subId");
3932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3933 }
3934 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003935 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003936 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003937 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3938 }
3939 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003940 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003941 }
Junda Liu29340342014-07-10 15:23:27 -07003942
3943 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003944 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3945 final Phone phone = getPhone(subId);
3946 if (phone == null) {
3947 loge("getCarrierPrivilegeStatus: Invalid subId");
3948 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3949 }
3950 UiccProfile profile =
3951 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3952 if (profile == null) {
3953 loge("getCarrierPrivilegeStatus: No UICC");
3954 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3955 }
3956 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3957 }
3958
3959 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003960 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003961 if (TextUtils.isEmpty(pkgName))
3962 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003963 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003964 if (card == null) {
3965 loge("checkCarrierPrivilegesForPackage: No UICC");
3966 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3967 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003968 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3969 }
3970
3971 @Override
3972 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003973 if (TextUtils.isEmpty(pkgName))
3974 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003975 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3976 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3977 UiccCard card = UiccController.getInstance().getUiccCard(i);
3978 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003979 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003980 continue;
3981 }
3982
3983 result = card.getCarrierPrivilegeStatus(
3984 mPhone.getContext().getPackageManager(), pkgName);
3985 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3986 break;
3987 }
3988 }
3989
3990 return result;
Junda Liu29340342014-07-10 15:23:27 -07003991 }
Derek Tan89e89d42014-07-08 17:00:10 -07003992
3993 @Override
Junda Liue64de782015-04-16 17:19:16 -07003994 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3995 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3996 loge("phoneId " + phoneId + " is not valid.");
3997 return null;
3998 }
3999 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004000 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004001 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004002 return null ;
4003 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004004 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004005 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004006 }
4007
Amith Yamasani6e118872016-02-19 12:53:51 -08004008 @Override
4009 public List<String> getPackagesWithCarrierPrivileges() {
4010 PackageManager pm = mPhone.getContext().getPackageManager();
4011 List<String> privilegedPackages = new ArrayList<>();
4012 List<PackageInfo> packages = null;
4013 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4014 UiccCard card = UiccController.getInstance().getUiccCard(i);
4015 if (card == null) {
4016 // No UICC in that slot.
4017 continue;
4018 }
4019 if (card.hasCarrierPrivilegeRules()) {
4020 if (packages == null) {
4021 // Only check packages in user 0 for now
4022 packages = pm.getInstalledPackagesAsUser(
4023 PackageManager.MATCH_DISABLED_COMPONENTS
4024 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4025 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4026 }
4027 for (int p = packages.size() - 1; p >= 0; p--) {
4028 PackageInfo pkgInfo = packages.get(p);
4029 if (pkgInfo != null && pkgInfo.packageName != null
4030 && card.getCarrierPrivilegeStatus(pkgInfo)
4031 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4032 privilegedPackages.add(pkgInfo.packageName);
4033 }
4034 }
4035 }
4036 }
4037 return privilegedPackages;
4038 }
4039
Wink Savilleb564aae2014-10-23 10:18:09 -07004040 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004041 final Phone phone = getPhone(subId);
4042 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004043 if (card == null) {
4044 loge("getIccId: No UICC");
4045 return null;
4046 }
4047 String iccId = card.getIccId();
4048 if (TextUtils.isEmpty(iccId)) {
4049 loge("getIccId: ICC ID is null or empty.");
4050 return null;
4051 }
4052 return iccId;
4053 }
4054
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004055 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004056 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4057 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004058 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4059 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 final String iccId = getIccId(subId);
4064 final Phone phone = getPhone(subId);
4065 if (phone == null) {
4066 return false;
4067 }
4068 final String subscriberId = phone.getSubscriberId();
4069
4070 if (DBG_MERGE) {
4071 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4072 + subscriberId + " to " + number);
4073 }
4074
4075 if (TextUtils.isEmpty(iccId)) {
4076 return false;
4077 }
4078
4079 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4080
4081 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4082 if (alphaTag == null) {
4083 editor.remove(alphaTagPrefKey);
4084 } else {
4085 editor.putString(alphaTagPrefKey, alphaTag);
4086 }
4087
4088 // Record both the line number and IMSI for this ICCID, since we need to
4089 // track all merged IMSIs based on line number
4090 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4091 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4092 if (number == null) {
4093 editor.remove(numberPrefKey);
4094 editor.remove(subscriberPrefKey);
4095 } else {
4096 editor.putString(numberPrefKey, number);
4097 editor.putString(subscriberPrefKey, subscriberId);
4098 }
4099
4100 editor.commit();
4101 return true;
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004104 }
Derek Tan7226c842014-07-02 17:42:23 -07004105 }
4106
4107 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004108 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004109 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004111 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004112 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004113 return null;
4114 }
Derek Tan97ebb422014-09-05 16:55:38 -07004115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 String iccId = getIccId(subId);
4119 if (iccId != null) {
4120 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4121 if (DBG_MERGE) {
4122 log("getLine1NumberForDisplay returning "
4123 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4124 }
4125 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4128 return null;
4129 } finally {
4130 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004131 }
Derek Tan7226c842014-07-02 17:42:23 -07004132 }
4133
4134 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004135 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004137 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004138 return null;
4139 }
Derek Tan97ebb422014-09-05 16:55:38 -07004140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 String iccId = getIccId(subId);
4144 if (iccId != null) {
4145 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4146 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4147 }
4148 return null;
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004151 }
Derek Tan7226c842014-07-02 17:42:23 -07004152 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004153
4154 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004155 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004156 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4157 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004159 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4160 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004161 return null;
4162 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004163
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004164 final long identity = Binder.clearCallingIdentity();
4165 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 final Context context = mPhone.getContext();
4167 final TelephonyManager tele = TelephonyManager.from(context);
4168 final SubscriptionManager sub = SubscriptionManager.from(context);
4169
4170 // Figure out what subscribers are currently active
4171 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4172 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4173 // the process, where TelephonyManager was instantiated.
4174 // Otherwise AppOps check will fail.
4175
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004176 final int[] subIds = sub.getActiveSubscriptionIdList();
4177 for (int subId : subIds) {
4178 activeSubscriberIds.add(tele.getSubscriberId(subId));
4179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180
4181 // First pass, find a number override for an active subscriber
4182 String mergeNumber = null;
4183 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4184 for (String key : prefs.keySet()) {
4185 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4186 final String subscriberId = (String) prefs.get(key);
4187 if (activeSubscriberIds.contains(subscriberId)) {
4188 final String iccId = key.substring(
4189 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4190 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4191 mergeNumber = (String) prefs.get(numberKey);
4192 if (DBG_MERGE) {
4193 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4194 + " for active subscriber " + subscriberId);
4195 }
4196 if (!TextUtils.isEmpty(mergeNumber)) {
4197 break;
4198 }
4199 }
4200 }
4201 }
4202
4203 // Shortcut when no active merged subscribers
4204 if (TextUtils.isEmpty(mergeNumber)) {
4205 return null;
4206 }
4207
4208 // Second pass, find all subscribers under that line override
4209 final ArraySet<String> result = new ArraySet<>();
4210 for (String key : prefs.keySet()) {
4211 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4212 final String number = (String) prefs.get(key);
4213 if (mergeNumber.equals(number)) {
4214 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4215 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4216 final String subscriberId = (String) prefs.get(subscriberKey);
4217 if (!TextUtils.isEmpty(subscriberId)) {
4218 result.add(subscriberId);
4219 }
4220 }
4221 }
4222 }
4223
4224 final String[] resultArray = result.toArray(new String[result.size()]);
4225 Arrays.sort(resultArray);
4226 if (DBG_MERGE) {
4227 Slog.d(LOG_TAG,
4228 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4229 }
4230 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004231 } finally {
4232 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004233 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004234 }
4235
4236 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004237 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004238 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4239 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240
4241 final long identity = Binder.clearCallingIdentity();
4242 try {
4243 final Phone phone = getPhone(subId);
4244 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004248 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004249
4250 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004251 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004252 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4253 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004254 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255
4256 final long identity = Binder.clearCallingIdentity();
4257 try {
4258 final Phone phone = getPhone(subId);
4259 if (phone == null) {
4260 return false;
4261 }
4262 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4263 cdmaNonRoamingList);
4264 } finally {
4265 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004266 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004267 }
4268
4269 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004270 @Deprecated
4271 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4272 enforceModifyPermission();
4273
4274 int returnValue = 0;
4275 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004276 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004277 if(result.exception == null) {
4278 if (result.result != null) {
4279 byte[] responseData = (byte[])(result.result);
4280 if(responseData.length > oemResp.length) {
4281 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4282 responseData.length + "bytes. Buffer Size is " +
4283 oemResp.length + "bytes.");
4284 }
4285 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4286 returnValue = responseData.length;
4287 }
4288 } else {
4289 CommandException ex = (CommandException) result.exception;
4290 returnValue = ex.getCommandError().ordinal();
4291 if(returnValue > 0) returnValue *= -1;
4292 }
4293 } catch (RuntimeException e) {
4294 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4295 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4296 if(returnValue > 0) returnValue *= -1;
4297 }
4298
4299 return returnValue;
4300 }
4301
4302 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004303 public void setRadioCapability(RadioAccessFamily[] rafs) {
4304 try {
4305 ProxyController.getInstance().setRadioCapability(rafs);
4306 } catch (RuntimeException e) {
4307 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4308 }
4309 }
4310
4311 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004312 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004313 Phone phone = PhoneFactory.getPhone(phoneId);
4314 if (phone == null) {
4315 return RadioAccessFamily.RAF_UNKNOWN;
4316 }
4317 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004318 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004319 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004320 return RadioAccessFamily.RAF_UNKNOWN;
4321 }
4322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004329 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004330
4331 @Override
4332 public void enableVideoCalling(boolean enable) {
4333 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334
4335 final long identity = Binder.clearCallingIdentity();
4336 try {
4337 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004341 }
4342
4343 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004344 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4346 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4347 return false;
4348 }
Svet Ganovb320e182015-04-16 12:30:10 -07004349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 // Check the user preference and the system-level IMS setting. Even if the user has
4353 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4354 // In the long run, we may instead need to check if there exists a connection service
4355 // which can support video calling.
4356 ImsManager imsManager =
4357 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4358 return imsManager.isVtEnabledByPlatform()
4359 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4360 && imsManager.isVtEnabledByUser();
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004364 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004365
Andrew Leea1239f22015-03-02 17:44:07 -08004366 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4369 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4370 return false;
4371 }
4372
4373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 CarrierConfigManager configManager =
4376 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4377 return configManager.getConfigForSubId(mPhone.getSubId())
4378 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
Andrew Leea1239f22015-03-02 17:44:07 -08004382 }
4383
4384 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385 public boolean isWorldPhone(int subId, String callingPackage) {
4386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4387 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4388 return false;
4389 }
4390
4391 final long identity = Binder.clearCallingIdentity();
4392 try {
4393 CarrierConfigManager configManager =
4394 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4395 return configManager.getConfigForSubId(mPhone.getSubId())
4396 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
Andrew Leea1239f22015-03-02 17:44:07 -08004400 }
4401
Andrew Lee9431b832015-03-09 18:46:45 -07004402 @Override
4403 public boolean isTtyModeSupported() {
4404 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004405 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004406 }
4407
4408 @Override
4409 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 final long identity = Binder.clearCallingIdentity();
4411 try {
4412 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
4415 }
Andrew Lee9431b832015-03-09 18:46:45 -07004416 }
4417
Hall Liu98187582018-01-22 19:15:32 -08004418 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4422 mPhone.getSubId()).getBoolean(
4423 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4424 boolean isDeviceSupported =
4425 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4426 return isCarrierSupported && isDeviceSupported;
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
Hall Liu98187582018-01-22 19:15:32 -08004430 }
4431
Hall Liu3ad5f012018-04-06 16:23:39 -07004432 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 final long identity = Binder.clearCallingIdentity();
4434 try {
4435 return isRttSupported() && Settings.Secure.getInt(
4436 mPhone.getContext().getContentResolver(),
4437 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4438 } finally {
4439 Binder.restoreCallingIdentity(identity);
4440 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004441 }
4442
Sanket Padawe7310cc72015-01-14 09:53:20 -08004443 /**
4444 * Returns the unique device ID of phone, for example, the IMEI for
4445 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4446 *
4447 * <p>Requires Permission:
4448 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4449 */
4450 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004451 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004452 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004453 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004454 return null;
4455 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004456 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004457 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4458 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004459 return null;
4460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
4464 return phone.getDeviceId();
4465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004468 }
4469
Ping Sunc67b7c22016-03-02 19:16:45 +08004470 /**
4471 * {@hide}
4472 * Returns the IMS Registration Status on a particular subid
4473 *
4474 * @param subId
4475 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004476 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004477 Phone phone = getPhone(subId);
4478 if (phone != null) {
4479 return phone.isImsRegistered();
4480 } else {
4481 return false;
4482 }
4483 }
4484
Santos Cordon7a1885b2015-02-03 11:15:19 -08004485 @Override
4486 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 final long identity = Binder.clearCallingIdentity();
4488 try {
4489 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004493 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004494
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004495 /**
4496 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004497 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004498 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 final long identity = Binder.clearCallingIdentity();
4500 try {
4501 Phone phone = getPhone(subId);
4502 if (phone != null) {
4503 return phone.isWifiCallingEnabled();
4504 } else {
4505 return false;
4506 }
4507 } finally {
4508 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004509 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004510 }
4511
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004512 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004513 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004514 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004515 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 final long identity = Binder.clearCallingIdentity();
4517 try {
4518 Phone phone = getPhone(subId);
4519 if (phone != null) {
4520 return phone.isVideoEnabled();
4521 } else {
4522 return false;
4523 }
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004526 }
4527 }
4528
4529 /**
4530 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4531 * defined in {@link ImsRegistrationImplBase}.
4532 */
4533 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 final long identity = Binder.clearCallingIdentity();
4535 try {
4536 Phone phone = getPhone(subId);
4537 if (phone != null) {
4538 return phone.getImsRegistrationTech();
4539 } else {
4540 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4541 }
4542 } finally {
4543 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004544 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004545 }
4546
Stuart Scott8eef64f2015-04-08 15:13:54 -07004547 @Override
4548 public void factoryReset(int subId) {
4549 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004550 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4551 return;
4552 }
4553
Svet Ganovcc087f82015-05-12 20:35:54 -07004554 final long identity = Binder.clearCallingIdentity();
4555 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004556 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4557 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004558 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004559 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004560 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4561 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004562 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004563 }
4564 } finally {
4565 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004566 }
4567 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004568
4569 @Override
4570 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 final long identity = Binder.clearCallingIdentity();
4572 try {
4573 // We query all subscriptions instead of just the active ones, because
4574 // this might be called early on in the provisioning flow when the
4575 // subscriptions potentially aren't active yet.
4576 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4577 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004578 return null;
4579 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 // This function may be called very early, say, from the setup wizard, at
4582 // which point we won't have a default subscription set. If that's the case
4583 // we just choose the first, which will be valid in "most cases".
4584 final int defaultSubId = getDefaultSubscription();
4585 SubscriptionInfo info = null;
4586 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4587 info = slist.get(0);
4588 } else {
4589 for (SubscriptionInfo item : slist) {
4590 if (item.getSubscriptionId() == defaultSubId) {
4591 info = item;
4592 break;
4593 }
4594 }
4595
4596 if (info == null) {
4597 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004598 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004599 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 // Try and fetch the locale from the carrier properties or from the SIM language
4602 // preferences (EF-PL and EF-LI)...
4603 final int mcc = info.getMcc();
4604 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4605 String simLanguage = null;
4606 if (defaultPhone != null) {
4607 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4608 if (localeFromDefaultSim != null) {
4609 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4610 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4611 return localeFromDefaultSim.toLanguageTag();
4612 } else {
4613 simLanguage = localeFromDefaultSim.getLanguage();
4614 }
4615 }
4616 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004618 // The SIM language preferences only store a language (e.g. fr = French), not an
4619 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4620 // the SIM and carrier preferences does not include a country we add the country
4621 // determined from the SIM MCC to provide an exact locale.
4622 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4623 simLanguage);
4624 if (mccLocale != null) {
4625 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4626 return mccLocale.toLanguageTag();
4627 }
4628
4629 if (DBG) log("No locale found - returning null");
4630 return null;
4631 } finally {
4632 Binder.restoreCallingIdentity(identity);
4633 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004634 }
4635
4636 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 return mSubscriptionController.getAllSubInfoList(
4638 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004639 }
4640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 /**
4642 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4643 */
4644 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4645 return mSubscriptionController.getActiveSubscriptionInfoList(
4646 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004647 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004648
Chenjie Yu1ba97252018-01-11 18:16:20 -08004649 private final ModemActivityInfo mLastModemActivityInfo =
4650 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4651
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004652 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004653 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4654 * representing the state of the modem.
4655 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004656 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4657 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004658 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004659 */
4660 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004661 public void requestModemActivityInfo(ResultReceiver result) {
4662 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004663 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664
4665 final long identity = Binder.clearCallingIdentity();
4666 try {
4667 ModemActivityInfo ret = null;
4668 synchronized (mLastModemActivityInfo) {
4669 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4670 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004671 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004672 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4674 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4675 mergedTxTimeMs[i] =
4676 info.getTxTimeMillis()[i]
4677 + mLastModemActivityInfo.getTxTimeMillis()[i];
4678 }
4679 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4680 mLastModemActivityInfo.setSleepTimeMillis(
4681 info.getSleepTimeMillis()
4682 + mLastModemActivityInfo.getSleepTimeMillis());
4683 mLastModemActivityInfo.setIdleTimeMillis(
4684 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4685 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4686 mLastModemActivityInfo.setRxTimeMillis(
4687 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4688 mLastModemActivityInfo.setEnergyUsed(
4689 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4692 mLastModemActivityInfo.getSleepTimeMillis(),
4693 mLastModemActivityInfo.getIdleTimeMillis(),
4694 mLastModemActivityInfo.getTxTimeMillis(),
4695 mLastModemActivityInfo.getRxTimeMillis(),
4696 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 Bundle bundle = new Bundle();
4699 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4700 result.send(0, bundle);
4701 } finally {
4702 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004703 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004704 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004705
Siddharth Rayb8114062018-06-17 15:02:38 -07004706 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4707 // less than total activity duration.
4708 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4709 if (info == null) {
4710 return false;
4711 }
4712 int activityDurationMs =
4713 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4714 int totalTxTimeMs = 0;
4715 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4716 totalTxTimeMs += info.getTxTimeMillis()[i];
4717 }
4718 return (info.isValid()
4719 && (info.getSleepTimeMillis() <= activityDurationMs)
4720 && (info.getIdleTimeMillis() <= activityDurationMs)
4721 && (info.getRxTimeMillis() <= activityDurationMs)
4722 && (totalTxTimeMs <= activityDurationMs));
4723 }
4724
Jack Yu85bd38a2015-11-09 11:34:32 -08004725 /**
4726 * {@hide}
4727 * Returns the service state information on specified subscription.
4728 */
4729 @Override
4730 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004731 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004732 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004733 return null;
4734 }
4735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736 final long identity = Binder.clearCallingIdentity();
4737 try {
4738 final Phone phone = getPhone(subId);
4739 if (phone == null) {
4740 return null;
4741 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 return phone.getServiceState();
4744 } finally {
4745 Binder.restoreCallingIdentity(identity);
4746 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004747 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004748
4749 /**
4750 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4751 *
4752 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4753 * voicemail ringtone.
4754 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4755 * PhoneAccount.
4756 */
4757 @Override
4758 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4762 if (phone == null) {
4763 phone = mPhone;
4764 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4767 } finally {
4768 Binder.restoreCallingIdentity(identity);
4769 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004770 }
4771
4772 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004773 * Sets the per-account voicemail ringtone.
4774 *
4775 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4776 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4777 *
4778 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4779 * voicemail ringtone.
4780 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4781 * PhoneAccount.
4782 */
4783 @Override
4784 public void setVoicemailRingtoneUri(String callingPackage,
4785 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4787 if (!TextUtils.equals(callingPackage,
4788 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4790 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4791 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793
4794 final long identity = Binder.clearCallingIdentity();
4795 try {
4796 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4797 if (phone == null) {
4798 phone = mPhone;
4799 }
4800 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4801 } finally {
4802 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004803 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004804 }
4805
4806 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004807 * Returns whether vibration is set for voicemail notification in Phone settings.
4808 *
4809 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4810 * voicemail vibration setting.
4811 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4812 */
4813 @Override
4814 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 final long identity = Binder.clearCallingIdentity();
4816 try {
4817 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4818 if (phone == null) {
4819 phone = mPhone;
4820 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4823 } finally {
4824 Binder.restoreCallingIdentity(identity);
4825 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004826 }
4827
Youhan Wange64578a2016-05-02 15:32:42 -07004828 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004829 * Sets the per-account voicemail vibration.
4830 *
4831 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4832 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4833 *
4834 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4835 * voicemail vibration setting.
4836 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4837 * specific PhoneAccount.
4838 */
4839 @Override
4840 public void setVoicemailVibrationEnabled(String callingPackage,
4841 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4842 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4843 if (!TextUtils.equals(callingPackage,
4844 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4846 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4847 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004848 }
4849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4853 if (phone == null) {
4854 phone = mPhone;
4855 }
4856 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4857 } finally {
4858 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004859 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004860 }
4861
4862 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004863 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4864 *
4865 * @throws SecurityException if the caller does not have the required permission
4866 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004867 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004869 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004870 }
4871
4872 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004873 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4874 * permission.
4875 *
4876 * @throws SecurityException if the caller does not have the required permission
4877 */
4878 private void enforceSendSmsPermission() {
4879 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4880 }
4881
4882 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004883 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004884 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004885 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004886 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004887 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
4890 ComponentName componentName =
4891 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4892 if (componentName == null) {
4893 throw new SecurityException(
4894 "Caller not current active visual voicemail package[null]");
4895 }
4896 String vvmPackage = componentName.getPackageName();
4897 if (!callingPackage.equals(vvmPackage)) {
4898 throw new SecurityException("Caller not current active visual voicemail package["
4899 + vvmPackage + "]");
4900 }
4901 } finally {
4902 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004903 }
4904 }
4905
4906 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004907 * Return the application ID for the app type.
4908 *
4909 * @param subId the subscription ID that this request applies to.
4910 * @param appType the uicc app type.
4911 * @return Application ID for specificied app type, or null if no uicc.
4912 */
4913 @Override
4914 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004915 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07004916 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917
4918 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004919 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004920 if (phone == null) {
4921 return null;
4922 }
4923 String aid = null;
4924 try {
4925 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4926 .getApplicationByType(appType).getAid();
4927 } catch (Exception e) {
4928 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4929 }
4930 return aid;
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004933 }
Youhan Wange64578a2016-05-02 15:32:42 -07004934 }
4935
Youhan Wang4001d252016-05-11 10:29:41 -07004936 /**
4937 * Return the Electronic Serial Number.
4938 *
4939 * @param subId the subscription ID that this request applies to.
4940 * @return ESN or null if error.
4941 */
4942 @Override
4943 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004944 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07004945 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946
4947 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004948 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 if (phone == null) {
4950 return null;
4951 }
4952 String esn = null;
4953 try {
4954 esn = phone.getEsn();
4955 } catch (Exception e) {
4956 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4957 }
4958 return esn;
4959 } finally {
4960 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004961 }
Youhan Wang4001d252016-05-11 10:29:41 -07004962 }
4963
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004964 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004965 * Return the Preferred Roaming List Version.
4966 *
4967 * @param subId the subscription ID that this request applies to.
4968 * @return PRLVersion or null if error.
4969 */
4970 @Override
4971 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07004973 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974
4975 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004976 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 if (phone == null) {
4978 return null;
4979 }
4980 String cdmaPrlVersion = null;
4981 try {
4982 cdmaPrlVersion = phone.getCdmaPrlVersion();
4983 } catch (Exception e) {
4984 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4985 }
4986 return cdmaPrlVersion;
4987 } finally {
4988 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004989 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004990 }
4991
4992 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004993 * Get snapshot of Telephony histograms
4994 * @return List of Telephony histograms
4995 * @hide
4996 */
4997 @Override
4998 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5000 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001
5002 final long identity = Binder.clearCallingIdentity();
5003 try {
5004 return RIL.getTelephonyRILTimingHistograms();
5005 } finally {
5006 Binder.restoreCallingIdentity(identity);
5007 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005008 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005009
5010 /**
5011 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005012 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005013 * Require system privileges. In the future we may add this to carrier APIs.
5014 *
5015 * @return The number of carriers set successfully, should match length of carriers
5016 */
5017 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005018 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005019 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005021
Meng Wang9b7c4e92017-02-17 11:41:27 -08005022 if (carriers == null) {
5023 throw new NullPointerException("carriers cannot be null");
5024 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005029 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5030 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 return retVal[0];
5032 } finally {
5033 Binder.restoreCallingIdentity(identity);
5034 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005035 }
5036
5037 /**
5038 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005039 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005040 * Require system privileges. In the future we may add this to carrier APIs.
5041 *
5042 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5043 * means all carriers are allowed.
5044 */
5045 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005046 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005047 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005048 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049
5050 final long identity = Binder.clearCallingIdentity();
5051 try {
5052 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005053 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5054 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005055 } finally {
5056 Binder.restoreCallingIdentity(identity);
5057 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005058 }
5059
fionaxu59545b42016-05-25 15:53:37 -07005060 /**
5061 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5062 * @param subId the subscription ID that this action applies to.
5063 * @param enabled control enable or disable metered apns.
5064 * {@hide}
5065 */
5066 @Override
5067 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5068 enforceModifyPermission();
5069 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070
5071 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005072 if (phone == null) {
5073 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5074 return;
5075 }
5076 try {
5077 phone.carrierActionSetMeteredApnsEnabled(enabled);
5078 } catch (Exception e) {
5079 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 } finally {
5081 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005082 }
5083 }
5084
5085 /**
5086 * Action set from carrier signalling broadcast receivers to enable/disable radio
5087 * @param subId the subscription ID that this action applies to.
5088 * @param enabled control enable or disable radio.
5089 * {@hide}
5090 */
5091 @Override
5092 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5093 enforceModifyPermission();
5094 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095
5096 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005097 if (phone == null) {
5098 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5099 return;
5100 }
5101 try {
5102 phone.carrierActionSetRadioEnabled(enabled);
5103 } catch (Exception e) {
5104 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 } finally {
5106 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005107 }
5108 }
5109
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005110 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005111 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5112 * network status based on which carrier apps could apply actions accordingly,
5113 * enable/disable default url handler for example.
5114 *
5115 * @param subId the subscription ID that this action applies to.
5116 * @param report control start/stop reporting the default network status.
5117 * {@hide}
5118 */
5119 @Override
5120 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5121 enforceModifyPermission();
5122 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123
5124 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005125 if (phone == null) {
5126 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5127 return;
5128 }
5129 try {
5130 phone.carrierActionReportDefaultNetworkStatus(report);
5131 } catch (Exception e) {
5132 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005135 }
5136 }
5137
5138 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005139 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5140 * bug report is being generated.
5141 */
5142 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005143 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005144 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5145 != PackageManager.PERMISSION_GRANTED) {
5146 writer.println("Permission Denial: can't dump Phone from pid="
5147 + Binder.getCallingPid()
5148 + ", uid=" + Binder.getCallingUid()
5149 + "without permission "
5150 + android.Manifest.permission.DUMP);
5151 return;
5152 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005153 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005154 }
Jack Yueb89b242016-06-22 13:27:47 -07005155
Brad Ebingerdac2f002018-04-03 15:17:52 -07005156 @Override
5157 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5158 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5159 throws RemoteException {
5160 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5161 }
5162
Jack Yueb89b242016-06-22 13:27:47 -07005163 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005164 * Get aggregated video call data usage since boot.
5165 *
5166 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5167 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005168 * {@hide}
5169 */
5170 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005171 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005172 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5173 null);
5174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 final long identity = Binder.clearCallingIdentity();
5176 try {
5177 // NetworkStatsService keeps tracking the active network interface and identity. It
5178 // records the delta with the corresponding network identity.
5179 // We just return the total video call data usage snapshot since boot.
5180 Phone phone = getPhone(subId);
5181 if (phone != null) {
5182 return phone.getVtDataUsage(perUidStats);
5183 }
5184 return null;
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005187 }
Jack Yueb89b242016-06-22 13:27:47 -07005188 }
Jack Yu75ab2952016-07-08 14:29:33 -07005189
5190 /**
5191 * Policy control of data connection. Usually used when data limit is passed.
5192 * @param enabled True if enabling the data, otherwise disabling.
5193 * @param subId Subscription index
5194 * {@hide}
5195 */
5196 @Override
5197 public void setPolicyDataEnabled(boolean enabled, int subId) {
5198 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199
5200 final long identity = Binder.clearCallingIdentity();
5201 try {
5202 Phone phone = getPhone(subId);
5203 if (phone != null) {
5204 phone.setPolicyDataEnabled(enabled);
5205 }
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005208 }
5209 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005210
5211 /**
5212 * Get Client request stats
5213 * @return List of Client Request Stats
5214 * @hide
5215 */
5216 @Override
5217 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005219 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005220 return null;
5221 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005222 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 if (phone != null) {
5227 return phone.getClientRequestStats();
5228 }
5229
5230 return null;
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005234 }
5235
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005236 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005237 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005238 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005239 }
Jack Yueb4124c2017-02-16 15:32:43 -08005240
5241 /**
Grace Chen70990072017-03-24 17:21:30 -07005242 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005243 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005244 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005245 * @param state State of SIM (power down, power up, pass through)
5246 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5247 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5248 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005249 *
5250 **/
5251 @Override
Grace Chen70990072017-03-24 17:21:30 -07005252 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005253 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005254 Phone phone = PhoneFactory.getPhone(slotIndex);
5255
vagdeviaf9a5b92018-08-15 16:01:53 -07005256 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 final long identity = Binder.clearCallingIdentity();
5259 try {
5260 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005261 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 }
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005265 }
5266 }
Shuo Qiandd210312017-04-12 22:11:33 +00005267
Tyler Gunn65d45c22017-06-05 11:22:26 -07005268 private boolean isUssdApiAllowed(int subId) {
5269 CarrierConfigManager configManager =
5270 (CarrierConfigManager) mPhone.getContext().getSystemService(
5271 Context.CARRIER_CONFIG_SERVICE);
5272 if (configManager == null) {
5273 return false;
5274 }
5275 PersistableBundle pb = configManager.getConfigForSubId(subId);
5276 if (pb == null) {
5277 return false;
5278 }
5279 return pb.getBoolean(
5280 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5281 }
5282
Shuo Qiandd210312017-04-12 22:11:33 +00005283 /**
5284 * Check if phone is in emergency callback mode
5285 * @return true if phone is in emergency callback mode
5286 * @param subId sub id
5287 */
goneil9c5f4872017-12-05 14:07:56 -08005288 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005289 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005290 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005291 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292
5293 final long identity = Binder.clearCallingIdentity();
5294 try {
5295 if (phone != null) {
5296 return phone.isInEcm();
5297 } else {
5298 return false;
5299 }
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005302 }
5303 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005304
5305 /**
5306 * Get the current signal strength information for the given subscription.
5307 * Because this information is not updated when the device is in a low power state
5308 * it should not be relied-upon to be current.
5309 * @param subId Subscription index
5310 * @return the most recent cached signal strength info from the modem
5311 */
5312 @Override
5313 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005314 final long identity = Binder.clearCallingIdentity();
5315 try {
5316 Phone p = getPhone(subId);
5317 if (p == null) {
5318 return null;
5319 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 return p.getSignalStrength();
5322 } finally {
5323 Binder.restoreCallingIdentity(identity);
5324 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005325 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005326
Pengquan Meng77b7f132018-08-22 14:49:57 -07005327 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005328 * Get the current modem radio state for the given slot.
5329 * @param slotIndex slot index.
5330 * @param callingPackage the name of the package making the call.
5331 * @return the current radio power state from the modem
5332 */
5333 @Override
5334 public int getRadioPowerState(int slotIndex, String callingPackage) {
5335 Phone phone = PhoneFactory.getPhone(slotIndex);
5336 if (phone != null) {
5337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5338 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5339 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5340 }
5341
5342 final long identity = Binder.clearCallingIdentity();
5343 try {
5344 return phone.getRadioPowerState();
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
5348 }
5349 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5350 }
5351
5352 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005353 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5354 *
5355 * <p>Requires one of the following permissions:
5356 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5357 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5358 * privileges.
5359 *
5360 * @param subId subscription id
5361 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5362 * {@code false}.
5363 */
5364 @Override
5365 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005366 boolean isEnabled = false;
5367 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005368 try {
5369 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005370 null /* message */);
5371 Phone phone = getPhone(subId);
5372 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005373 } catch (Exception e) {
5374 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5375 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005376 } finally {
5377 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005378 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005379 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005380 }
5381
5382
5383 /**
5384 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5385 *
5386 * <p> Requires permission:
5387 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5388 * privileges.
5389 *
5390 * @param subId subscription id
5391 * @param isEnabled {@code true} means enable, {@code false} means disable.
5392 */
5393 @Override
5394 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005395 final long identity = Binder.clearCallingIdentity();
5396 try {
5397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5398 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005399
Pengquan Menga1bb6272018-09-06 09:59:22 -07005400 Phone phone = getPhone(subId);
5401 if (phone != null) {
5402 phone.setDataRoamingEnabled(isEnabled);
5403 }
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005406 }
5407 }
5408
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005409 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005410 public boolean isManualNetworkSelectionAllowed(int subId) {
5411 boolean isAllowed = true;
5412 final long identity = Binder.clearCallingIdentity();
5413 try {
5414 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5415 mApp, subId, "isManualNetworkSelectionAllowed");
5416 Phone phone = getPhone(subId);
5417 if (phone != null) {
5418 isAllowed = phone.isCspPlmnEnabled();
5419 }
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
5423 return isAllowed;
5424 }
5425
5426 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005427 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005428 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5433 if (slots == null) {
5434 Rlog.i(LOG_TAG, "slots is null.");
5435 return null;
5436 }
5437
5438 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5439 for (int i = 0; i < slots.length; i++) {
5440 UiccSlot slot = slots[i];
5441 if (slot == null) {
5442 continue;
5443 }
5444
5445 String cardId;
5446 UiccCard card = slot.getUiccCard();
5447 if (card != null) {
5448 cardId = card.getCardId();
5449 } else {
5450 cardId = slot.getIccId();
5451 }
5452
5453 int cardState = 0;
5454 switch (slot.getCardState()) {
5455 case CARDSTATE_ABSENT:
5456 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5457 break;
5458 case CARDSTATE_PRESENT:
5459 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5460 break;
5461 case CARDSTATE_ERROR:
5462 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5463 break;
5464 case CARDSTATE_RESTRICTED:
5465 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5466 break;
5467 default:
5468 break;
5469
5470 }
5471
5472 infos[i] = new UiccSlotInfo(
5473 slot.isActive(),
5474 slot.isEuicc(),
5475 cardId,
5476 cardState,
5477 slot.getPhoneId(),
5478 slot.isExtendedApduSupported());
5479 }
5480 return infos;
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005483 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005484 }
5485
5486 @Override
5487 public boolean switchSlots(int[] physicalSlots) {
5488 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489
5490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005496 }
Jack Yu4c988042018-02-27 15:30:01 -08005497
5498 @Override
5499 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5500 enforceModifyPermission();
5501 final Phone phone = getPhone(subId);
5502 if (phone == null) {
5503 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5504 return;
5505 }
5506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 phone.setRadioIndicationUpdateMode(filters, mode);
5510 } finally {
5511 Binder.restoreCallingIdentity(identity);
5512 }
Jack Yu4c988042018-02-27 15:30:01 -08005513 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005514
5515 /**
goneil47ffb6e2018-04-06 15:40:58 -07005516 * A test API to reload the UICC profile.
5517 *
5518 * <p>Requires that the calling app has permission
5519 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5520 * @hide
5521 */
5522 @Override
5523 public void refreshUiccProfile(int subId) {
5524 enforceModifyPermission();
5525
5526 final long identity = Binder.clearCallingIdentity();
5527 try {
5528 Phone phone = getPhone(subId);
5529 if (phone == null) {
5530 return;
5531 }
5532 UiccCard uiccCard = phone.getUiccCard();
5533 if (uiccCard == null) {
5534 return;
5535 }
5536 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5537 if (uiccProfile == null) {
5538 return;
5539 }
5540 uiccProfile.refresh();
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
5544 }
5545
5546 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005547 * Returns false if the mobile data is disabled by default, otherwise return true.
5548 */
5549 private boolean getDefaultDataEnabled() {
5550 return "true".equalsIgnoreCase(
5551 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5552 }
5553
5554 /**
5555 * Returns true if the data roaming is enabled by default, i.e the system property
5556 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5557 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5558 */
5559 private boolean getDefaultDataRoamingEnabled(int subId) {
5560 final CarrierConfigManager configMgr = (CarrierConfigManager)
5561 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5562 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5563 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5564 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5565 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5566 return isDataRoamingEnabled;
5567 }
5568
5569 /**
5570 * Returns the default network type for the given {@code subId}, if the default network type is
5571 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5572 */
5573 private int getDefaultNetworkType(int subId) {
5574 return Integer.parseInt(
5575 TelephonyManager.getTelephonyProperty(
5576 mSubscriptionController.getPhoneId(subId),
5577 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5578 String.valueOf(Phone.PREFERRED_NT_MODE)));
5579 }
fionaxua13278b2018-03-21 00:08:13 -07005580
5581 @Override
5582 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5583 gid1, String gid2, String plmn, String spn) {
5584 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585
5586 final long identity = Binder.clearCallingIdentity();
5587 try {
5588 final Phone phone = getPhone(subId);
5589 if (phone == null) {
5590 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5591 return;
5592 }
5593 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005596 }
fionaxua13278b2018-03-21 00:08:13 -07005597 }
5598
5599 @Override
5600 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005601 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602
5603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 final Phone phone = getPhone(subId);
5606 if (phone == null) {
5607 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5608 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5609 }
5610 return phone.getCarrierIdListVersion();
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005613 }
fionaxua13278b2018-03-21 00:08:13 -07005614 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005615
5616 @Override
5617 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5619 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5620 return -1;
5621 }
5622
5623 final long identity = Binder.clearCallingIdentity();
5624 try {
5625 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
5629 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005630
5631 @Override
5632 public int getCdmaRoamingMode(int subId) {
5633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5634 mApp, subId, "getCdmaRoamingMode");
5635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
5642 }
5643
5644 @Override
5645 public boolean setCdmaRoamingMode(int subId, int mode) {
5646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5647 mApp, subId, "setCdmaRoamingMode");
5648
5649 final long identity = Binder.clearCallingIdentity();
5650 try {
5651 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5652 } finally {
5653 Binder.restoreCallingIdentity(identity);
5654 }
5655 }
5656
5657 @Override
5658 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5660 mApp, subId, "setCdmaSubscriptionMode");
5661
5662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
5668 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005669
5670 private void ensureUserRunning(int userId) {
5671 if (!mUserManager.isUserRunning(userId)) {
5672 throw new IllegalStateException("User " + userId + " does not exist or not running");
5673 }
5674 }
5675
5676 /**
5677 * Returns a list of SMS apps on a given user.
5678 *
5679 * Only the shell user (UID 2000 or 0) can call it.
5680 * Target user must be running.
5681 */
5682 @Override
5683 public String[] getSmsApps(int userId) {
5684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5685 ensureUserRunning(userId);
5686
5687 final Collection<SmsApplicationData> apps =
5688 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5689
5690 String[] ret = new String[apps.size()];
5691 int i = 0;
5692 for (SmsApplicationData app : apps) {
5693 ret[i++] = app.mPackageName;
5694 }
5695 return ret;
5696 }
5697
5698 /**
5699 * Returns the default SMS app package name on a given user.
5700 *
5701 * Only the shell user (UID 2000 or 0) can call it.
5702 * Target user must be running.
5703 */
5704 @Override
5705 public String getDefaultSmsApp(int userId) {
5706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5707 ensureUserRunning(userId);
5708
5709 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5710 /* updateIfNeeded= */ true, userId);
5711 return cn == null ? null : cn.getPackageName();
5712 }
5713
5714 /**
5715 * Set a package as the default SMS app on a given user.
5716 *
5717 * Only the shell user (UID 2000 or 0) can call it.
5718 * Target user must be running.
5719 */
5720 @Override
5721 public void setDefaultSmsApp(int userId, String packageName) {
5722 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5723 ensureUserRunning(userId);
5724
5725 boolean found = false;
5726 for (String pkg : getSmsApps(userId)) {
5727 if (TextUtils.equals(packageName, pkg)) {
5728 found = true;
5729 break;
5730 }
5731 }
5732 if (!found) {
5733 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5734 }
5735
5736 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005738}