blob: 3f86f3b9abf866cbe3cef736f278eb69794a9ecd [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;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070045import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070046import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070048import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070049import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070050import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080051import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070052import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080053import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080054import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070055import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070056import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070058import android.telephony.CellInfoGsm;
59import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070060import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070061import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080062import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070063import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080064import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070065import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070066import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070067import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080069import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070070import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080071import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080072import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070073import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070074import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000075import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070076import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080078import android.telephony.ims.aidl.IImsConfig;
79import android.telephony.ims.aidl.IImsMmTelFeature;
80import android.telephony.ims.aidl.IImsRcsFeature;
81import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080082import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080085import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080087import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080089
Andrew Lee312e8172014-10-23 17:01:36 -070090import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080091import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070092import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070093import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070094import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070095import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070096import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080099import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700100import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100101import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700102import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700103import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700105import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800106import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700107import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700108import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700110import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700111import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700112import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700113import com.android.internal.telephony.SmsApplication;
114import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800115import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800116import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700117import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.uicc.IccIoResult;
119import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800120import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700121import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800122import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800124import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700126import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800127import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700128import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800129import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700130import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700131import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800132
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700133import java.io.FileDescriptor;
134import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800135import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800137import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700138import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800139import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100140import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142
143/**
144 * Implementation of the ITelephony interface.
145 */
Santos Cordon117fee72014-05-16 17:56:12 -0700146public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147 private static final String LOG_TAG = "PhoneInterfaceManager";
148 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
149 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800150 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151
152 // Message codes used with mMainThreadHandler
153 private static final int CMD_HANDLE_PIN_MMI = 1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154 private static final int CMD_ANSWER_RINGING_CALL = 4;
155 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700156 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
157 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158 private static final int CMD_OPEN_CHANNEL = 9;
159 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
160 private static final int CMD_CLOSE_CHANNEL = 11;
161 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800162 private static final int CMD_NV_READ_ITEM = 13;
163 private static final int EVENT_NV_READ_ITEM_DONE = 14;
164 private static final int CMD_NV_WRITE_ITEM = 15;
165 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
166 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
167 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
168 private static final int CMD_NV_RESET_CONFIG = 19;
169 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800170 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
171 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
172 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
173 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800174 private static final int CMD_SEND_ENVELOPE = 25;
175 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000176 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
177 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700178 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
179 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
180 private static final int CMD_EXCHANGE_SIM_IO = 31;
181 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800182 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
183 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700184 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
185 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700186 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
187 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700188 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
189 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
190 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
191 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700192 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
193 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
194 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
195 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700196 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
198 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000199 private static final int CMD_SWITCH_SLOTS = 50;
200 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700201 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
202 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
203 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
204 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
205 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
206 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
207 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
208 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700209
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800210 // Parameters of select command.
211 private static final int SELECT_COMMAND = 0xA4;
212 private static final int SELECT_P1 = 0x04;
213 private static final int SELECT_P2 = 0;
214 private static final int SELECT_P3 = 0x10;
215
Pengquan Meng85728fb2018-03-12 16:31:21 -0700216 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
217 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
218 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
219
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220 /** The singleton instance. */
221 private static PhoneInterfaceManager sInstance;
222
Wink Saville3ab207e2014-11-20 13:07:20 -0800223 private PhoneGlobals mApp;
224 private Phone mPhone;
225 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700226 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800227 private AppOpsManager mAppOps;
228 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800229 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800230 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700231 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232
Derek Tan97ebb422014-09-05 16:55:38 -0700233 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
234 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800235 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700236
Derek Tan740e1672017-06-27 14:56:27 -0700237 // The AID of ISD-R.
238 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
239
yinxub1bed742017-04-17 11:45:04 -0700240 private NetworkScanRequestTracker mNetworkScanRequestTracker;
241
David Kelly5e06a7f2018-03-12 14:10:59 +0000242 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
243 private static final int MANUFACTURER_CODE_LENGTH = 8;
244
Derek Tan89e89d42014-07-08 17:00:10 -0700245 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700246 * A request object to use for transmitting data to an ICC.
247 */
248 private static final class IccAPDUArgument {
249 public int channel, cla, command, p1, p2, p3;
250 public String data;
251
252 public IccAPDUArgument(int channel, int cla, int command,
253 int p1, int p2, int p3, String data) {
254 this.channel = channel;
255 this.cla = cla;
256 this.command = command;
257 this.p1 = p1;
258 this.p2 = p2;
259 this.p3 = p3;
260 this.data = data;
261 }
262 }
263
264 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700265 * A request object to use for transmitting data to an ICC.
266 */
267 private static final class ManualNetworkSelectionArgument {
268 public OperatorInfo operatorInfo;
269 public boolean persistSelection;
270
271 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
272 this.operatorInfo = operatorInfo;
273 this.persistSelection = persistSelection;
274 }
275 }
276
277 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
279 * request after sending. The main thread will notify the request when it is complete.
280 */
281 private static final class MainThreadRequest {
282 /** The argument to use for the request */
283 public Object argument;
284 /** The result of the request that is run on the main thread */
285 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800286 // The subscriber id that this request applies to. Defaults to
287 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
288 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289
vagdeviaf9a5b92018-08-15 16:01:53 -0700290 public WorkSource workSource;
291
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 public MainThreadRequest(Object argument) {
293 this.argument = argument;
294 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800295
vagdeviaf9a5b92018-08-15 16:01:53 -0700296 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800297 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800298 if (subId != null) {
299 this.subId = subId;
300 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700301 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 }
304
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800305 private static final class IncomingThirdPartyCallArgs {
306 public final ComponentName component;
307 public final String callId;
308 public final String callerDisplayName;
309
310 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
311 String callerDisplayName) {
312 this.component = component;
313 this.callId = callId;
314 this.callerDisplayName = callerDisplayName;
315 }
316 }
317
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318 /**
319 * A handler that processes messages on the main thread in the phone process. Since many
320 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
321 * inbound binder threads to the main thread in the phone process. The Binder thread
322 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
323 * on, which will be notified when the operation completes and will contain the result of the
324 * request.
325 *
326 * <p>If a MainThreadRequest object is provided in the msg.obj field,
327 * note that request.result must be set to something non-null for the calling thread to
328 * unblock.
329 */
330 private final class MainThreadHandler extends Handler {
331 @Override
332 public void handleMessage(Message msg) {
333 MainThreadRequest request;
334 Message onCompleted;
335 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800336 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700337 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338
339 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700340 case CMD_HANDLE_USSD_REQUEST: {
341 request = (MainThreadRequest) msg.obj;
342 final Phone phone = getPhoneFromRequest(request);
343 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
344 String ussdRequest = ussdObject.first;
345 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700346
Pengquan Menga1bb6272018-09-06 09:59:22 -0700347 if (!isUssdApiAllowed(request.subId)) {
348 // Carrier does not support use of this API, return failure.
349 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
350 UssdResponse response = new UssdResponse(ussdRequest, null);
351 Bundle returnData = new Bundle();
352 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
353 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700354
Pengquan Menga1bb6272018-09-06 09:59:22 -0700355 request.result = true;
356 notifyRequester(request);
357 return;
358 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700359
Pengquan Menga1bb6272018-09-06 09:59:22 -0700360 try {
361 request.result = phone != null
362 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
363 } catch (CallStateException cse) {
364 request.result = false;
365 }
366 // Wake up the requesting thread
367 notifyRequester(request);
368 break;
pkanwar32d516d2016-10-14 19:37:38 -0700369 }
370
Yorke Lee716f67e2015-06-17 15:39:16 -0700371 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700373 final Phone phone = getPhoneFromRequest(request);
374 request.result = phone != null ?
375 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
376 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700378 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700383 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800384 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700385 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800386 request.result = ""; // dummy result for notifying the waiting thread
387 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700388 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 break;
390
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 case CMD_END_CALL:
392 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800393 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700394 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700395 Phone phone = getPhone(end_subId);
396 if (phone == null) {
397 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
398 break;
399 }
400 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
402 // CDMA: If the user presses the Power button we treat it as
403 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700404 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
406 // GSM: End the call as per the Phone state
407 hungUp = PhoneUtils.hangup(mCM);
408 } else {
409 throw new IllegalStateException("Unexpected phone type: " + phoneType);
410 }
411 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
412 request.result = hungUp;
413 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700414 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 break;
416
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800420 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700421 if (uiccCard == null) {
422 loge("iccTransmitApduLogicalChannel: No UICC");
423 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700425 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
427 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700428 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 iccArgument.channel, iccArgument.cla, iccArgument.command,
430 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700432 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 break;
434
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 ar = (AsyncResult) msg.obj;
437 request = (MainThreadRequest) ar.userObj;
438 if (ar.exception == null && ar.result != null) {
439 request.result = ar.result;
440 } else {
441 request.result = new IccIoResult(0x6F, 0, (byte[])null);
442 if (ar.result == null) {
443 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800444 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800446 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 } else {
448 loge("iccTransmitApduLogicalChannel: Unknown exception");
449 }
450 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 break;
453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
455 request = (MainThreadRequest) msg.obj;
456 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800457 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 if (uiccCard == null) {
459 loge("iccTransmitApduBasicChannel: No UICC");
460 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700461 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 } else {
463 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
464 request);
465 uiccCard.iccTransmitApduBasicChannel(
466 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
467 iccArgument.p3, iccArgument.data, onCompleted);
468 }
469 break;
470
471 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
472 ar = (AsyncResult) msg.obj;
473 request = (MainThreadRequest) ar.userObj;
474 if (ar.exception == null && ar.result != null) {
475 request.result = ar.result;
476 } else {
477 request.result = new IccIoResult(0x6F, 0, (byte[])null);
478 if (ar.result == null) {
479 loge("iccTransmitApduBasicChannel: Empty response");
480 } else if (ar.exception instanceof CommandException) {
481 loge("iccTransmitApduBasicChannel: CommandException: " +
482 ar.exception);
483 } else {
484 loge("iccTransmitApduBasicChannel: Unknown exception");
485 }
486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 break;
489
490 case CMD_EXCHANGE_SIM_IO:
491 request = (MainThreadRequest) msg.obj;
492 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800493 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 if (uiccCard == null) {
495 loge("iccExchangeSimIO: No UICC");
496 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 } else {
499 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
500 request);
501 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
502 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
503 iccArgument.data, onCompleted);
504 }
505 break;
506
507 case EVENT_EXCHANGE_SIM_IO_DONE:
508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6f, 0, (byte[])null);
514 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700515 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 break;
517
Derek Tan4d5e5c12014-02-04 11:54:58 -0800518 case CMD_SEND_ENVELOPE:
519 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800520 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700521 if (uiccCard == null) {
522 loge("sendEnvelopeWithStatus: No UICC");
523 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700525 } else {
526 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
527 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
528 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800529 break;
530
531 case EVENT_SEND_ENVELOPE_DONE:
532 ar = (AsyncResult) msg.obj;
533 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700534 if (ar.exception == null && ar.result != null) {
535 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800536 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
538 if (ar.result == null) {
539 loge("sendEnvelopeWithStatus: Empty response");
540 } else if (ar.exception instanceof CommandException) {
541 loge("sendEnvelopeWithStatus: CommandException: " +
542 ar.exception);
543 } else {
544 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
545 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800546 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 break;
549
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 case CMD_OPEN_CHANNEL:
551 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800553 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 if (uiccCard == null) {
555 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800556 request.result = new IccOpenLogicalChannelResponse(-1,
557 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 } else {
560 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800561 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
562 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 break;
565
566 case EVENT_OPEN_CHANNEL_DONE:
567 ar = (AsyncResult) msg.obj;
568 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 int[] result = (int[]) ar.result;
572 int channelId = result[0];
573 byte[] selectResponse = null;
574 if (result.length > 1) {
575 selectResponse = new byte[result.length - 1];
576 for (int i = 1; i < result.length; ++i) {
577 selectResponse[i - 1] = (byte) result[i];
578 }
579 }
580 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700581 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 if (ar.result == null) {
584 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 if (ar.exception != null) {
587 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
588 }
589
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700590 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700591 if (ar.exception instanceof CommandException) {
592 CommandException.Error error =
593 ((CommandException) (ar.exception)).getCommandError();
594 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700596 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700597 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 }
599 }
600 openChannelResp = new IccOpenLogicalChannelResponse(
601 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700603 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700604 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 break;
606
607 case CMD_CLOSE_CHANNEL:
608 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800609 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700610 if (uiccCard == null) {
611 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900612 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700614 } else {
615 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
616 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
617 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 break;
619
620 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800621 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
622 break;
623
624 case CMD_NV_READ_ITEM:
625 request = (MainThreadRequest) msg.obj;
626 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700627 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800628 break;
629
630 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800636 request.result = "";
637 if (ar.result == null) {
638 loge("nvReadItem: Empty response");
639 } else if (ar.exception instanceof CommandException) {
640 loge("nvReadItem: CommandException: " +
641 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800643 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
Jake Hambye994d462014-02-03 13:10:13 -0800649 case CMD_NV_WRITE_ITEM:
650 request = (MainThreadRequest) msg.obj;
651 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
652 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700653 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
654 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800655 break;
656
657 case EVENT_NV_WRITE_ITEM_DONE:
658 handleNullReturnEvent(msg, "nvWriteItem");
659 break;
660
661 case CMD_NV_WRITE_CDMA_PRL:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
664 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
665 break;
666
667 case EVENT_NV_WRITE_CDMA_PRL_DONE:
668 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
669 break;
670
671 case CMD_NV_RESET_CONFIG:
672 request = (MainThreadRequest) msg.obj;
673 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
674 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
675 break;
676
677 case EVENT_NV_RESET_CONFIG_DONE:
678 handleNullReturnEvent(msg, "nvResetConfig");
679 break;
680
Jake Hamby7c27be32014-03-03 13:25:59 -0800681 case CMD_GET_PREFERRED_NETWORK_TYPE:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700684 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800685 break;
686
687 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
688 ar = (AsyncResult) msg.obj;
689 request = (MainThreadRequest) ar.userObj;
690 if (ar.exception == null && ar.result != null) {
691 request.result = ar.result; // Integer
692 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800693 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800694 if (ar.result == null) {
695 loge("getPreferredNetworkType: Empty response");
696 } else if (ar.exception instanceof CommandException) {
697 loge("getPreferredNetworkType: CommandException: " +
698 ar.exception);
699 } else {
700 loge("getPreferredNetworkType: Unknown exception");
701 }
702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case CMD_SET_PREFERRED_NETWORK_TYPE:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
709 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700710 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 break;
712
713 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
714 handleNullReturnEvent(msg, "setPreferredNetworkType");
715 break;
716
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000717 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
718 request = (MainThreadRequest)msg.obj;
719 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700720 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000721 break;
722
723 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
724 ar = (AsyncResult)msg.obj;
725 request = (MainThreadRequest)ar.userObj;
726 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000728 break;
729
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800730 case CMD_SET_VOICEMAIL_NUMBER:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
733 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800734 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
735 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800736 break;
737
738 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
739 handleNullReturnEvent(msg, "setVoicemailNumber");
740 break;
741
Stuart Scott54788802015-03-30 13:18:01 -0700742 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
745 request);
746 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
747 break;
748
749 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
750 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
751 break;
752
Shishir Agrawal302c8692015-06-19 13:49:39 -0700753 case CMD_PERFORM_NETWORK_SCAN:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
756 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
757 break;
758
759 case EVENT_PERFORM_NETWORK_SCAN_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
762 CellNetworkScanResult cellScanResult;
763 if (ar.exception == null && ar.result != null) {
764 cellScanResult = new CellNetworkScanResult(
765 CellNetworkScanResult.STATUS_SUCCESS,
766 (List<OperatorInfo>) ar.result);
767 } else {
768 if (ar.result == null) {
769 loge("getCellNetworkScanResults: Empty response");
770 }
771 if (ar.exception != null) {
772 loge("getCellNetworkScanResults: Exception: " + ar.exception);
773 }
774 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
775 if (ar.exception instanceof CommandException) {
776 CommandException.Error error =
777 ((CommandException) (ar.exception)).getCommandError();
778 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
779 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
780 } else if (error == CommandException.Error.GENERIC_FAILURE) {
781 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
782 }
783 }
784 cellScanResult = new CellNetworkScanResult(errorCode, null);
785 }
786 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700787 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700788 break;
789
790 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
791 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700792 ManualNetworkSelectionArgument selArg =
793 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
795 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700796 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
797 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 break;
799
800 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
801 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
802 break;
803
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700804 case CMD_GET_MODEM_ACTIVITY_INFO:
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700807 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700808 break;
809
810 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
811 ar = (AsyncResult) msg.obj;
812 request = (MainThreadRequest) ar.userObj;
813 if (ar.exception == null && ar.result != null) {
814 request.result = ar.result;
815 } else {
816 if (ar.result == null) {
817 loge("queryModemActivityInfo: Empty response");
818 } else if (ar.exception instanceof CommandException) {
819 loge("queryModemActivityInfo: CommandException: " +
820 ar.exception);
821 } else {
822 loge("queryModemActivityInfo: Unknown exception");
823 }
824 }
Amit Mahajand4766222016-01-28 15:28:28 -0800825 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
826 if (request.result == null) {
827 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
828 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700829 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700830 break;
831
Meng Wang1a7c35a2016-05-05 20:56:15 -0700832 case CMD_SET_ALLOWED_CARRIERS:
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
835 mPhone.setAllowedCarriers(
836 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700837 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700838 break;
839
840 case EVENT_SET_ALLOWED_CARRIERS_DONE:
841 ar = (AsyncResult) msg.obj;
842 request = (MainThreadRequest) ar.userObj;
843 if (ar.exception == null && ar.result != null) {
844 request.result = ar.result;
845 } else {
846 if (ar.result == null) {
847 loge("setAllowedCarriers: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("setAllowedCarriers: CommandException: " +
850 ar.exception);
851 } else {
852 loge("setAllowedCarriers: Unknown exception");
853 }
854 }
855 // Result cannot be null. Return -1 on error.
856 if (request.result == null) {
857 request.result = new int[]{-1};
858 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700859 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700860 break;
861
862 case CMD_GET_ALLOWED_CARRIERS:
863 request = (MainThreadRequest) msg.obj;
864 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700865 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 break;
867
868 case EVENT_GET_ALLOWED_CARRIERS_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
874 if (ar.result == null) {
875 loge("getAllowedCarriers: Empty response");
876 } else if (ar.exception instanceof CommandException) {
877 loge("getAllowedCarriers: CommandException: " +
878 ar.exception);
879 } else {
880 loge("getAllowedCarriers: Unknown exception");
881 }
882 }
883 // Result cannot be null. Return empty list of CarrierIdentifier.
884 if (request.result == null) {
885 request.result = new ArrayList<CarrierIdentifier>(0);
886 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700887 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 break;
889
Nathan Haroldb3014052017-01-25 15:57:32 -0800890 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
891 ar = (AsyncResult) msg.obj;
892 request = (MainThreadRequest) ar.userObj;
893 if (ar.exception == null && ar.result != null) {
894 request.result = ar.result;
895 } else {
896 request.result = new IllegalArgumentException(
897 "Failed to retrieve Forbidden Plmns");
898 if (ar.result == null) {
899 loge("getForbiddenPlmns: Empty response");
900 } else {
901 loge("getForbiddenPlmns: Unknown exception");
902 }
903 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700904 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800905 break;
906
907 case CMD_GET_FORBIDDEN_PLMNS:
908 request = (MainThreadRequest) msg.obj;
909 uiccCard = getUiccCardFromRequest(request);
910 if (uiccCard == null) {
911 loge("getForbiddenPlmns() UiccCard is null");
912 request.result = new IllegalArgumentException(
913 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800915 break;
916 }
917 Integer appType = (Integer) request.argument;
918 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
919 if (uiccApp == null) {
920 loge("getForbiddenPlmns() no app with specified type -- "
921 + appType);
922 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700923 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800924 break;
925 } else {
926 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
927 + " specified type -- " + appType);
928 }
929 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
930 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
931 onCompleted);
932 break;
933
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000934 case CMD_SWITCH_SLOTS:
935 request = (MainThreadRequest) msg.obj;
936 int[] physicalSlots = (int[]) request.argument;
937 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
938 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
939 break;
940
941 case EVENT_SWITCH_SLOTS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700945 notifyRequester(request);
946 break;
947 case CMD_GET_NETWORK_SELECTION_MODE:
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
950 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
951 break;
952
953 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
956 if (ar.exception != null) {
957 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
958 } else {
959 int mode = ((int[]) ar.result)[0];
960 if (mode == 0) {
961 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
962 } else {
963 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
964 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000965 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700966 notifyRequester(request);
967 break;
968 case CMD_GET_CDMA_ROAMING_MODE:
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
971 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
972 break;
973 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
976 if (ar.exception != null) {
977 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
978 } else {
979 request.result = ((int[]) ar.result)[0];
980 }
981 notifyRequester(request);
982 break;
983 case CMD_SET_CDMA_ROAMING_MODE:
984 request = (MainThreadRequest) msg.obj;
985 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
986 int mode = (int) request.argument;
987 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
988 break;
989 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 request.result = ar.exception == null;
993 notifyRequester(request);
994 break;
995 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
996 request = (MainThreadRequest) msg.obj;
997 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
998 int subscriptionMode = (int) request.argument;
999 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1000 break;
1001 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 request.result = ar.exception == null;
1005 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001006 break;
1007
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001008 default:
1009 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1010 break;
1011 }
1012 }
Jake Hambye994d462014-02-03 13:10:13 -08001013
Pengquan Menga1bb6272018-09-06 09:59:22 -07001014 private void notifyRequester(MainThreadRequest request) {
1015 synchronized (request) {
1016 request.notifyAll();
1017 }
1018 }
1019
Jake Hambye994d462014-02-03 13:10:13 -08001020 private void handleNullReturnEvent(Message msg, String command) {
1021 AsyncResult ar = (AsyncResult) msg.obj;
1022 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1023 if (ar.exception == null) {
1024 request.result = true;
1025 } else {
1026 request.result = false;
1027 if (ar.exception instanceof CommandException) {
1028 loge(command + ": CommandException: " + ar.exception);
1029 } else {
1030 loge(command + ": Unknown exception");
1031 }
1032 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001033 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001034 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001035 }
1036
1037 /**
1038 * Posts the specified command to be executed on the main thread,
1039 * waits for the request to complete, and returns the result.
1040 * @see #sendRequestAsync
1041 */
1042 private Object sendRequest(int command, Object argument) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001043 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1044 }
1045
1046 /**
1047 * Posts the specified command to be executed on the main thread,
1048 * waits for the request to complete, and returns the result.
1049 * @see #sendRequestAsync
1050 */
1051 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1052 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1053 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001054 }
1055
1056 /**
1057 * Posts the specified command to be executed on the main thread,
1058 * waits for the request to complete, and returns the result.
1059 * @see #sendRequestAsync
1060 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001061 private Object sendRequest(int command, Object argument, Integer subId) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001062 return sendRequest(command, argument, subId, null);
1063 }
1064
1065 /**
1066 * Posts the specified command to be executed on the main thread,
1067 * waits for the request to complete, and returns the result.
1068 * @see #sendRequestAsync
1069 */
1070 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001071 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1072 throw new RuntimeException("This method will deadlock if called from the main thread.");
1073 }
1074
vagdeviaf9a5b92018-08-15 16:01:53 -07001075 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001076 Message msg = mMainThreadHandler.obtainMessage(command, request);
1077 msg.sendToTarget();
1078
1079 // Wait for the request to complete
1080 synchronized (request) {
1081 while (request.result == null) {
1082 try {
1083 request.wait();
1084 } catch (InterruptedException e) {
1085 // Do nothing, go back and wait until the request is complete
1086 }
1087 }
1088 }
1089 return request.result;
1090 }
1091
1092 /**
1093 * Asynchronous ("fire and forget") version of sendRequest():
1094 * Posts the specified command to be executed on the main thread, and
1095 * returns immediately.
1096 * @see #sendRequest
1097 */
1098 private void sendRequestAsync(int command) {
1099 mMainThreadHandler.sendEmptyMessage(command);
1100 }
1101
1102 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001103 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1104 * @see {@link #sendRequest(int,Object)}
1105 */
1106 private void sendRequestAsync(int command, Object argument) {
1107 MainThreadRequest request = new MainThreadRequest(argument);
1108 Message msg = mMainThreadHandler.obtainMessage(command, request);
1109 msg.sendToTarget();
1110 }
1111
1112 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001113 * Initialize the singleton PhoneInterfaceManager instance.
1114 * This is only done once, at startup, from PhoneApp.onCreate().
1115 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001116 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001117 synchronized (PhoneInterfaceManager.class) {
1118 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001119 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001120 } else {
1121 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1122 }
1123 return sInstance;
1124 }
1125 }
1126
1127 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001128 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001129 mApp = app;
1130 mPhone = phone;
1131 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001132 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001133 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1134 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001135 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001136 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001137 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001138 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001139 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001140
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 publish();
1142 }
1143
1144 private void publish() {
1145 if (DBG) log("publish: " + this);
1146
1147 ServiceManager.addService("phone", this);
1148 }
1149
Stuart Scott584921c2015-01-15 17:10:34 -08001150 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001151 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1152 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001153 }
1154
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001155 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1156 Phone phone = getPhoneFromRequest(request);
1157 return phone == null ? null :
1158 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1159 }
1160
Wink Saville36469e72014-06-11 15:17:00 -07001161 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001162 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001163 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 //
1166 // Implementation of the ITelephony interface.
1167 //
1168
1169 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001170 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001171 }
1172
Wink Savilleb564aae2014-10-23 10:18:09 -07001173 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 if (DBG) log("dial: " + number);
1175 // No permission check needed here: This is just a wrapper around the
1176 // ACTION_DIAL intent, which is available to any app since it puts up
1177 // the UI before it does anything.
1178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001179 final long identity = Binder.clearCallingIdentity();
1180 try {
1181 String url = createTelUrl(number);
1182 if (url == null) {
1183 return;
1184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001186 // PENDING: should we just silently fail if phone is offhook or ringing?
1187 PhoneConstants.State state = mCM.getState(subId);
1188 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1189 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1190 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1191 mApp.startActivity(intent);
1192 }
1193 } finally {
1194 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 }
1196 }
1197
1198 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001199 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001200 }
1201
Wink Savilleb564aae2014-10-23 10:18:09 -07001202 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203 if (DBG) log("call: " + number);
1204
1205 // This is just a wrapper around the ACTION_CALL intent, but we still
1206 // need to do a permission check since we're calling startActivity()
1207 // from the context of the phone app.
1208 enforceCallPermission();
1209
1210 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1211 != AppOpsManager.MODE_ALLOWED) {
1212 return;
1213 }
1214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001215 final long identity = Binder.clearCallingIdentity();
1216 try {
1217 String url = createTelUrl(number);
1218 if (url == null) {
1219 return;
1220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001222 boolean isValid = false;
1223 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1224 if (slist != null) {
1225 for (SubscriptionInfo subInfoRecord : slist) {
1226 if (subInfoRecord.getSubscriptionId() == subId) {
1227 isValid = true;
1228 break;
1229 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001230 }
Wink Saville08874612014-08-31 19:19:58 -07001231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001232 if (!isValid) {
1233 return;
1234 }
Wink Saville08874612014-08-31 19:19:58 -07001235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001236 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1237 intent.putExtra(SUBSCRIPTION_KEY, subId);
1238 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1239 mApp.startActivity(intent);
1240 } finally {
1241 Binder.restoreCallingIdentity(identity);
1242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 }
1244
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 /**
1246 * End a call based on call state
1247 * @return true is a call was ended
1248 */
1249 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001250 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001251 }
1252
1253 /**
1254 * End a call based on the call state of the subId
1255 * @return true is a call was ended
1256 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001257 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001258 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1259 != PackageManager.PERMISSION_GRANTED) {
1260 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1261 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1262 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001264
1265 final long identity = Binder.clearCallingIdentity();
1266 try {
1267 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1268 } finally {
1269 Binder.restoreCallingIdentity(identity);
1270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271 }
1272
1273 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001274 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001275 }
1276
Wink Savilleb564aae2014-10-23 10:18:09 -07001277 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 if (DBG) log("answerRingingCall...");
1279 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1280 // but that can probably wait till the big TelephonyManager API overhaul.
1281 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1282 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001283
1284 final long identity = Binder.clearCallingIdentity();
1285 try {
1286 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1287 } finally {
1288 Binder.restoreCallingIdentity(identity);
1289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 }
1291
1292 /**
1293 * Make the actual telephony calls to implement answerRingingCall().
1294 * This should only be called from the main thread of the Phone app.
1295 * @see #answerRingingCall
1296 *
1297 * TODO: it would be nice to return true if we answered the call, or
1298 * false if there wasn't actually a ringing incoming call, or some
1299 * other error occurred. (In other words, pass back the return value
1300 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1301 * But that would require calling this method via sendRequest() rather
1302 * than sendRequestAsync(), and right now we don't actually *need* that
1303 * return value, so let's just return void for now.
1304 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001305 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001306 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001308 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1309 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 if (hasActiveCall && hasHoldingCall) {
1311 // Both lines are in use!
1312 // TODO: provide a flag to let the caller specify what
1313 // policy to use if both lines are in use. (The current
1314 // behavior is hardwired to "answer incoming, end ongoing",
1315 // which is how the CALL button is specced to behave.)
1316 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1317 return;
1318 } else {
1319 // answerCall() will automatically hold the current active
1320 // call, if there is one.
1321 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1322 return;
1323 }
1324 } else {
1325 // No call was ringing.
1326 return;
1327 }
1328 }
1329
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001331 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001333 public void silenceRinger() {
1334 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 }
1336
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001337 @Override
1338 public boolean isOffhook(String callingPackage) {
1339 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001340 }
1341
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001342 @Override
1343 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001345 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001346 return false;
1347 }
1348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001349 final long identity = Binder.clearCallingIdentity();
1350 try {
1351 final Phone phone = getPhone(subId);
1352 if (phone != null) {
1353 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1354 } else {
1355 return false;
1356 }
1357 } finally {
1358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 }
1361
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001362 @Override
1363 public boolean isRinging(String callingPackage) {
1364 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001365 }
1366
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001367 @Override
1368 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001370 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001371 return false;
1372 }
1373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001374 final long identity = Binder.clearCallingIdentity();
1375 try {
1376 final Phone phone = getPhone(subId);
1377 if (phone != null) {
1378 return (phone.getState() == PhoneConstants.State.RINGING);
1379 } else {
1380 return false;
1381 }
1382 } finally {
1383 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 }
1386
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001387 @Override
1388 public boolean isIdle(String callingPackage) {
1389 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001390 }
1391
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001392 @Override
1393 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001395 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001396 return false;
1397 }
1398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001399 final long identity = Binder.clearCallingIdentity();
1400 try {
1401 final Phone phone = getPhone(subId);
1402 if (phone != null) {
1403 return (phone.getState() == PhoneConstants.State.IDLE);
1404 } else {
1405 return false;
1406 }
1407 } finally {
1408 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 }
1411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001413 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001414 }
1415
Wink Savilleb564aae2014-10-23 10:18:09 -07001416 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001417 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001418 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1419 }
1420
1421 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001422 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001423 }
1424
Wink Savilleb564aae2014-10-23 10:18:09 -07001425 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001426 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001427 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1428 }
1429
1430 /** {@hide} */
1431 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001432 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001433 }
1434
Wink Savilleb564aae2014-10-23 10:18:09 -07001435 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001436 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001437
1438 final long identity = Binder.clearCallingIdentity();
1439 try {
1440 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1441 checkSimPin.start();
1442 return checkSimPin.unlockSim(null, pin);
1443 } finally {
1444 Binder.restoreCallingIdentity(identity);
1445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 }
1447
Wink Saville9de0f752013-10-22 19:04:03 -07001448 /** {@hide} */
1449 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001450 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001451 }
1452
Wink Savilleb564aae2014-10-23 10:18:09 -07001453 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001455
1456 final long identity = Binder.clearCallingIdentity();
1457 try {
1458 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1459 checkSimPuk.start();
1460 return checkSimPuk.unlockSim(puk, pin);
1461 } finally {
1462 Binder.restoreCallingIdentity(identity);
1463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 }
1465
1466 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001467 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 * a synchronous one.
1469 */
1470 private static class UnlockSim extends Thread {
1471
1472 private final IccCard mSimCard;
1473
1474 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001475 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1476 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477
1478 // For replies from SimCard interface
1479 private Handler mHandler;
1480
1481 // For async handler to identify request type
1482 private static final int SUPPLY_PIN_COMPLETE = 100;
1483
1484 public UnlockSim(IccCard simCard) {
1485 mSimCard = simCard;
1486 }
1487
1488 @Override
1489 public void run() {
1490 Looper.prepare();
1491 synchronized (UnlockSim.this) {
1492 mHandler = new Handler() {
1493 @Override
1494 public void handleMessage(Message msg) {
1495 AsyncResult ar = (AsyncResult) msg.obj;
1496 switch (msg.what) {
1497 case SUPPLY_PIN_COMPLETE:
1498 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1499 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001500 mRetryCount = msg.arg1;
1501 if (ar.exception != null) {
1502 if (ar.exception instanceof CommandException &&
1503 ((CommandException)(ar.exception)).getCommandError()
1504 == CommandException.Error.PASSWORD_INCORRECT) {
1505 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1506 } else {
1507 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1508 }
1509 } else {
1510 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 mDone = true;
1513 UnlockSim.this.notifyAll();
1514 }
1515 break;
1516 }
1517 }
1518 };
1519 UnlockSim.this.notifyAll();
1520 }
1521 Looper.loop();
1522 }
1523
1524 /*
1525 * Use PIN or PUK to unlock SIM card
1526 *
1527 * If PUK is null, unlock SIM card with PIN
1528 *
1529 * If PUK is not null, unlock SIM card with PUK and set PIN code
1530 */
Wink Saville9de0f752013-10-22 19:04:03 -07001531 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532
1533 while (mHandler == null) {
1534 try {
1535 wait();
1536 } catch (InterruptedException e) {
1537 Thread.currentThread().interrupt();
1538 }
1539 }
1540 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1541
1542 if (puk == null) {
1543 mSimCard.supplyPin(pin, callback);
1544 } else {
1545 mSimCard.supplyPuk(puk, pin, callback);
1546 }
1547
1548 while (!mDone) {
1549 try {
1550 Log.d(LOG_TAG, "wait for done");
1551 wait();
1552 } catch (InterruptedException e) {
1553 // Restore the interrupted status
1554 Thread.currentThread().interrupt();
1555 }
1556 }
1557 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001558 int[] resultArray = new int[2];
1559 resultArray[0] = mResult;
1560 resultArray[1] = mRetryCount;
1561 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 }
1563 }
1564
1565 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001566 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001567
1568 }
1569
Wink Savilleb564aae2014-10-23 10:18:09 -07001570 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 // No permission check needed here: this call is harmless, and it's
1572 // needed for the ServiceState.requestStateUpdate() call (which is
1573 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001574 final long identity = Binder.clearCallingIdentity();
1575 try {
1576 final Phone phone = getPhone(subId);
1577 if (phone != null) {
1578 phone.updateServiceLocation();
1579 }
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001585 @Override
1586 public boolean isRadioOn(String callingPackage) {
1587 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001588 }
1589
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001590 @Override
1591 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001593 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001594 return false;
1595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001596
1597 final long identity = Binder.clearCallingIdentity();
1598 try {
1599 return isRadioOnForSubscriber(subId);
1600 } finally {
1601 Binder.restoreCallingIdentity(identity);
1602 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001603 }
1604
1605 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001606 final long identity = Binder.clearCallingIdentity();
1607 try {
1608 final Phone phone = getPhone(subId);
1609 if (phone != null) {
1610 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1611 } else {
1612 return false;
1613 }
1614 } finally {
1615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 }
1618
1619 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001620 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
Wink Saville36469e72014-06-11 15:17:00 -07001622
Wink Savilleb564aae2014-10-23 10:18:09 -07001623 public void toggleRadioOnOffForSubscriber(int subId) {
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(!isRadioOnForSubscriber(subId));
1631 }
1632 } finally {
1633 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001634 }
Wink Saville36469e72014-06-11 15:17:00 -07001635 }
1636
1637 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001638 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001639 }
1640
Wink Savilleb564aae2014-10-23 10:18:09 -07001641 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001642 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001643
1644 final long identity = Binder.clearCallingIdentity();
1645 try {
1646 final Phone phone = getPhone(subId);
1647 if (phone == null) {
1648 return false;
1649 }
1650 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1651 toggleRadioOnOffForSubscriber(subId);
1652 }
1653 return true;
1654 } finally {
1655 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 }
Wink Saville36469e72014-06-11 15:17:00 -07001658
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001659 public boolean needMobileRadioShutdown() {
1660 /*
1661 * If any of the Radios are available, it will need to be
1662 * shutdown. So return true if any Radio is available.
1663 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1667 Phone phone = PhoneFactory.getPhone(i);
1668 if (phone != null && phone.isRadioAvailable()) return true;
1669 }
1670 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1671 return false;
1672 } finally {
1673 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001674 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001675 }
1676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001677 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001678 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001679 enforceModifyPermission();
1680
1681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1684 logv("Shutting down Phone " + i);
1685 shutdownRadioUsingPhoneId(i);
1686 }
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001689 }
1690 }
1691
1692 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001693 Phone phone = PhoneFactory.getPhone(phoneId);
1694 if (phone != null && phone.isRadioAvailable()) {
1695 phone.shutdownRadio();
1696 }
1697 }
1698
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001700 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001701
1702 final long identity = Binder.clearCallingIdentity();
1703 try {
1704 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1705 if (defaultPhone != null) {
1706 defaultPhone.setRadioPower(turnOn);
1707 return true;
1708 } else {
1709 loge("There's no default phone.");
1710 return false;
1711 }
1712 } finally {
1713 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001714 }
Wink Saville36469e72014-06-11 15:17:00 -07001715 }
1716
Wink Savilleb564aae2014-10-23 10:18:09 -07001717 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001719
1720 final long identity = Binder.clearCallingIdentity();
1721 try {
1722 final Phone phone = getPhone(subId);
1723 if (phone != null) {
1724 phone.setRadioPower(turnOn);
1725 return true;
1726 } else {
1727 return false;
1728 }
1729 } finally {
1730 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 }
1733
Wink Saville36469e72014-06-11 15:17:00 -07001734 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 public boolean enableDataConnectivity() {
1737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001738
1739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 int subId = mSubscriptionController.getDefaultDataSubId();
1742 final Phone phone = getPhone(subId);
1743 if (phone != null) {
1744 phone.setUserDataEnabled(true);
1745 return true;
1746 } else {
1747 return false;
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
1753
Wink Saville36469e72014-06-11 15:17:00 -07001754 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001755 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 public boolean disableDataConnectivity() {
1757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001758
1759 final long identity = Binder.clearCallingIdentity();
1760 try {
1761 int subId = mSubscriptionController.getDefaultDataSubId();
1762 final Phone phone = getPhone(subId);
1763 if (phone != null) {
1764 phone.setUserDataEnabled(false);
1765 return true;
1766 } else {
1767 return false;
1768 }
1769 } finally {
1770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
Sanket Padawe356d7632015-06-22 14:03:32 -07001774 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001775 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 final Phone phone = getPhone(subId);
1779 if (phone != null) {
1780 return phone.isDataAllowed();
1781 } else {
1782 return false;
1783 }
1784 } finally {
1785 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 }
1788
1789 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001790 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001791 }
1792
pkanwarae03a6b2016-11-06 20:37:09 -08001793 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001794 enforceCallPermission();
1795
1796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1799 return;
1800 }
1801 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1802 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1803 } finally {
1804 Binder.restoreCallingIdentity(identity);
1805 }
pkanwar32d516d2016-10-14 19:37:38 -07001806 };
1807
Wink Savilleb564aae2014-10-23 10:18:09 -07001808 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001810
1811 final long identity = Binder.clearCallingIdentity();
1812 try {
1813 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1814 return false;
1815 }
1816 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1817 } finally {
1818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 }
1821
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001823 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001824 }
1825
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001826 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001827 final long identity = Binder.clearCallingIdentity();
1828 try {
1829 Phone phone = PhoneFactory.getPhone(slotIndex);
1830 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1831 PhoneConstantConversions.convertCallState(phone.getState());
1832 } finally {
1833 Binder.restoreCallingIdentity(identity);
1834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 }
1836
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001839 final long identity = Binder.clearCallingIdentity();
1840 try {
1841 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1842 if (phone != null) {
1843 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1844 } else {
1845 return PhoneConstantConversions.convertDataState(
1846 PhoneConstants.DataState.DISCONNECTED);
1847 }
1848 } finally {
1849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 }
1852
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001855 final long identity = Binder.clearCallingIdentity();
1856 try {
1857 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1858 if (phone != null) {
1859 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1860 } else {
1861 return TelephonyManager.DATA_ACTIVITY_NONE;
1862 }
1863 } finally {
1864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 }
1867
1868 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001869 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001870 mPhone.getContext().getSystemService(AppOpsManager.class)
1871 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001872 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001873 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001874 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 }
1876
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001877 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878 final long identity = Binder.clearCallingIdentity();
1879 try {
1880 if (DBG_LOC) log("getCellLocation: is active user");
1881 Bundle data = new Bundle();
1882 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1883 if (phone == null) {
1884 return null;
1885 }
1886
1887 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1888 return data;
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
1891 }
Svetoslav64fad262015-04-14 14:35:21 -07001892 }
1893
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001895 public String getNetworkCountryIsoForPhone(int phoneId) {
1896 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1897 // registered cell info, so return a NULL country instead.
1898 final long identity = Binder.clearCallingIdentity();
1899 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001900 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1901 // Get default phone in this case.
1902 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1903 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001904 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001905 // Todo: fix this when we can get the actual cellular network info when the device
1906 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001907 if (TelephonyManager.NETWORK_TYPE_IWLAN
1908 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1909 return "";
1910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911 Phone phone = PhoneFactory.getPhone(phoneId);
1912 if (phone != null) {
1913 ServiceStateTracker sst = phone.getServiceStateTracker();
1914 if (sst != null) {
1915 LocaleTracker lt = sst.getLocaleTracker();
1916 if (lt != null) {
1917 return lt.getCurrentCountry();
1918 }
1919 }
1920 }
1921 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001922 } finally {
1923 Binder.restoreCallingIdentity(identity);
1924 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001925 }
1926
1927 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001929 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001930 }
1931
Sanket Padawe356d7632015-06-22 14:03:32 -07001932 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001933 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 mApp.enforceCallingOrSelfPermission(
1935 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001936
1937 final long identity = Binder.clearCallingIdentity();
1938 try {
1939 final Phone phone = getPhone(subId);
1940 if (phone != null) {
1941 phone.enableLocationUpdates();
1942 }
1943 } finally {
1944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
1948 @Override
1949 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001950 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001951 }
1952
Sanket Padawe356d7632015-06-22 14:03:32 -07001953 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001954 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 mApp.enforceCallingOrSelfPermission(
1956 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001957
1958 final long identity = Binder.clearCallingIdentity();
1959 try {
1960 final Phone phone = getPhone(subId);
1961 if (phone != null) {
1962 phone.disableLocationUpdates();
1963 }
1964 } finally {
1965 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 }
1968
1969 @Override
1970 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001971 public List<NeighboringCellInfo>
1972 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001973 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1974 throw new SecurityException(
1975 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1976 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001977
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1979 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1980 return null;
1981 }
Svetoslav64fad262015-04-14 14:35:21 -07001982
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001983 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984
Nathan Haroldf180aac2018-06-01 18:43:55 -07001985 List<CellInfo> info = getAllCellInfo(callingPackage);
1986 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987
Nathan Haroldf180aac2018-06-01 18:43:55 -07001988 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1989 for (CellInfo ci : info) {
1990 if (ci instanceof CellInfoGsm) {
1991 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1992 } else if (ci instanceof CellInfoWcdma) {
1993 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001996 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
1999
2000 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002001 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08002002 mPhone.getContext().getSystemService(AppOpsManager.class)
2003 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002004 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08002005 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07002006 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 }
2008
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002009 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002010 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002011 final long identity = Binder.clearCallingIdentity();
2012 try {
2013 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2014 for (Phone phone : PhoneFactory.getPhones()) {
2015 final List<CellInfo> info = phone.getAllCellInfo(workSource);
2016 if (info != null) cellInfos.addAll(info);
2017 }
2018 return cellInfos;
2019 } finally {
2020 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 }
2022 }
2023
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002024 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002025 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002026 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002027 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028
2029 final long identity = Binder.clearCallingIdentity();
2030 try {
2031 mPhone.setCellInfoListRate(rateInMillis, workSource);
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
2034 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 }
2036
Shishir Agrawala9f32182016-04-12 12:00:16 -07002037 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002038 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002039 Phone phone = PhoneFactory.getPhone(slotIndex);
2040 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002041 return null;
2042 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002043 int subId = phone.getSubId();
2044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2045 mApp, subId, callingPackage, "getImeiForSlot")) {
2046 return null;
2047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002048
2049 final long identity = Binder.clearCallingIdentity();
2050 try {
2051 return phone.getImei();
2052 } finally {
2053 Binder.restoreCallingIdentity(identity);
2054 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002055 }
2056
2057 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002058 public String getTypeAllocationCodeForSlot(int slotIndex) {
2059 Phone phone = PhoneFactory.getPhone(slotIndex);
2060 String tac = null;
2061 if (phone != null) {
2062 String imei = phone.getImei();
2063 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2064 }
2065 return tac;
2066 }
2067
2068 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002069 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002070 Phone phone = PhoneFactory.getPhone(slotIndex);
2071 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002072 return null;
2073 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002074 int subId = phone.getSubId();
2075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2076 mApp, subId, callingPackage, "getMeidForSlot")) {
2077 return null;
2078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002079
2080 final long identity = Binder.clearCallingIdentity();
2081 try {
2082 return phone.getMeid();
2083 } finally {
2084 Binder.restoreCallingIdentity(identity);
2085 }
Jack Yu2af8d712017-03-15 17:14:14 -07002086 }
2087
2088 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002089 public String getManufacturerCodeForSlot(int slotIndex) {
2090 Phone phone = PhoneFactory.getPhone(slotIndex);
2091 String manufacturerCode = null;
2092 if (phone != null) {
2093 String meid = phone.getMeid();
2094 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2095 }
2096 return manufacturerCode;
2097 }
2098
2099 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002100 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002101 Phone phone = PhoneFactory.getPhone(slotIndex);
2102 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002103 return null;
2104 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002105 int subId = phone.getSubId();
2106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2107 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2108 return null;
2109 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002110
2111 final long identity = Binder.clearCallingIdentity();
2112 try {
2113 return phone.getDeviceSvn();
2114 } finally {
2115 Binder.restoreCallingIdentity(identity);
2116 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002117 }
2118
fionaxu43304da2017-11-27 22:51:16 -08002119 @Override
2120 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 final Phone phone = getPhone(subId);
2124 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2125 } finally {
2126 Binder.restoreCallingIdentity(identity);
2127 }
fionaxu43304da2017-11-27 22:51:16 -08002128 }
2129
2130 @Override
2131 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 final Phone phone = getPhone(subId);
2135 return phone == null ? null : phone.getCarrierName();
2136 } finally {
2137 Binder.restoreCallingIdentity(identity);
2138 }
fionaxu43304da2017-11-27 22:51:16 -08002139 }
2140
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 //
2142 // Internal helper methods.
2143 //
2144
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002145 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2147 *
2148 * @throws SecurityException if the caller does not have the required permission
2149 */
2150 private void enforceModifyPermission() {
2151 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2152 }
2153
2154 /**
2155 * Make sure the caller has the CALL_PHONE permission.
2156 *
2157 * @throws SecurityException if the caller does not have the required permission
2158 */
2159 private void enforceCallPermission() {
2160 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2161 }
2162
Stuart Scott8eef64f2015-04-08 15:13:54 -07002163 private void enforceConnectivityInternalPermission() {
2164 mApp.enforceCallingOrSelfPermission(
2165 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2166 "ConnectivityService");
2167 }
2168
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 private String createTelUrl(String number) {
2170 if (TextUtils.isEmpty(number)) {
2171 return null;
2172 }
2173
Jake Hambye994d462014-02-03 13:10:13 -08002174 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 }
2176
Ihab Awadf9e92732013-12-05 18:02:52 -08002177 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2179 }
2180
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002181 private static void logv(String msg) {
2182 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2183 }
2184
Ihab Awadf9e92732013-12-05 18:02:52 -08002185 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2187 }
2188
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002189 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002191 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
Sanket Padawe356d7632015-06-22 14:03:32 -07002194 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002195 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002196 final long identity = Binder.clearCallingIdentity();
2197 try {
2198 final Phone phone = PhoneFactory.getPhone(slotIndex);
2199 if (phone == null) {
2200 return PhoneConstants.PHONE_TYPE_NONE;
2201 } else {
2202 return phone.getPhoneType();
2203 }
2204 } finally {
2205 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 }
2208
2209 /**
2210 * Returns the CDMA ERI icon index to display
2211 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002212 @Override
2213 public int getCdmaEriIconIndex(String callingPackage) {
2214 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002215 }
2216
Sanket Padawe356d7632015-06-22 14:03:32 -07002217 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002218 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002220 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002221 return -1;
2222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223
2224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 final Phone phone = getPhone(subId);
2227 if (phone != null) {
2228 return phone.getCdmaEriIconIndex();
2229 } else {
2230 return -1;
2231 }
2232 } finally {
2233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 }
2236
2237 /**
2238 * Returns the CDMA ERI icon mode,
2239 * 0 - ON
2240 * 1 - FLASHING
2241 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002242 @Override
2243 public int getCdmaEriIconMode(String callingPackage) {
2244 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002245 }
2246
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002248 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002250 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002251 return -1;
2252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253
2254 final long identity = Binder.clearCallingIdentity();
2255 try {
2256 final Phone phone = getPhone(subId);
2257 if (phone != null) {
2258 return phone.getCdmaEriIconMode();
2259 } else {
2260 return -1;
2261 }
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 }
2266
2267 /**
2268 * Returns the CDMA ERI text,
2269 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002270 @Override
2271 public String getCdmaEriText(String callingPackage) {
2272 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002273 }
2274
Sanket Padawe356d7632015-06-22 14:03:32 -07002275 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002276 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002278 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002279 return null;
2280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002281
2282 final long identity = Binder.clearCallingIdentity();
2283 try {
2284 final Phone phone = getPhone(subId);
2285 if (phone != null) {
2286 return phone.getCdmaEriText();
2287 } else {
2288 return null;
2289 }
2290 } finally {
2291 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
2295 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002296 * Returns the CDMA MDN.
2297 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002298 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002299 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2301 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302
2303 final long identity = Binder.clearCallingIdentity();
2304 try {
2305 final Phone phone = getPhone(subId);
2306 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2307 return phone.getLine1Number();
2308 } else {
2309 return null;
2310 }
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002313 }
2314 }
2315
2316 /**
2317 * Returns the CDMA MIN.
2318 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002320 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2322 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002323
2324 final long identity = Binder.clearCallingIdentity();
2325 try {
2326 final Phone phone = getPhone(subId);
2327 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2328 return phone.getCdmaMin();
2329 } else {
2330 return null;
2331 }
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002334 }
2335 }
2336
2337 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 * Returns true if CDMA provisioning needs to run.
2339 */
2340 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 return mPhone.needsOtaServiceProvisioning();
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
2346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 }
2348
2349 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002350 * Sets the voice mail number of a given subId.
2351 */
2352 @Override
2353 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002354 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355
2356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2359 new Pair<String, String>(alphaTag, number), new Integer(subId));
2360 return success;
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
2363 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002364 }
2365
Ta-wei Yen87c49842016-05-13 21:19:52 -07002366 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002367 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2369 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2370 if (!TextUtils.equals(callingPackage, systemDialer)) {
2371 throw new SecurityException("caller must be system dialer");
2372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002373
2374 final long identity = Binder.clearCallingIdentity();
2375 try {
2376 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2377 if (phoneAccountHandle == null) {
2378 return null;
2379 }
2380 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002383 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002384 }
2385
2386 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002387 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002390 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002391 return null;
2392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 return RemoteVvmTaskManager
2397 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2398 } finally {
2399 Binder.restoreCallingIdentity(identity);
2400 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002401 }
2402
2403 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002404 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2405 VisualVoicemailSmsFilterSettings settings) {
2406 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002407
2408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2411 mPhone.getContext(), callingPackage, subId, settings);
2412 } finally {
2413 Binder.restoreCallingIdentity(identity);
2414 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002415 }
2416
2417 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002418 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2419 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420
2421 final long identity = Binder.clearCallingIdentity();
2422 try {
2423 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2424 mPhone.getContext(), callingPackage, subId);
2425 } finally {
2426 Binder.restoreCallingIdentity(identity);
2427 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002428 }
2429
2430 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002431 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2432 String callingPackage, int subId) {
2433 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434
2435 final long identity = Binder.clearCallingIdentity();
2436 try {
2437 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2438 mPhone.getContext(), callingPackage, subId);
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
2441 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002442 }
2443
2444 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002445 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002446 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447
2448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2451 mPhone.getContext(), subId);
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
2454 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002455 }
2456
2457 @Override
2458 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2459 String number, int port, String text, PendingIntent sentIntent) {
2460 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002461 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002462 enforceSendSmsPermission();
2463 // Make the calls as the phone process.
2464 final long identity = Binder.clearCallingIdentity();
2465 try {
2466 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2467 if (port == 0) {
2468 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2469 sentIntent, null, false);
2470 } else {
2471 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2472 smsManager.sendDataMessageWithSelfPermissions(number, null,
2473 (short) port, data, sentIntent, null);
2474 }
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
2477 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002478 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002479 /**
fionaxu0152e512016-11-14 13:36:14 -08002480 * Sets the voice activation state of a given subId.
2481 */
2482 @Override
2483 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2485 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486
2487 final long identity = Binder.clearCallingIdentity();
2488 try {
2489 final Phone phone = getPhone(subId);
2490 if (phone != null) {
2491 phone.setVoiceActivationState(activationState);
2492 } else {
2493 loge("setVoiceActivationState fails with invalid subId: " + subId);
2494 }
2495 } finally {
2496 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002497 }
2498 }
2499
2500 /**
2501 * Sets the data activation state of a given subId.
2502 */
2503 @Override
2504 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2506 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507
2508 final long identity = Binder.clearCallingIdentity();
2509 try {
2510 final Phone phone = getPhone(subId);
2511 if (phone != null) {
2512 phone.setDataActivationState(activationState);
2513 } else {
2514 loge("setVoiceActivationState fails with invalid subId: " + subId);
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002518 }
2519 }
2520
2521 /**
2522 * Returns the voice activation state of a given subId.
2523 */
2524 @Override
2525 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002526 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527
fionaxu0152e512016-11-14 13:36:14 -08002528 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529 final long identity = Binder.clearCallingIdentity();
2530 try {
2531 if (phone != null) {
2532 return phone.getVoiceActivationState();
2533 } else {
2534 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2535 }
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002538 }
2539 }
2540
2541 /**
2542 * Returns the data activation state of a given subId.
2543 */
2544 @Override
2545 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002546 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547
fionaxu0152e512016-11-14 13:36:14 -08002548 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 if (phone != null) {
2552 return phone.getDataActivationState();
2553 } else {
2554 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2555 }
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002558 }
2559 }
2560
2561 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 * Returns the unread count of voicemails
2563 */
2564 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002565 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002566 }
2567
2568 /**
2569 * Returns the unread count of voicemails for a subId
2570 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002571 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002572 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 final Phone phone = getPhone(subId);
2576 if (phone != null) {
2577 return phone.getVoiceMessageCount();
2578 } else {
2579 return 0;
2580 }
2581 } finally {
2582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 }
2585
2586 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002587 * returns true, if the device is in a state where both voice and data
2588 * are supported simultaneously. This can change based on location or network condition.
2589 */
2590 @Override
2591 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = getPhone(subId);
2595 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2596 } finally {
2597 Binder.restoreCallingIdentity(identity);
2598 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002599 }
2600
2601 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002602 * Send the dialer code if called from the current default dialer or the caller has
2603 * carrier privilege.
2604 * @param inputCode The dialer code to send
2605 */
2606 @Override
2607 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2608 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2609 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2610 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002611 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2612 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 mPhone.sendDialerSpecialCode(inputCode);
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
2620 }
fionaxu235cc5e2017-03-06 22:25:57 -08002621 }
2622
2623 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002624 * Returns the data network type.
2625 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 *
2627 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2628 */
2629 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002630 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 final Phone phone = getPhone(getDefaultSubscription());
2634 if (phone != null) {
2635 return phone.getServiceState().getDataNetworkType();
2636 } else {
2637 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2638 }
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002641 }
Wink Saville36469e72014-06-11 15:17:00 -07002642 }
2643
Pengquan Menga1bb6272018-09-06 09:59:22 -07002644 @Override
2645 public int getNetworkSelectionMode(int subId) {
2646 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2647 }
2648
Wink Saville36469e72014-06-11 15:17:00 -07002649 /**
2650 * Returns the network type for a subId
2651 */
2652 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002653 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002655 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002656 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2657 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 final Phone phone = getPhone(subId);
2662 if (phone != null) {
2663 return phone.getServiceState().getDataNetworkType();
2664 } else {
2665 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2666 }
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
2672 /**
2673 * Returns the data network type
2674 */
2675 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002676 public int getDataNetworkType(String callingPackage) {
2677 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002678 }
2679
2680 /**
2681 * Returns the data network type for a subId
2682 */
2683 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002684 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002686 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002687 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2688 }
2689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 final long identity = Binder.clearCallingIdentity();
2691 try {
2692 final Phone phone = getPhone(subId);
2693 if (phone != null) {
2694 return phone.getServiceState().getDataNetworkType();
2695 } else {
2696 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2697 }
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 }
2702
2703 /**
Wink Saville36469e72014-06-11 15:17:00 -07002704 * Returns the Voice network type for a subId
2705 */
2706 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002707 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002709 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002710 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2711 }
2712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 final Phone phone = getPhone(subId);
2716 if (phone != null) {
2717 return phone.getServiceState().getVoiceNetworkType();
2718 } else {
2719 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2720 }
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
2725
2726 /**
2727 * @return true if a ICC card is present
2728 */
2729 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002730 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002731 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2732 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002733 }
2734
2735 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002736 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002737 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002738 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002739 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 final long identity = Binder.clearCallingIdentity();
2741 try {
2742 final Phone phone = PhoneFactory.getPhone(slotIndex);
2743 if (phone != null) {
2744 return phone.getIccCard().hasIccCard();
2745 } else {
2746 return false;
2747 }
2748 } finally {
2749 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 }
2752
2753 /**
2754 * Return if the current radio is LTE on CDMA. This
2755 * is a tri-state return value as for a period of time
2756 * the mode may be unknown.
2757 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002758 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002760 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002762 @Override
2763 public int getLteOnCdmaMode(String callingPackage) {
2764 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002765 }
2766
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002768 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002770 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002771 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2772 }
2773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 final long identity = Binder.clearCallingIdentity();
2775 try {
2776 final Phone phone = getPhone(subId);
2777 if (phone == null) {
2778 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2779 } else {
2780 return phone.getLteOnCdmaMode();
2781 }
2782 } finally {
2783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002784 }
Wink Saville36469e72014-06-11 15:17:00 -07002785 }
2786
2787 public void setPhone(Phone phone) {
2788 mPhone = phone;
2789 }
2790
2791 /**
2792 * {@hide}
2793 * Returns Default subId, 0 in the case of single standby.
2794 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002795 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002796 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002797 }
2798
Shishir Agrawala9f32182016-04-12 12:00:16 -07002799 private int getSlotForDefaultSubscription() {
2800 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2801 }
2802
Wink Savilleb564aae2014-10-23 10:18:09 -07002803 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002804 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002806
2807 /**
2808 * @see android.telephony.TelephonyManager.WifiCallingChoices
2809 */
2810 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 final long identity = Binder.clearCallingIdentity();
2812 try {
2813 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2814 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2815 getWhenToMakeWifiCallsDefaultPreference());
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
2818 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002819 }
2820
2821 /**
2822 * @see android.telephony.TelephonyManager.WifiCallingChoices
2823 */
2824 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2828 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2829 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
2832 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002833 }
2834
Sailesh Nepald1e68152013-12-12 19:08:02 -08002835 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002836 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002837 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002838 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002839
Shishir Agrawal566b7612013-10-28 14:41:00 -07002840 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002841 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2842 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2844 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 if (TextUtils.equals(ISDR_AID, aid)) {
2850 // Only allows LPA to open logical channel to ISD-R.
2851 ComponentInfo bestComponent =
2852 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2853 if (bestComponent == null
2854 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2855 loge("The calling package is not allowed to access ISD-R.");
2856 throw new SecurityException(
2857 "The calling package is not allowed to access ISD-R.");
2858 }
Derek Tan740e1672017-06-27 14:56:27 -07002859 }
Derek Tan740e1672017-06-27 14:56:27 -07002860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002861 if (DBG) {
2862 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2863 }
2864 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2865 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2866 if (DBG) log("iccOpenLogicalChannel: " + response);
2867 return response;
2868 } finally {
2869 Binder.restoreCallingIdentity(identity);
2870 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002871 }
2872
2873 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002874 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2876 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2881 if (channel < 0) {
2882 return false;
2883 }
2884 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2885 if (DBG) log("iccCloseLogicalChannel: " + success);
2886 return success;
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002889 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002890 }
2891
2892 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002893 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002894 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2896 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898 final long identity = Binder.clearCallingIdentity();
2899 try {
2900 if (DBG) {
2901 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2902 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2903 + p3 + " data=" + data);
2904 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 if (channel < 0) {
2907 return "";
2908 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2911 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2912 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914 // Append the returned status code to the end of the response payload.
2915 String s = Integer.toHexString(
2916 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2917 if (response.payload != null) {
2918 s = IccUtils.bytesToHexString(response.payload) + s;
2919 }
2920 return s;
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002923 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002924 }
Jake Hambye994d462014-02-03 13:10:13 -08002925
Evan Charltonc66da362014-05-16 14:06:40 -07002926 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002927 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2928 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2930 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2936 && TextUtils.equals(ISDR_AID, data)) {
2937 // Only allows LPA to select ISD-R.
2938 ComponentInfo bestComponent =
2939 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2940 if (bestComponent == null
2941 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2942 loge("The calling package is not allowed to select ISD-R.");
2943 throw new SecurityException(
2944 "The calling package is not allowed to select ISD-R.");
2945 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002946 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 if (DBG) {
2949 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2950 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2951 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002953 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2954 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2955 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957 // Append the returned status code to the end of the response payload.
2958 String s = Integer.toHexString(
2959 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2960 if (response.payload != null) {
2961 s = IccUtils.bytesToHexString(response.payload) + s;
2962 }
2963 return s;
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002966 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002967 }
2968
2969 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002970 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002971 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2973 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 if (DBG) {
2978 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2979 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2980 }
2981
2982 IccIoResult response =
2983 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2984 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2985 subId);
2986
2987 if (DBG) {
2988 log("Exchange SIM_IO [R]" + response);
2989 }
2990
2991 byte[] result = null;
2992 int length = 2;
2993 if (response.payload != null) {
2994 length = 2 + response.payload.length;
2995 result = new byte[length];
2996 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2997 } else {
2998 result = new byte[length];
2999 }
3000
3001 result[length - 1] = (byte) response.sw2;
3002 result[length - 2] = (byte) response.sw1;
3003 return result;
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003006 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003007 }
3008
Nathan Haroldb3014052017-01-25 15:57:32 -08003009 /**
3010 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3011 * on a particular subscription
3012 */
sqianb6e41952018-03-12 14:54:01 -07003013 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3015 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3016 return null;
3017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 if (appType != TelephonyManager.APPTYPE_USIM
3022 && appType != TelephonyManager.APPTYPE_SIM) {
3023 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3024 return null;
3025 }
3026 Object response = sendRequest(
3027 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3028 if (response instanceof String[]) {
3029 return (String[]) response;
3030 }
3031 // Response is an Exception of some kind,
3032 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003033 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 } finally {
3035 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003036 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003037 }
3038
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003039 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003040 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3042 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3047 if (response.payload == null) {
3048 return "";
3049 }
Evan Charltonc66da362014-05-16 14:06:40 -07003050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051 // Append the returned status code to the end of the response payload.
3052 String s = Integer.toHexString(
3053 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3054 s = IccUtils.bytesToHexString(response.payload) + s;
3055 return s;
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
Evan Charltonc66da362014-05-16 14:06:40 -07003059 }
3060
Jake Hambye994d462014-02-03 13:10:13 -08003061 /**
3062 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3063 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3064 *
3065 * @param itemID the ID of the item to read
3066 * @return the NV item as a String, or null on error.
3067 */
3068 @Override
3069 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003070 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3072 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003077 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3079 return value;
3080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
Jake Hambye994d462014-02-03 13:10:13 -08003083 }
3084
3085 /**
3086 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3087 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3088 *
3089 * @param itemID the ID of the item to read
3090 * @param itemValue the value to write, as a String
3091 * @return true on success; false on any failure
3092 */
3093 @Override
3094 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003095 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3097 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003098
3099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3102 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003103 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003104 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3105 return success;
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
Jake Hambye994d462014-02-03 13:10:13 -08003109 }
3110
3111 /**
3112 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3113 * Used for device configuration by some CDMA operators.
3114 *
3115 * @param preferredRoamingList byte array containing the new PRL
3116 * @return true on success; false on any failure
3117 */
3118 @Override
3119 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3121 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3126 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3127 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3128 return success;
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
Jake Hambye994d462014-02-03 13:10:13 -08003132 }
3133
3134 /**
3135 * Perform the specified type of NV config reset.
3136 * Used for device configuration by some CDMA operators.
3137 *
3138 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3139 * @return true on success; false on any failure
3140 */
3141 @Override
3142 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3144 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145
3146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 if (DBG) log("nvResetConfig: type " + resetType);
3149 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3150 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3151 return success;
3152 } finally {
3153 Binder.restoreCallingIdentity(identity);
3154 }
Jake Hambye994d462014-02-03 13:10:13 -08003155 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003156
Svet Ganovb320e182015-04-16 12:30:10 -07003157 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003159 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003160 return new String[0];
3161 }
3162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 return mPhone.getPcscfAddress(apnType);
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
3168 }
Wink Saville36469e72014-06-11 15:17:00 -07003169 }
3170
Brad Ebinger51f743a2017-01-23 13:50:20 -08003171 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003172 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3173 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003174 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003175 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003176 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177
3178 final long identity = Binder.clearCallingIdentity();
3179 try {
3180 PhoneFactory.getImsResolver().enableIms(slotId);
3181 } finally {
3182 Binder.restoreCallingIdentity(identity);
3183 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003184 }
3185
3186 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003187 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3188 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003189 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003190 public void disableIms(int slotId) {
3191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192
3193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 PhoneFactory.getImsResolver().disableIms(slotId);
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003199 }
3200
3201 /**
3202 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3203 * feature or {@link null} if the service is not available. If the feature is available, the
3204 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3205 */
3206 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003207 IImsServiceFeatureCallback callback) {
3208 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003216 }
3217
3218 /**
3219 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3220 * feature during emergency calling or {@link null} if the service is not available. If the
3221 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3222 * listener for feature updates.
3223 */
3224 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3225 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3230 } finally {
3231 Binder.restoreCallingIdentity(identity);
3232 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003233 }
3234
Brad Ebinger5f64b052017-12-14 14:26:15 -08003235 /**
3236 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3237 * specified.
3238 */
3239 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3240 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241
3242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003248 }
3249
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003250 /**
3251 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3252 * specified.
3253 */
3254 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3255 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003256
3257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3260 } finally {
3261 Binder.restoreCallingIdentity(identity);
3262 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003263 }
3264
Brad Ebinger884c07b2018-02-15 16:17:40 -08003265 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003266 * Sets the ImsService Package Name that Telephony will bind to.
3267 *
3268 * @param slotId the slot ID that the ImsService should bind for.
3269 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3270 * ImsService is the device default ImsService.
3271 * @param packageName The package name of the application that contains the ImsService to bind
3272 * to.
3273 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3274 * @hide
3275 */
3276 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003277 int[] subIds = SubscriptionManager.getSubId(slotId);
3278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3279 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3280 "setImsService");
3281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3285 isCarrierImsService, packageName);
3286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003289 }
3290
3291 /**
3292 * Return the ImsService configuration.
3293 *
3294 * @param slotId The slot that the ImsService is associated with.
3295 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3296 * the device default.
3297 * @return the package name of the ImsService configuration.
3298 */
3299 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003300 int[] subIds = SubscriptionManager.getSubId(slotId);
3301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3302 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3303 "getImsService");
3304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3308 isCarrierImsService);
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003312 }
3313
Wink Saville36469e72014-06-11 15:17:00 -07003314 public void setImsRegistrationState(boolean registered) {
3315 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316
3317 final long identity = Binder.clearCallingIdentity();
3318 try {
3319 mPhone.setImsRegistrationState(registered);
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
3322 }
Wink Saville36469e72014-06-11 15:17:00 -07003323 }
3324
3325 /**
Stuart Scott54788802015-03-30 13:18:01 -07003326 * Set the network selection mode to automatic.
3327 *
3328 */
3329 @Override
3330 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3332 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333
3334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3337 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3338 } finally {
3339 Binder.restoreCallingIdentity(identity);
3340 }
Stuart Scott54788802015-03-30 13:18:01 -07003341 }
3342
3343 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003344 * Set the network selection mode to manual with the selected carrier.
3345 */
3346 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003347 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003348 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3350 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351
3352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003355 /* operatorAlphaLong */ "",
3356 /* operatorAlphaShort */ "",
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 operatorNumeric);
3358 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3359 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3360 persistSelection);
3361 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003365 }
3366
3367 /**
3368 * Scans for available networks.
3369 */
3370 @Override
3371 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3373 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003374
Pengquan Menga1bb6272018-09-06 09:59:22 -07003375 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376 try {
3377 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003378 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003383 }
3384
3385 /**
yinxub1bed742017-04-17 11:45:04 -07003386 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003387 *
yinxub1bed742017-04-17 11:45:04 -07003388 * @param subId id of the subscription
3389 * @param request contains the radio access networks with bands/channels to scan
3390 * @param messenger callback messenger for scan results or errors
3391 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003392 * @return the id of the requested scan which can be used to stop the scan.
3393 */
3394 @Override
3395 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3396 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3398 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399
3400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 return mNetworkScanRequestTracker.startNetworkScan(
3403 request, messenger, binder, getPhone(subId));
3404 } finally {
3405 Binder.restoreCallingIdentity(identity);
3406 }
yinxu504e1392017-04-12 16:03:22 -07003407 }
3408
3409 /**
3410 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003411 *
3412 * @param subId id of the subscription
3413 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003414 */
3415 @Override
3416 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3418 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
yinxu504e1392017-04-12 16:03:22 -07003426 }
3427
3428 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003429 * Get the calculated preferred network type.
3430 * Used for debugging incorrect network type.
3431 *
3432 * @return the preferred network type, defined in RILConstants.java.
3433 */
3434 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003435 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003437 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003438 return RILConstants.PREFERRED_NETWORK_MODE;
3439 }
3440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 // FIXME: need to get SubId from somewhere.
3444 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
Junda Liu84d15a22014-07-02 11:21:04 -07003448 }
3449
3450 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003451 * Get the preferred network type.
3452 * Used for device configuration by some CDMA operators.
3453 *
3454 * @return the preferred network type, defined in RILConstants.java.
3455 */
3456 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003457 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3459 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003460
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 if (DBG) log("getPreferredNetworkType");
3464 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3465 int networkType = (result != null ? result[0] : -1);
3466 if (DBG) log("getPreferredNetworkType: " + networkType);
3467 return networkType;
3468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003471 }
3472
3473 /**
3474 * Set the preferred network type.
3475 * Used for device configuration by some CDMA operators.
3476 *
3477 * @param networkType the preferred network type, defined in RILConstants.java.
3478 * @return true on success; false on any failure.
3479 */
3480 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003481 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3483 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003484
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3488 Boolean success = (Boolean) sendRequest(
3489 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3490 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3491 if (success) {
3492 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3493 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3494 }
3495 return success;
3496 } finally {
3497 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003498 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003499 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003500
3501 /**
Junda Liu475951f2014-11-07 16:45:03 -08003502 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3503 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3504 * tethering.
3505 *
3506 * @return 0: Not required. 1: required. 2: Not set.
3507 * @hide
3508 */
3509 @Override
3510 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003511 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512
3513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3516 Settings.Global.TETHER_DUN_REQUIRED, 2);
3517 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3518 // config_tether_apndata.
3519 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3520 dunRequired = 1;
3521 }
3522 return dunRequired;
3523 } finally {
3524 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003525 }
Junda Liu475951f2014-11-07 16:45:03 -08003526 }
3527
3528 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003529 * Set mobile data enabled
3530 * Used by the user through settings etc to turn on/off mobile data
3531 *
3532 * @param enable {@code true} turn turn data on, else {@code false}
3533 */
3534 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003535 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3537 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538
3539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 int phoneId = mSubscriptionController.getPhoneId(subId);
3542 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3543 Phone phone = PhoneFactory.getPhone(phoneId);
3544 if (phone != null) {
3545 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3546 phone.setUserDataEnabled(enable);
3547 } else {
3548 loge("setUserDataEnabled: no phone for subId=" + subId);
3549 }
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003552 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003553 }
3554
3555 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003556 * Get the user enabled state of Mobile Data.
3557 *
3558 * TODO: remove and use isUserDataEnabled.
3559 * This can't be removed now because some vendor codes
3560 * calls through ITelephony directly while they should
3561 * use TelephonyManager.
3562 *
3563 * @return true on enabled
3564 */
3565 @Override
3566 public boolean getDataEnabled(int subId) {
3567 return isUserDataEnabled(subId);
3568 }
3569
3570 /**
3571 * Get whether mobile data is enabled per user setting.
3572 *
3573 * There are other factors deciding whether mobile data is actually enabled, but they are
3574 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003575 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003576 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003577 *
3578 * @return {@code true} if data is enabled else {@code false}
3579 */
3580 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003581 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003582 try {
3583 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3584 null);
3585 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3587 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589
3590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 int phoneId = mSubscriptionController.getPhoneId(subId);
3593 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3594 Phone phone = PhoneFactory.getPhone(phoneId);
3595 if (phone != null) {
3596 boolean retVal = phone.isUserDataEnabled();
3597 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3598 return retVal;
3599 } else {
3600 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3601 return false;
3602 }
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003605 }
3606 }
3607
3608 /**
3609 * Get whether mobile data is enabled.
3610 *
3611 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3612 * whether mobile data is actually enabled.
3613 *
3614 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3615 *
3616 * @return {@code true} if data is enabled else {@code false}
3617 */
3618 @Override
3619 public boolean isDataEnabled(int subId) {
3620 try {
3621 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3622 null);
3623 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3625 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003627
3628 final long identity = Binder.clearCallingIdentity();
3629 try {
3630 int phoneId = mSubscriptionController.getPhoneId(subId);
3631 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3632 Phone phone = PhoneFactory.getPhone(phoneId);
3633 if (phone != null) {
3634 boolean retVal = phone.isDataEnabled();
3635 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3636 return retVal;
3637 } else {
3638 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3639 return false;
3640 }
3641 } finally {
3642 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003643 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003644 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003645
3646 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003647 public int getCarrierPrivilegeStatus(int subId) {
3648 final Phone phone = getPhone(subId);
3649 if (phone == null) {
3650 loge("getCarrierPrivilegeStatus: Invalid subId");
3651 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3652 }
3653 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003654 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003655 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003656 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3657 }
3658 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003659 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003660 }
Junda Liu29340342014-07-10 15:23:27 -07003661
3662 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003663 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3664 final Phone phone = getPhone(subId);
3665 if (phone == null) {
3666 loge("getCarrierPrivilegeStatus: Invalid subId");
3667 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3668 }
3669 UiccProfile profile =
3670 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3671 if (profile == null) {
3672 loge("getCarrierPrivilegeStatus: No UICC");
3673 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3674 }
3675 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3676 }
3677
3678 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003679 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003680 if (TextUtils.isEmpty(pkgName))
3681 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003682 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003683 if (card == null) {
3684 loge("checkCarrierPrivilegesForPackage: No UICC");
3685 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3686 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003687 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3688 }
3689
3690 @Override
3691 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003692 if (TextUtils.isEmpty(pkgName))
3693 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003694 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3695 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3696 UiccCard card = UiccController.getInstance().getUiccCard(i);
3697 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003698 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003699 continue;
3700 }
3701
3702 result = card.getCarrierPrivilegeStatus(
3703 mPhone.getContext().getPackageManager(), pkgName);
3704 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3705 break;
3706 }
3707 }
3708
3709 return result;
Junda Liu29340342014-07-10 15:23:27 -07003710 }
Derek Tan89e89d42014-07-08 17:00:10 -07003711
3712 @Override
Junda Liue64de782015-04-16 17:19:16 -07003713 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3714 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3715 loge("phoneId " + phoneId + " is not valid.");
3716 return null;
3717 }
3718 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003719 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003720 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003721 return null ;
3722 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003723 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003724 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003725 }
3726
Amith Yamasani6e118872016-02-19 12:53:51 -08003727 @Override
3728 public List<String> getPackagesWithCarrierPrivileges() {
3729 PackageManager pm = mPhone.getContext().getPackageManager();
3730 List<String> privilegedPackages = new ArrayList<>();
3731 List<PackageInfo> packages = null;
3732 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3733 UiccCard card = UiccController.getInstance().getUiccCard(i);
3734 if (card == null) {
3735 // No UICC in that slot.
3736 continue;
3737 }
3738 if (card.hasCarrierPrivilegeRules()) {
3739 if (packages == null) {
3740 // Only check packages in user 0 for now
3741 packages = pm.getInstalledPackagesAsUser(
3742 PackageManager.MATCH_DISABLED_COMPONENTS
3743 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3744 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3745 }
3746 for (int p = packages.size() - 1; p >= 0; p--) {
3747 PackageInfo pkgInfo = packages.get(p);
3748 if (pkgInfo != null && pkgInfo.packageName != null
3749 && card.getCarrierPrivilegeStatus(pkgInfo)
3750 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3751 privilegedPackages.add(pkgInfo.packageName);
3752 }
3753 }
3754 }
3755 }
3756 return privilegedPackages;
3757 }
3758
Wink Savilleb564aae2014-10-23 10:18:09 -07003759 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003760 final Phone phone = getPhone(subId);
3761 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003762 if (card == null) {
3763 loge("getIccId: No UICC");
3764 return null;
3765 }
3766 String iccId = card.getIccId();
3767 if (TextUtils.isEmpty(iccId)) {
3768 loge("getIccId: ICC ID is null or empty.");
3769 return null;
3770 }
3771 return iccId;
3772 }
3773
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003774 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003775 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3776 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003777 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3778 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780 final long identity = Binder.clearCallingIdentity();
3781 try {
3782 final String iccId = getIccId(subId);
3783 final Phone phone = getPhone(subId);
3784 if (phone == null) {
3785 return false;
3786 }
3787 final String subscriberId = phone.getSubscriberId();
3788
3789 if (DBG_MERGE) {
3790 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3791 + subscriberId + " to " + number);
3792 }
3793
3794 if (TextUtils.isEmpty(iccId)) {
3795 return false;
3796 }
3797
3798 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3799
3800 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3801 if (alphaTag == null) {
3802 editor.remove(alphaTagPrefKey);
3803 } else {
3804 editor.putString(alphaTagPrefKey, alphaTag);
3805 }
3806
3807 // Record both the line number and IMSI for this ICCID, since we need to
3808 // track all merged IMSIs based on line number
3809 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3810 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3811 if (number == null) {
3812 editor.remove(numberPrefKey);
3813 editor.remove(subscriberPrefKey);
3814 } else {
3815 editor.putString(numberPrefKey, number);
3816 editor.putString(subscriberPrefKey, subscriberId);
3817 }
3818
3819 editor.commit();
3820 return true;
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003823 }
Derek Tan7226c842014-07-02 17:42:23 -07003824 }
3825
3826 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003827 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003828 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003830 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003831 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003832 return null;
3833 }
Derek Tan97ebb422014-09-05 16:55:38 -07003834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003835 final long identity = Binder.clearCallingIdentity();
3836 try {
3837 String iccId = getIccId(subId);
3838 if (iccId != null) {
3839 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3840 if (DBG_MERGE) {
3841 log("getLine1NumberForDisplay returning "
3842 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3843 }
3844 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3847 return null;
3848 } finally {
3849 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003850 }
Derek Tan7226c842014-07-02 17:42:23 -07003851 }
3852
3853 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003854 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003856 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003857 return null;
3858 }
Derek Tan97ebb422014-09-05 16:55:38 -07003859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 String iccId = getIccId(subId);
3863 if (iccId != null) {
3864 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3865 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3866 }
3867 return null;
3868 } finally {
3869 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003870 }
Derek Tan7226c842014-07-02 17:42:23 -07003871 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003872
3873 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003874 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003875 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3876 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003878 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3879 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003880 return null;
3881 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003882
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003883 final long identity = Binder.clearCallingIdentity();
3884 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885 final Context context = mPhone.getContext();
3886 final TelephonyManager tele = TelephonyManager.from(context);
3887 final SubscriptionManager sub = SubscriptionManager.from(context);
3888
3889 // Figure out what subscribers are currently active
3890 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3891 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3892 // the process, where TelephonyManager was instantiated.
3893 // Otherwise AppOps check will fail.
3894
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003895 final int[] subIds = sub.getActiveSubscriptionIdList();
3896 for (int subId : subIds) {
3897 activeSubscriberIds.add(tele.getSubscriberId(subId));
3898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899
3900 // First pass, find a number override for an active subscriber
3901 String mergeNumber = null;
3902 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3903 for (String key : prefs.keySet()) {
3904 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3905 final String subscriberId = (String) prefs.get(key);
3906 if (activeSubscriberIds.contains(subscriberId)) {
3907 final String iccId = key.substring(
3908 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3909 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3910 mergeNumber = (String) prefs.get(numberKey);
3911 if (DBG_MERGE) {
3912 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3913 + " for active subscriber " + subscriberId);
3914 }
3915 if (!TextUtils.isEmpty(mergeNumber)) {
3916 break;
3917 }
3918 }
3919 }
3920 }
3921
3922 // Shortcut when no active merged subscribers
3923 if (TextUtils.isEmpty(mergeNumber)) {
3924 return null;
3925 }
3926
3927 // Second pass, find all subscribers under that line override
3928 final ArraySet<String> result = new ArraySet<>();
3929 for (String key : prefs.keySet()) {
3930 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3931 final String number = (String) prefs.get(key);
3932 if (mergeNumber.equals(number)) {
3933 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3934 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3935 final String subscriberId = (String) prefs.get(subscriberKey);
3936 if (!TextUtils.isEmpty(subscriberId)) {
3937 result.add(subscriberId);
3938 }
3939 }
3940 }
3941 }
3942
3943 final String[] resultArray = result.toArray(new String[result.size()]);
3944 Arrays.sort(resultArray);
3945 if (DBG_MERGE) {
3946 Slog.d(LOG_TAG,
3947 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3948 }
3949 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003950 } finally {
3951 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003952 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003953 }
3954
3955 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003956 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003957 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3958 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959
3960 final long identity = Binder.clearCallingIdentity();
3961 try {
3962 final Phone phone = getPhone(subId);
3963 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003967 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003968
3969 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003970 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003971 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3972 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003973 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974
3975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 final Phone phone = getPhone(subId);
3978 if (phone == null) {
3979 return false;
3980 }
3981 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3982 cdmaNonRoamingList);
3983 } finally {
3984 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003985 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003986 }
3987
3988 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003989 @Deprecated
3990 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3991 enforceModifyPermission();
3992
3993 int returnValue = 0;
3994 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07003995 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003996 if(result.exception == null) {
3997 if (result.result != null) {
3998 byte[] responseData = (byte[])(result.result);
3999 if(responseData.length > oemResp.length) {
4000 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4001 responseData.length + "bytes. Buffer Size is " +
4002 oemResp.length + "bytes.");
4003 }
4004 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4005 returnValue = responseData.length;
4006 }
4007 } else {
4008 CommandException ex = (CommandException) result.exception;
4009 returnValue = ex.getCommandError().ordinal();
4010 if(returnValue > 0) returnValue *= -1;
4011 }
4012 } catch (RuntimeException e) {
4013 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4014 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4015 if(returnValue > 0) returnValue *= -1;
4016 }
4017
4018 return returnValue;
4019 }
4020
4021 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004022 public void setRadioCapability(RadioAccessFamily[] rafs) {
4023 try {
4024 ProxyController.getInstance().setRadioCapability(rafs);
4025 } catch (RuntimeException e) {
4026 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4027 }
4028 }
4029
4030 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004031 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004032 Phone phone = PhoneFactory.getPhone(phoneId);
4033 if (phone == null) {
4034 return RadioAccessFamily.RAF_UNKNOWN;
4035 }
4036 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004038 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004039 return RadioAccessFamily.RAF_UNKNOWN;
4040 }
4041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4045 } finally {
4046 Binder.restoreCallingIdentity(identity);
4047 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004048 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004049
4050 @Override
4051 public void enableVideoCalling(boolean enable) {
4052 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053
4054 final long identity = Binder.clearCallingIdentity();
4055 try {
4056 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004060 }
4061
4062 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004063 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4065 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4066 return false;
4067 }
Svet Ganovb320e182015-04-16 12:30:10 -07004068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004069 final long identity = Binder.clearCallingIdentity();
4070 try {
4071 // Check the user preference and the system-level IMS setting. Even if the user has
4072 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4073 // In the long run, we may instead need to check if there exists a connection service
4074 // which can support video calling.
4075 ImsManager imsManager =
4076 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4077 return imsManager.isVtEnabledByPlatform()
4078 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4079 && imsManager.isVtEnabledByUser();
4080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004083 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004084
Andrew Leea1239f22015-03-02 17:44:07 -08004085 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4088 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4089 return false;
4090 }
4091
4092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 CarrierConfigManager configManager =
4095 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4096 return configManager.getConfigForSubId(mPhone.getSubId())
4097 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
4100 }
Andrew Leea1239f22015-03-02 17:44:07 -08004101 }
4102
4103 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 public boolean isWorldPhone(int subId, String callingPackage) {
4105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4106 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4107 return false;
4108 }
4109
4110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 CarrierConfigManager configManager =
4113 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4114 return configManager.getConfigForSubId(mPhone.getSubId())
4115 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4116 } finally {
4117 Binder.restoreCallingIdentity(identity);
4118 }
Andrew Leea1239f22015-03-02 17:44:07 -08004119 }
4120
Andrew Lee9431b832015-03-09 18:46:45 -07004121 @Override
4122 public boolean isTtyModeSupported() {
4123 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004124 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004125 }
4126
4127 @Override
4128 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129 final long identity = Binder.clearCallingIdentity();
4130 try {
4131 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
Andrew Lee9431b832015-03-09 18:46:45 -07004135 }
4136
Hall Liu98187582018-01-22 19:15:32 -08004137 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4141 mPhone.getSubId()).getBoolean(
4142 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4143 boolean isDeviceSupported =
4144 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4145 return isCarrierSupported && isDeviceSupported;
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
Hall Liu98187582018-01-22 19:15:32 -08004149 }
4150
Hall Liu3ad5f012018-04-06 16:23:39 -07004151 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 return isRttSupported() && Settings.Secure.getInt(
4155 mPhone.getContext().getContentResolver(),
4156 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004160 }
4161
Sanket Padawe7310cc72015-01-14 09:53:20 -08004162 /**
4163 * Returns the unique device ID of phone, for example, the IMEI for
4164 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4165 *
4166 * <p>Requires Permission:
4167 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4168 */
4169 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004170 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004171 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004172 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004173 return null;
4174 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004175 int subId = phone.getSubId();
4176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4177 mApp, subId, callingPackage, "getDeviceId")) {
4178 return null;
4179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180
4181 final long identity = Binder.clearCallingIdentity();
4182 try {
4183 return phone.getDeviceId();
4184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004187 }
4188
Ping Sunc67b7c22016-03-02 19:16:45 +08004189 /**
4190 * {@hide}
4191 * Returns the IMS Registration Status on a particular subid
4192 *
4193 * @param subId
4194 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004195 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004196 Phone phone = getPhone(subId);
4197 if (phone != null) {
4198 return phone.isImsRegistered();
4199 } else {
4200 return false;
4201 }
4202 }
4203
Santos Cordon7a1885b2015-02-03 11:15:19 -08004204 @Override
4205 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004206 final long identity = Binder.clearCallingIdentity();
4207 try {
4208 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004212 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004213
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004214 /**
4215 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004216 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004217 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 final long identity = Binder.clearCallingIdentity();
4219 try {
4220 Phone phone = getPhone(subId);
4221 if (phone != null) {
4222 return phone.isWifiCallingEnabled();
4223 } else {
4224 return false;
4225 }
4226 } finally {
4227 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004228 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004229 }
4230
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004231 /**
4232 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004233 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004234 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235 final long identity = Binder.clearCallingIdentity();
4236 try {
4237 Phone phone = getPhone(subId);
4238 if (phone != null) {
4239 return phone.isVolteEnabled();
4240 } else {
4241 return false;
4242 }
4243 } finally {
4244 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004245 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004246 }
Svet Ganovb320e182015-04-16 12:30:10 -07004247
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004248 /**
4249 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004250 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004251 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 Phone phone = getPhone(subId);
4255 if (phone != null) {
4256 return phone.isVideoEnabled();
4257 } else {
4258 return false;
4259 }
4260 } finally {
4261 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004262 }
4263 }
4264
4265 /**
4266 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4267 * defined in {@link ImsRegistrationImplBase}.
4268 */
4269 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 final long identity = Binder.clearCallingIdentity();
4271 try {
4272 Phone phone = getPhone(subId);
4273 if (phone != null) {
4274 return phone.getImsRegistrationTech();
4275 } else {
4276 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4277 }
4278 } finally {
4279 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004280 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004281 }
4282
Stuart Scott8eef64f2015-04-08 15:13:54 -07004283 @Override
4284 public void factoryReset(int subId) {
4285 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004286 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4287 return;
4288 }
4289
Svet Ganovcc087f82015-05-12 20:35:54 -07004290 final long identity = Binder.clearCallingIdentity();
4291 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004292 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4293 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004294 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004295 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004296 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4297 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004298 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004299 }
4300 } finally {
4301 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004302 }
4303 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004304
4305 @Override
4306 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 final long identity = Binder.clearCallingIdentity();
4308 try {
4309 // We query all subscriptions instead of just the active ones, because
4310 // this might be called early on in the provisioning flow when the
4311 // subscriptions potentially aren't active yet.
4312 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4313 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004314 return null;
4315 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 // This function may be called very early, say, from the setup wizard, at
4318 // which point we won't have a default subscription set. If that's the case
4319 // we just choose the first, which will be valid in "most cases".
4320 final int defaultSubId = getDefaultSubscription();
4321 SubscriptionInfo info = null;
4322 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4323 info = slist.get(0);
4324 } else {
4325 for (SubscriptionInfo item : slist) {
4326 if (item.getSubscriptionId() == defaultSubId) {
4327 info = item;
4328 break;
4329 }
4330 }
4331
4332 if (info == null) {
4333 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004334 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004335 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 // Try and fetch the locale from the carrier properties or from the SIM language
4338 // preferences (EF-PL and EF-LI)...
4339 final int mcc = info.getMcc();
4340 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4341 String simLanguage = null;
4342 if (defaultPhone != null) {
4343 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4344 if (localeFromDefaultSim != null) {
4345 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4346 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4347 return localeFromDefaultSim.toLanguageTag();
4348 } else {
4349 simLanguage = localeFromDefaultSim.getLanguage();
4350 }
4351 }
4352 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004354 // The SIM language preferences only store a language (e.g. fr = French), not an
4355 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4356 // the SIM and carrier preferences does not include a country we add the country
4357 // determined from the SIM MCC to provide an exact locale.
4358 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4359 simLanguage);
4360 if (mccLocale != null) {
4361 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4362 return mccLocale.toLanguageTag();
4363 }
4364
4365 if (DBG) log("No locale found - returning null");
4366 return null;
4367 } finally {
4368 Binder.restoreCallingIdentity(identity);
4369 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004370 }
4371
4372 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 return mSubscriptionController.getAllSubInfoList(
4374 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004375 }
4376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 /**
4378 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4379 */
4380 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4381 return mSubscriptionController.getActiveSubscriptionInfoList(
4382 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004383 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004384
Chenjie Yu1ba97252018-01-11 18:16:20 -08004385 private final ModemActivityInfo mLastModemActivityInfo =
4386 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4387
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004388 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004389 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4390 * representing the state of the modem.
4391 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004392 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4393 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004394 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004395 */
4396 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004397 public void requestModemActivityInfo(ResultReceiver result) {
4398 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004399 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400
4401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 ModemActivityInfo ret = null;
4404 synchronized (mLastModemActivityInfo) {
4405 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4406 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004407 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004408 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4410 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4411 mergedTxTimeMs[i] =
4412 info.getTxTimeMillis()[i]
4413 + mLastModemActivityInfo.getTxTimeMillis()[i];
4414 }
4415 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4416 mLastModemActivityInfo.setSleepTimeMillis(
4417 info.getSleepTimeMillis()
4418 + mLastModemActivityInfo.getSleepTimeMillis());
4419 mLastModemActivityInfo.setIdleTimeMillis(
4420 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4421 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4422 mLastModemActivityInfo.setRxTimeMillis(
4423 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4424 mLastModemActivityInfo.setEnergyUsed(
4425 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4428 mLastModemActivityInfo.getSleepTimeMillis(),
4429 mLastModemActivityInfo.getIdleTimeMillis(),
4430 mLastModemActivityInfo.getTxTimeMillis(),
4431 mLastModemActivityInfo.getRxTimeMillis(),
4432 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004433 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434 Bundle bundle = new Bundle();
4435 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4436 result.send(0, bundle);
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004439 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004440 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004441
Siddharth Rayb8114062018-06-17 15:02:38 -07004442 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4443 // less than total activity duration.
4444 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4445 if (info == null) {
4446 return false;
4447 }
4448 int activityDurationMs =
4449 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4450 int totalTxTimeMs = 0;
4451 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4452 totalTxTimeMs += info.getTxTimeMillis()[i];
4453 }
4454 return (info.isValid()
4455 && (info.getSleepTimeMillis() <= activityDurationMs)
4456 && (info.getIdleTimeMillis() <= activityDurationMs)
4457 && (info.getRxTimeMillis() <= activityDurationMs)
4458 && (totalTxTimeMs <= activityDurationMs));
4459 }
4460
Jack Yu85bd38a2015-11-09 11:34:32 -08004461 /**
4462 * {@hide}
4463 * Returns the service state information on specified subscription.
4464 */
4465 @Override
4466 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004468 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004469 return null;
4470 }
4471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 final long identity = Binder.clearCallingIdentity();
4473 try {
4474 final Phone phone = getPhone(subId);
4475 if (phone == null) {
4476 return null;
4477 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479 return phone.getServiceState();
4480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004483 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004484
4485 /**
4486 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4487 *
4488 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4489 * voicemail ringtone.
4490 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4491 * PhoneAccount.
4492 */
4493 @Override
4494 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
4497 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4498 if (phone == null) {
4499 phone = mPhone;
4500 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004506 }
4507
4508 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004509 * Sets the per-account voicemail ringtone.
4510 *
4511 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4512 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4513 *
4514 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4515 * voicemail ringtone.
4516 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4517 * PhoneAccount.
4518 */
4519 @Override
4520 public void setVoicemailRingtoneUri(String callingPackage,
4521 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4522 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4523 if (!TextUtils.equals(callingPackage,
4524 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4526 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4527 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529
4530 final long identity = Binder.clearCallingIdentity();
4531 try {
4532 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4533 if (phone == null) {
4534 phone = mPhone;
4535 }
4536 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4537 } finally {
4538 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004539 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004540 }
4541
4542 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004543 * Returns whether vibration is set for voicemail notification in Phone settings.
4544 *
4545 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4546 * voicemail vibration setting.
4547 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4548 */
4549 @Override
4550 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551 final long identity = Binder.clearCallingIdentity();
4552 try {
4553 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4554 if (phone == null) {
4555 phone = mPhone;
4556 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004558 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4559 } finally {
4560 Binder.restoreCallingIdentity(identity);
4561 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004562 }
4563
Youhan Wange64578a2016-05-02 15:32:42 -07004564 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004565 * Sets the per-account voicemail vibration.
4566 *
4567 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4568 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4569 *
4570 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4571 * voicemail vibration setting.
4572 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4573 * specific PhoneAccount.
4574 */
4575 @Override
4576 public void setVoicemailVibrationEnabled(String callingPackage,
4577 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4578 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4579 if (!TextUtils.equals(callingPackage,
4580 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4582 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4583 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004584 }
4585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586 final long identity = Binder.clearCallingIdentity();
4587 try {
4588 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4589 if (phone == null) {
4590 phone = mPhone;
4591 }
4592 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4593 } finally {
4594 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004595 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004596 }
4597
4598 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004599 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4600 *
4601 * @throws SecurityException if the caller does not have the required permission
4602 */
4603 private void enforceReadPrivilegedPermission() {
4604 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4605 null);
4606 }
4607
4608 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004609 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4610 * permission.
4611 *
4612 * @throws SecurityException if the caller does not have the required permission
4613 */
4614 private void enforceSendSmsPermission() {
4615 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4616 }
4617
4618 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004619 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004620 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004621 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004622 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004623 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 final long identity = Binder.clearCallingIdentity();
4625 try {
4626 ComponentName componentName =
4627 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4628 if (componentName == null) {
4629 throw new SecurityException(
4630 "Caller not current active visual voicemail package[null]");
4631 }
4632 String vvmPackage = componentName.getPackageName();
4633 if (!callingPackage.equals(vvmPackage)) {
4634 throw new SecurityException("Caller not current active visual voicemail package["
4635 + vvmPackage + "]");
4636 }
4637 } finally {
4638 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004639 }
4640 }
4641
4642 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004643 * Return the application ID for the app type.
4644 *
4645 * @param subId the subscription ID that this request applies to.
4646 * @param appType the uicc app type.
4647 * @return Application ID for specificied app type, or null if no uicc.
4648 */
4649 @Override
4650 public String getAidForAppType(int subId, int appType) {
4651 enforceReadPrivilegedPermission();
4652 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653
4654 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004655 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 if (phone == null) {
4657 return null;
4658 }
4659 String aid = null;
4660 try {
4661 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4662 .getApplicationByType(appType).getAid();
4663 } catch (Exception e) {
4664 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4665 }
4666 return aid;
4667 } finally {
4668 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004669 }
Youhan Wange64578a2016-05-02 15:32:42 -07004670 }
4671
Youhan Wang4001d252016-05-11 10:29:41 -07004672 /**
4673 * Return the Electronic Serial Number.
4674 *
4675 * @param subId the subscription ID that this request applies to.
4676 * @return ESN or null if error.
4677 */
4678 @Override
4679 public String getEsn(int subId) {
4680 enforceReadPrivilegedPermission();
4681 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004682
4683 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004684 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 if (phone == null) {
4686 return null;
4687 }
4688 String esn = null;
4689 try {
4690 esn = phone.getEsn();
4691 } catch (Exception e) {
4692 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4693 }
4694 return esn;
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004697 }
Youhan Wang4001d252016-05-11 10:29:41 -07004698 }
4699
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004700 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004701 * Return the Preferred Roaming List Version.
4702 *
4703 * @param subId the subscription ID that this request applies to.
4704 * @return PRLVersion or null if error.
4705 */
4706 @Override
4707 public String getCdmaPrlVersion(int subId) {
4708 enforceReadPrivilegedPermission();
4709 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004710
4711 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004712 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004713 if (phone == null) {
4714 return null;
4715 }
4716 String cdmaPrlVersion = null;
4717 try {
4718 cdmaPrlVersion = phone.getCdmaPrlVersion();
4719 } catch (Exception e) {
4720 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4721 }
4722 return cdmaPrlVersion;
4723 } finally {
4724 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004725 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004726 }
4727
4728 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004729 * Get snapshot of Telephony histograms
4730 * @return List of Telephony histograms
4731 * @hide
4732 */
4733 @Override
4734 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4736 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 return RIL.getTelephonyRILTimingHistograms();
4741 } finally {
4742 Binder.restoreCallingIdentity(identity);
4743 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004744 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004745
4746 /**
4747 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004748 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004749 * Require system privileges. In the future we may add this to carrier APIs.
4750 *
4751 * @return The number of carriers set successfully, should match length of carriers
4752 */
4753 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004754 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004755 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004757
Meng Wang9b7c4e92017-02-17 11:41:27 -08004758 if (carriers == null) {
4759 throw new NullPointerException("carriers cannot be null");
4760 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 final long identity = Binder.clearCallingIdentity();
4763 try {
4764 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004765 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4766 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767 return retVal[0];
4768 } finally {
4769 Binder.restoreCallingIdentity(identity);
4770 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004771 }
4772
4773 /**
4774 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004775 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004776 * Require system privileges. In the future we may add this to carrier APIs.
4777 *
4778 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4779 * means all carriers are allowed.
4780 */
4781 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004782 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004783 enforceReadPrivilegedPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004784 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785
4786 final long identity = Binder.clearCallingIdentity();
4787 try {
4788 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004789 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4790 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 } finally {
4792 Binder.restoreCallingIdentity(identity);
4793 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004794 }
4795
fionaxu59545b42016-05-25 15:53:37 -07004796 /**
4797 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4798 * @param subId the subscription ID that this action applies to.
4799 * @param enabled control enable or disable metered apns.
4800 * {@hide}
4801 */
4802 @Override
4803 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4804 enforceModifyPermission();
4805 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004806
4807 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004808 if (phone == null) {
4809 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4810 return;
4811 }
4812 try {
4813 phone.carrierActionSetMeteredApnsEnabled(enabled);
4814 } catch (Exception e) {
4815 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 } finally {
4817 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004818 }
4819 }
4820
4821 /**
4822 * Action set from carrier signalling broadcast receivers to enable/disable radio
4823 * @param subId the subscription ID that this action applies to.
4824 * @param enabled control enable or disable radio.
4825 * {@hide}
4826 */
4827 @Override
4828 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4829 enforceModifyPermission();
4830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831
4832 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004833 if (phone == null) {
4834 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4835 return;
4836 }
4837 try {
4838 phone.carrierActionSetRadioEnabled(enabled);
4839 } catch (Exception e) {
4840 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 } finally {
4842 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004843 }
4844 }
4845
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004846 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004847 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4848 * network status based on which carrier apps could apply actions accordingly,
4849 * enable/disable default url handler for example.
4850 *
4851 * @param subId the subscription ID that this action applies to.
4852 * @param report control start/stop reporting the default network status.
4853 * {@hide}
4854 */
4855 @Override
4856 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4857 enforceModifyPermission();
4858 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859
4860 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004861 if (phone == null) {
4862 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4863 return;
4864 }
4865 try {
4866 phone.carrierActionReportDefaultNetworkStatus(report);
4867 } catch (Exception e) {
4868 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 } finally {
4870 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004871 }
4872 }
4873
4874 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004875 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4876 * bug report is being generated.
4877 */
4878 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004879 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004880 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4881 != PackageManager.PERMISSION_GRANTED) {
4882 writer.println("Permission Denial: can't dump Phone from pid="
4883 + Binder.getCallingPid()
4884 + ", uid=" + Binder.getCallingUid()
4885 + "without permission "
4886 + android.Manifest.permission.DUMP);
4887 return;
4888 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004889 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004890 }
Jack Yueb89b242016-06-22 13:27:47 -07004891
Brad Ebingerdac2f002018-04-03 15:17:52 -07004892 @Override
4893 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4894 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4895 throws RemoteException {
4896 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4897 }
4898
Jack Yueb89b242016-06-22 13:27:47 -07004899 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004900 * Get aggregated video call data usage since boot.
4901 *
4902 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4903 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004904 * {@hide}
4905 */
4906 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004907 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004908 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4909 null);
4910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 final long identity = Binder.clearCallingIdentity();
4912 try {
4913 // NetworkStatsService keeps tracking the active network interface and identity. It
4914 // records the delta with the corresponding network identity.
4915 // We just return the total video call data usage snapshot since boot.
4916 Phone phone = getPhone(subId);
4917 if (phone != null) {
4918 return phone.getVtDataUsage(perUidStats);
4919 }
4920 return null;
4921 } finally {
4922 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004923 }
Jack Yueb89b242016-06-22 13:27:47 -07004924 }
Jack Yu75ab2952016-07-08 14:29:33 -07004925
4926 /**
4927 * Policy control of data connection. Usually used when data limit is passed.
4928 * @param enabled True if enabling the data, otherwise disabling.
4929 * @param subId Subscription index
4930 * {@hide}
4931 */
4932 @Override
4933 public void setPolicyDataEnabled(boolean enabled, int subId) {
4934 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935
4936 final long identity = Binder.clearCallingIdentity();
4937 try {
4938 Phone phone = getPhone(subId);
4939 if (phone != null) {
4940 phone.setPolicyDataEnabled(enabled);
4941 }
4942 } finally {
4943 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004944 }
4945 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004946
4947 /**
4948 * Get Client request stats
4949 * @return List of Client Request Stats
4950 * @hide
4951 */
4952 @Override
4953 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004955 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004956 return null;
4957 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004958 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 final long identity = Binder.clearCallingIdentity();
4961 try {
4962 if (phone != null) {
4963 return phone.getClientRequestStats();
4964 }
4965
4966 return null;
4967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004970 }
4971
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004972 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004973 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004974 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004975 }
Jack Yueb4124c2017-02-16 15:32:43 -08004976
4977 /**
Grace Chen70990072017-03-24 17:21:30 -07004978 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004979 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004980 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004981 * @param state State of SIM (power down, power up, pass through)
4982 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4983 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4984 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004985 *
4986 **/
4987 @Override
Grace Chen70990072017-03-24 17:21:30 -07004988 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004989 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004990 Phone phone = PhoneFactory.getPhone(slotIndex);
4991
vagdeviaf9a5b92018-08-15 16:01:53 -07004992 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 final long identity = Binder.clearCallingIdentity();
4995 try {
4996 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004997 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 }
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005001 }
5002 }
Shuo Qiandd210312017-04-12 22:11:33 +00005003
Tyler Gunn65d45c22017-06-05 11:22:26 -07005004 private boolean isUssdApiAllowed(int subId) {
5005 CarrierConfigManager configManager =
5006 (CarrierConfigManager) mPhone.getContext().getSystemService(
5007 Context.CARRIER_CONFIG_SERVICE);
5008 if (configManager == null) {
5009 return false;
5010 }
5011 PersistableBundle pb = configManager.getConfigForSubId(subId);
5012 if (pb == null) {
5013 return false;
5014 }
5015 return pb.getBoolean(
5016 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5017 }
5018
Shuo Qiandd210312017-04-12 22:11:33 +00005019 /**
5020 * Check if phone is in emergency callback mode
5021 * @return true if phone is in emergency callback mode
5022 * @param subId sub id
5023 */
goneil9c5f4872017-12-05 14:07:56 -08005024 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005025 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08005026 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00005027 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028
5029 final long identity = Binder.clearCallingIdentity();
5030 try {
5031 if (phone != null) {
5032 return phone.isInEcm();
5033 } else {
5034 return false;
5035 }
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005038 }
5039 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005040
5041 /**
5042 * Get the current signal strength information for the given subscription.
5043 * Because this information is not updated when the device is in a low power state
5044 * it should not be relied-upon to be current.
5045 * @param subId Subscription index
5046 * @return the most recent cached signal strength info from the modem
5047 */
5048 @Override
5049 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 final long identity = Binder.clearCallingIdentity();
5051 try {
5052 Phone p = getPhone(subId);
5053 if (p == null) {
5054 return null;
5055 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 return p.getSignalStrength();
5058 } finally {
5059 Binder.restoreCallingIdentity(identity);
5060 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005061 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005062
Pengquan Meng77b7f132018-08-22 14:49:57 -07005063 /**
5064 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5065 *
5066 * <p>Requires one of the following permissions:
5067 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5068 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5069 * privileges.
5070 *
5071 * @param subId subscription id
5072 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5073 * {@code false}.
5074 */
5075 @Override
5076 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005077 boolean isEnabled = false;
5078 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005079 try {
5080 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005081 null /* message */);
5082 Phone phone = getPhone(subId);
5083 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005084 } catch (Exception e) {
5085 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5086 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005089 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005090 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005091 }
5092
5093
5094 /**
5095 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5096 *
5097 * <p> Requires permission:
5098 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5099 * privileges.
5100 *
5101 * @param subId subscription id
5102 * @param isEnabled {@code true} means enable, {@code false} means disable.
5103 */
5104 @Override
5105 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5109 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005110
Pengquan Menga1bb6272018-09-06 09:59:22 -07005111 Phone phone = getPhone(subId);
5112 if (phone != null) {
5113 phone.setDataRoamingEnabled(isEnabled);
5114 }
5115 } finally {
5116 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005117 }
5118 }
5119
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005120 @Override
5121 public UiccSlotInfo[] getUiccSlotsInfo() {
5122 enforceReadPrivilegedPermission();
5123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 final long identity = Binder.clearCallingIdentity();
5125 try {
5126 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5127 if (slots == null) {
5128 Rlog.i(LOG_TAG, "slots is null.");
5129 return null;
5130 }
5131
5132 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5133 for (int i = 0; i < slots.length; i++) {
5134 UiccSlot slot = slots[i];
5135 if (slot == null) {
5136 continue;
5137 }
5138
5139 String cardId;
5140 UiccCard card = slot.getUiccCard();
5141 if (card != null) {
5142 cardId = card.getCardId();
5143 } else {
5144 cardId = slot.getIccId();
5145 }
5146
5147 int cardState = 0;
5148 switch (slot.getCardState()) {
5149 case CARDSTATE_ABSENT:
5150 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5151 break;
5152 case CARDSTATE_PRESENT:
5153 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5154 break;
5155 case CARDSTATE_ERROR:
5156 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5157 break;
5158 case CARDSTATE_RESTRICTED:
5159 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5160 break;
5161 default:
5162 break;
5163
5164 }
5165
5166 infos[i] = new UiccSlotInfo(
5167 slot.isActive(),
5168 slot.isEuicc(),
5169 cardId,
5170 cardState,
5171 slot.getPhoneId(),
5172 slot.isExtendedApduSupported());
5173 }
5174 return infos;
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005177 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005178 }
5179
5180 @Override
5181 public boolean switchSlots(int[] physicalSlots) {
5182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183
5184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5187 } finally {
5188 Binder.restoreCallingIdentity(identity);
5189 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005190 }
Jack Yu4c988042018-02-27 15:30:01 -08005191
5192 @Override
5193 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5194 enforceModifyPermission();
5195 final Phone phone = getPhone(subId);
5196 if (phone == null) {
5197 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5198 return;
5199 }
5200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 final long identity = Binder.clearCallingIdentity();
5202 try {
5203 phone.setRadioIndicationUpdateMode(filters, mode);
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
5206 }
Jack Yu4c988042018-02-27 15:30:01 -08005207 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005208
5209 /**
goneil47ffb6e2018-04-06 15:40:58 -07005210 * A test API to reload the UICC profile.
5211 *
5212 * <p>Requires that the calling app has permission
5213 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5214 * @hide
5215 */
5216 @Override
5217 public void refreshUiccProfile(int subId) {
5218 enforceModifyPermission();
5219
5220 final long identity = Binder.clearCallingIdentity();
5221 try {
5222 Phone phone = getPhone(subId);
5223 if (phone == null) {
5224 return;
5225 }
5226 UiccCard uiccCard = phone.getUiccCard();
5227 if (uiccCard == null) {
5228 return;
5229 }
5230 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5231 if (uiccProfile == null) {
5232 return;
5233 }
5234 uiccProfile.refresh();
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
5238 }
5239
5240 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005241 * Returns false if the mobile data is disabled by default, otherwise return true.
5242 */
5243 private boolean getDefaultDataEnabled() {
5244 return "true".equalsIgnoreCase(
5245 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5246 }
5247
5248 /**
5249 * Returns true if the data roaming is enabled by default, i.e the system property
5250 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5251 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5252 */
5253 private boolean getDefaultDataRoamingEnabled(int subId) {
5254 final CarrierConfigManager configMgr = (CarrierConfigManager)
5255 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5256 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5257 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5258 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5259 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5260 return isDataRoamingEnabled;
5261 }
5262
5263 /**
5264 * Returns the default network type for the given {@code subId}, if the default network type is
5265 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5266 */
5267 private int getDefaultNetworkType(int subId) {
5268 return Integer.parseInt(
5269 TelephonyManager.getTelephonyProperty(
5270 mSubscriptionController.getPhoneId(subId),
5271 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5272 String.valueOf(Phone.PREFERRED_NT_MODE)));
5273 }
fionaxua13278b2018-03-21 00:08:13 -07005274
5275 @Override
5276 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5277 gid1, String gid2, String plmn, String spn) {
5278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279
5280 final long identity = Binder.clearCallingIdentity();
5281 try {
5282 final Phone phone = getPhone(subId);
5283 if (phone == null) {
5284 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5285 return;
5286 }
5287 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005290 }
fionaxua13278b2018-03-21 00:08:13 -07005291 }
5292
5293 @Override
5294 public int getCarrierIdListVersion(int subId) {
5295 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296
5297 final long identity = Binder.clearCallingIdentity();
5298 try {
5299 final Phone phone = getPhone(subId);
5300 if (phone == null) {
5301 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5302 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5303 }
5304 return phone.getCarrierIdListVersion();
5305 } finally {
5306 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005307 }
fionaxua13278b2018-03-21 00:08:13 -07005308 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005309
5310 @Override
5311 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5313 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5314 return -1;
5315 }
5316
5317 final long identity = Binder.clearCallingIdentity();
5318 try {
5319 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5320 } finally {
5321 Binder.restoreCallingIdentity(identity);
5322 }
5323 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005324
5325 @Override
5326 public int getCdmaRoamingMode(int subId) {
5327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5328 mApp, subId, "getCdmaRoamingMode");
5329
5330 final long identity = Binder.clearCallingIdentity();
5331 try {
5332 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
5336 }
5337
5338 @Override
5339 public boolean setCdmaRoamingMode(int subId, int mode) {
5340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5341 mApp, subId, "setCdmaRoamingMode");
5342
5343 final long identity = Binder.clearCallingIdentity();
5344 try {
5345 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
5348 }
5349 }
5350
5351 @Override
5352 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5354 mApp, subId, "setCdmaSubscriptionMode");
5355
5356 final long identity = Binder.clearCallingIdentity();
5357 try {
5358 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5359 } finally {
5360 Binder.restoreCallingIdentity(identity);
5361 }
5362 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005363
5364 private void ensureUserRunning(int userId) {
5365 if (!mUserManager.isUserRunning(userId)) {
5366 throw new IllegalStateException("User " + userId + " does not exist or not running");
5367 }
5368 }
5369
5370 /**
5371 * Returns a list of SMS apps on a given user.
5372 *
5373 * Only the shell user (UID 2000 or 0) can call it.
5374 * Target user must be running.
5375 */
5376 @Override
5377 public String[] getSmsApps(int userId) {
5378 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5379 ensureUserRunning(userId);
5380
5381 final Collection<SmsApplicationData> apps =
5382 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5383
5384 String[] ret = new String[apps.size()];
5385 int i = 0;
5386 for (SmsApplicationData app : apps) {
5387 ret[i++] = app.mPackageName;
5388 }
5389 return ret;
5390 }
5391
5392 /**
5393 * Returns the default SMS app package name on a given user.
5394 *
5395 * Only the shell user (UID 2000 or 0) can call it.
5396 * Target user must be running.
5397 */
5398 @Override
5399 public String getDefaultSmsApp(int userId) {
5400 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5401 ensureUserRunning(userId);
5402
5403 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5404 /* updateIfNeeded= */ true, userId);
5405 return cn == null ? null : cn.getPackageName();
5406 }
5407
5408 /**
5409 * Set a package as the default SMS app on a given user.
5410 *
5411 * Only the shell user (UID 2000 or 0) can call it.
5412 * Target user must be running.
5413 */
5414 @Override
5415 public void setDefaultSmsApp(int userId, String packageName) {
5416 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5417 ensureUserRunning(userId);
5418
5419 boolean found = false;
5420 for (String pkg : getSmsApps(userId)) {
5421 if (TextUtils.equals(packageName, pkg)) {
5422 found = true;
5423 break;
5424 }
5425 }
5426 if (!found) {
5427 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5428 }
5429
5430 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005432}