blob: 44e922ea1d0a06814727e9e10236152ef51df1b8 [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 Chenf144d942018-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;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800113import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800114import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700115import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.uicc.IccIoResult;
117import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800118import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700119import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800120import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800122import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000123import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700124import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800125import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700126import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800127import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700128import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700129import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700131import java.io.FileDescriptor;
132import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800133import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800135import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800136import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100137import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139
140/**
141 * Implementation of the ITelephony interface.
142 */
Santos Cordon117fee72014-05-16 17:56:12 -0700143public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144 private static final String LOG_TAG = "PhoneInterfaceManager";
145 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
146 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800147 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148
149 // Message codes used with mMainThreadHandler
150 private static final int CMD_HANDLE_PIN_MMI = 1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 private static final int CMD_ANSWER_RINGING_CALL = 4;
152 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700153 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
154 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155 private static final int CMD_OPEN_CHANNEL = 9;
156 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
157 private static final int CMD_CLOSE_CHANNEL = 11;
158 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800159 private static final int CMD_NV_READ_ITEM = 13;
160 private static final int EVENT_NV_READ_ITEM_DONE = 14;
161 private static final int CMD_NV_WRITE_ITEM = 15;
162 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
163 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
164 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
165 private static final int CMD_NV_RESET_CONFIG = 19;
166 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800167 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
168 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
169 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
170 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800171 private static final int CMD_SEND_ENVELOPE = 25;
172 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000173 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
174 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700175 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
176 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
177 private static final int CMD_EXCHANGE_SIM_IO = 31;
178 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800179 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
180 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700181 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
182 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700183 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
184 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700185 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
186 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
187 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
188 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700189 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
190 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
191 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
192 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700193 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800194 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
195 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000196 private static final int CMD_SWITCH_SLOTS = 50;
197 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700198 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
199 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
200 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
201 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
202 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
203 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
204 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
205 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800207 // Parameters of select command.
208 private static final int SELECT_COMMAND = 0xA4;
209 private static final int SELECT_P1 = 0x04;
210 private static final int SELECT_P2 = 0;
211 private static final int SELECT_P3 = 0x10;
212
Pengquan Meng85728fb2018-03-12 16:31:21 -0700213 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
214 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
215 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
216
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 /** The singleton instance. */
218 private static PhoneInterfaceManager sInstance;
219
Wink Saville3ab207e2014-11-20 13:07:20 -0800220 private PhoneGlobals mApp;
221 private Phone mPhone;
222 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700223 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800224 private AppOpsManager mAppOps;
225 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800226 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800227 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700228 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
Derek Tan97ebb422014-09-05 16:55:38 -0700230 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
231 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700233
Derek Tan740e1672017-06-27 14:56:27 -0700234 // The AID of ISD-R.
235 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
236
yinxub1bed742017-04-17 11:45:04 -0700237 private NetworkScanRequestTracker mNetworkScanRequestTracker;
238
David Kelly5e06a7f2018-03-12 14:10:59 +0000239 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
240 private static final int MANUFACTURER_CODE_LENGTH = 8;
241
Derek Tan89e89d42014-07-08 17:00:10 -0700242 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243 * A request object to use for transmitting data to an ICC.
244 */
245 private static final class IccAPDUArgument {
246 public int channel, cla, command, p1, p2, p3;
247 public String data;
248
249 public IccAPDUArgument(int channel, int cla, int command,
250 int p1, int p2, int p3, String data) {
251 this.channel = channel;
252 this.cla = cla;
253 this.command = command;
254 this.p1 = p1;
255 this.p2 = p2;
256 this.p3 = p3;
257 this.data = data;
258 }
259 }
260
261 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700262 * A request object to use for transmitting data to an ICC.
263 */
264 private static final class ManualNetworkSelectionArgument {
265 public OperatorInfo operatorInfo;
266 public boolean persistSelection;
267
268 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
269 this.operatorInfo = operatorInfo;
270 this.persistSelection = persistSelection;
271 }
272 }
273
274 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
276 * request after sending. The main thread will notify the request when it is complete.
277 */
278 private static final class MainThreadRequest {
279 /** The argument to use for the request */
280 public Object argument;
281 /** The result of the request that is run on the main thread */
282 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800283 // The subscriber id that this request applies to. Defaults to
284 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
285 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
vagdevie435a3e2018-08-15 16:01:53 -0700287 public WorkSource workSource;
288
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 public MainThreadRequest(Object argument) {
290 this.argument = argument;
291 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800292
vagdevie435a3e2018-08-15 16:01:53 -0700293 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800294 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800295 if (subId != null) {
296 this.subId = subId;
297 }
vagdevie435a3e2018-08-15 16:01:53 -0700298 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 }
301
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800302 private static final class IncomingThirdPartyCallArgs {
303 public final ComponentName component;
304 public final String callId;
305 public final String callerDisplayName;
306
307 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
308 String callerDisplayName) {
309 this.component = component;
310 this.callId = callId;
311 this.callerDisplayName = callerDisplayName;
312 }
313 }
314
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 /**
316 * A handler that processes messages on the main thread in the phone process. Since many
317 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
318 * inbound binder threads to the main thread in the phone process. The Binder thread
319 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
320 * on, which will be notified when the operation completes and will contain the result of the
321 * request.
322 *
323 * <p>If a MainThreadRequest object is provided in the msg.obj field,
324 * note that request.result must be set to something non-null for the calling thread to
325 * unblock.
326 */
327 private final class MainThreadHandler extends Handler {
328 @Override
329 public void handleMessage(Message msg) {
330 MainThreadRequest request;
331 Message onCompleted;
332 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800333 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700334 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335
336 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700337 case CMD_HANDLE_USSD_REQUEST: {
338 request = (MainThreadRequest) msg.obj;
339 final Phone phone = getPhoneFromRequest(request);
340 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
341 String ussdRequest = ussdObject.first;
342 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700343
Pengquan Meng0c05b502018-09-06 09:59:22 -0700344 if (!isUssdApiAllowed(request.subId)) {
345 // Carrier does not support use of this API, return failure.
346 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
347 UssdResponse response = new UssdResponse(ussdRequest, null);
348 Bundle returnData = new Bundle();
349 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
350 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700351
Pengquan Meng0c05b502018-09-06 09:59:22 -0700352 request.result = true;
353 notifyRequester(request);
354 return;
355 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700356
Pengquan Meng0c05b502018-09-06 09:59:22 -0700357 try {
358 request.result = phone != null
359 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
360 } catch (CallStateException cse) {
361 request.result = false;
362 }
363 // Wake up the requesting thread
364 notifyRequester(request);
365 break;
pkanwar32d516d2016-10-14 19:37:38 -0700366 }
367
Yorke Lee716f67e2015-06-17 15:39:16 -0700368 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700370 final Phone phone = getPhoneFromRequest(request);
371 request.result = phone != null ?
372 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
373 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700375 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700380 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800381 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700382 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800383 request.result = ""; // dummy result for notifying the waiting thread
384 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700385 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 break;
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 case CMD_END_CALL:
389 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800390 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700391 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700392 Phone phone = getPhone(end_subId);
393 if (phone == null) {
394 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
395 break;
396 }
397 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
399 // CDMA: If the user presses the Power button we treat it as
400 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700401 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
403 // GSM: End the call as per the Phone state
404 hungUp = PhoneUtils.hangup(mCM);
405 } else {
406 throw new IllegalStateException("Unexpected phone type: " + phoneType);
407 }
408 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
409 request.result = hungUp;
410 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700411 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 break;
413
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700415 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800417 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 if (uiccCard == null) {
419 loge("iccTransmitApduLogicalChannel: No UICC");
420 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700421 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
424 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700425 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 iccArgument.channel, iccArgument.cla, iccArgument.command,
427 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 break;
431
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 ar = (AsyncResult) msg.obj;
434 request = (MainThreadRequest) ar.userObj;
435 if (ar.exception == null && ar.result != null) {
436 request.result = ar.result;
437 } else {
438 request.result = new IccIoResult(0x6F, 0, (byte[])null);
439 if (ar.result == null) {
440 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800441 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800443 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 } else {
445 loge("iccTransmitApduLogicalChannel: Unknown exception");
446 }
447 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700448 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 break;
450
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
452 request = (MainThreadRequest) msg.obj;
453 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800454 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 if (uiccCard == null) {
456 loge("iccTransmitApduBasicChannel: No UICC");
457 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700458 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 } else {
460 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
461 request);
462 uiccCard.iccTransmitApduBasicChannel(
463 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
464 iccArgument.p3, iccArgument.data, onCompleted);
465 }
466 break;
467
468 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
469 ar = (AsyncResult) msg.obj;
470 request = (MainThreadRequest) ar.userObj;
471 if (ar.exception == null && ar.result != null) {
472 request.result = ar.result;
473 } else {
474 request.result = new IccIoResult(0x6F, 0, (byte[])null);
475 if (ar.result == null) {
476 loge("iccTransmitApduBasicChannel: Empty response");
477 } else if (ar.exception instanceof CommandException) {
478 loge("iccTransmitApduBasicChannel: CommandException: " +
479 ar.exception);
480 } else {
481 loge("iccTransmitApduBasicChannel: Unknown exception");
482 }
483 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700484 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 break;
486
487 case CMD_EXCHANGE_SIM_IO:
488 request = (MainThreadRequest) msg.obj;
489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 if (uiccCard == null) {
492 loge("iccExchangeSimIO: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 } else {
496 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
497 request);
498 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
499 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
500 iccArgument.data, onCompleted);
501 }
502 break;
503
504 case EVENT_EXCHANGE_SIM_IO_DONE:
505 ar = (AsyncResult) msg.obj;
506 request = (MainThreadRequest) ar.userObj;
507 if (ar.exception == null && ar.result != null) {
508 request.result = ar.result;
509 } else {
510 request.result = new IccIoResult(0x6f, 0, (byte[])null);
511 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 break;
514
Derek Tan4d5e5c12014-02-04 11:54:58 -0800515 case CMD_SEND_ENVELOPE:
516 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800517 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 if (uiccCard == null) {
519 loge("sendEnvelopeWithStatus: No UICC");
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 } else {
523 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
524 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
525 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 break;
527
528 case EVENT_SEND_ENVELOPE_DONE:
529 ar = (AsyncResult) msg.obj;
530 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700531 if (ar.exception == null && ar.result != null) {
532 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
535 if (ar.result == null) {
536 loge("sendEnvelopeWithStatus: Empty response");
537 } else if (ar.exception instanceof CommandException) {
538 loge("sendEnvelopeWithStatus: CommandException: " +
539 ar.exception);
540 } else {
541 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
542 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700544 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 break;
546
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 case CMD_OPEN_CHANNEL:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800550 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 if (uiccCard == null) {
552 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800553 request.result = new IccOpenLogicalChannelResponse(-1,
554 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 } else {
557 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800558 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
559 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 break;
562
563 case EVENT_OPEN_CHANNEL_DONE:
564 ar = (AsyncResult) msg.obj;
565 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 int[] result = (int[]) ar.result;
569 int channelId = result[0];
570 byte[] selectResponse = null;
571 if (result.length > 1) {
572 selectResponse = new byte[result.length - 1];
573 for (int i = 1; i < result.length; ++i) {
574 selectResponse[i - 1] = (byte) result[i];
575 }
576 }
577 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700578 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 if (ar.result == null) {
581 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 if (ar.exception != null) {
584 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
585 }
586
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700587 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700588 if (ar.exception instanceof CommandException) {
589 CommandException.Error error =
590 ((CommandException) (ar.exception)).getCommandError();
591 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700593 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 }
596 }
597 openChannelResp = new IccOpenLogicalChannelResponse(
598 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700600 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
604 case CMD_CLOSE_CHANNEL:
605 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800606 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 if (uiccCard == null) {
608 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900609 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 } else {
612 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
613 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
614 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 break;
616
617 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800618 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
619 break;
620
621 case CMD_NV_READ_ITEM:
622 request = (MainThreadRequest) msg.obj;
623 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700624 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800625 break;
626
627 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800630 if (ar.exception == null && ar.result != null) {
631 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800633 request.result = "";
634 if (ar.result == null) {
635 loge("nvReadItem: Empty response");
636 } else if (ar.exception instanceof CommandException) {
637 loge("nvReadItem: CommandException: " +
638 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800640 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 }
642 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 break;
645
Jake Hambye994d462014-02-03 13:10:13 -0800646 case CMD_NV_WRITE_ITEM:
647 request = (MainThreadRequest) msg.obj;
648 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
649 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700650 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
651 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800652 break;
653
654 case EVENT_NV_WRITE_ITEM_DONE:
655 handleNullReturnEvent(msg, "nvWriteItem");
656 break;
657
658 case CMD_NV_WRITE_CDMA_PRL:
659 request = (MainThreadRequest) msg.obj;
660 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
661 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
662 break;
663
664 case EVENT_NV_WRITE_CDMA_PRL_DONE:
665 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
666 break;
667
668 case CMD_NV_RESET_CONFIG:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
671 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
672 break;
673
674 case EVENT_NV_RESET_CONFIG_DONE:
675 handleNullReturnEvent(msg, "nvResetConfig");
676 break;
677
Jake Hamby7c27be32014-03-03 13:25:59 -0800678 case CMD_GET_PREFERRED_NETWORK_TYPE:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700681 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800682 break;
683
684 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
685 ar = (AsyncResult) msg.obj;
686 request = (MainThreadRequest) ar.userObj;
687 if (ar.exception == null && ar.result != null) {
688 request.result = ar.result; // Integer
689 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800690 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800691 if (ar.result == null) {
692 loge("getPreferredNetworkType: Empty response");
693 } else if (ar.exception instanceof CommandException) {
694 loge("getPreferredNetworkType: CommandException: " +
695 ar.exception);
696 } else {
697 loge("getPreferredNetworkType: Unknown exception");
698 }
699 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700700 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 break;
702
703 case CMD_SET_PREFERRED_NETWORK_TYPE:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
706 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700707 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800708 break;
709
710 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
711 handleNullReturnEvent(msg, "setPreferredNetworkType");
712 break;
713
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000714 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
715 request = (MainThreadRequest)msg.obj;
716 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700717 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000718 break;
719
720 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
721 ar = (AsyncResult)msg.obj;
722 request = (MainThreadRequest)ar.userObj;
723 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700724 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000725 break;
726
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800727 case CMD_SET_VOICEMAIL_NUMBER:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
730 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800731 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
732 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800733 break;
734
735 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
736 handleNullReturnEvent(msg, "setVoicemailNumber");
737 break;
738
Stuart Scott54788802015-03-30 13:18:01 -0700739 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
742 request);
743 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
744 break;
745
746 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
747 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
748 break;
749
Shishir Agrawal302c8692015-06-19 13:49:39 -0700750 case CMD_PERFORM_NETWORK_SCAN:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
753 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
754 break;
755
756 case EVENT_PERFORM_NETWORK_SCAN_DONE:
757 ar = (AsyncResult) msg.obj;
758 request = (MainThreadRequest) ar.userObj;
759 CellNetworkScanResult cellScanResult;
760 if (ar.exception == null && ar.result != null) {
761 cellScanResult = new CellNetworkScanResult(
762 CellNetworkScanResult.STATUS_SUCCESS,
763 (List<OperatorInfo>) ar.result);
764 } else {
765 if (ar.result == null) {
766 loge("getCellNetworkScanResults: Empty response");
767 }
768 if (ar.exception != null) {
769 loge("getCellNetworkScanResults: Exception: " + ar.exception);
770 }
771 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
772 if (ar.exception instanceof CommandException) {
773 CommandException.Error error =
774 ((CommandException) (ar.exception)).getCommandError();
775 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
776 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
777 } else if (error == CommandException.Error.GENERIC_FAILURE) {
778 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
779 }
780 }
781 cellScanResult = new CellNetworkScanResult(errorCode, null);
782 }
783 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700785 break;
786
787 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
788 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700789 ManualNetworkSelectionArgument selArg =
790 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
792 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700793 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
794 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 break;
796
797 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
798 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
799 break;
800
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700801 case CMD_GET_MODEM_ACTIVITY_INFO:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700804 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700805 break;
806
807 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
810 if (ar.exception == null && ar.result != null) {
811 request.result = ar.result;
812 } else {
813 if (ar.result == null) {
814 loge("queryModemActivityInfo: Empty response");
815 } else if (ar.exception instanceof CommandException) {
816 loge("queryModemActivityInfo: CommandException: " +
817 ar.exception);
818 } else {
819 loge("queryModemActivityInfo: Unknown exception");
820 }
821 }
Amit Mahajand4766222016-01-28 15:28:28 -0800822 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
823 if (request.result == null) {
824 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
825 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700826 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700827 break;
828
Meng Wang1a7c35a2016-05-05 20:56:15 -0700829 case CMD_SET_ALLOWED_CARRIERS:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
832 mPhone.setAllowedCarriers(
833 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700834 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700835 break;
836
837 case EVENT_SET_ALLOWED_CARRIERS_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result;
842 } else {
843 if (ar.result == null) {
844 loge("setAllowedCarriers: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("setAllowedCarriers: CommandException: " +
847 ar.exception);
848 } else {
849 loge("setAllowedCarriers: Unknown exception");
850 }
851 }
852 // Result cannot be null. Return -1 on error.
853 if (request.result == null) {
854 request.result = new int[]{-1};
855 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700856 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700857 break;
858
859 case CMD_GET_ALLOWED_CARRIERS:
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700862 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700863 break;
864
865 case EVENT_GET_ALLOWED_CARRIERS_DONE:
866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
868 if (ar.exception == null && ar.result != null) {
869 request.result = ar.result;
870 } else {
871 if (ar.result == null) {
872 loge("getAllowedCarriers: Empty response");
873 } else if (ar.exception instanceof CommandException) {
874 loge("getAllowedCarriers: CommandException: " +
875 ar.exception);
876 } else {
877 loge("getAllowedCarriers: Unknown exception");
878 }
879 }
880 // Result cannot be null. Return empty list of CarrierIdentifier.
881 if (request.result == null) {
882 request.result = new ArrayList<CarrierIdentifier>(0);
883 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700884 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 break;
886
Nathan Haroldb3014052017-01-25 15:57:32 -0800887 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
888 ar = (AsyncResult) msg.obj;
889 request = (MainThreadRequest) ar.userObj;
890 if (ar.exception == null && ar.result != null) {
891 request.result = ar.result;
892 } else {
893 request.result = new IllegalArgumentException(
894 "Failed to retrieve Forbidden Plmns");
895 if (ar.result == null) {
896 loge("getForbiddenPlmns: Empty response");
897 } else {
898 loge("getForbiddenPlmns: Unknown exception");
899 }
900 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700901 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800902 break;
903
904 case CMD_GET_FORBIDDEN_PLMNS:
905 request = (MainThreadRequest) msg.obj;
906 uiccCard = getUiccCardFromRequest(request);
907 if (uiccCard == null) {
908 loge("getForbiddenPlmns() UiccCard is null");
909 request.result = new IllegalArgumentException(
910 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700911 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800912 break;
913 }
914 Integer appType = (Integer) request.argument;
915 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
916 if (uiccApp == null) {
917 loge("getForbiddenPlmns() no app with specified type -- "
918 + appType);
919 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700920 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800921 break;
922 } else {
923 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
924 + " specified type -- " + appType);
925 }
926 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
927 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
928 onCompleted);
929 break;
930
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000931 case CMD_SWITCH_SLOTS:
932 request = (MainThreadRequest) msg.obj;
933 int[] physicalSlots = (int[]) request.argument;
934 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
935 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
936 break;
937
938 case EVENT_SWITCH_SLOTS_DONE:
939 ar = (AsyncResult) msg.obj;
940 request = (MainThreadRequest) ar.userObj;
941 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700942 notifyRequester(request);
943 break;
944 case CMD_GET_NETWORK_SELECTION_MODE:
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
947 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
948 break;
949
950 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
951 ar = (AsyncResult) msg.obj;
952 request = (MainThreadRequest) ar.userObj;
953 if (ar.exception != null) {
954 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
955 } else {
956 int mode = ((int[]) ar.result)[0];
957 if (mode == 0) {
958 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
959 } else {
960 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
961 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000962 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700963 notifyRequester(request);
964 break;
965 case CMD_GET_CDMA_ROAMING_MODE:
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
968 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
969 break;
970 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
973 if (ar.exception != null) {
974 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
975 } else {
976 request.result = ((int[]) ar.result)[0];
977 }
978 notifyRequester(request);
979 break;
980 case CMD_SET_CDMA_ROAMING_MODE:
981 request = (MainThreadRequest) msg.obj;
982 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
983 int mode = (int) request.argument;
984 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
985 break;
986 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
987 ar = (AsyncResult) msg.obj;
988 request = (MainThreadRequest) ar.userObj;
989 request.result = ar.exception == null;
990 notifyRequester(request);
991 break;
992 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
993 request = (MainThreadRequest) msg.obj;
994 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
995 int subscriptionMode = (int) request.argument;
996 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
997 break;
998 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 request.result = ar.exception == null;
1002 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001003 break;
1004
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001005 default:
1006 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1007 break;
1008 }
1009 }
Jake Hambye994d462014-02-03 13:10:13 -08001010
Pengquan Meng0c05b502018-09-06 09:59:22 -07001011 private void notifyRequester(MainThreadRequest request) {
1012 synchronized (request) {
1013 request.notifyAll();
1014 }
1015 }
1016
Jake Hambye994d462014-02-03 13:10:13 -08001017 private void handleNullReturnEvent(Message msg, String command) {
1018 AsyncResult ar = (AsyncResult) msg.obj;
1019 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1020 if (ar.exception == null) {
1021 request.result = true;
1022 } else {
1023 request.result = false;
1024 if (ar.exception instanceof CommandException) {
1025 loge(command + ": CommandException: " + ar.exception);
1026 } else {
1027 loge(command + ": Unknown exception");
1028 }
1029 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001030 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001032 }
1033
1034 /**
1035 * Posts the specified command to be executed on the main thread,
1036 * waits for the request to complete, and returns the result.
1037 * @see #sendRequestAsync
1038 */
1039 private Object sendRequest(int command, Object argument) {
vagdevie435a3e2018-08-15 16:01:53 -07001040 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1041 }
1042
1043 /**
1044 * Posts the specified command to be executed on the main thread,
1045 * waits for the request to complete, and returns the result.
1046 * @see #sendRequestAsync
1047 */
1048 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1049 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1050 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001051 }
1052
1053 /**
1054 * Posts the specified command to be executed on the main thread,
1055 * waits for the request to complete, and returns the result.
1056 * @see #sendRequestAsync
1057 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001058 private Object sendRequest(int command, Object argument, Integer subId) {
vagdevie435a3e2018-08-15 16:01:53 -07001059 return sendRequest(command, argument, subId, null);
1060 }
1061
1062 /**
1063 * Posts the specified command to be executed on the main thread,
1064 * waits for the request to complete, and returns the result.
1065 * @see #sendRequestAsync
1066 */
1067 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001068 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1069 throw new RuntimeException("This method will deadlock if called from the main thread.");
1070 }
1071
vagdevie435a3e2018-08-15 16:01:53 -07001072 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001073 Message msg = mMainThreadHandler.obtainMessage(command, request);
1074 msg.sendToTarget();
1075
1076 // Wait for the request to complete
1077 synchronized (request) {
1078 while (request.result == null) {
1079 try {
1080 request.wait();
1081 } catch (InterruptedException e) {
1082 // Do nothing, go back and wait until the request is complete
1083 }
1084 }
1085 }
1086 return request.result;
1087 }
1088
1089 /**
1090 * Asynchronous ("fire and forget") version of sendRequest():
1091 * Posts the specified command to be executed on the main thread, and
1092 * returns immediately.
1093 * @see #sendRequest
1094 */
1095 private void sendRequestAsync(int command) {
1096 mMainThreadHandler.sendEmptyMessage(command);
1097 }
1098
1099 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001100 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1101 * @see {@link #sendRequest(int,Object)}
1102 */
1103 private void sendRequestAsync(int command, Object argument) {
1104 MainThreadRequest request = new MainThreadRequest(argument);
1105 Message msg = mMainThreadHandler.obtainMessage(command, request);
1106 msg.sendToTarget();
1107 }
1108
1109 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 * Initialize the singleton PhoneInterfaceManager instance.
1111 * This is only done once, at startup, from PhoneApp.onCreate().
1112 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001113 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 synchronized (PhoneInterfaceManager.class) {
1115 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001116 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001117 } else {
1118 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1119 }
1120 return sInstance;
1121 }
1122 }
1123
1124 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001125 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001126 mApp = app;
1127 mPhone = phone;
1128 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001129 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1131 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001132 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001133 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001134 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001135 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001136 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001137
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 publish();
1139 }
1140
1141 private void publish() {
1142 if (DBG) log("publish: " + this);
1143
1144 ServiceManager.addService("phone", this);
1145 }
1146
Stuart Scott584921c2015-01-15 17:10:34 -08001147 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001148 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1149 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001150 }
1151
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001152 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1153 Phone phone = getPhoneFromRequest(request);
1154 return phone == null ? null :
1155 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1156 }
1157
Wink Saville36469e72014-06-11 15:17:00 -07001158 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001159 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001160 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 //
1163 // Implementation of the ITelephony interface.
1164 //
1165
1166 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001167 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001168 }
1169
Wink Savilleb564aae2014-10-23 10:18:09 -07001170 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 if (DBG) log("dial: " + number);
1172 // No permission check needed here: This is just a wrapper around the
1173 // ACTION_DIAL intent, which is available to any app since it puts up
1174 // the UI before it does anything.
1175
Malcolm Chenaabec062018-02-28 15:00:40 -08001176 final long identity = Binder.clearCallingIdentity();
1177 try {
1178 String url = createTelUrl(number);
1179 if (url == null) {
1180 return;
1181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001182
Malcolm Chenaabec062018-02-28 15:00:40 -08001183 // PENDING: should we just silently fail if phone is offhook or ringing?
1184 PhoneConstants.State state = mCM.getState(subId);
1185 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1186 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1187 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1188 mApp.startActivity(intent);
1189 }
1190 } finally {
1191 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 }
1193 }
1194
1195 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001196 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001197 }
1198
Wink Savilleb564aae2014-10-23 10:18:09 -07001199 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001200 if (DBG) log("call: " + number);
1201
1202 // This is just a wrapper around the ACTION_CALL intent, but we still
1203 // need to do a permission check since we're calling startActivity()
1204 // from the context of the phone app.
1205 enforceCallPermission();
1206
1207 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1208 != AppOpsManager.MODE_ALLOWED) {
1209 return;
1210 }
1211
Malcolm Chenaabec062018-02-28 15:00:40 -08001212 final long identity = Binder.clearCallingIdentity();
1213 try {
1214 String url = createTelUrl(number);
1215 if (url == null) {
1216 return;
1217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218
Malcolm Chenaabec062018-02-28 15:00:40 -08001219 boolean isValid = false;
1220 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1221 if (slist != null) {
1222 for (SubscriptionInfo subInfoRecord : slist) {
1223 if (subInfoRecord.getSubscriptionId() == subId) {
1224 isValid = true;
1225 break;
1226 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001227 }
Wink Saville08874612014-08-31 19:19:58 -07001228 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001229 if (!isValid) {
1230 return;
1231 }
Wink Saville08874612014-08-31 19:19:58 -07001232
Malcolm Chenaabec062018-02-28 15:00:40 -08001233 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1234 intent.putExtra(SUBSCRIPTION_KEY, subId);
1235 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1236 mApp.startActivity(intent);
1237 } finally {
1238 Binder.restoreCallingIdentity(identity);
1239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001240 }
1241
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 /**
1243 * End a call based on call state
1244 * @return true is a call was ended
1245 */
1246 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001247 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001248 }
1249
1250 /**
1251 * End a call based on the call state of the subId
1252 * @return true is a call was ended
1253 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001254 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001255 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1256 != PackageManager.PERMISSION_GRANTED) {
1257 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1258 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1259 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1260 }
Hall Liu0c2d4d62018-09-18 14:04:38 -07001261
Malcolm Chenaabec062018-02-28 15:00:40 -08001262 final long identity = Binder.clearCallingIdentity();
1263 try {
1264 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1265 } finally {
1266 Binder.restoreCallingIdentity(identity);
1267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 }
1269
1270 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001271 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001272 }
1273
Wink Savilleb564aae2014-10-23 10:18:09 -07001274 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001275 if (DBG) log("answerRingingCall...");
1276 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1277 // but that can probably wait till the big TelephonyManager API overhaul.
1278 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1279 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001280
1281 final long identity = Binder.clearCallingIdentity();
1282 try {
1283 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1284 } finally {
1285 Binder.restoreCallingIdentity(identity);
1286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001287 }
1288
1289 /**
1290 * Make the actual telephony calls to implement answerRingingCall().
1291 * This should only be called from the main thread of the Phone app.
1292 * @see #answerRingingCall
1293 *
1294 * TODO: it would be nice to return true if we answered the call, or
1295 * false if there wasn't actually a ringing incoming call, or some
1296 * other error occurred. (In other words, pass back the return value
1297 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1298 * But that would require calling this method via sendRequest() rather
1299 * than sendRequestAsync(), and right now we don't actually *need* that
1300 * return value, so let's just return void for now.
1301 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001302 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001303 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001305 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1306 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 if (hasActiveCall && hasHoldingCall) {
1308 // Both lines are in use!
1309 // TODO: provide a flag to let the caller specify what
1310 // policy to use if both lines are in use. (The current
1311 // behavior is hardwired to "answer incoming, end ongoing",
1312 // which is how the CALL button is specced to behave.)
1313 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1314 return;
1315 } else {
1316 // answerCall() will automatically hold the current active
1317 // call, if there is one.
1318 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1319 return;
1320 }
1321 } else {
1322 // No call was ringing.
1323 return;
1324 }
1325 }
1326
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001328 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001330 public void silenceRinger() {
1331 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 }
1333
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001334 @Override
1335 public boolean isOffhook(String callingPackage) {
1336 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001337 }
1338
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001339 @Override
1340 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001342 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001343 return false;
1344 }
1345
Malcolm Chenaabec062018-02-28 15:00:40 -08001346 final long identity = Binder.clearCallingIdentity();
1347 try {
1348 final Phone phone = getPhone(subId);
1349 if (phone != null) {
1350 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1351 } else {
1352 return false;
1353 }
1354 } finally {
1355 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 }
1358
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001359 @Override
1360 public boolean isRinging(String callingPackage) {
1361 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001362 }
1363
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001364 @Override
1365 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001367 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001368 return false;
1369 }
1370
Malcolm Chenaabec062018-02-28 15:00:40 -08001371 final long identity = Binder.clearCallingIdentity();
1372 try {
1373 final Phone phone = getPhone(subId);
1374 if (phone != null) {
1375 return (phone.getState() == PhoneConstants.State.RINGING);
1376 } else {
1377 return false;
1378 }
1379 } finally {
1380 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 }
1383
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001384 @Override
1385 public boolean isIdle(String callingPackage) {
1386 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001387 }
1388
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001389 @Override
1390 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001392 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001393 return false;
1394 }
1395
Malcolm Chenaabec062018-02-28 15:00:40 -08001396 final long identity = Binder.clearCallingIdentity();
1397 try {
1398 final Phone phone = getPhone(subId);
1399 if (phone != null) {
1400 return (phone.getState() == PhoneConstants.State.IDLE);
1401 } else {
1402 return false;
1403 }
1404 } finally {
1405 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 }
1408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001410 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001411 }
1412
Wink Savilleb564aae2014-10-23 10:18:09 -07001413 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001414 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001415 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1416 }
1417
1418 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001419 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001420 }
1421
Wink Savilleb564aae2014-10-23 10:18:09 -07001422 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001423 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001424 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1425 }
1426
1427 /** {@hide} */
1428 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001429 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001430 }
1431
Wink Savilleb564aae2014-10-23 10:18:09 -07001432 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001434
1435 final long identity = Binder.clearCallingIdentity();
1436 try {
1437 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1438 checkSimPin.start();
1439 return checkSimPin.unlockSim(null, pin);
1440 } finally {
1441 Binder.restoreCallingIdentity(identity);
1442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 }
1444
Wink Saville9de0f752013-10-22 19:04:03 -07001445 /** {@hide} */
1446 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001447 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001448 }
1449
Wink Savilleb564aae2014-10-23 10:18:09 -07001450 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001452
1453 final long identity = Binder.clearCallingIdentity();
1454 try {
1455 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1456 checkSimPuk.start();
1457 return checkSimPuk.unlockSim(puk, pin);
1458 } finally {
1459 Binder.restoreCallingIdentity(identity);
1460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 }
1462
1463 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001464 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 * a synchronous one.
1466 */
1467 private static class UnlockSim extends Thread {
1468
1469 private final IccCard mSimCard;
1470
1471 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001472 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1473 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474
1475 // For replies from SimCard interface
1476 private Handler mHandler;
1477
1478 // For async handler to identify request type
1479 private static final int SUPPLY_PIN_COMPLETE = 100;
1480
1481 public UnlockSim(IccCard simCard) {
1482 mSimCard = simCard;
1483 }
1484
1485 @Override
1486 public void run() {
1487 Looper.prepare();
1488 synchronized (UnlockSim.this) {
1489 mHandler = new Handler() {
1490 @Override
1491 public void handleMessage(Message msg) {
1492 AsyncResult ar = (AsyncResult) msg.obj;
1493 switch (msg.what) {
1494 case SUPPLY_PIN_COMPLETE:
1495 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1496 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001497 mRetryCount = msg.arg1;
1498 if (ar.exception != null) {
1499 if (ar.exception instanceof CommandException &&
1500 ((CommandException)(ar.exception)).getCommandError()
1501 == CommandException.Error.PASSWORD_INCORRECT) {
1502 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1503 } else {
1504 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1505 }
1506 } else {
1507 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 mDone = true;
1510 UnlockSim.this.notifyAll();
1511 }
1512 break;
1513 }
1514 }
1515 };
1516 UnlockSim.this.notifyAll();
1517 }
1518 Looper.loop();
1519 }
1520
1521 /*
1522 * Use PIN or PUK to unlock SIM card
1523 *
1524 * If PUK is null, unlock SIM card with PIN
1525 *
1526 * If PUK is not null, unlock SIM card with PUK and set PIN code
1527 */
Wink Saville9de0f752013-10-22 19:04:03 -07001528 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529
1530 while (mHandler == null) {
1531 try {
1532 wait();
1533 } catch (InterruptedException e) {
1534 Thread.currentThread().interrupt();
1535 }
1536 }
1537 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1538
1539 if (puk == null) {
1540 mSimCard.supplyPin(pin, callback);
1541 } else {
1542 mSimCard.supplyPuk(puk, pin, callback);
1543 }
1544
1545 while (!mDone) {
1546 try {
1547 Log.d(LOG_TAG, "wait for done");
1548 wait();
1549 } catch (InterruptedException e) {
1550 // Restore the interrupted status
1551 Thread.currentThread().interrupt();
1552 }
1553 }
1554 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001555 int[] resultArray = new int[2];
1556 resultArray[0] = mResult;
1557 resultArray[1] = mRetryCount;
1558 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 }
1560 }
1561
1562 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001563 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001564
1565 }
1566
Wink Savilleb564aae2014-10-23 10:18:09 -07001567 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 // No permission check needed here: this call is harmless, and it's
1569 // needed for the ServiceState.requestStateUpdate() call (which is
1570 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001571 final long identity = Binder.clearCallingIdentity();
1572 try {
1573 final Phone phone = getPhone(subId);
1574 if (phone != null) {
1575 phone.updateServiceLocation();
1576 }
1577 } finally {
1578 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 }
1581
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001582 @Override
1583 public boolean isRadioOn(String callingPackage) {
1584 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001585 }
1586
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001587 @Override
1588 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001590 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001591 return false;
1592 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001593
1594 final long identity = Binder.clearCallingIdentity();
1595 try {
1596 return isRadioOnForSubscriber(subId);
1597 } finally {
1598 Binder.restoreCallingIdentity(identity);
1599 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001600 }
1601
1602 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001603 final long identity = Binder.clearCallingIdentity();
1604 try {
1605 final Phone phone = getPhone(subId);
1606 if (phone != null) {
1607 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1608 } else {
1609 return false;
1610 }
1611 } finally {
1612 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 }
1615
1616 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001617 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 }
Wink Saville36469e72014-06-11 15:17:00 -07001619
Wink Savilleb564aae2014-10-23 10:18:09 -07001620 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001622
1623 final long identity = Binder.clearCallingIdentity();
1624 try {
1625 final Phone phone = getPhone(subId);
1626 if (phone != null) {
1627 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1628 }
1629 } finally {
1630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001631 }
Wink Saville36469e72014-06-11 15:17:00 -07001632 }
1633
1634 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001635 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001636 }
1637
Wink Savilleb564aae2014-10-23 10:18:09 -07001638 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001639 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001640
1641 final long identity = Binder.clearCallingIdentity();
1642 try {
1643 final Phone phone = getPhone(subId);
1644 if (phone == null) {
1645 return false;
1646 }
1647 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1648 toggleRadioOnOffForSubscriber(subId);
1649 }
1650 return true;
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 }
Wink Saville36469e72014-06-11 15:17:00 -07001655
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001656 public boolean needMobileRadioShutdown() {
1657 /*
1658 * If any of the Radios are available, it will need to be
1659 * shutdown. So return true if any Radio is available.
1660 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001661 final long identity = Binder.clearCallingIdentity();
1662 try {
1663 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1664 Phone phone = PhoneFactory.getPhone(i);
1665 if (phone != null && phone.isRadioAvailable()) return true;
1666 }
1667 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1668 return false;
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001671 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001672 }
1673
Malcolm Chenaabec062018-02-28 15:00:40 -08001674 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001675 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001676 enforceModifyPermission();
1677
1678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1681 logv("Shutting down Phone " + i);
1682 shutdownRadioUsingPhoneId(i);
1683 }
1684 } finally {
1685 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001686 }
1687 }
1688
1689 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001690 Phone phone = PhoneFactory.getPhone(phoneId);
1691 if (phone != null && phone.isRadioAvailable()) {
1692 phone.shutdownRadio();
1693 }
1694 }
1695
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001697 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001698
1699 final long identity = Binder.clearCallingIdentity();
1700 try {
1701 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1702 if (defaultPhone != null) {
1703 defaultPhone.setRadioPower(turnOn);
1704 return true;
1705 } else {
1706 loge("There's no default phone.");
1707 return false;
1708 }
1709 } finally {
1710 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001711 }
Wink Saville36469e72014-06-11 15:17:00 -07001712 }
1713
Wink Savilleb564aae2014-10-23 10:18:09 -07001714 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 final Phone phone = getPhone(subId);
1720 if (phone != null) {
1721 phone.setRadioPower(turnOn);
1722 return true;
1723 } else {
1724 return false;
1725 }
1726 } finally {
1727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 }
1730
Wink Saville36469e72014-06-11 15:17:00 -07001731 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 public boolean enableDataConnectivity() {
1734 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001735
1736 final long identity = Binder.clearCallingIdentity();
1737 try {
1738 int subId = mSubscriptionController.getDefaultDataSubId();
1739 final Phone phone = getPhone(subId);
1740 if (phone != null) {
1741 phone.setUserDataEnabled(true);
1742 return true;
1743 } else {
1744 return false;
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
1750
Wink Saville36469e72014-06-11 15:17:00 -07001751 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001752 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 public boolean disableDataConnectivity() {
1754 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001755
1756 final long identity = Binder.clearCallingIdentity();
1757 try {
1758 int subId = mSubscriptionController.getDefaultDataSubId();
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.setUserDataEnabled(false);
1762 return true;
1763 } else {
1764 return false;
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001772 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001773 final long identity = Binder.clearCallingIdentity();
1774 try {
1775 final Phone phone = getPhone(subId);
1776 if (phone != null) {
1777 return phone.isDataAllowed();
1778 } else {
1779 return false;
1780 }
1781 } finally {
1782 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 }
1785
1786 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001787 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001788 }
1789
pkanwarae03a6b2016-11-06 20:37:09 -08001790 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001791 enforceCallPermission();
1792
1793 final long identity = Binder.clearCallingIdentity();
1794 try {
1795 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1796 return;
1797 }
1798 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1799 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
1802 }
pkanwar32d516d2016-10-14 19:37:38 -07001803 };
1804
Wink Savilleb564aae2014-10-23 10:18:09 -07001805 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001807
1808 final long identity = Binder.clearCallingIdentity();
1809 try {
1810 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1811 return false;
1812 }
1813 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1814 } finally {
1815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 }
1818
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001820 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001821 }
1822
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001823 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001824 final long identity = Binder.clearCallingIdentity();
1825 try {
1826 Phone phone = PhoneFactory.getPhone(slotIndex);
1827 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1828 PhoneConstantConversions.convertCallState(phone.getState());
1829 } finally {
1830 Binder.restoreCallingIdentity(identity);
1831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 }
1833
Sanket Padawe356d7632015-06-22 14:03:32 -07001834 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1839 if (phone != null) {
1840 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1841 } else {
1842 return PhoneConstantConversions.convertDataState(
1843 PhoneConstants.DataState.DISCONNECTED);
1844 }
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
Sanket Padawe356d7632015-06-22 14:03:32 -07001850 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1855 if (phone != null) {
1856 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1857 } else {
1858 return TelephonyManager.DATA_ACTIVITY_NONE;
1859 }
1860 } finally {
1861 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 }
1864
1865 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001866 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001867 mPhone.getContext().getSystemService(AppOpsManager.class)
1868 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001869 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001870 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001871 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001874 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001875 final long identity = Binder.clearCallingIdentity();
1876 try {
1877 if (DBG_LOC) log("getCellLocation: is active user");
1878 Bundle data = new Bundle();
1879 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1880 if (phone == null) {
1881 return null;
1882 }
1883
1884 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1885 return data;
1886 } finally {
1887 Binder.restoreCallingIdentity(identity);
1888 }
Svetoslav64fad262015-04-14 14:35:21 -07001889 }
1890
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001892 public String getNetworkCountryIsoForPhone(int phoneId) {
1893 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1894 // registered cell info, so return a NULL country instead.
1895 final long identity = Binder.clearCallingIdentity();
1896 try {
1897 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001898 // Todo: fix this when we can get the actual cellular network info when the device
1899 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001900 if (TelephonyManager.NETWORK_TYPE_IWLAN
1901 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1902 return "";
1903 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001904 Phone phone = PhoneFactory.getPhone(phoneId);
1905 if (phone != null) {
1906 ServiceStateTracker sst = phone.getServiceStateTracker();
1907 if (sst != null) {
1908 LocaleTracker lt = sst.getLocaleTracker();
1909 if (lt != null) {
1910 return lt.getCurrentCountry();
1911 }
1912 }
1913 }
1914 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001915 } finally {
1916 Binder.restoreCallingIdentity(identity);
1917 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001918 }
1919
1920 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001922 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001923 }
1924
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001926 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 mApp.enforceCallingOrSelfPermission(
1928 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001929
1930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 final Phone phone = getPhone(subId);
1933 if (phone != null) {
1934 phone.enableLocationUpdates();
1935 }
1936 } finally {
1937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 }
1940
1941 @Override
1942 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001943 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001944 }
1945
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001947 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 mApp.enforceCallingOrSelfPermission(
1949 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001950
1951 final long identity = Binder.clearCallingIdentity();
1952 try {
1953 final Phone phone = getPhone(subId);
1954 if (phone != null) {
1955 phone.disableLocationUpdates();
1956 }
1957 } finally {
1958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 }
1961
1962 @Override
1963 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001964 public List<NeighboringCellInfo>
1965 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001966 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1967 throw new SecurityException(
1968 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1969 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001970
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1972 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1973 return null;
1974 }
Svetoslav64fad262015-04-14 14:35:21 -07001975
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001976 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977
Nathan Haroldf180aac2018-06-01 18:43:55 -07001978 List<CellInfo> info = getAllCellInfo(callingPackage);
1979 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980
Nathan Haroldf180aac2018-06-01 18:43:55 -07001981 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1982 for (CellInfo ci : info) {
1983 if (ci instanceof CellInfoGsm) {
1984 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1985 } else if (ci instanceof CellInfoWcdma) {
1986 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001989 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 }
1991
1992
1993 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001994 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001995 mPhone.getContext().getSystemService(AppOpsManager.class)
1996 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001997 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001998 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001999 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
2001
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002002 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002003 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08002004 final long identity = Binder.clearCallingIdentity();
2005 try {
2006 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2007 for (Phone phone : PhoneFactory.getPhones()) {
2008 final List<CellInfo> info = phone.getAllCellInfo(workSource);
2009 if (info != null) cellInfos.addAll(info);
2010 }
2011 return cellInfos;
2012 } finally {
2013 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 }
2015 }
2016
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002017 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002019 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08002021
2022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 mPhone.setCellInfoListRate(rateInMillis, workSource);
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 }
2029
Shishir Agrawala9f32182016-04-12 12:00:16 -07002030 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002031 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002032 Phone phone = PhoneFactory.getPhone(slotIndex);
2033 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002034 return null;
2035 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002036 int subId = phone.getSubId();
2037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2038 mApp, subId, callingPackage, "getImeiForSlot")) {
2039 return null;
2040 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002041
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 return phone.getImei();
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
2047 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002048 }
2049
2050 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002051 public String getTypeAllocationCodeForSlot(int slotIndex) {
2052 Phone phone = PhoneFactory.getPhone(slotIndex);
2053 String tac = null;
2054 if (phone != null) {
2055 String imei = phone.getImei();
2056 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2057 }
2058 return tac;
2059 }
2060
2061 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002062 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002063 Phone phone = PhoneFactory.getPhone(slotIndex);
2064 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002065 return null;
2066 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002067 int subId = phone.getSubId();
2068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2069 mApp, subId, callingPackage, "getMeidForSlot")) {
2070 return null;
2071 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002072
2073 final long identity = Binder.clearCallingIdentity();
2074 try {
2075 return phone.getMeid();
2076 } finally {
2077 Binder.restoreCallingIdentity(identity);
2078 }
Jack Yu2af8d712017-03-15 17:14:14 -07002079 }
2080
2081 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002082 public String getManufacturerCodeForSlot(int slotIndex) {
2083 Phone phone = PhoneFactory.getPhone(slotIndex);
2084 String manufacturerCode = null;
2085 if (phone != null) {
2086 String meid = phone.getMeid();
2087 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2088 }
2089 return manufacturerCode;
2090 }
2091
2092 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002093 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002094 Phone phone = PhoneFactory.getPhone(slotIndex);
2095 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002096 return null;
2097 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002098 int subId = phone.getSubId();
2099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2100 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2101 return null;
2102 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002103
2104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 return phone.getDeviceSvn();
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
2109 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002110 }
2111
fionaxu43304da2017-11-27 22:51:16 -08002112 @Override
2113 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 final Phone phone = getPhone(subId);
2117 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
fionaxu43304da2017-11-27 22:51:16 -08002121 }
2122
2123 @Override
2124 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002125 final long identity = Binder.clearCallingIdentity();
2126 try {
2127 final Phone phone = getPhone(subId);
2128 return phone == null ? null : phone.getCarrierName();
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
2131 }
fionaxu43304da2017-11-27 22:51:16 -08002132 }
2133
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 //
2135 // Internal helper methods.
2136 //
2137
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002138 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2140 *
2141 * @throws SecurityException if the caller does not have the required permission
2142 */
2143 private void enforceModifyPermission() {
2144 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2145 }
2146
2147 /**
2148 * Make sure the caller has the CALL_PHONE permission.
2149 *
2150 * @throws SecurityException if the caller does not have the required permission
2151 */
2152 private void enforceCallPermission() {
2153 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2154 }
2155
Stuart Scott8eef64f2015-04-08 15:13:54 -07002156 private void enforceConnectivityInternalPermission() {
2157 mApp.enforceCallingOrSelfPermission(
2158 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2159 "ConnectivityService");
2160 }
2161
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 private String createTelUrl(String number) {
2163 if (TextUtils.isEmpty(number)) {
2164 return null;
2165 }
2166
Jake Hambye994d462014-02-03 13:10:13 -08002167 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Ihab Awadf9e92732013-12-05 18:02:52 -08002170 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2172 }
2173
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002174 private static void logv(String msg) {
2175 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2176 }
2177
Ihab Awadf9e92732013-12-05 18:02:52 -08002178 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2180 }
2181
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002182 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002184 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002185 }
2186
Sanket Padawe356d7632015-06-22 14:03:32 -07002187 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002188 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002189 final long identity = Binder.clearCallingIdentity();
2190 try {
2191 final Phone phone = PhoneFactory.getPhone(slotIndex);
2192 if (phone == null) {
2193 return PhoneConstants.PHONE_TYPE_NONE;
2194 } else {
2195 return phone.getPhoneType();
2196 }
2197 } finally {
2198 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
2202 /**
2203 * Returns the CDMA ERI icon index to display
2204 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002205 @Override
2206 public int getCdmaEriIconIndex(String callingPackage) {
2207 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002208 }
2209
Sanket Padawe356d7632015-06-22 14:03:32 -07002210 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002211 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002212 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002213 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002214 return -1;
2215 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002216
2217 final long identity = Binder.clearCallingIdentity();
2218 try {
2219 final Phone phone = getPhone(subId);
2220 if (phone != null) {
2221 return phone.getCdmaEriIconIndex();
2222 } else {
2223 return -1;
2224 }
2225 } finally {
2226 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 }
2229
2230 /**
2231 * Returns the CDMA ERI icon mode,
2232 * 0 - ON
2233 * 1 - FLASHING
2234 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002235 @Override
2236 public int getCdmaEriIconMode(String callingPackage) {
2237 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002238 }
2239
Sanket Padawe356d7632015-06-22 14:03:32 -07002240 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002241 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002243 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002244 return -1;
2245 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002246
2247 final long identity = Binder.clearCallingIdentity();
2248 try {
2249 final Phone phone = getPhone(subId);
2250 if (phone != null) {
2251 return phone.getCdmaEriIconMode();
2252 } else {
2253 return -1;
2254 }
2255 } finally {
2256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259
2260 /**
2261 * Returns the CDMA ERI text,
2262 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002263 @Override
2264 public String getCdmaEriText(String callingPackage) {
2265 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002266 }
2267
Sanket Padawe356d7632015-06-22 14:03:32 -07002268 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002269 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002271 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002272 return null;
2273 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002274
2275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 final Phone phone = getPhone(subId);
2278 if (phone != null) {
2279 return phone.getCdmaEriText();
2280 } else {
2281 return null;
2282 }
2283 } finally {
2284 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 }
2287
2288 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002289 * Returns the CDMA MDN.
2290 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002291 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002292 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2294 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 final Phone phone = getPhone(subId);
2299 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2300 return phone.getLine1Number();
2301 } else {
2302 return null;
2303 }
2304 } finally {
2305 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002306 }
2307 }
2308
2309 /**
2310 * Returns the CDMA MIN.
2311 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002312 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002313 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2315 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002316
2317 final long identity = Binder.clearCallingIdentity();
2318 try {
2319 final Phone phone = getPhone(subId);
2320 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2321 return phone.getCdmaMin();
2322 } else {
2323 return null;
2324 }
2325 } finally {
2326 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002327 }
2328 }
2329
2330 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 * Returns true if CDMA provisioning needs to run.
2332 */
2333 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002334 final long identity = Binder.clearCallingIdentity();
2335 try {
2336 return mPhone.needsOtaServiceProvisioning();
2337 } finally {
2338 Binder.restoreCallingIdentity(identity);
2339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
2341
2342 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002343 * Sets the voice mail number of a given subId.
2344 */
2345 @Override
2346 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002347 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002348
2349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2352 new Pair<String, String>(alphaTag, number), new Integer(subId));
2353 return success;
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
2356 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002357 }
2358
Ta-wei Yen87c49842016-05-13 21:19:52 -07002359 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002360 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2361 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2362 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2363 if (!TextUtils.equals(callingPackage, systemDialer)) {
2364 throw new SecurityException("caller must be system dialer");
2365 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002366
2367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2370 if (phoneAccountHandle == null) {
2371 return null;
2372 }
2373 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002376 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002377 }
2378
2379 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002380 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002381 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002383 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002384 return null;
2385 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002386
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002387 final long identity = Binder.clearCallingIdentity();
2388 try {
2389 return RemoteVvmTaskManager
2390 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002394 }
2395
2396 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002397 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2398 VisualVoicemailSmsFilterSettings settings) {
2399 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002400
2401 final long identity = Binder.clearCallingIdentity();
2402 try {
2403 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2404 mPhone.getContext(), callingPackage, subId, settings);
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
2407 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002408 }
2409
2410 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002411 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2412 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002413
2414 final long identity = Binder.clearCallingIdentity();
2415 try {
2416 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2417 mPhone.getContext(), callingPackage, subId);
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
2420 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002421 }
2422
2423 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002424 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2425 String callingPackage, int subId) {
2426 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002427
2428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2431 mPhone.getContext(), callingPackage, subId);
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
2434 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002435 }
2436
2437 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002438 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002439 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
2443 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2444 mPhone.getContext(), subId);
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
2447 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002448 }
2449
2450 @Override
2451 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2452 String number, int port, String text, PendingIntent sentIntent) {
2453 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002454 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002455 enforceSendSmsPermission();
2456 // Make the calls as the phone process.
2457 final long identity = Binder.clearCallingIdentity();
2458 try {
2459 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2460 if (port == 0) {
2461 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2462 sentIntent, null, false);
2463 } else {
2464 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2465 smsManager.sendDataMessageWithSelfPermissions(number, null,
2466 (short) port, data, sentIntent, null);
2467 }
2468 } finally {
2469 Binder.restoreCallingIdentity(identity);
2470 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002471 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002472 /**
fionaxu0152e512016-11-14 13:36:14 -08002473 * Sets the voice activation state of a given subId.
2474 */
2475 @Override
2476 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2478 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002479
2480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 final Phone phone = getPhone(subId);
2483 if (phone != null) {
2484 phone.setVoiceActivationState(activationState);
2485 } else {
2486 loge("setVoiceActivationState fails with invalid subId: " + subId);
2487 }
2488 } finally {
2489 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002490 }
2491 }
2492
2493 /**
2494 * Sets the data activation state of a given subId.
2495 */
2496 @Override
2497 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2499 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 final Phone phone = getPhone(subId);
2504 if (phone != null) {
2505 phone.setDataActivationState(activationState);
2506 } else {
2507 loge("setVoiceActivationState fails with invalid subId: " + subId);
2508 }
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002511 }
2512 }
2513
2514 /**
2515 * Returns the voice activation state of a given subId.
2516 */
2517 @Override
2518 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002519 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002520
fionaxu0152e512016-11-14 13:36:14 -08002521 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 if (phone != null) {
2525 return phone.getVoiceActivationState();
2526 } else {
2527 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2528 }
2529 } finally {
2530 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002531 }
2532 }
2533
2534 /**
2535 * Returns the data activation state of a given subId.
2536 */
2537 @Override
2538 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002539 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002540
fionaxu0152e512016-11-14 13:36:14 -08002541 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 if (phone != null) {
2545 return phone.getDataActivationState();
2546 } else {
2547 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2548 }
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002551 }
2552 }
2553
2554 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 * Returns the unread count of voicemails
2556 */
2557 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002558 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002559 }
2560
2561 /**
2562 * Returns the unread count of voicemails for a subId
2563 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002564 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002565 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 final Phone phone = getPhone(subId);
2569 if (phone != null) {
2570 return phone.getVoiceMessageCount();
2571 } else {
2572 return 0;
2573 }
2574 } finally {
2575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 }
2578
2579 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002580 * returns true, if the device is in a state where both voice and data
2581 * are supported simultaneously. This can change based on location or network condition.
2582 */
2583 @Override
2584 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 final Phone phone = getPhone(subId);
2588 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002592 }
2593
2594 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002595 * Send the dialer code if called from the current default dialer or the caller has
2596 * carrier privilege.
2597 * @param inputCode The dialer code to send
2598 */
2599 @Override
2600 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2601 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2602 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2603 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002604 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2605 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002606 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002607
2608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 mPhone.sendDialerSpecialCode(inputCode);
2611 } finally {
2612 Binder.restoreCallingIdentity(identity);
2613 }
fionaxu235cc5e2017-03-06 22:25:57 -08002614 }
2615
2616 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002617 * Returns the data network type.
2618 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 *
2620 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2621 */
2622 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002623 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 final Phone phone = getPhone(getDefaultSubscription());
2627 if (phone != null) {
2628 return phone.getServiceState().getDataNetworkType();
2629 } else {
2630 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2631 }
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002634 }
Wink Saville36469e72014-06-11 15:17:00 -07002635 }
2636
Pengquan Meng0c05b502018-09-06 09:59:22 -07002637 @Override
2638 public int getNetworkSelectionMode(int subId) {
2639 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2640 }
2641
Wink Saville36469e72014-06-11 15:17:00 -07002642 /**
2643 * Returns the network type for a subId
2644 */
2645 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002646 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002648 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002649 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2650 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002651
Malcolm Chenaabec062018-02-28 15:00:40 -08002652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 final Phone phone = getPhone(subId);
2655 if (phone != null) {
2656 return phone.getServiceState().getDataNetworkType();
2657 } else {
2658 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2659 }
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002662 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 }
2664
2665 /**
2666 * Returns the data network type
2667 */
2668 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002669 public int getDataNetworkType(String callingPackage) {
2670 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002671 }
2672
2673 /**
2674 * Returns the data network type for a subId
2675 */
2676 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002677 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002679 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002680 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2681 }
2682
Malcolm Chenaabec062018-02-28 15:00:40 -08002683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 final Phone phone = getPhone(subId);
2686 if (phone != null) {
2687 return phone.getServiceState().getDataNetworkType();
2688 } else {
2689 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2690 }
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
2695
2696 /**
Wink Saville36469e72014-06-11 15:17:00 -07002697 * Returns the Voice network type for a subId
2698 */
2699 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002700 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002702 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002703 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2704 }
2705
Malcolm Chenaabec062018-02-28 15:00:40 -08002706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 final Phone phone = getPhone(subId);
2709 if (phone != null) {
2710 return phone.getServiceState().getVoiceNetworkType();
2711 } else {
2712 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2713 }
2714 } finally {
2715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 }
2718
2719 /**
2720 * @return true if a ICC card is present
2721 */
2722 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002723 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002724 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2725 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002726 }
2727
2728 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002729 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002730 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002731 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002732 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002733 final long identity = Binder.clearCallingIdentity();
2734 try {
2735 final Phone phone = PhoneFactory.getPhone(slotIndex);
2736 if (phone != null) {
2737 return phone.getIccCard().hasIccCard();
2738 } else {
2739 return false;
2740 }
2741 } finally {
2742 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 }
2745
2746 /**
2747 * Return if the current radio is LTE on CDMA. This
2748 * is a tri-state return value as for a period of time
2749 * the mode may be unknown.
2750 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002751 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002752 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002753 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002755 @Override
2756 public int getLteOnCdmaMode(String callingPackage) {
2757 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002758 }
2759
Sanket Padawe356d7632015-06-22 14:03:32 -07002760 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002761 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002763 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002764 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2765 }
2766
Malcolm Chenaabec062018-02-28 15:00:40 -08002767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 final Phone phone = getPhone(subId);
2770 if (phone == null) {
2771 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2772 } else {
2773 return phone.getLteOnCdmaMode();
2774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 }
Wink Saville36469e72014-06-11 15:17:00 -07002778 }
2779
2780 public void setPhone(Phone phone) {
2781 mPhone = phone;
2782 }
2783
2784 /**
2785 * {@hide}
2786 * Returns Default subId, 0 in the case of single standby.
2787 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002788 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002789 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002790 }
2791
Shishir Agrawala9f32182016-04-12 12:00:16 -07002792 private int getSlotForDefaultSubscription() {
2793 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2794 }
2795
Wink Savilleb564aae2014-10-23 10:18:09 -07002796 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002797 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002799
2800 /**
2801 * @see android.telephony.TelephonyManager.WifiCallingChoices
2802 */
2803 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2807 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2808 getWhenToMakeWifiCallsDefaultPreference());
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
2811 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002812 }
2813
2814 /**
2815 * @see android.telephony.TelephonyManager.WifiCallingChoices
2816 */
2817 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2821 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2822 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2823 } finally {
2824 Binder.restoreCallingIdentity(identity);
2825 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002826 }
2827
Sailesh Nepald1e68152013-12-12 19:08:02 -08002828 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002829 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002830 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002831 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002832
Shishir Agrawal566b7612013-10-28 14:41:00 -07002833 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002834 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2835 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2837 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002839
Malcolm Chenaabec062018-02-28 15:00:40 -08002840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 if (TextUtils.equals(ISDR_AID, aid)) {
2843 // Only allows LPA to open logical channel to ISD-R.
2844 ComponentInfo bestComponent =
2845 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2846 if (bestComponent == null
2847 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2848 loge("The calling package is not allowed to access ISD-R.");
2849 throw new SecurityException(
2850 "The calling package is not allowed to access ISD-R.");
2851 }
Derek Tan740e1672017-06-27 14:56:27 -07002852 }
Derek Tan740e1672017-06-27 14:56:27 -07002853
Malcolm Chenaabec062018-02-28 15:00:40 -08002854 if (DBG) {
2855 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2856 }
2857 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2858 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2859 if (DBG) log("iccOpenLogicalChannel: " + response);
2860 return response;
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
2863 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002864 }
2865
2866 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002867 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2869 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002870
Malcolm Chenaabec062018-02-28 15:00:40 -08002871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2874 if (channel < 0) {
2875 return false;
2876 }
2877 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2878 if (DBG) log("iccCloseLogicalChannel: " + success);
2879 return success;
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002882 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002883 }
2884
2885 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002886 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002887 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2889 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002890
Malcolm Chenaabec062018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 if (DBG) {
2894 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2895 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2896 + p3 + " data=" + data);
2897 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002898
Malcolm Chenaabec062018-02-28 15:00:40 -08002899 if (channel < 0) {
2900 return "";
2901 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002902
Malcolm Chenaabec062018-02-28 15:00:40 -08002903 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2904 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2905 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002906
Malcolm Chenaabec062018-02-28 15:00:40 -08002907 // Append the returned status code to the end of the response payload.
2908 String s = Integer.toHexString(
2909 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2910 if (response.payload != null) {
2911 s = IccUtils.bytesToHexString(response.payload) + s;
2912 }
2913 return s;
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002916 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002917 }
Jake Hambye994d462014-02-03 13:10:13 -08002918
Evan Charltonc66da362014-05-16 14:06:40 -07002919 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002920 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2921 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2923 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002924 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002925
Malcolm Chenaabec062018-02-28 15:00:40 -08002926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2929 && TextUtils.equals(ISDR_AID, data)) {
2930 // Only allows LPA to select ISD-R.
2931 ComponentInfo bestComponent =
2932 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2933 if (bestComponent == null
2934 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2935 loge("The calling package is not allowed to select ISD-R.");
2936 throw new SecurityException(
2937 "The calling package is not allowed to select ISD-R.");
2938 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002939 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002940
Malcolm Chenaabec062018-02-28 15:00:40 -08002941 if (DBG) {
2942 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2943 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2944 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002945
Malcolm Chenaabec062018-02-28 15:00:40 -08002946 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2947 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2948 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002949
Malcolm Chenaabec062018-02-28 15:00:40 -08002950 // Append the returned status code to the end of the response payload.
2951 String s = Integer.toHexString(
2952 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2953 if (response.payload != null) {
2954 s = IccUtils.bytesToHexString(response.payload) + s;
2955 }
2956 return s;
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002959 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002960 }
2961
2962 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002963 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002964 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2966 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002967
Malcolm Chenaabec062018-02-28 15:00:40 -08002968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 if (DBG) {
2971 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2972 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2973 }
2974
2975 IccIoResult response =
2976 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2977 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2978 subId);
2979
2980 if (DBG) {
2981 log("Exchange SIM_IO [R]" + response);
2982 }
2983
2984 byte[] result = null;
2985 int length = 2;
2986 if (response.payload != null) {
2987 length = 2 + response.payload.length;
2988 result = new byte[length];
2989 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2990 } else {
2991 result = new byte[length];
2992 }
2993
2994 result[length - 1] = (byte) response.sw2;
2995 result[length - 2] = (byte) response.sw1;
2996 return result;
2997 } finally {
2998 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002999 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003000 }
3001
Nathan Haroldb3014052017-01-25 15:57:32 -08003002 /**
3003 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3004 * on a particular subscription
3005 */
sqianb6e41952018-03-12 14:54:01 -07003006 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3008 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3009 return null;
3010 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003011 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
3012 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3013 return null;
3014 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003015
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3019 if (response instanceof String[]) {
3020 return (String[]) response;
3021 }
3022 // Response is an Exception of some kind,
3023 // which is signalled to the user as a NULL retval
3024 return null;
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003027 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003028 }
3029
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003030 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003031 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3033 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003034
Malcolm Chenaabec062018-02-28 15:00:40 -08003035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3038 if (response.payload == null) {
3039 return "";
3040 }
Evan Charltonc66da362014-05-16 14:06:40 -07003041
Malcolm Chenaabec062018-02-28 15:00:40 -08003042 // Append the returned status code to the end of the response payload.
3043 String s = Integer.toHexString(
3044 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3045 s = IccUtils.bytesToHexString(response.payload) + s;
3046 return s;
3047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
Evan Charltonc66da362014-05-16 14:06:40 -07003050 }
3051
Jake Hambye994d462014-02-03 13:10:13 -08003052 /**
3053 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3054 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3055 *
3056 * @param itemID the ID of the item to read
3057 * @return the NV item as a String, or null on error.
3058 */
3059 @Override
3060 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003061 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3063 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003064
3065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003068 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003069 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3070 return value;
3071 } finally {
3072 Binder.restoreCallingIdentity(identity);
3073 }
Jake Hambye994d462014-02-03 13:10:13 -08003074 }
3075
3076 /**
3077 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3078 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3079 *
3080 * @param itemID the ID of the item to read
3081 * @param itemValue the value to write, as a String
3082 * @return true on success; false on any failure
3083 */
3084 @Override
3085 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003086 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3088 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003089
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3093 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003094 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08003095 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3096 return success;
3097 } finally {
3098 Binder.restoreCallingIdentity(identity);
3099 }
Jake Hambye994d462014-02-03 13:10:13 -08003100 }
3101
3102 /**
3103 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3104 * Used for device configuration by some CDMA operators.
3105 *
3106 * @param preferredRoamingList byte array containing the new PRL
3107 * @return true on success; false on any failure
3108 */
3109 @Override
3110 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3112 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003113
3114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3117 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3118 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3119 return success;
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
Jake Hambye994d462014-02-03 13:10:13 -08003123 }
3124
3125 /**
3126 * Perform the specified type of NV config reset.
3127 * Used for device configuration by some CDMA operators.
3128 *
3129 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3130 * @return true on success; false on any failure
3131 */
3132 @Override
3133 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3135 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003136
3137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 if (DBG) log("nvResetConfig: type " + resetType);
3140 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3141 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3142 return success;
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
Jake Hambye994d462014-02-03 13:10:13 -08003146 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003147
Svet Ganovb320e182015-04-16 12:30:10 -07003148 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003150 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003151 return new String[0];
3152 }
3153
Malcolm Chenaabec062018-02-28 15:00:40 -08003154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 return mPhone.getPcscfAddress(apnType);
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
Wink Saville36469e72014-06-11 15:17:00 -07003160 }
3161
Brad Ebinger51f743a2017-01-23 13:50:20 -08003162 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003163 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3164 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003165 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003166 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003167 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003168
3169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 PhoneFactory.getImsResolver().enableIms(slotId);
3172 } finally {
3173 Binder.restoreCallingIdentity(identity);
3174 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003175 }
3176
3177 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003178 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3179 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003180 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003181 public void disableIms(int slotId) {
3182 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003183
3184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 PhoneFactory.getImsResolver().disableIms(slotId);
3187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003190 }
3191
3192 /**
3193 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3194 * feature or {@link null} if the service is not available. If the feature is available, the
3195 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3196 */
3197 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003198 IImsServiceFeatureCallback callback) {
3199 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003200
3201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003207 }
3208
3209 /**
3210 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3211 * feature during emergency calling or {@link null} if the service is not available. If the
3212 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3213 * listener for feature updates.
3214 */
3215 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3216 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003217
3218 final long identity = Binder.clearCallingIdentity();
3219 try {
3220 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3221 } finally {
3222 Binder.restoreCallingIdentity(identity);
3223 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003224 }
3225
Brad Ebinger5f64b052017-12-14 14:26:15 -08003226 /**
3227 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3228 * specified.
3229 */
3230 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3231 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003232
3233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003239 }
3240
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003241 /**
3242 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3243 * specified.
3244 */
3245 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3246 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003247
3248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003254 }
3255
Brad Ebinger884c07b2018-02-15 16:17:40 -08003256 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003257 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3258 * available, false if the IMS resolver is idle.
3259 */
3260 public boolean isResolvingImsBinding() {
3261 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003262
3263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 return PhoneFactory.getImsResolver().isResolvingBinding();
3266 } finally {
3267 Binder.restoreCallingIdentity(identity);
3268 }
Brad Ebinger67801702018-03-02 13:43:36 -08003269 }
3270
Brad Ebingerdac2f002018-04-03 15:17:52 -07003271 /**
3272 * Sets the ImsService Package Name that Telephony will bind to.
3273 *
3274 * @param slotId the slot ID that the ImsService should bind for.
3275 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3276 * ImsService is the device default ImsService.
3277 * @param packageName The package name of the application that contains the ImsService to bind
3278 * to.
3279 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3280 * @hide
3281 */
3282 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003283 int[] subIds = SubscriptionManager.getSubId(slotId);
3284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3285 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3286 "setImsService");
3287
Malcolm Chenaabec062018-02-28 15:00:40 -08003288 final long identity = Binder.clearCallingIdentity();
3289 try {
3290 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3291 isCarrierImsService, packageName);
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003295 }
3296
3297 /**
3298 * Return the ImsService configuration.
3299 *
3300 * @param slotId The slot that the ImsService is associated with.
3301 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3302 * the device default.
3303 * @return the package name of the ImsService configuration.
3304 */
3305 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003306 int[] subIds = SubscriptionManager.getSubId(slotId);
3307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3308 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3309 "getImsService");
3310
Malcolm Chenaabec062018-02-28 15:00:40 -08003311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3314 isCarrierImsService);
3315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003318 }
3319
Wink Saville36469e72014-06-11 15:17:00 -07003320 public void setImsRegistrationState(boolean registered) {
3321 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003322
3323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 mPhone.setImsRegistrationState(registered);
3326 } finally {
3327 Binder.restoreCallingIdentity(identity);
3328 }
Wink Saville36469e72014-06-11 15:17:00 -07003329 }
3330
3331 /**
Stuart Scott54788802015-03-30 13:18:01 -07003332 * Set the network selection mode to automatic.
3333 *
3334 */
3335 @Override
3336 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3338 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003339
3340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3343 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
3346 }
Stuart Scott54788802015-03-30 13:18:01 -07003347 }
3348
3349 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003350 * Set the network selection mode to manual with the selected carrier.
3351 */
3352 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003353 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003354 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3356 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaabec062018-02-28 15:00:40 -08003357
3358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003361 /* operatorAlphaLong */ "",
3362 /* operatorAlphaShort */ "",
Malcolm Chenaabec062018-02-28 15:00:40 -08003363 operatorNumeric);
3364 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3365 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3366 persistSelection);
3367 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003371 }
3372
3373 /**
3374 * Scans for available networks.
3375 */
3376 @Override
3377 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3379 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003380
Pengquan Meng0c05b502018-09-06 09:59:22 -07003381 long identity = Binder.clearCallingIdentity();
Malcolm Chenaabec062018-02-28 15:00:40 -08003382 try {
3383 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003384 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaabec062018-02-28 15:00:40 -08003385 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08003386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003389 }
3390
3391 /**
yinxub1bed742017-04-17 11:45:04 -07003392 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003393 *
yinxub1bed742017-04-17 11:45:04 -07003394 * @param subId id of the subscription
3395 * @param request contains the radio access networks with bands/channels to scan
3396 * @param messenger callback messenger for scan results or errors
3397 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003398 * @return the id of the requested scan which can be used to stop the scan.
3399 */
3400 @Override
3401 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3402 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3404 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003405
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 return mNetworkScanRequestTracker.startNetworkScan(
3409 request, messenger, binder, getPhone(subId));
3410 } finally {
3411 Binder.restoreCallingIdentity(identity);
3412 }
yinxu504e1392017-04-12 16:03:22 -07003413 }
3414
3415 /**
3416 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003417 *
3418 * @param subId id of the subscription
3419 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003420 */
3421 @Override
3422 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3424 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003425
3426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
yinxu504e1392017-04-12 16:03:22 -07003432 }
3433
3434 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003435 * Get the calculated preferred network type.
3436 * Used for debugging incorrect network type.
3437 *
3438 * @return the preferred network type, defined in RILConstants.java.
3439 */
3440 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003441 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003443 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003444 return RILConstants.PREFERRED_NETWORK_MODE;
3445 }
3446
Malcolm Chenaabec062018-02-28 15:00:40 -08003447 final long identity = Binder.clearCallingIdentity();
3448 try {
3449 // FIXME: need to get SubId from somewhere.
3450 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
Junda Liu84d15a22014-07-02 11:21:04 -07003454 }
3455
3456 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003457 * Get the preferred network type.
3458 * Used for device configuration by some CDMA operators.
3459 *
3460 * @return the preferred network type, defined in RILConstants.java.
3461 */
3462 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003463 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3465 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003466
3467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 if (DBG) log("getPreferredNetworkType");
3470 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3471 int networkType = (result != null ? result[0] : -1);
3472 if (DBG) log("getPreferredNetworkType: " + networkType);
3473 return networkType;
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
3476 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003477 }
3478
3479 /**
3480 * Set the preferred network type.
3481 * Used for device configuration by some CDMA operators.
3482 *
3483 * @param networkType the preferred network type, defined in RILConstants.java.
3484 * @return true on success; false on any failure.
3485 */
3486 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003487 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3489 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003490
3491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3494 Boolean success = (Boolean) sendRequest(
3495 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3496 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3497 if (success) {
3498 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3499 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3500 }
3501 return success;
3502 } finally {
3503 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003504 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003505 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003506
3507 /**
Junda Liu475951f2014-11-07 16:45:03 -08003508 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3509 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3510 * tethering.
3511 *
3512 * @return 0: Not required. 1: required. 2: Not set.
3513 * @hide
3514 */
3515 @Override
3516 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003517 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003518
3519 final long identity = Binder.clearCallingIdentity();
3520 try {
3521 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3522 Settings.Global.TETHER_DUN_REQUIRED, 2);
3523 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3524 // config_tether_apndata.
3525 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3526 dunRequired = 1;
3527 }
3528 return dunRequired;
3529 } finally {
3530 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003531 }
Junda Liu475951f2014-11-07 16:45:03 -08003532 }
3533
3534 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003535 * Set mobile data enabled
3536 * Used by the user through settings etc to turn on/off mobile data
3537 *
3538 * @param enable {@code true} turn turn data on, else {@code false}
3539 */
3540 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003541 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3543 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003544
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 int phoneId = mSubscriptionController.getPhoneId(subId);
3548 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3549 Phone phone = PhoneFactory.getPhone(phoneId);
3550 if (phone != null) {
3551 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3552 phone.setUserDataEnabled(enable);
3553 } else {
3554 loge("setUserDataEnabled: no phone for subId=" + subId);
3555 }
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003558 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003559 }
3560
3561 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003562 * Get the user enabled state of Mobile Data.
3563 *
3564 * TODO: remove and use isUserDataEnabled.
3565 * This can't be removed now because some vendor codes
3566 * calls through ITelephony directly while they should
3567 * use TelephonyManager.
3568 *
3569 * @return true on enabled
3570 */
3571 @Override
3572 public boolean getDataEnabled(int subId) {
3573 return isUserDataEnabled(subId);
3574 }
3575
3576 /**
3577 * Get whether mobile data is enabled per user setting.
3578 *
3579 * There are other factors deciding whether mobile data is actually enabled, but they are
3580 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003581 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003582 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003583 *
3584 * @return {@code true} if data is enabled else {@code false}
3585 */
3586 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003587 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003588 try {
3589 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3590 null);
3591 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3593 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003594 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 int phoneId = mSubscriptionController.getPhoneId(subId);
3599 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3600 Phone phone = PhoneFactory.getPhone(phoneId);
3601 if (phone != null) {
3602 boolean retVal = phone.isUserDataEnabled();
3603 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3604 return retVal;
3605 } else {
3606 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3607 return false;
3608 }
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003611 }
3612 }
3613
3614 /**
3615 * Get whether mobile data is enabled.
3616 *
3617 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3618 * whether mobile data is actually enabled.
3619 *
3620 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3621 *
3622 * @return {@code true} if data is enabled else {@code false}
3623 */
3624 @Override
3625 public boolean isDataEnabled(int subId) {
3626 try {
3627 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3628 null);
3629 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3631 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003632 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003633
3634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 int phoneId = mSubscriptionController.getPhoneId(subId);
3637 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3638 Phone phone = PhoneFactory.getPhone(phoneId);
3639 if (phone != null) {
3640 boolean retVal = phone.isDataEnabled();
3641 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3642 return retVal;
3643 } else {
3644 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3645 return false;
3646 }
3647 } finally {
3648 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003649 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003650 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003651
3652 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003653 public int getCarrierPrivilegeStatus(int subId) {
3654 final Phone phone = getPhone(subId);
3655 if (phone == null) {
3656 loge("getCarrierPrivilegeStatus: Invalid subId");
3657 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3658 }
3659 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003660 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003661 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003662 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3663 }
3664 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003665 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003666 }
Junda Liu29340342014-07-10 15:23:27 -07003667
3668 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003669 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3670 final Phone phone = getPhone(subId);
3671 if (phone == null) {
3672 loge("getCarrierPrivilegeStatus: Invalid subId");
3673 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3674 }
3675 UiccProfile profile =
3676 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3677 if (profile == null) {
3678 loge("getCarrierPrivilegeStatus: No UICC");
3679 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3680 }
3681 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3682 }
3683
3684 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003685 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003686 if (TextUtils.isEmpty(pkgName))
3687 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003688 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003689 if (card == null) {
3690 loge("checkCarrierPrivilegesForPackage: No UICC");
3691 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3692 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003693 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3694 }
3695
3696 @Override
3697 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003698 if (TextUtils.isEmpty(pkgName))
3699 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003700 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3701 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3702 UiccCard card = UiccController.getInstance().getUiccCard(i);
3703 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003704 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003705 continue;
3706 }
3707
3708 result = card.getCarrierPrivilegeStatus(
3709 mPhone.getContext().getPackageManager(), pkgName);
3710 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3711 break;
3712 }
3713 }
3714
3715 return result;
Junda Liu29340342014-07-10 15:23:27 -07003716 }
Derek Tan89e89d42014-07-08 17:00:10 -07003717
3718 @Override
Junda Liue64de782015-04-16 17:19:16 -07003719 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3720 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3721 loge("phoneId " + phoneId + " is not valid.");
3722 return null;
3723 }
3724 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003725 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003726 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003727 return null ;
3728 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003729 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003730 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003731 }
3732
Amith Yamasani6e118872016-02-19 12:53:51 -08003733 @Override
3734 public List<String> getPackagesWithCarrierPrivileges() {
3735 PackageManager pm = mPhone.getContext().getPackageManager();
3736 List<String> privilegedPackages = new ArrayList<>();
3737 List<PackageInfo> packages = null;
3738 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3739 UiccCard card = UiccController.getInstance().getUiccCard(i);
3740 if (card == null) {
3741 // No UICC in that slot.
3742 continue;
3743 }
3744 if (card.hasCarrierPrivilegeRules()) {
3745 if (packages == null) {
3746 // Only check packages in user 0 for now
3747 packages = pm.getInstalledPackagesAsUser(
3748 PackageManager.MATCH_DISABLED_COMPONENTS
3749 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3750 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3751 }
3752 for (int p = packages.size() - 1; p >= 0; p--) {
3753 PackageInfo pkgInfo = packages.get(p);
3754 if (pkgInfo != null && pkgInfo.packageName != null
3755 && card.getCarrierPrivilegeStatus(pkgInfo)
3756 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3757 privilegedPackages.add(pkgInfo.packageName);
3758 }
3759 }
3760 }
3761 }
3762 return privilegedPackages;
3763 }
3764
Wink Savilleb564aae2014-10-23 10:18:09 -07003765 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003766 final Phone phone = getPhone(subId);
3767 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003768 if (card == null) {
3769 loge("getIccId: No UICC");
3770 return null;
3771 }
3772 String iccId = card.getIccId();
3773 if (TextUtils.isEmpty(iccId)) {
3774 loge("getIccId: ICC ID is null or empty.");
3775 return null;
3776 }
3777 return iccId;
3778 }
3779
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003780 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003781 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3782 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3784 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003785
Malcolm Chenaabec062018-02-28 15:00:40 -08003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 final String iccId = getIccId(subId);
3789 final Phone phone = getPhone(subId);
3790 if (phone == null) {
3791 return false;
3792 }
3793 final String subscriberId = phone.getSubscriberId();
3794
3795 if (DBG_MERGE) {
3796 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3797 + subscriberId + " to " + number);
3798 }
3799
3800 if (TextUtils.isEmpty(iccId)) {
3801 return false;
3802 }
3803
3804 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3805
3806 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3807 if (alphaTag == null) {
3808 editor.remove(alphaTagPrefKey);
3809 } else {
3810 editor.putString(alphaTagPrefKey, alphaTag);
3811 }
3812
3813 // Record both the line number and IMSI for this ICCID, since we need to
3814 // track all merged IMSIs based on line number
3815 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3816 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3817 if (number == null) {
3818 editor.remove(numberPrefKey);
3819 editor.remove(subscriberPrefKey);
3820 } else {
3821 editor.putString(numberPrefKey, number);
3822 editor.putString(subscriberPrefKey, subscriberId);
3823 }
3824
3825 editor.commit();
3826 return true;
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003829 }
Derek Tan7226c842014-07-02 17:42:23 -07003830 }
3831
3832 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003833 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003834 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003836 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003837 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003838 return null;
3839 }
Derek Tan97ebb422014-09-05 16:55:38 -07003840
Malcolm Chenaabec062018-02-28 15:00:40 -08003841 final long identity = Binder.clearCallingIdentity();
3842 try {
3843 String iccId = getIccId(subId);
3844 if (iccId != null) {
3845 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3846 if (DBG_MERGE) {
3847 log("getLine1NumberForDisplay returning "
3848 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3849 }
3850 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003851 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003852 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3853 return null;
3854 } finally {
3855 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003856 }
Derek Tan7226c842014-07-02 17:42:23 -07003857 }
3858
3859 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003860 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003862 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003863 return null;
3864 }
Derek Tan97ebb422014-09-05 16:55:38 -07003865
Malcolm Chenaabec062018-02-28 15:00:40 -08003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 String iccId = getIccId(subId);
3869 if (iccId != null) {
3870 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3871 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3872 }
3873 return null;
3874 } finally {
3875 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003876 }
Derek Tan7226c842014-07-02 17:42:23 -07003877 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003878
3879 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003880 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003881 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3882 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003884 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3885 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003886 return null;
3887 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003888
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003889 final long identity = Binder.clearCallingIdentity();
3890 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003891 final Context context = mPhone.getContext();
3892 final TelephonyManager tele = TelephonyManager.from(context);
3893 final SubscriptionManager sub = SubscriptionManager.from(context);
3894
3895 // Figure out what subscribers are currently active
3896 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3897 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3898 // the process, where TelephonyManager was instantiated.
3899 // Otherwise AppOps check will fail.
3900
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003901 final int[] subIds = sub.getActiveSubscriptionIdList();
3902 for (int subId : subIds) {
3903 activeSubscriberIds.add(tele.getSubscriberId(subId));
3904 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003905
3906 // First pass, find a number override for an active subscriber
3907 String mergeNumber = null;
3908 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3909 for (String key : prefs.keySet()) {
3910 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3911 final String subscriberId = (String) prefs.get(key);
3912 if (activeSubscriberIds.contains(subscriberId)) {
3913 final String iccId = key.substring(
3914 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3915 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3916 mergeNumber = (String) prefs.get(numberKey);
3917 if (DBG_MERGE) {
3918 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3919 + " for active subscriber " + subscriberId);
3920 }
3921 if (!TextUtils.isEmpty(mergeNumber)) {
3922 break;
3923 }
3924 }
3925 }
3926 }
3927
3928 // Shortcut when no active merged subscribers
3929 if (TextUtils.isEmpty(mergeNumber)) {
3930 return null;
3931 }
3932
3933 // Second pass, find all subscribers under that line override
3934 final ArraySet<String> result = new ArraySet<>();
3935 for (String key : prefs.keySet()) {
3936 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3937 final String number = (String) prefs.get(key);
3938 if (mergeNumber.equals(number)) {
3939 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3940 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3941 final String subscriberId = (String) prefs.get(subscriberKey);
3942 if (!TextUtils.isEmpty(subscriberId)) {
3943 result.add(subscriberId);
3944 }
3945 }
3946 }
3947 }
3948
3949 final String[] resultArray = result.toArray(new String[result.size()]);
3950 Arrays.sort(resultArray);
3951 if (DBG_MERGE) {
3952 Slog.d(LOG_TAG,
3953 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3954 }
3955 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003956 } finally {
3957 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003958 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003959 }
3960
3961 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003962 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003963 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3964 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003965
3966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 final Phone phone = getPhone(subId);
3969 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3970 } finally {
3971 Binder.restoreCallingIdentity(identity);
3972 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003973 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003974
3975 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003976 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003977 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3978 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003979 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003980
3981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 final Phone phone = getPhone(subId);
3984 if (phone == null) {
3985 return false;
3986 }
3987 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3988 cdmaNonRoamingList);
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003991 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003992 }
3993
3994 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003995 @Deprecated
3996 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3997 enforceModifyPermission();
3998
3999 int returnValue = 0;
4000 try {
vagdevie435a3e2018-08-15 16:01:53 -07004001 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004002 if(result.exception == null) {
4003 if (result.result != null) {
4004 byte[] responseData = (byte[])(result.result);
4005 if(responseData.length > oemResp.length) {
4006 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4007 responseData.length + "bytes. Buffer Size is " +
4008 oemResp.length + "bytes.");
4009 }
4010 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4011 returnValue = responseData.length;
4012 }
4013 } else {
4014 CommandException ex = (CommandException) result.exception;
4015 returnValue = ex.getCommandError().ordinal();
4016 if(returnValue > 0) returnValue *= -1;
4017 }
4018 } catch (RuntimeException e) {
4019 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4020 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4021 if(returnValue > 0) returnValue *= -1;
4022 }
4023
4024 return returnValue;
4025 }
4026
4027 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004028 public void setRadioCapability(RadioAccessFamily[] rafs) {
4029 try {
4030 ProxyController.getInstance().setRadioCapability(rafs);
4031 } catch (RuntimeException e) {
4032 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4033 }
4034 }
4035
4036 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004037 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004038 Phone phone = PhoneFactory.getPhone(phoneId);
4039 if (phone == null) {
4040 return RadioAccessFamily.RAF_UNKNOWN;
4041 }
4042 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004043 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004044 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004045 return RadioAccessFamily.RAF_UNKNOWN;
4046 }
4047
Malcolm Chenaabec062018-02-28 15:00:40 -08004048 final long identity = Binder.clearCallingIdentity();
4049 try {
4050 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4051 } finally {
4052 Binder.restoreCallingIdentity(identity);
4053 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004054 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004055
4056 @Override
4057 public void enableVideoCalling(boolean enable) {
4058 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004059
4060 final long identity = Binder.clearCallingIdentity();
4061 try {
4062 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4063 } finally {
4064 Binder.restoreCallingIdentity(identity);
4065 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004066 }
4067
4068 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004069 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4071 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4072 return false;
4073 }
Svet Ganovb320e182015-04-16 12:30:10 -07004074
Malcolm Chenaabec062018-02-28 15:00:40 -08004075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 // Check the user preference and the system-level IMS setting. Even if the user has
4078 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4079 // In the long run, we may instead need to check if there exists a connection service
4080 // which can support video calling.
4081 ImsManager imsManager =
4082 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4083 return imsManager.isVtEnabledByPlatform()
4084 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4085 && imsManager.isVtEnabledByUser();
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004089 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004090
Andrew Leea1239f22015-03-02 17:44:07 -08004091 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004092 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4094 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4095 return false;
4096 }
4097
4098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 CarrierConfigManager configManager =
4101 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4102 return configManager.getConfigForSubId(mPhone.getSubId())
4103 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
Andrew Leea1239f22015-03-02 17:44:07 -08004107 }
4108
4109 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004110 public boolean isWorldPhone(int subId, String callingPackage) {
4111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4112 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4113 return false;
4114 }
4115
4116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 CarrierConfigManager configManager =
4119 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4120 return configManager.getConfigForSubId(mPhone.getSubId())
4121 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
Andrew Leea1239f22015-03-02 17:44:07 -08004125 }
4126
Andrew Lee9431b832015-03-09 18:46:45 -07004127 @Override
4128 public boolean isTtyModeSupported() {
4129 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004130 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004131 }
4132
4133 @Override
4134 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
Andrew Lee9431b832015-03-09 18:46:45 -07004141 }
4142
Hall Liu98187582018-01-22 19:15:32 -08004143 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4147 mPhone.getSubId()).getBoolean(
4148 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4149 boolean isDeviceSupported =
4150 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4151 return isCarrierSupported && isDeviceSupported;
4152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
Hall Liu98187582018-01-22 19:15:32 -08004155 }
4156
Hall Liu3ad5f012018-04-06 16:23:39 -07004157 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004158 final long identity = Binder.clearCallingIdentity();
4159 try {
4160 return isRttSupported() && Settings.Secure.getInt(
4161 mPhone.getContext().getContentResolver(),
4162 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004166 }
4167
Sanket Padawe7310cc72015-01-14 09:53:20 -08004168 /**
4169 * Returns the unique device ID of phone, for example, the IMEI for
4170 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4171 *
4172 * <p>Requires Permission:
4173 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4174 */
4175 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004176 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004177 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004178 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004179 return null;
4180 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004181 int subId = phone.getSubId();
4182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4183 mApp, subId, callingPackage, "getDeviceId")) {
4184 return null;
4185 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004186
4187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 return phone.getDeviceId();
4190 } finally {
4191 Binder.restoreCallingIdentity(identity);
4192 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004193 }
4194
Ping Sunc67b7c22016-03-02 19:16:45 +08004195 /**
4196 * {@hide}
4197 * Returns the IMS Registration Status on a particular subid
4198 *
4199 * @param subId
4200 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004201 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004202 Phone phone = getPhone(subId);
4203 if (phone != null) {
4204 return phone.isImsRegistered();
4205 } else {
4206 return false;
4207 }
4208 }
4209
Santos Cordon7a1885b2015-02-03 11:15:19 -08004210 @Override
4211 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4215 } finally {
4216 Binder.restoreCallingIdentity(identity);
4217 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004218 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004219
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004220 /**
4221 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004222 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004223 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004224 final long identity = Binder.clearCallingIdentity();
4225 try {
4226 Phone phone = getPhone(subId);
4227 if (phone != null) {
4228 return phone.isWifiCallingEnabled();
4229 } else {
4230 return false;
4231 }
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004234 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004235 }
4236
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004237 /**
4238 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004239 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004240 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004241 final long identity = Binder.clearCallingIdentity();
4242 try {
4243 Phone phone = getPhone(subId);
4244 if (phone != null) {
4245 return phone.isVolteEnabled();
4246 } else {
4247 return false;
4248 }
4249 } finally {
4250 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004251 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004252 }
Svet Ganovb320e182015-04-16 12:30:10 -07004253
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004254 /**
4255 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004256 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004257 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004258 final long identity = Binder.clearCallingIdentity();
4259 try {
4260 Phone phone = getPhone(subId);
4261 if (phone != null) {
4262 return phone.isVideoEnabled();
4263 } else {
4264 return false;
4265 }
4266 } finally {
4267 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004268 }
4269 }
4270
4271 /**
4272 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4273 * defined in {@link ImsRegistrationImplBase}.
4274 */
4275 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 Phone phone = getPhone(subId);
4279 if (phone != null) {
4280 return phone.getImsRegistrationTech();
4281 } else {
4282 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4283 }
4284 } finally {
4285 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004286 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004287 }
4288
Stuart Scott8eef64f2015-04-08 15:13:54 -07004289 @Override
4290 public void factoryReset(int subId) {
4291 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004292 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4293 return;
4294 }
4295
Svet Ganovcc087f82015-05-12 20:35:54 -07004296 final long identity = Binder.clearCallingIdentity();
4297 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004298 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4299 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004300 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004301 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004302 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4303 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004304 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004305 }
4306 } finally {
4307 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004308 }
4309 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004310
4311 @Override
4312 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 // We query all subscriptions instead of just the active ones, because
4316 // this might be called early on in the provisioning flow when the
4317 // subscriptions potentially aren't active yet.
4318 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4319 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004320 return null;
4321 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004322
Malcolm Chenaabec062018-02-28 15:00:40 -08004323 // This function may be called very early, say, from the setup wizard, at
4324 // which point we won't have a default subscription set. If that's the case
4325 // we just choose the first, which will be valid in "most cases".
4326 final int defaultSubId = getDefaultSubscription();
4327 SubscriptionInfo info = null;
4328 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4329 info = slist.get(0);
4330 } else {
4331 for (SubscriptionInfo item : slist) {
4332 if (item.getSubscriptionId() == defaultSubId) {
4333 info = item;
4334 break;
4335 }
4336 }
4337
4338 if (info == null) {
4339 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004340 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004341 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004342
Malcolm Chenaabec062018-02-28 15:00:40 -08004343 // Try and fetch the locale from the carrier properties or from the SIM language
4344 // preferences (EF-PL and EF-LI)...
4345 final int mcc = info.getMcc();
4346 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4347 String simLanguage = null;
4348 if (defaultPhone != null) {
4349 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4350 if (localeFromDefaultSim != null) {
4351 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4352 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4353 return localeFromDefaultSim.toLanguageTag();
4354 } else {
4355 simLanguage = localeFromDefaultSim.getLanguage();
4356 }
4357 }
4358 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004359
Malcolm Chenaabec062018-02-28 15:00:40 -08004360 // The SIM language preferences only store a language (e.g. fr = French), not an
4361 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4362 // the SIM and carrier preferences does not include a country we add the country
4363 // determined from the SIM MCC to provide an exact locale.
4364 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4365 simLanguage);
4366 if (mccLocale != null) {
4367 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4368 return mccLocale.toLanguageTag();
4369 }
4370
4371 if (DBG) log("No locale found - returning null");
4372 return null;
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004376 }
4377
4378 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004379 return mSubscriptionController.getAllSubInfoList(
4380 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004381 }
4382
Malcolm Chenaabec062018-02-28 15:00:40 -08004383 /**
4384 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4385 */
4386 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4387 return mSubscriptionController.getActiveSubscriptionInfoList(
4388 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004389 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004390
Chenjie Yu1ba97252018-01-11 18:16:20 -08004391 private final ModemActivityInfo mLastModemActivityInfo =
4392 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4393
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004394 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004395 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4396 * representing the state of the modem.
4397 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004398 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4399 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004400 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004401 */
4402 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004403 public void requestModemActivityInfo(ResultReceiver result) {
4404 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004405 ModemActivityInfo ret = null;
vagdevie435a3e2018-08-15 16:01:53 -07004406 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Adam Lesinski903a54c2016-04-11 14:49:52 -07004407
Malcolm Chenaabec062018-02-28 15:00:40 -08004408 final long identity = Binder.clearCallingIdentity();
4409 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004410 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004411 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4412 CMD_GET_MODEM_ACTIVITY_INFO,
4413 null, workSource);
Siddharth Rayc339f892018-06-17 15:02:38 -07004414 if (isModemActivityInfoValid(info)) {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004415 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4416 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4417 mergedTxTimeMs[i] =
4418 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4419 }
4420 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4421 mLastModemActivityInfo.setSleepTimeMillis(
4422 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4423 mLastModemActivityInfo.setIdleTimeMillis(
4424 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4425 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4426 mLastModemActivityInfo.setRxTimeMillis(
4427 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4428 mLastModemActivityInfo.setEnergyUsed(
4429 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004430 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004431 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4432 mLastModemActivityInfo.getSleepTimeMillis(),
4433 mLastModemActivityInfo.getIdleTimeMillis(),
4434 mLastModemActivityInfo.getTxTimeMillis(),
4435 mLastModemActivityInfo.getRxTimeMillis(),
4436 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004437 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004438 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004439 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004440 result.send(0, bundle);
4441 } finally {
4442 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004443 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004444 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004445
Siddharth Rayc339f892018-06-17 15:02:38 -07004446 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4447 // less than total activity duration.
4448 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4449 if (info == null) {
4450 return false;
4451 }
4452 int activityDurationMs =
4453 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4454 int totalTxTimeMs = 0;
4455 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4456 totalTxTimeMs += info.getTxTimeMillis()[i];
4457 }
4458 return (info.isValid()
4459 && (info.getSleepTimeMillis() <= activityDurationMs)
4460 && (info.getIdleTimeMillis() <= activityDurationMs)
4461 && (info.getRxTimeMillis() <= activityDurationMs)
4462 && (totalTxTimeMs <= activityDurationMs));
4463 }
4464
Jack Yu85bd38a2015-11-09 11:34:32 -08004465 /**
4466 * {@hide}
4467 * Returns the service state information on specified subscription.
4468 */
4469 @Override
4470 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004472 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004473 return null;
4474 }
4475
Malcolm Chenaabec062018-02-28 15:00:40 -08004476 final long identity = Binder.clearCallingIdentity();
4477 try {
4478 final Phone phone = getPhone(subId);
4479 if (phone == null) {
4480 return null;
4481 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004482
Malcolm Chenaabec062018-02-28 15:00:40 -08004483 return phone.getServiceState();
4484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004487 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004488
4489 /**
4490 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4491 *
4492 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4493 * voicemail ringtone.
4494 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4495 * PhoneAccount.
4496 */
4497 @Override
4498 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004499 final long identity = Binder.clearCallingIdentity();
4500 try {
4501 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4502 if (phone == null) {
4503 phone = mPhone;
4504 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004505
Malcolm Chenaabec062018-02-28 15:00:40 -08004506 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4507 } finally {
4508 Binder.restoreCallingIdentity(identity);
4509 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004510 }
4511
4512 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004513 * Sets the per-account voicemail ringtone.
4514 *
4515 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4516 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4517 *
4518 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4519 * voicemail ringtone.
4520 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4521 * PhoneAccount.
4522 */
4523 @Override
4524 public void setVoicemailRingtoneUri(String callingPackage,
4525 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4526 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4527 if (!TextUtils.equals(callingPackage,
4528 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4530 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4531 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004532 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004533
4534 final long identity = Binder.clearCallingIdentity();
4535 try {
4536 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4537 if (phone == null) {
4538 phone = mPhone;
4539 }
4540 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4541 } finally {
4542 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004543 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004544 }
4545
4546 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004547 * Returns whether vibration is set for voicemail notification in Phone settings.
4548 *
4549 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4550 * voicemail vibration setting.
4551 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4552 */
4553 @Override
4554 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004555 final long identity = Binder.clearCallingIdentity();
4556 try {
4557 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4558 if (phone == null) {
4559 phone = mPhone;
4560 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004561
Malcolm Chenaabec062018-02-28 15:00:40 -08004562 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004566 }
4567
Youhan Wange64578a2016-05-02 15:32:42 -07004568 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004569 * Sets the per-account voicemail vibration.
4570 *
4571 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4572 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4573 *
4574 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4575 * voicemail vibration setting.
4576 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4577 * specific PhoneAccount.
4578 */
4579 @Override
4580 public void setVoicemailVibrationEnabled(String callingPackage,
4581 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4583 if (!TextUtils.equals(callingPackage,
4584 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4586 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4587 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004588 }
4589
Malcolm Chenaabec062018-02-28 15:00:40 -08004590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4593 if (phone == null) {
4594 phone = mPhone;
4595 }
4596 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004599 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004600 }
4601
4602 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004603 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4604 *
4605 * @throws SecurityException if the caller does not have the required permission
4606 */
4607 private void enforceReadPrivilegedPermission() {
4608 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4609 null);
4610 }
4611
4612 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004613 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4614 * permission.
4615 *
4616 * @throws SecurityException if the caller does not have the required permission
4617 */
4618 private void enforceSendSmsPermission() {
4619 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4620 }
4621
4622 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004623 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004624 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004625 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004626 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004627 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 ComponentName componentName =
4631 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4632 if (componentName == null) {
4633 throw new SecurityException(
4634 "Caller not current active visual voicemail package[null]");
4635 }
4636 String vvmPackage = componentName.getPackageName();
4637 if (!callingPackage.equals(vvmPackage)) {
4638 throw new SecurityException("Caller not current active visual voicemail package["
4639 + vvmPackage + "]");
4640 }
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004643 }
4644 }
4645
4646 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004647 * Return the application ID for the app type.
4648 *
4649 * @param subId the subscription ID that this request applies to.
4650 * @param appType the uicc app type.
4651 * @return Application ID for specificied app type, or null if no uicc.
4652 */
4653 @Override
4654 public String getAidForAppType(int subId, int appType) {
4655 enforceReadPrivilegedPermission();
4656 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004657
4658 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004659 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004660 if (phone == null) {
4661 return null;
4662 }
4663 String aid = null;
4664 try {
4665 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4666 .getApplicationByType(appType).getAid();
4667 } catch (Exception e) {
4668 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4669 }
4670 return aid;
4671 } finally {
4672 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004673 }
Youhan Wange64578a2016-05-02 15:32:42 -07004674 }
4675
Youhan Wang4001d252016-05-11 10:29:41 -07004676 /**
4677 * Return the Electronic Serial Number.
4678 *
4679 * @param subId the subscription ID that this request applies to.
4680 * @return ESN or null if error.
4681 */
4682 @Override
4683 public String getEsn(int subId) {
4684 enforceReadPrivilegedPermission();
4685 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004686
4687 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004688 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004689 if (phone == null) {
4690 return null;
4691 }
4692 String esn = null;
4693 try {
4694 esn = phone.getEsn();
4695 } catch (Exception e) {
4696 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4697 }
4698 return esn;
4699 } finally {
4700 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004701 }
Youhan Wang4001d252016-05-11 10:29:41 -07004702 }
4703
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004704 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004705 * Return the Preferred Roaming List Version.
4706 *
4707 * @param subId the subscription ID that this request applies to.
4708 * @return PRLVersion or null if error.
4709 */
4710 @Override
4711 public String getCdmaPrlVersion(int subId) {
4712 enforceReadPrivilegedPermission();
4713 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004714
4715 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004716 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004717 if (phone == null) {
4718 return null;
4719 }
4720 String cdmaPrlVersion = null;
4721 try {
4722 cdmaPrlVersion = phone.getCdmaPrlVersion();
4723 } catch (Exception e) {
4724 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4725 }
4726 return cdmaPrlVersion;
4727 } finally {
4728 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004729 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004730 }
4731
4732 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004733 * Get snapshot of Telephony histograms
4734 * @return List of Telephony histograms
4735 * @hide
4736 */
4737 @Override
4738 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4740 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004741
4742 final long identity = Binder.clearCallingIdentity();
4743 try {
4744 return RIL.getTelephonyRILTimingHistograms();
4745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004748 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004749
4750 /**
4751 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004752 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004753 * Require system privileges. In the future we may add this to carrier APIs.
4754 *
4755 * @return The number of carriers set successfully, should match length of carriers
4756 */
4757 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004758 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004759 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004760 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004761
Meng Wang9b7c4e92017-02-17 11:41:27 -08004762 if (carriers == null) {
4763 throw new NullPointerException("carriers cannot be null");
4764 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004765
Malcolm Chenaabec062018-02-28 15:00:40 -08004766 final long identity = Binder.clearCallingIdentity();
4767 try {
4768 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004769 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4770 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004771 return retVal[0];
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
4774 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004775 }
4776
4777 /**
4778 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004779 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004780 * Require system privileges. In the future we may add this to carrier APIs.
4781 *
4782 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4783 * means all carriers are allowed.
4784 */
4785 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004786 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004787 enforceReadPrivilegedPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004788 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08004789
4790 final long identity = Binder.clearCallingIdentity();
4791 try {
4792 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07004793 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4794 workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08004795 } finally {
4796 Binder.restoreCallingIdentity(identity);
4797 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004798 }
4799
fionaxu59545b42016-05-25 15:53:37 -07004800 /**
4801 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4802 * @param subId the subscription ID that this action applies to.
4803 * @param enabled control enable or disable metered apns.
4804 * {@hide}
4805 */
4806 @Override
4807 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4808 enforceModifyPermission();
4809 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004810
4811 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004812 if (phone == null) {
4813 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4814 return;
4815 }
4816 try {
4817 phone.carrierActionSetMeteredApnsEnabled(enabled);
4818 } catch (Exception e) {
4819 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004820 } finally {
4821 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004822 }
4823 }
4824
4825 /**
4826 * Action set from carrier signalling broadcast receivers to enable/disable radio
4827 * @param subId the subscription ID that this action applies to.
4828 * @param enabled control enable or disable radio.
4829 * {@hide}
4830 */
4831 @Override
4832 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4833 enforceModifyPermission();
4834 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004835
4836 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004837 if (phone == null) {
4838 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4839 return;
4840 }
4841 try {
4842 phone.carrierActionSetRadioEnabled(enabled);
4843 } catch (Exception e) {
4844 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004845 } finally {
4846 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004847 }
4848 }
4849
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004850 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004851 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4852 * network status based on which carrier apps could apply actions accordingly,
4853 * enable/disable default url handler for example.
4854 *
4855 * @param subId the subscription ID that this action applies to.
4856 * @param report control start/stop reporting the default network status.
4857 * {@hide}
4858 */
4859 @Override
4860 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4861 enforceModifyPermission();
4862 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004863
4864 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004865 if (phone == null) {
4866 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4867 return;
4868 }
4869 try {
4870 phone.carrierActionReportDefaultNetworkStatus(report);
4871 } catch (Exception e) {
4872 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004873 } finally {
4874 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004875 }
4876 }
4877
4878 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004879 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4880 * bug report is being generated.
4881 */
4882 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004883 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004884 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4885 != PackageManager.PERMISSION_GRANTED) {
4886 writer.println("Permission Denial: can't dump Phone from pid="
4887 + Binder.getCallingPid()
4888 + ", uid=" + Binder.getCallingUid()
4889 + "without permission "
4890 + android.Manifest.permission.DUMP);
4891 return;
4892 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004893 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004894 }
Jack Yueb89b242016-06-22 13:27:47 -07004895
Brad Ebingerdac2f002018-04-03 15:17:52 -07004896 @Override
4897 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4898 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4899 throws RemoteException {
4900 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4901 }
4902
Jack Yueb89b242016-06-22 13:27:47 -07004903 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004904 * Get aggregated video call data usage since boot.
4905 *
4906 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4907 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004908 * {@hide}
4909 */
4910 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004911 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004912 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4913 null);
4914
Malcolm Chenaabec062018-02-28 15:00:40 -08004915 final long identity = Binder.clearCallingIdentity();
4916 try {
4917 // NetworkStatsService keeps tracking the active network interface and identity. It
4918 // records the delta with the corresponding network identity.
4919 // We just return the total video call data usage snapshot since boot.
4920 Phone phone = getPhone(subId);
4921 if (phone != null) {
4922 return phone.getVtDataUsage(perUidStats);
4923 }
4924 return null;
4925 } finally {
4926 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004927 }
Jack Yueb89b242016-06-22 13:27:47 -07004928 }
Jack Yu75ab2952016-07-08 14:29:33 -07004929
4930 /**
4931 * Policy control of data connection. Usually used when data limit is passed.
4932 * @param enabled True if enabling the data, otherwise disabling.
4933 * @param subId Subscription index
4934 * {@hide}
4935 */
4936 @Override
4937 public void setPolicyDataEnabled(boolean enabled, int subId) {
4938 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004939
4940 final long identity = Binder.clearCallingIdentity();
4941 try {
4942 Phone phone = getPhone(subId);
4943 if (phone != null) {
4944 phone.setPolicyDataEnabled(enabled);
4945 }
4946 } finally {
4947 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004948 }
4949 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004950
4951 /**
4952 * Get Client request stats
4953 * @return List of Client Request Stats
4954 * @hide
4955 */
4956 @Override
4957 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004959 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004960 return null;
4961 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004962 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004963
Malcolm Chenaabec062018-02-28 15:00:40 -08004964 final long identity = Binder.clearCallingIdentity();
4965 try {
4966 if (phone != null) {
4967 return phone.getClientRequestStats();
4968 }
4969
4970 return null;
4971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004974 }
4975
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004976 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004977 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004978 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004979 }
Jack Yueb4124c2017-02-16 15:32:43 -08004980
4981 /**
Grace Chen70990072017-03-24 17:21:30 -07004982 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004983 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004984 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004985 * @param state State of SIM (power down, power up, pass through)
4986 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4987 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4988 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004989 *
4990 **/
4991 @Override
Grace Chen70990072017-03-24 17:21:30 -07004992 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004993 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004994 Phone phone = PhoneFactory.getPhone(slotIndex);
4995
vagdevie435a3e2018-08-15 16:01:53 -07004996 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4997
Malcolm Chenaabec062018-02-28 15:00:40 -08004998 final long identity = Binder.clearCallingIdentity();
4999 try {
5000 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005001 phone.setSimPowerState(state, workSource);
Malcolm Chenaabec062018-02-28 15:00:40 -08005002 }
5003 } finally {
5004 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005005 }
5006 }
Shuo Qiandd210312017-04-12 22:11:33 +00005007
Tyler Gunn65d45c22017-06-05 11:22:26 -07005008 private boolean isUssdApiAllowed(int subId) {
5009 CarrierConfigManager configManager =
5010 (CarrierConfigManager) mPhone.getContext().getSystemService(
5011 Context.CARRIER_CONFIG_SERVICE);
5012 if (configManager == null) {
5013 return false;
5014 }
5015 PersistableBundle pb = configManager.getConfigForSubId(subId);
5016 if (pb == null) {
5017 return false;
5018 }
5019 return pb.getBoolean(
5020 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5021 }
5022
Shuo Qiandd210312017-04-12 22:11:33 +00005023 /**
5024 * Check if phone is in emergency callback mode
5025 * @return true if phone is in emergency callback mode
5026 * @param subId sub id
5027 */
goneil9c5f4872017-12-05 14:07:56 -08005028 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005029 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08005030 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00005031 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08005032
5033 final long identity = Binder.clearCallingIdentity();
5034 try {
5035 if (phone != null) {
5036 return phone.isInEcm();
5037 } else {
5038 return false;
5039 }
5040 } finally {
5041 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005042 }
5043 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005044
5045 /**
5046 * Get the current signal strength information for the given subscription.
5047 * Because this information is not updated when the device is in a low power state
5048 * it should not be relied-upon to be current.
5049 * @param subId Subscription index
5050 * @return the most recent cached signal strength info from the modem
5051 */
5052 @Override
5053 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
5056 Phone p = getPhone(subId);
5057 if (p == null) {
5058 return null;
5059 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005060
Malcolm Chenaabec062018-02-28 15:00:40 -08005061 return p.getSignalStrength();
5062 } finally {
5063 Binder.restoreCallingIdentity(identity);
5064 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005065 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005066
Pengquan Meng9140aec2018-08-22 14:49:57 -07005067 /**
5068 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5069 *
5070 * <p>Requires one of the following permissions:
5071 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5072 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5073 * privileges.
5074 *
5075 * @param subId subscription id
5076 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5077 * {@code false}.
5078 */
5079 @Override
5080 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005081 boolean isEnabled = false;
5082 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005083 try {
5084 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005085 null /* message */);
5086 Phone phone = getPhone(subId);
5087 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005088 } catch (Exception e) {
5089 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5090 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005091 } finally {
5092 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005093 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005094 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005095 }
5096
5097
5098 /**
5099 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5100 *
5101 * <p> Requires permission:
5102 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5103 * privileges.
5104 *
5105 * @param subId subscription id
5106 * @param isEnabled {@code true} means enable, {@code false} means disable.
5107 */
5108 @Override
5109 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005110 final long identity = Binder.clearCallingIdentity();
5111 try {
5112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5113 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005114
Pengquan Meng0c05b502018-09-06 09:59:22 -07005115 Phone phone = getPhone(subId);
5116 if (phone != null) {
5117 phone.setDataRoamingEnabled(isEnabled);
5118 }
5119 } finally {
5120 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005121 }
5122 }
5123
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005124 @Override
5125 public UiccSlotInfo[] getUiccSlotsInfo() {
5126 enforceReadPrivilegedPermission();
5127
Malcolm Chenaabec062018-02-28 15:00:40 -08005128 final long identity = Binder.clearCallingIdentity();
5129 try {
5130 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005131 if (slots == null) {
5132 Rlog.i(LOG_TAG, "slots is null.");
5133 return null;
5134 }
5135
Malcolm Chenaabec062018-02-28 15:00:40 -08005136 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5137 for (int i = 0; i < slots.length; i++) {
5138 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005139 if (slot == null) {
5140 continue;
5141 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005142
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005143 String cardId;
5144 UiccCard card = slot.getUiccCard();
5145 if (card != null) {
5146 cardId = card.getCardId();
5147 } else {
5148 cardId = slot.getIccId();
5149 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005150
Malcolm Chenaabec062018-02-28 15:00:40 -08005151 int cardState = 0;
5152 switch (slot.getCardState()) {
5153 case CARDSTATE_ABSENT:
5154 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5155 break;
5156 case CARDSTATE_PRESENT:
5157 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5158 break;
5159 case CARDSTATE_ERROR:
5160 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5161 break;
5162 case CARDSTATE_RESTRICTED:
5163 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5164 break;
5165 default:
5166 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005167
Malcolm Chenaabec062018-02-28 15:00:40 -08005168 }
5169
5170 infos[i] = new UiccSlotInfo(
5171 slot.isActive(),
5172 slot.isEuicc(),
5173 cardId,
5174 cardState,
5175 slot.getPhoneId(),
5176 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005177 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005178 return infos;
5179 } finally {
5180 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005181 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005182 }
5183
5184 @Override
5185 public boolean switchSlots(int[] physicalSlots) {
5186 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005187
5188 final long identity = Binder.clearCallingIdentity();
5189 try {
5190 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005194 }
Jack Yu4c988042018-02-27 15:30:01 -08005195
5196 @Override
5197 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5198 enforceModifyPermission();
5199 final Phone phone = getPhone(subId);
5200 if (phone == null) {
5201 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5202 return;
5203 }
5204
Malcolm Chenaabec062018-02-28 15:00:40 -08005205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 phone.setRadioIndicationUpdateMode(filters, mode);
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
Jack Yu4c988042018-02-27 15:30:01 -08005211 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005212
5213 /**
goneil47ffb6e2018-04-06 15:40:58 -07005214 * A test API to reload the UICC profile.
5215 *
5216 * <p>Requires that the calling app has permission
5217 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5218 * @hide
5219 */
5220 @Override
5221 public void refreshUiccProfile(int subId) {
5222 enforceModifyPermission();
5223
5224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 Phone phone = getPhone(subId);
5227 if (phone == null) {
5228 return;
5229 }
5230 UiccCard uiccCard = phone.getUiccCard();
5231 if (uiccCard == null) {
5232 return;
5233 }
5234 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5235 if (uiccProfile == null) {
5236 return;
5237 }
5238 uiccProfile.refresh();
5239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241 }
5242 }
5243
5244 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005245 * Returns false if the mobile data is disabled by default, otherwise return true.
5246 */
5247 private boolean getDefaultDataEnabled() {
5248 return "true".equalsIgnoreCase(
5249 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5250 }
5251
5252 /**
5253 * Returns true if the data roaming is enabled by default, i.e the system property
5254 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5255 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5256 */
5257 private boolean getDefaultDataRoamingEnabled(int subId) {
5258 final CarrierConfigManager configMgr = (CarrierConfigManager)
5259 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5260 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5261 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5262 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5263 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5264 return isDataRoamingEnabled;
5265 }
5266
5267 /**
5268 * Returns the default network type for the given {@code subId}, if the default network type is
5269 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5270 */
5271 private int getDefaultNetworkType(int subId) {
5272 return Integer.parseInt(
5273 TelephonyManager.getTelephonyProperty(
5274 mSubscriptionController.getPhoneId(subId),
5275 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5276 String.valueOf(Phone.PREFERRED_NT_MODE)));
5277 }
fionaxua13278b2018-03-21 00:08:13 -07005278
5279 @Override
5280 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5281 gid1, String gid2, String plmn, String spn) {
5282 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005283
5284 final long identity = Binder.clearCallingIdentity();
5285 try {
5286 final Phone phone = getPhone(subId);
5287 if (phone == null) {
5288 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5289 return;
5290 }
5291 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5292 } finally {
5293 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005294 }
fionaxua13278b2018-03-21 00:08:13 -07005295 }
5296
5297 @Override
5298 public int getCarrierIdListVersion(int subId) {
5299 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005300
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 final Phone phone = getPhone(subId);
5304 if (phone == null) {
5305 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5306 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5307 }
5308 return phone.getCarrierIdListVersion();
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005311 }
fionaxua13278b2018-03-21 00:08:13 -07005312 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005313
5314 @Override
5315 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5317 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5318 return -1;
5319 }
5320
5321 final long identity = Binder.clearCallingIdentity();
5322 try {
5323 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5324 } finally {
5325 Binder.restoreCallingIdentity(identity);
5326 }
5327 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005328
5329 @Override
5330 public int getCdmaRoamingMode(int subId) {
5331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5332 mApp, subId, "getCdmaRoamingMode");
5333
5334 final long identity = Binder.clearCallingIdentity();
5335 try {
5336 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
5340 }
5341
5342 @Override
5343 public boolean setCdmaRoamingMode(int subId, int mode) {
5344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5345 mApp, subId, "setCdmaRoamingMode");
5346
5347 final long identity = Binder.clearCallingIdentity();
5348 try {
5349 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5350 } finally {
5351 Binder.restoreCallingIdentity(identity);
5352 }
5353 }
5354
5355 @Override
5356 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5358 mApp, subId, "setCdmaSubscriptionMode");
5359
5360 final long identity = Binder.clearCallingIdentity();
5361 try {
5362 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
5365 }
5366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005367}